- split mesh_deform off from object_deform
authorDaniel Dunbar <daniel@zuster.org>
Tue, 19 Jul 2005 02:36:21 +0000 (02:36 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 19 Jul 2005 02:36:21 +0000 (02:36 +0000)
 - changed mesh_modifier, sbObjectStep, object_deform to take vertexCo
   argument instead of operating on mesh
 - fixed bug where a derived mesh would not be returned in editmode
 - removed object_wave, replaced by init_wave_deform and calc_wave_deform
 - moved cached DerivedMesh to Object, not Mesh... fixes heisenbugs
   with linked objects

16 files changed:
source/blender/blenkernel/BKE_deform.h
source/blender/blenkernel/BKE_effect.h
source/blender/blenkernel/BKE_lattice.h
source/blender/blenkernel/BKE_softbody.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/anim.c
source/blender/blenkernel/intern/deform.c
source/blender/blenkernel/intern/effect.c
source/blender/blenkernel/intern/lattice.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/softbody.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_mesh_types.h
source/blender/makesdna/DNA_object_types.h
source/blender/python/api2_2x/Lattice.c

index 6b82a163d3f4e88d2189d81eb5e55239c0937fb0..d3baa8e7bf3ed7752ccfc5f71e49608a7fcecfa3 100644 (file)
@@ -40,7 +40,6 @@
 
 struct Object;
 struct ListBase;
-struct MVert;
 struct bDeformGroup;
 
 void copy_defgroups (struct ListBase *lb1, struct ListBase *lb2);
@@ -51,7 +50,7 @@ int  get_defgroup_num (struct Object *ob, struct bDeformGroup   *dg);
 void hook_object_deform(struct Object *ob, int index, float *vec);
 
 int curve_modifier(struct Object *ob, char mode);
-void mesh_modifier(struct Object *ob, struct MVert **mvert_r);
+void mesh_modifier(struct Object *ob, float (**vertexCos_r)[3]);
 int lattice_modifier(struct Object *ob, char mode);
 
 
index a69fc7ef1031318442a383cbdc592af42b8136da..4ed2febc0d7a1fb4009a1874f20e95b4ee069bb9 100644 (file)
@@ -58,8 +58,8 @@ void particle_tex(struct MTex *mtex, struct PartEff *paf, float *co, float *no);
 void make_particle_keys(int depth, int nr, struct PartEff *paf, struct Particle *part, float *force, int deform, struct MTex *mtex, unsigned int par_layer);
 void init_mv_jit(float *jit, int num,int seed2);
 void build_particle_system(struct Object *ob);
+void init_wave_deform(struct WaveEff *wav);
 void calc_wave_deform(struct WaveEff *wav, float ctime, float *co);
-int object_wave(struct Object *ob);                            
 
 /* particle deflector */
 #define PE_WIND_AS_SPEED 0x00000001
index 9186850e583504dc4c989ffd591a0d8a9cacdcdc..fb3afc98df807be51c5bbdab768c100e77074b12 100644 (file)
@@ -50,6 +50,7 @@ void calc_lat_fudu(int flag, int res, float *fu, float *du);
 void init_latt_deform(struct Object *oblatt, struct Object *ob);
 void calc_latt_deform(float *co);
 void end_latt_deform(void);
+int mesh_deform(struct Object *ob, float (*vertexCos)[3]);
 int object_deform(struct Object *ob);
 struct BPoint *latt_bp(struct Lattice *lt, int u, int v, int w);
 void outside_lattice(struct Lattice *lt);
index e612769c3058b795a019313ebf0436c5553b4bd1..529668c5fc8b5ae964dde64d18aefddf15bb7ee1 100644 (file)
@@ -56,8 +56,10 @@ extern struct SoftBody       *sbNew(void);
 /* frees internal data and softbody itself */
 extern void                            sbFree(struct SoftBody *sb);
 
-/* go one step in simulation, copy result in displist vertices */
-extern void                            sbObjectStep(struct Object *ob, float framnr);
+/* go one step in simulation, copy result in vertexCos for meshes, or
+ * directly for lattices.
+ */
+extern void                            sbObjectStep(struct Object *ob, float framnr, float (*vertexCos)[3]);
 
 /* makes totally fresh start situation, resets time */
 extern void                            sbObjectToSoftbody(struct Object *ob);
index 03171b1019c547cd065f3295041b3331e635aa4b..099a121ed57ad24efc287c7ecd46940fe1da6aac 100644 (file)
@@ -71,7 +71,7 @@ typedef struct {
        MVert *verts;
        float *nors;
 
-       int freeNors;
+       int freeNors, freeVerts;
 } MeshDerivedMesh;
 
 static DispListMesh *meshDM_convertToDispListMesh(DerivedMesh *dm)
@@ -446,7 +446,7 @@ static void meshDM_release(DerivedMesh *dm)
        MeshDerivedMesh *mdm = (MeshDerivedMesh*) dm;
 
        if (mdm->freeNors) MEM_freeN(mdm->nors);
-       if (mdm->verts!=((Mesh*) mdm->me)->mvert) MEM_freeN(mdm->verts);
+       if (mdm->freeVerts) MEM_freeN(mdm->verts);
        MEM_freeN(mdm);
 }
 
