diff --git a/source/blender/blenkernel/intern/context.cc b/source/blender/blenkernel/intern/context.cc index 0362368c2ab..ed76e258d9e 100644 --- a/source/blender/blenkernel/intern/context.cc +++ b/source/blender/blenkernel/intern/context.cc @@ -1514,8 +1514,20 @@ AssetHandle CTX_wm_asset_handle(const bContext *C, bool *r_is_valid) blender::asset_system::AssetRepresentation *CTX_wm_asset(const bContext *C) { - return static_cast( - ctx_data_pointer_get(C, "asset")); + if (auto *asset = static_cast( + ctx_data_pointer_get(C, "asset"))) + { + return asset; + } + + /* Expose the asset representation from the asset-handle. + * TODO(Julian): #AssetHandle should be properly replaced by #AssetRepresentation. */ + bool is_valid; + if (AssetHandle handle = CTX_wm_asset_handle(C, &is_valid); is_valid) { + return handle.file_data->asset; + } + + return nullptr; } Depsgraph *CTX_data_depsgraph_pointer(const bContext *C) diff --git a/source/blender/makesrna/intern/rna_context.cc b/source/blender/makesrna/intern/rna_context.cc index 4dc1339cba7..d405978e0c7 100644 --- a/source/blender/makesrna/intern/rna_context.cc +++ b/source/blender/makesrna/intern/rna_context.cc @@ -125,6 +125,12 @@ static PointerRNA rna_Context_gizmo_group_get(PointerRNA *ptr) return newptr; } +static PointerRNA rna_Context_asset_get(PointerRNA *ptr) +{ + bContext *C = (bContext *)ptr->data; + return RNA_pointer_create(nullptr, &RNA_AssetRepresentation, CTX_wm_asset(C)); +} + static PointerRNA rna_Context_asset_file_handle_get(PointerRNA *ptr) { bContext *C = (bContext *)ptr->data; @@ -290,6 +296,11 @@ void RNA_def_context(BlenderRNA *brna) RNA_def_property_struct_type(prop, "GizmoGroup"); RNA_def_property_pointer_funcs(prop, "rna_Context_gizmo_group_get", nullptr, nullptr, nullptr); + prop = RNA_def_property(srna, "asset", PROP_POINTER, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_struct_type(prop, "AssetRepresentation"); + RNA_def_property_pointer_funcs(prop, "rna_Context_asset_get", nullptr, nullptr, nullptr); + /* TODO can't expose AssetHandle, since there is no permanent storage to it (so we can't * return a pointer). Instead provide the FileDirEntry pointer it wraps. */ prop = RNA_def_property(srna, "asset_file_handle", PROP_POINTER, PROP_NONE);