Commit: 2fd55e1443c7e0dea32701608f755bec310f748e
Author: Bastien Montagne
Date:   Mon Jan 2 22:08:50 2017 +0100
Branches: id_override_static
https://developer.blender.org/rB2fd55e1443c7e0dea32701608f755bec310f748e

Add first basic working auto-override.

Still called from pre-depsgraph eval step, does an RNA comparison and
generate overriding rules for changed props...

Note: we most certainly do not want to run this on all depsgraph eval.
Own current idea would be to just tag IDs e.g. in depsgraph callback,
and run actual auto-generation e.g. in a low-priority job, maybe? not
sure... :|

Also, fix stupid mistake in RNA applying of override (used when reading
file to apply static override), and add object's loc/rot/scale as
overridable properties.

===================================================================

M       source/blender/blenkernel/intern/library_override.c
M       source/blender/editors/object/object_relations.c
M       source/blender/makesrna/RNA_access.h
M       source/blender/makesrna/intern/rna_access.c
M       source/blender/makesrna/intern/rna_object.c

===================================================================

diff --git a/source/blender/blenkernel/intern/library_override.c 
b/source/blender/blenkernel/intern/library_override.c
index fed8b3f..0ce436f 100644
--- a/source/blender/blenkernel/intern/library_override.c
+++ b/source/blender/blenkernel/intern/library_override.c
@@ -178,7 +178,16 @@ bool BKE_override_operations_create(ID *local)
 {
        BLI_assert(local->override != NULL);
        if (local->flag & LIB_AUTOOVERRIDE) {
-               printf("Should generate static override rules for %s\n", 
local->name);
+               PointerRNA rnaptr_local, rnaptr_reference;
+               RNA_id_pointer_create(local, &rnaptr_local);
+               RNA_id_pointer_create(local->override->reference, 
&rnaptr_reference);
+
+               if (RNA_struct_auto_override(&rnaptr_local, &rnaptr_reference, 
local->override)) {
+                       printf("We did generate static override rules for 
%s\n", local->name);
+               }
+               else {
+                       printf("No new static override rules for %s\n", 
local->name);
+               }
        }
        return false;
 }
diff --git a/source/blender/editors/object/object_relations.c 
b/source/blender/editors/object/object_relations.c
index 070ef49..2082731 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -2366,15 +2366,15 @@ static int make_override_exec(bContext *C, wmOperator 
*UNUSED(op))
        /* Note that we most likely want to do this in a more BKE generic 
function later, but for now will do for testing. */
 
        id_copy(bmain, &refobj->id, (ID **)&locobj, false);
-       locobj->id.flag |= LIB_AUTOOVERRIDE;
 
        /* Remapping *before* defining override (this will have to be fixed 
btw, remapping of ref pointer...). */
        BKE_libblock_remap(bmain, refobj, locobj, ID_REMAP_SKIP_INDIRECT_USAGE);
 
        IDOverride *override = BKE_override_init(&locobj->id, &refobj->id);
+       locobj->id.flag |= LIB_AUTOOVERRIDE;
 
        /* For testing only of course! This will have to be 
auto-generated/editable by user... */
-       {
+       if (0) {
                IDOverrideProperty *overp = 
MEM_callocN(sizeof(IDOverrideProperty), __func__);
                overp->rna_path = BLI_strdup("location");
 
diff --git a/source/blender/makesrna/RNA_access.h 
b/source/blender/makesrna/RNA_access.h
index 8d0b667..9aa07ab 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -1225,6 +1225,8 @@ void RNA_property_override_apply(struct PointerRNA *dst,
         struct PointerRNA *src, struct PropertyRNA *prop, struct 
IDOverrideProperty *op);
 void RNA_struct_override_apply(struct PointerRNA *dst, struct PointerRNA *src, 
struct IDOverride *override);
 
+bool RNA_struct_auto_override(struct PointerRNA *local, struct PointerRNA 
*reference, struct IDOverride *override);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/makesrna/intern/rna_access.c 
b/source/blender/makesrna/intern/rna_access.c
index 5c6882c..61040f4 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -6826,7 +6826,7 @@ bool RNA_property_copy(PointerRNA *ptr, PointerRNA 
*fromptr, PropertyRNA *prop,
                                        
                                        RNA_property_float_get_array(fromptr, 
fromprop, tmparray);
                                        RNA_property_float_set_array(ptr, prop, 
tmparray);
-                                       
+
                                        MEM_freeN(tmparray);
                                }
                                else {
@@ -7158,11 +7158,91 @@ void RNA_struct_override_apply(PointerRNA *dst, 
PointerRNA *src, IDOverride *ove
                {
                        BLI_assert(src_prop == dst_prop);
 
-                       RNA_property_override_apply(&src_data, &dst_data, 
src_prop, op);
+                       RNA_property_override_apply(&dst_data, &src_data, 
src_prop, op);
                }
        }
 }
 
+/** Automatically define override rules by comparing \a local and \a reference 
RNA structs. */
+bool RNA_struct_auto_override(PointerRNA *local, PointerRNA *reference, 
IDOverride *override)
+{
+       CollectionPropertyIterator iter;
+       PropertyRNA *iterprop;
+       bool changed = false;
+
+       BLI_assert(local->type == reference->type);
+       BLI_assert(local->id.data && reference->id.data);
+
+       if ((((ID *)local->id.data)->flag & LIB_AUTOOVERRIDE) == 0) {
+               return changed;
+       }
+
+       iterprop = RNA_struct_iterator_property(local->type);
+
+       for (RNA_property_collection_begin(local, iterprop, &iter); iter.valid; 
RNA_property_collection_next(&iter)) {
+               PropertyRNA *prop = iter.ptr.data;
+               IDOverrideProperty *op = NULL;
+
+               if (!(prop->flag & PROP_OVERRIDABLE)) {
+                       continue;
+               }
+
+               /* XXX TODO this will have to be refined to handle collections 
insertions, and array items */
+               char *rna_path = RNA_path_from_ID_to_property(local, prop);
+               if (rna_path == NULL) {
+                       continue;
+               }
+
+               if (STREQ(prop->identifier, "location")) {
+                       printf("loc: %d\n", rna_property_equals(local, 
reference, prop, RNA_EQ_STRICT, override, NULL, true, true));
+               }
+               if (!rna_property_equals(local, reference, prop, RNA_EQ_STRICT, 
override, NULL, true, true)) {
+                       switch (RNA_property_type(prop)) {
+                               case PROP_POINTER:
+                               {
+                                       PointerRNA sub_local, sub_reference;
+                                       sub_local = 
RNA_property_pointer_get(local, prop);
+                                       sub_reference = 
RNA_property_pointer_get(reference, prop);
+                                       changed = changed || 
RNA_struct_auto_override(&sub_local, &sub_reference, override);
+                                       break;
+                               }
+                               case PROP_COLLECTION:
+                                       /* TODO... of course... */
+                                       break;
+                               default:
+                               {
+                                       /* All other types. */
+                                       /* TODO: handle arrays! */
+                                       op = 
BKE_override_property_find(override, rna_path);
+
+                                       if (op != NULL) {
+                                               /* Already overriden prop, 
later we'll have to check arrays items and such,
+                                                * for now assume we have 
nothing to do. */
+                                               break;
+                                       }
+
+                                       op = 
MEM_callocN(sizeof(IDOverrideProperty), __func__);
+                                       op->rna_path = BLI_strdup(rna_path);
+
+                                       IDOverridePropertyOperation *opop = 
MEM_callocN(sizeof(IDOverridePropertyOperation), __func__);
+                                       opop->subitem_local_index = 
opop->subitem_reference_index = -1;
+                                       opop->operation = IDOVERRIDE_REPLACE;
+
+                                       BLI_addtail(&op->operations, opop);
+                                       BLI_addtail(&override->properties, op);
+
+                                       changed = true;
+                                       break;
+                               }
+                       }
+               }
+
+               MEM_SAFE_FREE(rna_path);
+       }
+       RNA_property_collection_end(&iter);
+
+       return changed;
+}
 
 bool RNA_path_resolved_create(
         PointerRNA *ptr, struct PropertyRNA *prop,
diff --git a/source/blender/makesrna/intern/rna_object.c 
b/source/blender/makesrna/intern/rna_object.c
index 0cffba4..28714c8 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -2341,6 +2341,7 @@ static void rna_def_object(BlenderRNA *brna)
        prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
        RNA_def_property_float_sdna(prop, NULL, "loc");
        RNA_def_property_editable_array_func(prop, 
"rna_Object_location_editable");
+       RNA_def_property_flag(prop, PROP_OVERRIDABLE);
        RNA_def_property_ui_text(prop, "Location", "Location of the object");
        RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 
RNA_TRANSLATION_PREC_DEFAULT);
        RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, 
"rna_Object_internal_update");
@@ -2348,6 +2349,7 @@ static void rna_def_object(BlenderRNA *brna)
        prop = RNA_def_property(srna, "rotation_quaternion", PROP_FLOAT, 
PROP_QUATERNION);
        RNA_def_property_float_sdna(prop, NULL, "quat");
        RNA_def_property_editable_array_func(prop, 
"rna_Object_rotation_4d_editable");
+       RNA_def_property_flag(prop, PROP_OVERRIDABLE);
        RNA_def_property_float_array_default(prop, default_quat);
        RNA_def_property_ui_text(prop, "Quaternion Rotation", "Rotation in 
Quaternions");
        RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, 
"rna_Object_internal_update");
@@ -2361,12 +2363,14 @@ static void rna_def_object(BlenderRNA *brna)
                                     "rna_Object_rotation_axis_angle_set", 
NULL);
        RNA_def_property_editable_array_func(prop, 
"rna_Object_rotation_4d_editable");
        RNA_def_property_float_array_default(prop, default_axisAngle);
+       RNA_def_property_flag(prop, PROP_OVERRIDABLE);
        RNA_def_property_ui_text(prop, "Axis-Angle Rotation", "Angle of 
Rotation for Axis-Angle rotation representation");
        RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, 
"rna_Object_internal_update");
        
        prop = RNA_def_property(srna, "rotation_euler", PROP_FLOAT, PROP_EULER);
        RNA_def_property_float_sdna(prop, NULL, "rot");
        RNA_def_property_editable_array_func(prop, 
"rna_Object_rotation_euler_editable");
+       RNA_def_property_flag(prop, PROP_OVERRIDABLE);
        RNA_def_property_ui_text(prop, "Euler Rotation", "Rotation in Eulers");
        RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, 
"rna_Object_internal_update");
        
@@ -2379,7 +2383,7 @@ static void rna_def_object(BlenderRNA *brna)
        
        prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ);
        RNA_def_property_float_sdna(prop, NULL, "size");
-       RNA_def_property_flag(prop, PROP_PROPORTIONAL);
+       RNA_def_property_flag(prop, PROP_PROPORTIONAL | PROP_OVERRIDABLE);
        RNA_def_property_editable_array_func(prop, "rna_Object_scale_editable");
        RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 3);
        RNA_def_property_float_array_default(prop, default_scale);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to