Fix T58118: Make duplicates real does nothing
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 4 Dec 2018 15:04:10 +0000 (16:04 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 4 Dec 2018 15:04:10 +0000 (16:04 +0100)
The issue was caused by transflag set in geometry evaluation
never copied back top original object.

Now we have a dedicated operation which does all sort copy
back to original object, so we don't have to worry about
atomic assignments or what gets set where.

Still need to move boundbox to the same function, but it
needs some careful doublechecking first.

source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/object_update.c
source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
source/blender/depsgraph/intern/builder/deg_builder_relations.cc
source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc
source/blender/depsgraph/intern/depsgraph_type_defines.cc
source/blender/depsgraph/intern/depsgraph_types.h
source/blender/depsgraph/intern/nodes/deg_node_component.cc
source/blender/depsgraph/intern/nodes/deg_node_component.h

index 35de15014947dc843987c444e12a4da09d88c177..ff069bcbe794f961919a1eefec026925c5542062 100644 (file)
@@ -247,7 +247,10 @@ void BKE_object_eval_uber_data(
         struct Scene *scene,
         struct Object *ob);
 
-void BKE_object_eval_boundbox(struct Depsgraph *depsgraph, struct Object *object);
+void BKE_object_eval_boundbox(struct Depsgraph *depsgraph,
+                              struct Object *object);
+void BKE_object_synchronize_to_original(struct Depsgraph *depsgraph,
+                                        struct Object *object);
 
 void BKE_object_eval_ptcache_reset(
         struct Depsgraph *depsgraph,
index 2ac4c739e090a3816aa3c1e6cd8f4807fa0cf29d..b95f1c821e298d6cb03714e22c0aeaea0bcd747e 100644 (file)
@@ -142,14 +142,6 @@ void BKE_object_eval_transform_final(Depsgraph *depsgraph, Object *ob)
        /* Set negative scale flag in object. */
        if (is_negative_m4(ob->obmat)) ob->transflag |= OB_NEG_SCALE;
        else ob->transflag &= ~OB_NEG_SCALE;
-
-       if (DEG_is_active(depsgraph)) {
-               Object *ob_orig = DEG_get_original_object(ob);
-               copy_m4_m4(ob_orig->obmat, ob->obmat);
-               copy_m4_m4(ob_orig->constinv, ob->constinv);
-               ob_orig->transflag = ob->transflag;
-               ob_orig->flag = ob->flag;
-       }
 }
 
 void BKE_object_handle_data_update(
@@ -271,6 +263,8 @@ void BKE_object_handle_data_update(
        BKE_object_eval_boundbox(depsgraph, ob);
 }
 
+/* TODO(sergey): Ensure that bounding box is already calculated, and move this
+ * into BKE_object_synchronize_to_original(). */
 void BKE_object_eval_boundbox(Depsgraph *depsgraph, Object *object)
 {
        if (!DEG_is_active(depsgraph)) {
@@ -286,6 +280,21 @@ void BKE_object_eval_boundbox(Depsgraph *depsgraph, Object *object)
        }
 }
 
+void BKE_object_synchronize_to_original(Depsgraph *depsgraph, Object *object)
+{
+       if (!DEG_is_active(depsgraph)) {
+               return;
+       }
+       Object *object_orig = DEG_get_original_object(object);
+       /* Base flags. */
+       object_orig->base_flag = object->base_flag;
+       /* Transformation flags. */
+       copy_m4_m4(object_orig->obmat, object->obmat);
+       copy_m4_m4(object_orig->constinv, object->constinv);
+       object_orig->transflag = object->transflag;
+       object_orig->flag = object->flag;
+}
+
 bool BKE_object_eval_proxy_copy(Depsgraph *depsgraph,
                                 Object *object)
 {
@@ -430,12 +439,6 @@ void BKE_object_eval_flush_base_flags(Depsgraph *depsgraph,
        }
        object->base_local_view_bits = base->local_view_bits;
 
-       /* Copy to original object datablock if needed. */
-       if (DEG_is_active(depsgraph)) {
-               Object *object_orig = DEG_get_original_object(object);
-               object_orig->base_flag = object->base_flag;
-       }
-
        if (object->mode == OB_MODE_PARTICLE_EDIT) {
                for (ParticleSystem *psys = object->particlesystem.first;
                     psys != NULL;
index 8726f51012ed41a560c7345c2626197ace5f6d1c..d1837e7a69add1d77cc2361725c9b0595a5bf4a2 100644 (file)
@@ -579,6 +579,7 @@ void DepsgraphNodeBuilder::build_object(int base_index,
        }
        /* Create ID node for object and begin init. */
        IDDepsNode *id_node = add_id_node(&object->id);
+       Object *object_cow = get_cow_datablock(object);
        id_node->linked_state = linked_state;
        if (object == scene_->camera) {
                id_node->is_directly_visible = true;
@@ -663,6 +664,13 @@ void DepsgraphNodeBuilder::build_object(int base_index,
                                   DEG_OPCODE_PLACEHOLDER,
                                   "Dupli");
        }
+       /* Syncronization back to original object. */
+       add_operation_node(&object->id,
+                          DEG_NODE_TYPE_SYNCHRONIZE,
+                          function_bind(BKE_object_synchronize_to_original,
+                                        _1,
+                                        object_cow),
+                          DEG_OPCODE_SYNCHRONIZE_TO_ORIGINAL);
 }
 
 void DepsgraphNodeBuilder::build_object_flags(
index 649bc1a427536c0e3f98d93253c892d52fba1d57..23f1d229d6adeee449102744a9479e0c139d2d93 100644 (file)
@@ -683,6 +683,12 @@ void DepsgraphRelationBuilder::build_object(Base *base, Object *object)
        }
        /* Point caches. */
        build_object_pointcache(object);
+       /* Syncronization back to original object. */
+       OperationKey synchronize_key(&object->id,
+                                    DEG_NODE_TYPE_SYNCHRONIZE,
+                                    DEG_OPCODE_SYNCHRONIZE_TO_ORIGINAL);
+       add_relation(
+               final_transform_key, synchronize_key, "Synchronize to Original");
 }
 
 void DepsgraphRelationBuilder::build_object_flags(Base *base, Object *object)
@@ -697,6 +703,12 @@ void DepsgraphRelationBuilder::build_object_flags(Base *base, Object *object)
                                      DEG_NODE_TYPE_OBJECT_FROM_LAYER,
                                      DEG_OPCODE_OBJECT_BASE_FLAGS);
        add_relation(view_layer_done_key, object_flags_key, "Base flags flush");
+       /* Syncronization back to original object. */
+       OperationKey synchronize_key(&object->id,
+                                    DEG_NODE_TYPE_SYNCHRONIZE,
+                                    DEG_OPCODE_SYNCHRONIZE_TO_ORIGINAL);
+       add_relation(
+               object_flags_key, synchronize_key, "Synchronize to Original");
 }
 
 void DepsgraphRelationBuilder::build_object_data(Object *object)
@@ -2023,6 +2035,13 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object)
                        }
                }
        }