@@ -505,6 +505,7 @@ static DerivedMesh *getMeshDerivedMesh(Mesh *me, Object *ob, float (*vertCos)[3]
        mdm->verts = me->mvert;
        mdm->nors = NULL;
        mdm->freeNors = 0;
+       mdm->freeVerts = 0;
 
        if (vertCos) {
                int i;
@@ -517,6 +518,7 @@ static DerivedMesh *getMeshDerivedMesh(Mesh *me, Object *ob, float (*vertCos)[3]
                }
                mesh_calc_normals(mdm->verts, me->totvert, me->mface, me->totface, &mdm->nors);
                mdm->freeNors = 1;
+               mdm->freeVerts = 1;
        } else {
                mdm->nors = mesh_build_faceNormals(ob);
                mdm->freeNors = 1;
@@ -1018,22 +1020,7 @@ static void mesh_calc_modifiers(Mesh *me, Object *ob, float (*inputVertexCos)[3]
        *final_r = NULL;
 
        if (useDeform && ob) {
-               MVert *deformedMVerts;
-
-               mesh_modifier(ob, &deformedMVerts);
-               if (deformedMVerts) {
-                       int i;
-
-                       deformedVerts = MEM_mallocN(sizeof(*deformedVerts)*me->totvert, "deformedverts");
-
-                       for (i=0; i<me->totvert; i++) {
-                               VECCOPY(deformedVerts[i], deformedMVerts[i].co);
-                       }
-
-                       MEM_freeN(deformedMVerts);
-               } else {
-                       deformedVerts = NULL;
-               }
+               mesh_modifier(ob, &deformedVerts);
 
                if (deform_r) *deform_r = getMeshDerivedMesh(me, ob, deformedVerts);
        } else {
@@ -1053,22 +1040,70 @@ static void mesh_calc_modifiers(Mesh *me, Object *ob, float (*inputVertexCos)[3]
 
 /***/
 
+static void clear_and_build_mesh_data(Object *ob, int mustBuildForMesh)
+{
+       float min[3], max[3];
+       Mesh *me= ob->data;
+
+       if(ob->flag&OB_FROMDUPLI) return; // XXX is this needed
+
+               /* also serves as signal to remake texspace */
+       if (me->bb) {
+               MEM_freeN(me->bb);
+               me->bb = NULL;
+       }
+
+       freedisplist(&ob->disp);
+
+       if (ob->derivedFinal) {
+               ob->derivedFinal->release(ob->derivedFinal);
+               ob->derivedFinal= NULL;
+       }
+       if (ob->derivedDeform) {
+               ob->derivedDeform->release(ob->derivedDeform);
+               ob->derivedDeform= NULL;
+       }
+
+       if (ob==G.obedit) {
+               G.editMesh->derived= subsurf_make_derived_from_editmesh(G.editMesh, me->subdiv, me->subsurftype, G.editMesh->derived);
+       } 
+       
+       if (ob!=G.obedit || mustBuildForMesh) {
+               mesh_calc_modifiers(ob->data, ob, NULL, &ob->derivedDeform, &ob->derivedFinal, 0, 1);
+       
+               INIT_MINMAX(min, max);
+
+               ob->derivedFinal->getMinMax(ob->derivedFinal, min, max);
+
+               boundbox_set_from_min_max(mesh_get_bb(ob->data), min, max);
+
+               build_particle_system(ob);
+       }
+}
+
+void makeDispListMesh(Object *ob)
+{
+       clear_and_build_mesh_data(ob, 0);
+}
+
+/***/
+
 DerivedMesh *mesh_get_derived_final(Object *ob, int *needsFree_r)
 {
        Mesh *me = ob->data;
 
-       if (!me->derived) {
-               makeDispListMesh(ob);
+       if (!ob->derivedFinal) {
+               clear_and_build_mesh_data(ob, 1);
        }
 
        *needsFree_r = 0;
-       return me->derived;
+       return ob->derivedFinal;
 }
 
 DerivedMesh *mesh_get_derived_deform(Object *ob, int *needsFree_r)
 {
        if (!ob->derivedDeform) {
-               makeDispListMesh(ob);
+               clear_and_build_mesh_data(ob, 1);
        } 
 
        *needsFree_r = 0;
@@ -1141,46 +1176,3 @@ DerivedMesh *editmesh_get_derived_cage(int *needsFree_r)
 
        return dm;
 }
-
-/***/
-
-void makeDispListMesh(Object *ob)
-{
-       MVert *deformedMVerts = NULL;
-       float min[3], max[3];
-       Mesh *me;
-
-       if(ob->flag&OB_FROMDUPLI) return; // XXX is this needed
-       me= ob->data;
-
-               /* also serves as signal to remake texspace */
-       if (me->bb) {
-               MEM_freeN(me->bb);
-               me->bb = NULL;
-       }
-
-       freedisplist(&ob->disp);
-
-       if (me->derived) {
-               me->derived->release(me->derived);
-               me->derived= NULL;
-       }
-       if (ob->derivedDeform) {
-               ob->derivedDeform->release(ob->derivedDeform);
-               ob->derivedDeform= NULL;
-       }
-
-       if (ob==G.obedit) {
-               G.editMesh->derived= subsurf_make_derived_from_editmesh(G.editMesh, me->subdiv, me->subsurftype, G.editMesh->derived);
-       } else {
-               mesh_calc_modifiers(ob->data, ob, NULL, &ob->derivedDeform, &me->derived, 0, 1);
-       
-               INIT_MINMAX(min, max);
-
-               me->derived->getMinMax(me->derived, min, max);
-
-               boundbox_set_from_min_max(mesh_get_bb(ob->data), min, max);
-
-               build_particle_system(ob);
-       }
-}
index e7a33c1ca92ac3689ca822016b95945e5a135475..ab210b0a6537d2f88ba5bee401c6d1bbd7cc4a6b 100644 (file)
@@ -275,6 +275,7 @@ static Object *new_dupli_object(ListBase *lb, Object *ob, Object *par)
        Object *newob;
        
        newob= MEM_mallocN(sizeof(Object), "newobj dupli");
+
        memcpy(newob, ob, sizeof(Object));
        newob->flag |= OB_FROMDUPLI;
        newob->id.newid= (ID *)par;     /* store duplicator */
index cb2d54ed5babe00bb0e87d11b1582b411d0c3c24..55b49744fbcb1a8624a608176e7ad4dbf2fc5082 100644 (file)
@@ -227,14 +227,14 @@ void hook_object_deform(Object *ob, int index, float *vec)
 }
 
 
-void mesh_modifier(Object *ob, MVert **mvert_r)
+void mesh_modifier(Object *ob, float (**vertexCos_r)[3])
 {
        MVert *origMVert=NULL;
        Mesh *me= ob->data;
-       MVert *mv;
        int a, done=0;
+       float (*vertexCos)[3];
 
-       *mvert_r = NULL;
+       *vertexCos_r = NULL;
        
        do_mesh_key(me);
        
@@ -248,8 +248,11 @@ void mesh_modifier(Object *ob, MVert **mvert_r)
        
        if(me->totvert==0) return;
        
-       origMVert= MEM_dupallocN(me->mvert);
-               
+       vertexCos = MEM_mallocN(sizeof(*vertexCos)*me->totvert, "vertexcos");
+       for (a=0; a<me->totvert; a++) {
+               VECCOPY(vertexCos[a], me->mvert[a].co);
+       }
+
        /* hooks */
        if(ob->hooks.first) {
                done= 1;
@@ -257,29 +260,46 @@ void mesh_modifier(Object *ob, MVert **mvert_r)
                /* NULL signals initialize */
                hook_object_deform(ob, 0, NULL);
                
-               for(a=0, mv= me->mvert; a<me->totvert; a++, mv++) {
-                       hook_object_deform(ob, a, mv->co);
+               for(a=0; a<me->totvert; a++) {
+                       hook_object_deform(ob, a, vertexCos[a]);
                }
        }
                
-       if(ob->effect.first) done |= object_wave(ob);
+       if(ob->effect.first) {
+               WaveEff *wav;
+               float ctime = bsystem_time(ob, 0, (float)G.scene->r.cfra, 0.0);
+               int a;
+       
+               for (wav= ob->effect.first; wav; wav= wav->next) {
+                       if(wav->type==EFF_WAVE) {
+                               init_wave_deform(wav);
+
+                               for(a=0; a<me->totvert; a++) {
+                                       calc_wave_deform(wav, ctime, vertexCos[a]);
+                               }
+
+                               done = 1;
+                       }
+               }
+       }
 
        if((ob->softflag & OB_SB_ENABLE) && !(ob->softflag & OB_SB_POSTDEF)) {
                done= 1;
-               sbObjectStep(ob, (float)G.scene->r.cfra);
+               sbObjectStep(ob, (float)G.scene->r.cfra, vertexCos);
        }
 
        /* object_deform: output for mesh is in mesh->mvert */
-       done |= object_deform(ob);      
+       done |= mesh_deform(ob, vertexCos);     
 
        if((ob->softflag & OB_SB_ENABLE) && (ob->softflag & OB_SB_POSTDEF)) {
                done= 1;
-               sbObjectStep(ob, (float)G.scene->r.cfra);
+               sbObjectStep(ob, (float)G.scene->r.cfra, vertexCos);
        }
 
        if (done) {
-               *mvert_r = me->mvert;
-               me->mvert = origMVert;
+               *vertexCos_r = vertexCos;
+       } else {
+               MEM_freeN(vertexCos_r);
        }
 }
 
@@ -390,7 +410,7 @@ int lattice_modifier(Object *ob, char mode)
                }
                
                if((ob->softflag & OB_SB_ENABLE)) {
-                       sbObjectStep(ob, (float)G.scene->r.cfra);
+                       sbObjectStep(ob, (float)G.scene->r.cfra, NULL);
                }
                
        }
index b1a990ce193bb97e29c1957023ba295cfea3fefb..b26be0578792716962784c623df61bbf4e4d62d7 100644 (file)
@@ -1418,6 +1418,11 @@ void build_particle_system(Object *ob)
 
 /* ************* WAVE **************** */
 
+void init_wave_deform(WaveEff *wav) {
+       wav->minfac= (float)(1.0/exp(wav->width*wav->narrow*wav->width*wav->narrow));
+       if(wav->damp==0) wav->damp= 10.0f;
+}
+
 void calc_wave_deform(WaveEff *wav, float ctime, float *co)
 {
        /* co is in local coords */
@@ -1467,51 +1472,6 @@ void calc_wave_deform(WaveEff *wav, float ctime, float *co)
        }
 }
 
-/* return 1 if deformed
-   Note: it works on mvert now, so assumes to be callied in modifier stack \
-*/
-int object_wave(Object *ob)
-{
-       WaveEff *wav;
-       Mesh *me;
-       MVert *mvert;
-       float ctime;
-       int a;
-       
-       /* is there a wave */
-       wav= ob->effect.first;
-       while(wav) {
-               if(wav->type==EFF_WAVE) break;
-               wav= wav->next;
-       }
-       if(wav==NULL) return 0;
-       
-       if(ob->type==OB_MESH) {
-
-               ctime= bsystem_time(ob, 0, (float)G.scene->r.cfra, 0.0);
-               
-               me= ob->data;
-
-               wav= ob->effect.first;
-               while(wav) {
-                       if(wav->type==EFF_WAVE) {
-                               
-                               /* precalculate */
-                               wav->minfac= (float)(1.0/exp(wav->width*wav->narrow*wav->width*wav->narrow));
-                               if(wav->damp==0) wav->damp= 10.0f;
-                               
-                               mvert= me->mvert;
-                               
-                               for(a=0; a<me->totvert; a++, mvert++) {
-                                       calc_wave_deform(wav, ctime, mvert->co);
-                               }
-                       }
-                       wav= wav->next;
-               }
-       }
-       return 1;
-}
-
 int SoftBodyDetectCollision(float opco[3], float npco[3], float colco[3],
                                                        float facenormal[3], float *damp, float force[3], int mode,
                                                        float cur_time, unsigned int par_layer,struct Object *vertexowner)
index 12a86dcc65132d713202e544f6520d2af17e0787..eff9d813afda6babf08b2d99f12aa1462a80d7c8 100644 (file)
@@ -516,70 +516,79 @@ static void calc_curve_deform(Object *par, float *co, short axis, CurveDeform *c
 
 }
 
-/* Mesh now applies on mesh itself, others do displist */
-int object_deform(Object *ob)
+int mesh_deform(Object *ob, float (*vertexCos)[3])
 {
-       Mesh *me;
-       Curve *cu;
-       DispList *dl;
-       MVert *mvert;
-       float *fp;
-       int a, tot, flag;
+       Mesh *me = ob->data;
+       int a;
 
-       if(ob->parent==NULL) return 0;
+       if(ob->parent==NULL || ob->type!=OB_MESH || !me->totvert) return 0;
        
-       /* always try to do the entire deform in this function: apply! */
-
-       if(ob->parent->type==OB_CURVE) {
+       if(ob->parent->type==OB_CURVE && ob->partype==PARSKEL) {
+               Curve *cu = ob->parent->data;
+               int flag = cu->flag;
                CurveDeform cd;
                
-               if (ob->partype != PARSKEL){
-                       return 0;
-               }
-               cu= ob->parent->data;
-               flag= cu->flag;
                cu->flag |= (CU_PATH|CU_FOLLOW); // needed for path & bevlist
-               
-               if(ob->type==OB_MESH) {
-                       
-                       me= ob->data;
-                       if(me->totvert==0) return 0;
-                       
-                       /* init deform */
-                       init_curve_deform(ob->parent, ob, &cd);
+       
+               init_curve_deform(ob->parent, ob, &cd);
                        
                        /* transformation to curve space, and min max*/
-                       INIT_MINMAX(cd.dmin, cd.dmax);
+               INIT_MINMAX(cd.dmin, cd.dmax);
                        
-                       for(a=0, mvert=me->mvert; a<me->totvert; a++, mvert++) {
-                               Mat4MulVecfl(cd.curvespace, mvert->co);
-                               DO_MINMAX(mvert->co, cd.dmin, cd.dmax);
-                       }
+               for(a=0; a<me->totvert; a++) {
+                       Mat4MulVecfl(cd.curvespace, vertexCos[a]);
+                       DO_MINMAX(vertexCos[a], cd.dmin, cd.dmax);
+               }
 
-                       mvert= me->mvert;
-                       for(a=0; a<me->totvert; a++, mvert++) {
-                               calc_curve_deform(ob->parent, mvert->co, ob->trackflag, &cd);
-                               /* move coord back to objectspace */
-                               Mat4MulVecfl(cd.objectspace, mvert->co);
-                       }
+               for(a=0; a<me->totvert; a++) {
+                       calc_curve_deform(ob->parent, vertexCos[a], ob->trackflag, &cd);
+                       Mat4MulVecfl(cd.objectspace, vertexCos[a]); /* move coord back to objectspace */
                }
-               /* restore */
+
                cu->flag = flag;
+
                return 1;
        }
        else if(ob->parent->type==OB_LATTICE) {
-               
                init_latt_deform(ob->parent, ob);
-               
                if(ob->type==OB_MESH) {
-                       me= ob->data;
-                       
-                       mvert= me->mvert;
-                       for(a=0; a<me->totvert; a++, mvert++) {
-                               calc_latt_deform(mvert->co);
+                       for(a=0; a<me->totvert; a++) {
+                               calc_latt_deform(vertexCos[a]);
                        }
                }
-               else if(ob->type==OB_MBALL) {
+               end_latt_deform();
+
+               return 1;
+       }
+       else if(ob->parent->type==OB_ARMATURE && ob->partype==PARSKEL) {
+               if (ob->parent==G.obedit) // misleading making displists... very bad
+                       return 1;
+               
+               init_armature_deform (ob->parent, ob);
+
+               for(a=0; a<me->totvert; a++) {
+                       calc_armature_deform(ob->parent, vertexCos[a], a);
+               }
+               
+               return 1;
+       }
+       
+       return 0;
+}
+
+int object_deform(Object *ob)
+{
+       Curve *cu;
+       DispList *dl;
+       float *fp;
+       int a, tot;
+
+       if(ob->parent==NULL) return 0;
+       
+       if(ob->parent->type==OB_LATTICE) {
+               init_latt_deform(ob->parent, ob);
+               
+               if(ob->type==OB_MBALL) {
                        dl=ob->disp.first;
                        while(dl) {
                                fp = dl->verts;
@@ -609,31 +618,6 @@ int object_deform(Object *ob)
                end_latt_deform();
                return 1;
        }
-       else if(ob->parent->type==OB_ARMATURE) {
-               if (ob->partype != PARSKEL)
-                       return 0;
-
-               if (ob->parent==G.obedit) // misleading making displists... very bad
-                       return 1;
-               
-               init_armature_deform (ob->parent, ob);
-
-               switch (ob->type){
-               case OB_MESH:
-                       me= ob->data;
-                       
-                       mvert= me->mvert;
-                       for(a=0; a<me->totvert; a++, mvert++) {
-                               calc_armature_deform(ob->parent, mvert->co, a);
-                       }
-                       break;
-               case OB_CURVE:
-               case OB_SURF:
-                       break;
-               }
-               
-               return 1;
-       }
        
        return 0;
 
index 52791ae0e06e5650aa43e88a4db531400c25bc9e..8c33098a9f5508dece6517ba38bc88cb909ae491 100644 (file)
@@ -136,7 +136,6 @@ void unlink_mesh(Mesh *me)
 /* do not free mesh itself */
 void free_mesh(Mesh *me)
 {
-
        unlink_mesh(me);
 
        if(me->mvert) MEM_freeN(me->mvert);
@@ -151,7 +150,6 @@ void free_mesh(Mesh *me)
        if(me->mat) MEM_freeN(me->mat);
        
        if(me->bb) MEM_freeN(me->bb);
-       if(me->derived) me->derived->release(me->derived);
 }
 
 void copy_dverts(MDeformVert *dst, MDeformVert *src, int copycount)
@@ -238,7 +236,6 @@ Mesh *copy_mesh(Mesh *me)
        men->key= copy_key(me->key);
        if(men->key) men->key->from= (ID *)men;
        
-       men->derived = NULL;
        men->decimated = NULL;
 
        return men;
@@ -681,8 +678,6 @@ void flipnorm_mesh(Mesh *me)
 {
        MFace *mface;
        MVert *mvert;
-       DispList *dl;
-       float *fp;
        int a, temp;
        
        mvert= me->mvert;
index 342453df08ad3b319b832d0cb1a6931a0420ea3c..1661711fc60b9df5bee7f898c7ce867c0c362efa 100644 (file)
@@ -176,6 +176,7 @@ void free_object(Object *ob)
        int a;
        
        if(ob->derivedDeform) ob->derivedDeform->release(ob->derivedDeform);
+       if(ob->derivedFinal) ob->derivedFinal->release(ob->derivedFinal);
 
        /* disconnect specific data */
        if(ob->data) {
@@ -841,6 +842,7 @@ Object *copy_object(Object *ob)
        obn->soft= copy_softbody(ob->soft);
        
        ob->derivedDeform = NULL;
+       ob->derivedFinal = NULL;
 
        return obn;
 }
index 78d90c4f456918f7bb2b8ce8d6aaa1b0b6207570..93c2c46ae22c3eb3a34f2b149832469355488efe 100644 (file)
@@ -910,20 +910,16 @@ static void mesh_to_softbody(Object *ob)
 }
 
 /* copies current sofbody position in mesh, so do this within modifier stacks! */
-static void softbody_to_mesh(Object *ob)
+static void softbody_to_mesh(Object *ob, float (*vertexCos)[3])
 {
        Mesh *me= ob->data;
-       MVert *mvert;
-       BodyPoint *bp;
+       BodyPoint *bp= ob->soft->bpoint;
        int a;
 
-       bp= ob->soft->bpoint;
-       mvert= me->mvert;
-       for(a=me->totvert; a>0; a--, mvert++, bp++) {
-               VECCOPY(mvert->co, bp->pos);
-               Mat4MulVecfl(ob->imat, mvert->co);      // softbody is in global coords
+       for(a=me->totvert; a>0; a--, bp++, vertexCos++) {
+               VECCOPY(vertexCos[0], bp->pos);
+               Mat4MulVecfl(ob->imat, vertexCos[0]);   // softbody is in global coords
        }
-
 }
 
 /* makes totally fresh start situation */
@@ -991,7 +987,7 @@ static void lattice_update_softbody(Object *ob)
 
 /* copies softbody result back in object */
 /* only used in sbObjectStep() */
-static void softbody_to_object(Object *ob)
+static void softbody_to_object(Object *ob, float (*vertexCos)[3])
 {
        
        if(ob->soft==NULL) return;
@@ -1001,7 +997,7 @@ static void softbody_to_object(Object *ob)
        
        switch(ob->type) {
        case OB_MESH:
-               softbody_to_mesh(ob);
+               softbody_to_mesh(ob, vertexCos);
                break;
        case OB_LATTICE:
                softbody_to_lattice(ob);
@@ -1027,7 +1023,7 @@ static void object_update_softbody(Object *ob)
 }
 
 /* return 1 if succesfully baked and applied step */
-static int softbody_baked_step(Object *ob, float framenr)
+static int softbody_baked_step(Object *ob, float framenr, float (*vertexCos)[3])
 {
        SoftBody *sb= ob->soft;
        SBVertex *key0, *key1, *key2, *key3;
@@ -1079,7 +1075,7 @@ static int softbody_baked_step(Object *ob, float framenr)
                bp->pos[2]= data[0]*key0->vec[2] +  data[1]*key1->vec[2] + data[2]*key2->vec[2] + data[3]*key3->vec[2];
        }
        
-       softbody_to_object(ob);
+       softbody_to_object(ob, vertexCos);
        
        return 1;
 }
@@ -1220,7 +1216,7 @@ void sbObjectReset(Object *ob)
 
 /* simulates one step. framenr is in frames */
 /* copies result back to object, displist */
-void sbObjectStep(Object *ob, float framenr)
+void sbObjectStep(Object *ob, float framenr, float (*vertexCos)[3])
 {
        SoftBody *sb;
        Base *base;
@@ -1237,7 +1233,7 @@ void sbObjectStep(Object *ob, float framenr)
        
        /* baking works with global time */
        if(!(ob->softflag & OB_SB_BAKEDO) )
-               if(softbody_baked_step(ob, framenr) ) return;
+               if(softbody_baked_step(ob, framenr, vertexCos) ) return;
        
        /* remake softbody if: */
        if( (ob->softflag & OB_SB_REDO) ||              // signal after weightpainting
@@ -1367,7 +1363,7 @@ void sbObjectStep(Object *ob, float framenr)
                }
                
                /* and apply to vertices */
-                softbody_to_object(ob);
+                softbody_to_object(ob, vertexCos);
                
                sb->ctime= ctime;
        } // if(ABS(dtime) > 0.0) 
@@ -1376,7 +1372,7 @@ void sbObjectStep(Object *ob, float framenr)
                // since dtime= ctime - ob->soft->ctime== 0.0;
                // and we were not notifified about any other time changes 
                // so here it is !
-               softbody_to_object(ob);
+               softbody_to_object(ob, vertexCos);
        }
 
        /* reset deflector cache */
index 0911ccc73121824d5d169eb96d74e6992b9547af..564017e0de68234fc2ea6e1f7d2d292193fe8053 100644 (file)
@@ -2090,7 +2090,6 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh)
        mesh->oc= 0;
        mesh->dface= NULL;
        mesh->decimated= NULL;
-       mesh->derived= NULL;
 
        if (mesh->tface) {
                TFace *tfaces= mesh->tface;
@@ -2371,6 +2370,7 @@ static void direct_link_object(FileData *fd, Object *ob)
        
        ob->bb= NULL;
        ob->derivedDeform= NULL;
+       ob->derivedFinal= NULL;
 }
 
 /* ************ READ SCENE ***************** */
index 8ec820b578c99fe870e79f9ca2c5b18e7a815707..1b183c3cb398f26950404c5a81e528c2c6ba0415 100644 (file)
@@ -80,8 +80,6 @@ typedef struct Mesh {
        struct MSticky *msticky;
        struct Mesh *texcomesh;
 
-               /* not written in file, caches derived mesh */
-       struct DerivedMesh *derived;
                /* hacky place to store temporary decimated mesh */
        struct DispListMesh *decimated;
 
index 0e5d331b48b439ce14b7779a098025950a582fa6..5959f6da594cdd3a52d2e8a37f7ba354ea1f824b 100644 (file)
@@ -194,7 +194,7 @@ typedef struct Object {
        
        float toonedge, smoothresh;     /* smoothresh is phong interpolation ray_shadow correction in render */
   
-       struct DerivedMesh *derivedDeform;
+       struct DerivedMesh *derivedDeform, *derivedFinal;
 } Object;
 
 typedef struct ObHook {
index 16e3d704eb815689732d7b62739d73f4cbf1fc47..efb19794e39d775c6df7edac1f436808d9ebe5ac 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "Lattice.h" /*This must come first*/
 
+#include "BKE_utildefines.h"
 #include "BKE_main.h"
 #include "BKE_global.h"
 #include "BKE_library.h"
@@ -39,6 +40,8 @@
 #include "BLI_blenlib.h"
 #include "DNA_object_types.h"
 #include "DNA_key_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_scene_types.h"
 #include "BIF_editkey.h"
@@ -702,8 +705,26 @@ static PyObject *Lattice_applyDeform( BPy_Lattice * self, PyObject *args )
                         * method is needed.  Or for users who actually want to apply the
                         * deformation n times. */
                        if((self->Lattice == par->data)) {
-                               if ((base->object->type != OB_MESH) || forced)
-                                       object_deform( base->object );
+                               if ((base->object->type != OB_MESH) || forced) {
+
+                                       if (base->object->type==OB_MESH) {
+                                               Mesh *me = base->object->data;
+                                               float (*vcos)[3] = malloc(sizeof(*vcos)*me->totvert);
+                                               int a;
+
+                                               for (a=0; a<me->totvert; a++) {
+                                                       VECCOPY(vcos[a], me->mvert[a].co);
+                                               }
+                                               mesh_deform( base->object, vcos );
+                                               for (a=0; a<me->totvert; a++) {
+                                                       VECCOPY(me->mvert[a].co, vcos[a]);
+                                               }
+
+                                               free(vcos);
+                                       } else {
+                                               object_deform( base->object );
+                                       }
+                               }
                        }
                }
                base = base->next;