Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2022-07-05 13:49:53 +0300
committerBastien Montagne <bastien@blender.org>2022-07-05 13:52:21 +0300
commit7f24d90f11a6d26b2737bf28df1c66d169e7e8c2 (patch)
tree8331559a9b302e08ad86bd3608d365a798869a9a /source/blender/makesrna/intern/rna_mesh.c
parentce1d023667c8d3ca565a67f8205e532b9aaad848 (diff)
Fix T99272: Regression: location override ignored when used in a shadertree.
This is not strictly speaking a regression, this worked before partial resync was introduced purely because the whole override hierarchy was systematically re-built. But support for material pointers in obdata (meshes etc.) was simply not implemented. NOTE: This commit also greatly improves general support of materials in liboverrides, although there is still more work needed in that area to consider it properly supported.
Diffstat (limited to 'source/blender/makesrna/intern/rna_mesh.c')
-rw-r--r--source/blender/makesrna/intern/rna_mesh.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c
index 015b6d4055b..65468977ccb 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -1723,6 +1723,56 @@ static void UNUSED_FUNCTION(rna_mesh_unused)(void)
/* end unused function block */
}
+static bool rna_Mesh_materials_override_apply(Main *bmain,
+ PointerRNA *ptr_dst,
+ PointerRNA *UNUSED(ptr_src),
+ PointerRNA *UNUSED(ptr_storage),
+ PropertyRNA *prop_dst,
+ PropertyRNA *UNUSED(prop_src),
+ PropertyRNA *UNUSED(prop_storage),
+ const int UNUSED(len_dst),
+ const int UNUSED(len_src),
+ const int UNUSED(len_storage),
+ PointerRNA *ptr_item_dst,
+ PointerRNA *ptr_item_src,
+ PointerRNA *UNUSED(ptr_item_storage),
+ IDOverrideLibraryPropertyOperation *opop)
+{
+ BLI_assert_msg(opop->operation == IDOVERRIDE_LIBRARY_OP_REPLACE,
+ "Unsupported RNA override operation on collections' objects");
+ UNUSED_VARS_NDEBUG(opop);
+
+ Mesh *mesh_dst = (Mesh *)ptr_dst->owner_id;
+
+ if (ptr_item_dst->type == NULL || ptr_item_src->type == NULL) {
+ // BLI_assert_msg(0, "invalid source or destination material.");
+ return false;
+ }
+
+ Material *mat_dst = ptr_item_dst->data;
+ Material *mat_src = ptr_item_src->data;
+
+ if (mat_src == mat_dst) {
+ return true;
+ }
+
+ bool is_modified = false;
+ for (int i = 0; i < mesh_dst->totcol; i++) {
+ if (mesh_dst->mat[i] == mat_dst) {
+ id_us_min(&mat_dst->id);
+ mesh_dst->mat[i] = mat_src;
+ id_us_plus(&mat_src->id);
+ is_modified = true;
+ }
+ }
+
+ if (is_modified) {
+ RNA_property_update_main(bmain, NULL, ptr_dst, prop_dst);
+ }
+
+ return true;
+}
+
/** \} */
#else
@@ -2478,6 +2528,8 @@ void rna_def_texmat_common(StructRNA *srna, const char *texspace_editable)
RNA_def_property_struct_type(prop, "Material");
RNA_def_property_ui_text(prop, "Materials", "");
RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */
+ RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
+ RNA_def_property_override_funcs(prop, NULL, NULL, "rna_Mesh_materials_override_apply");
RNA_def_property_collection_funcs(
prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "rna_IDMaterials_assign_int");
}