+       /* Syncronization back to original object. */
+       ComponentKey final_geometry_jey(&object->id, DEG_NODE_TYPE_GEOMETRY);
+       OperationKey synchronize_key(&object->id,
+                                    DEG_NODE_TYPE_SYNCHRONIZE,
+                                    DEG_OPCODE_SYNCHRONIZE_TO_ORIGINAL);
+       add_relation(
+               final_geometry_jey, synchronize_key, "Synchronize to Original");
 }
 
 void DepsgraphRelationBuilder::build_object_data_geometry_datablock(ID *obdata)
index ec1ea1e02b2bcc2a8c2b2becfa56196113c68fd6..55eaf314a0a74becbb59902b31be034021e17ce8 100644 (file)
@@ -421,6 +421,7 @@ static void deg_debug_graphviz_node(const DebugContext &ctx,
                case DEG_NODE_TYPE_OBJECT_FROM_LAYER:
                case DEG_NODE_TYPE_BATCH_CACHE:
                case DEG_NODE_TYPE_DUPLI:
+               case DEG_NODE_TYPE_SYNCHRONIZE:
                {
                        ComponentDepsNode *comp_node = (ComponentDepsNode *)node;
                        if (!comp_node->operations.empty()) {
index 3f36b9f7831c42cf4dd7c57645cdcc8405837239..d93882a71704390ac24c3a628413d1913089ded2 100644 (file)
@@ -104,6 +104,8 @@ const char *nodeTypeAsString(eDepsNode_Type type)
                STRINGIFY_TYPE(BATCH_CACHE);
                /* Duplication. */
                STRINGIFY_TYPE(DUPLI);
+               /* Synchronization. */
+               STRINGIFY_TYPE(SYNCHRONIZE);
 
                /* Total number of meaningful node types. */
                case NUM_DEG_NODE_TYPES: return "SpecialCase";
@@ -180,6 +182,8 @@ const char *operationCodeAsString(eDepsOperation_Code opcode)
                /* Movie clip. */
                STRINGIFY_OPCODE(MOVIECLIP_EVAL);
                STRINGIFY_OPCODE(MOVIECLIP_SELECT_UPDATE);
+               /* Synchronization. */
+               STRINGIFY_OPCODE(SYNCHRONIZE_TO_ORIGINAL);
 
                case DEG_NUM_OPCODES: return "SpecialCase";
 #undef STRINGIFY_OPCODE
index f8b519cb1aa9805b835b84c73c3d49ea95f93186..61a91c139137a80294dca3fa6069b61562f630e9 100644 (file)
@@ -157,11 +157,12 @@ typedef enum eDepsNode_Type {
        DEG_NODE_TYPE_CACHE,
        /* Batch Cache Component - TODO (dfelinto/sergey) rename to make it more generic. */
        DEG_NODE_TYPE_BATCH_CACHE,
-
        /* Duplication system. Used to force duplicated objects visible when
         * when duplicator is visible.
         */
        DEG_NODE_TYPE_DUPLI,
+       /* Synchronization back to original datablock. */
+       DEG_NODE_TYPE_SYNCHRONIZE,
 
        /* Total number of meaningful node types. */
        NUM_DEG_NODE_TYPES,
@@ -170,7 +171,7 @@ const char *nodeTypeAsString(eDepsNode_Type type);
 
 /* Identifiers for common operations (as an enum). */
 typedef enum eDepsOperation_Code {
-       /* Generic Operations. ------------------------------ */
+       /* Generic Operations. -------------------------------------------------- */
 
        /* Placeholder for operations which don't need special mention */
        DEG_OPCODE_OPERATION = 0,
@@ -182,16 +183,16 @@ typedef enum eDepsOperation_Code {
        // XXX: Placeholder while porting depsgraph code
        DEG_OPCODE_PLACEHOLDER,
 
-       /* Animation, Drivers, etc. ------------------------ */
+       /* Animation, Drivers, etc. --------------------------------------------- */
        /* NLA + Action */
        DEG_OPCODE_ANIMATION,
        /* Driver */
        DEG_OPCODE_DRIVER,
 
-       /* Object related. --------------------------------- */
+       /* Object related. ------------------------------------------------------ */
        DEG_OPCODE_OBJECT_BASE_FLAGS,
 
-       /* Transform. -------------------------------------- */
+       /* Transform. ----------------------------------------------------------- */
        /* Transform entry point - local transforms only */
        DEG_OPCODE_TRANSFORM_LOCAL,
        /* Parenting */
@@ -203,25 +204,25 @@ typedef enum eDepsOperation_Code {
        /* Handle object-level updates, mainly proxies hacks and recalc flags.  */
        DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL,
 
-       /* Rigid body. -------------------------------------- */
+       /* Rigid body. ---------------------------------------------------------- */
        /* Perform Simulation */
        DEG_OPCODE_RIGIDBODY_REBUILD,
        DEG_OPCODE_RIGIDBODY_SIM,
        /* Copy results to object */
        DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY,
 
-       /* Geometry. ---------------------------------------- */
+       /* Geometry. ------------------------------------------------------------ */
 
        /* Evaluate the whole geometry, including modifiers. */
        DEG_OPCODE_GEOMETRY_UBEREVAL,
        /* Evaluation of a shape key. */
        DEG_OPCODE_GEOMETRY_SHAPEKEY,
 
-       /* Object data. ------------------------------------- */
+       /* Object data. --------------------------------------------------------- */
        DEG_OPCODE_LIGHT_PROBE_EVAL,
        DEG_OPCODE_SPEAKER_EVAL,
 
-       /* Pose. -------------------------------------------- */
+       /* Pose. ---------------------------------------------------------------- */
        /* Init pose, clear flags, etc. */
        DEG_OPCODE_POSE_INIT,
        /* Initialize IK solver related pose stuff. */
@@ -234,7 +235,7 @@ typedef enum eDepsOperation_Code {
        DEG_OPCODE_POSE_IK_SOLVER,
        DEG_OPCODE_POSE_SPLINE_IK_SOLVER,
 
-       /* Bone. -------------------------------------------- */
+       /* Bone. ---------------------------------------------------------------- */
        /* Bone local transforms - entry point */
        DEG_OPCODE_BONE_LOCAL,
        /* Pose-space conversion (includes parent + restpose, */
@@ -257,37 +258,40 @@ typedef enum eDepsOperation_Code {
        /* B-Bone segment shape computation (after DONE) */
        DEG_OPCODE_BONE_SEGMENTS,
 
-       /* Particles. --------------------------------------- */
+       /* Particles. ----------------------------------------------------------- */
        /* Particle System evaluation. */
        DEG_OPCODE_PARTICLE_SYSTEM_EVAL_INIT,
        DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
        DEG_OPCODE_PARTICLE_SETTINGS_EVAL,
 
-       /* Point Cache. ------------------------------------- */
+       /* Point Cache. --------------------------------------------------------- */
        DEG_OPCODE_POINT_CACHE_RESET,
 
-       /* Collections. ------------------------------------- */
+       /* Collections. --------------------------------------------------------- */
        DEG_OPCODE_VIEW_LAYER_EVAL,
 
-       /* Copy on Write. ------------------------------------ */
+       /* Copy on Write. ------------------------------------------------------- */
        DEG_OPCODE_COPY_ON_WRITE,
 
-       /* Shading. ------------------------------------------- */
+       /* Shading. ------------------------------------------------------------- */
        DEG_OPCODE_SHADING,
        DEG_OPCODE_MATERIAL_UPDATE,
        DEG_OPCODE_WORLD_UPDATE,
 
-       /* Batch caches. -------------------------------------- */
+       /* Batch caches. -------------------------------------------------------- */
        DEG_OPCODE_GEOMETRY_SELECT_UPDATE,
 
-       /* Masks. ------------------------------------------ */
+       /* Masks. --------------------------------------------------------------- */
        DEG_OPCODE_MASK_ANIMATION,
        DEG_OPCODE_MASK_EVAL,
 
-       /* Movie clips. ------------------------------------ */
+       /* Movie clips. --------------------------------------------------------- */
        DEG_OPCODE_MOVIECLIP_EVAL,
        DEG_OPCODE_MOVIECLIP_SELECT_UPDATE,
 
+       /* Synchronization clips. ----------------------------------------------- */
+       DEG_OPCODE_SYNCHRONIZE_TO_ORIGINAL,
+
        DEG_NUM_OPCODES,
 } eDepsOperation_Code;
 const char *operationCodeAsString(eDepsOperation_Code opcode);
index 4bb9b9d17b3c754e7af5b21e728a1f32a2833cd5..c1c5899db37ec32038a11473675d407dd1791c4c 100644 (file)
@@ -401,6 +401,7 @@ DEG_COMPONENT_NODE_DEFINE(ShadingParameters, SHADING_PARAMETERS, ID_RECALC_DRAW)
 DEG_COMPONENT_NODE_DEFINE(Transform,         TRANSFORM,          ID_RECALC_TRANSFORM);
 DEG_COMPONENT_NODE_DEFINE(ObjectFromLayer,   OBJECT_FROM_LAYER,  ID_RECALC);
 DEG_COMPONENT_NODE_DEFINE(Dupli,             DUPLI,              0);
+DEG_COMPONENT_NODE_DEFINE(Synchronize,       SYNCHRONIZE,        0);
 
 /* Node Types Register =================================== */
 
@@ -424,6 +425,7 @@ void deg_register_component_depsnodes()
        deg_register_node_typeinfo(&DNTI_TRANSFORM);
        deg_register_node_typeinfo(&DNTI_OBJECT_FROM_LAYER);
        deg_register_node_typeinfo(&DNTI_DUPLI);
+       deg_register_node_typeinfo(&DNTI_SYNCHRONIZE);
 }
 
 }  // namespace DEG
index e3057e1d3cefd0377db0e5fc4bbefdbf4fe6b32a..f1ad320895210479c41be1bebbac79e7281e91b9 100644 (file)
@@ -200,6 +200,7 @@ DEG_COMPONENT_NODE_DECLARE_GENERIC(ShadingParameters);
 DEG_COMPONENT_NODE_DECLARE_GENERIC(Transform);
 DEG_COMPONENT_NODE_DECLARE_NO_COW_TAG_ON_UPDATE(ObjectFromLayer);
 DEG_COMPONENT_NODE_DECLARE_GENERIC(Dupli);
+DEG_COMPONENT_NODE_DECLARE_GENERIC(Synchronize);
 
 /* Bone Component */
 struct BoneComponentDepsNode : public ComponentDepsNode {