Fix #27654: vertex parenting not working with constructive modifiers.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 15 Jun 2011 09:45:26 +0000 (09:45 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 15 Jun 2011 09:45:26 +0000 (09:45 +0000)
Vertex parents were not requesting the original index layer, now do this as
part of depsgraph building, and make constraints with vertex groups use the
same system. Fix is based on patch by Campbell, but with some changes.

source/blender/blenkernel/depsgraph_private.h
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/depsgraph.c
source/blender/blenkernel/intern/object.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_object_types.h

index 1fed115893cdbd74e75fa9e7cb64025dd0eee6e2..ef4f320602b1d7f071d0c83bd0c1c7acd696aed9 100644 (file)
@@ -69,8 +69,9 @@ typedef struct DagNode
        void * ob;
        void * first_ancestor;
        int ancestor_count;
-       unsigned int lay;                       // accumulated layers of its relations + itself
+       unsigned int lay;                               // accumulated layers of its relations + itself
        unsigned int scelay;                    // layers due to being in scene
+       unsigned int customdata_mask;   // customdata mask
        int lasttime;           // if lasttime != DagForest->time, this node was not evaluated yet for flushing
        int BFS_dist;           // BFS distance
        int DFS_dist;           // DFS distance
index d3c14a9dd12c57f3f836b4f9e94578ae98a5709d..18c9ab7dc90be75ee25725040db4d41afad03953 100644 (file)
@@ -449,16 +449,9 @@ static void contarget_get_mesh_mat (Scene *scene, Object *ob, const char *substr
                freeDM= 1;
        }
        else {
-               /* when not in EditMode, use the 'final' derived mesh 
-                *      - check if the custom data masks for derivedFinal mean that we can just use that
-                *        (this is more effficient + sufficient for most cases)
-                */
-               if (!(ob->lastDataMask & CD_MASK_MDEFORMVERT)) {
-                       dm = mesh_get_derived_final(scene, ob, CD_MASK_MDEFORMVERT);
-                       freeDM= 1;
-               }
-               else 
-                       dm = (DerivedMesh *)ob->derivedFinal;
+               /* when not in EditMode, use the 'final' derived mesh, depsgraph
+                * ensures we build with CD_MDEFORMVERT layer */
+               dm = (DerivedMesh *)ob->derivedFinal;
        }
        
        /* only continue if there's a valid DerivedMesh */
index 472d7d77b80fd654bf882e56387822d3d643d135..c2800410657a83a602c6309cf34a502321f33e11 100644 (file)
@@ -372,6 +372,9 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O
                node2->first_ancestor = ob;
                node2->ancestor_count += 1;
        }
+
+       /* also build a custom data mask for dependencies that need certain layers */
+       node->customdata_mask= 0;
        
        if (ob->type == OB_ARMATURE) {
                if (ob->pose){
@@ -451,8 +454,12 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O
                        case PARSKEL:
                                dag_add_relation(dag,node2,node,DAG_RL_DATA_DATA|DAG_RL_OB_OB, "Parent");
                                break;
-                       case PARVERT1: case PARVERT3: case PARBONE:
+                       case PARVERT1: case PARVERT3:
                                dag_add_relation(dag,node2,node,DAG_RL_DATA_OB|DAG_RL_OB_OB, "Vertex Parent");
+                               node2->customdata_mask |= CD_MASK_ORIGINDEX;
+                               break;
+                       case PARBONE:
+                               dag_add_relation(dag,node2,node,DAG_RL_DATA_OB|DAG_RL_OB_OB, "Bone Parent");
                                break;
                        default:
                                if(ob->parent->type==OB_LATTICE) 
@@ -647,8 +654,11 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O
                                if (ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH, CONSTRAINT_TYPE_CLAMPTO))
                                        dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, cti->name);
                                else {
-                                       if (ELEM3(obt->type, OB_ARMATURE, OB_MESH, OB_LATTICE) && (ct->subtarget[0]))
+                                       if (ELEM3(obt->type, OB_ARMATURE, OB_MESH, OB_LATTICE) && (ct->subtarget[0])) {
                                                dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, cti->name);
+                                               if (obt->type == OB_MESH)
+                                                       node2->customdata_mask |= CD_MASK_MDEFORMVERT;
+                                       }
                                        else
                                                dag_add_relation(dag, node2, node, DAG_RL_OB_OB, cti->name);
                                }
@@ -722,6 +732,9 @@ struct DagForest *build_dag(Main *bmain, Scene *sce, short mask)
                                        itA->node->color |= itA->type;
                                }
                        }
+
+                       /* also flush custom data mask */
+                       ((Object*)node->ob)->customdata_mask= node->customdata_mask;
                }
        }
        /* now set relations equal, so that when only one parent changes, the correct recalcs are found */
index 16fa16054674ead7fd31cd523b752747695b0499..dff62b05bd35fc0a6763f17448dea71772456f19 100644 (file)
@@ -2641,11 +2641,12 @@ void object_handle_update(Scene *scene, Object *ob)
 
 #else                          /* ensure CD_MASK_BAREMESH for now */
                                        EditMesh *em = (ob == scene->obedit)? BKE_mesh_get_editmesh(ob->data): NULL;
+                                       unsigned int data_mask= scene->customdata_mask | ob->customdata_mask | CD_MASK_BAREMESH;
                                        if(em) {
-                                               makeDerivedMesh(scene, ob, em,  scene->customdata_mask | CD_MASK_BAREMESH); /* was CD_MASK_BAREMESH */
+                                               makeDerivedMesh(scene, ob, em,  data_mask); /* was CD_MASK_BAREMESH */
                                                BKE_mesh_end_editmesh(ob->data, em);
                                        } else
-                                               makeDerivedMesh(scene, ob, NULL, scene->customdata_mask | CD_MASK_BAREMESH);
+                                               makeDerivedMesh(scene, ob, NULL, data_mask);
 #endif
 
                                }
index 1e604c45772fa884eccbf7a63ddf54363133e2ef..222c4bcf6fc0a3f29d03d163db8b0f5abe93fa5b 100644 (file)
@@ -4321,6 +4321,7 @@ static void direct_link_object(FileData *fd, Object *ob)
                MEM_freeN(hook);
        }
        
+       ob->customdata_mask= 0;
        ob->bb= NULL;
        ob->derivedDeform= NULL;
        ob->derivedFinal= NULL;
index 54a885a08605525fa2e21a94586422a6545ba703..f4488c140a0298206a4bda3122d81f9379905fb7 100644 (file)
@@ -250,12 +250,11 @@ typedef struct Object {
        struct FluidsimSettings *fluidsimSettings; /* if fluidsim enabled, store additional settings */
 
        struct DerivedMesh *derivedDeform, *derivedFinal;
-       int lastDataMask;                       /* the custom data layer mask that was last used to calculate derivedDeform and derivedFinal */
+       unsigned int lastDataMask;   /* the custom data layer mask that was last used to calculate derivedDeform and derivedFinal */
+       unsigned int customdata_mask; /* (extra) custom data layer mask to use for creating derivedmesh, set by depsgraph */
        unsigned int state;                     /* bit masks of game controllers that are active */
        unsigned int init_state;        /* bit masks of initial state as recorded by the users */
 
-       int pad2;
-
        ListBase gpulamp;               /* runtime, for lamps only */
        ListBase pc_ids;
        ListBase *duplilist;    /* for temporary dupli list storage, only for use by RNA API */