Added Lattice vgroup support to shrinkwrap and simple deform modifier.
authorAndre Susano Pinto <andresusanopinto@gmail.com>
Mon, 3 Nov 2008 23:17:36 +0000 (23:17 +0000)
committerAndre Susano Pinto <andresusanopinto@gmail.com>
Mon, 3 Nov 2008 23:17:36 +0000 (23:17 +0000)
source/blender/blenkernel/BKE_lattice.h
source/blender/blenkernel/BKE_shrinkwrap.h
source/blender/blenkernel/intern/deform.c
source/blender/blenkernel/intern/lattice.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenkernel/intern/shrinkwrap.c
source/blender/blenkernel/intern/simple_deform.c

index 5620674e791eee6838b09a65fa7b13342b7ee370..131c8cb5aafc9bfe4c53243e5cb07c668fc120cd 100644 (file)
@@ -35,6 +35,7 @@ struct Lattice;
 struct Object;
 struct DerivedMesh;
 struct BPoint;
+struct MDeform;
 
 extern struct Lattice *editLatt;
 
@@ -67,5 +68,7 @@ float (*lattice_getVertexCos(struct Object *ob, int *numVerts_r))[3];
 void lattice_applyVertexCos(struct Object *ob, float (*vertexCos)[3]);
 void lattice_calc_modifiers(struct Object *ob);
 
+struct MDeform* lattice_get_deform_verts(struct Object *lattice);
+
 #endif
 
index e8276238ff220213cbdacb262ad9afb99adb847f..d016348da3ee033d6c5c91b9ab4377cb9c5e5566 100644 (file)
@@ -96,6 +96,7 @@ void space_transform_invert_normal(const SpaceTransform *data, float *no);
 struct Object;
 struct DerivedMesh;
 struct ShrinkwrapModifierData;
+struct MDeform;
 struct BVHTree;
 
 
@@ -109,6 +110,9 @@ typedef struct ShrinkwrapCalcData
        float (*vertexCos)[3];                  //vertexs being shrinkwraped
        int numVerts;
 
+       struct MDeform* dvert;                  //Pointer to mdeform array
+       int vgroup;                                             //Vertex group num
+
        struct DerivedMesh *target;             //mesh we are shrinking to      
        SpaceTransform local2target;    //transform to move bettwem local and target space
 
index 3143c5e4df2328e80647f9e73c9d13171756c28c..477368652735e598ae62104b3b1300e97c67cf43 100644 (file)
@@ -239,12 +239,9 @@ float deformvert_get_weight(const struct MDeformVert *dvert, int group_num)
 
 float vertexgroup_get_vertex_weight(const struct MDeformVert *dvert, int index, int group_num)
 {
-       if(group_num == -1)
+       if(group_num == -1 || dvert == NULL)
                return 1.0;
 
-       if(dvert == 0)
-               return 0.0;
-
        return deformvert_get_weight(dvert+index, group_num);
 }
 
index 54915058bab7b21778a8c29ff0a3db9d86e04ab2..2737cac149e9aacd4b4f762a794b74f59f3a018e 100644 (file)
@@ -928,3 +928,15 @@ void lattice_calc_modifiers(Object *ob)
                BLI_addtail(&ob->disp, dl);
        }
 }
+
+struct MDeform* lattice_get_deform_verts(struct Object *oblatt)
+{
+       if(oblatt->type == OB_LATTICE)
+       {
+               Lattice *lt = (oblatt==G.obedit)?editLatt:(Lattice*)oblatt->data;
+               return lt->dvert;
+       }
+
+       return NULL;    
+}
+
index 13dc2e834f234de04fa532aec14fec4932adb325..6bdd395a2ac1f22d1c737b6d7bb20f8fdcb00f5d 100644 (file)
@@ -7804,9 +7804,10 @@ static void shrinkwrapModifier_deformVerts(ModifierData *md, Object *ob, Derived
        {
                if(derivedData) dm = CDDM_copy(derivedData);
                else if(ob->type==OB_MESH) dm = CDDM_from_mesh(ob->data, ob);
+               else if(ob->type==OB_LATTICE) dm = NULL;
                else return;
 
-               if(dataMask & CD_MVERT)
+               if(dm != NULL && (dataMask & CD_MVERT))
                {
                        CDDM_apply_vert_coords(dm, vertexCos);
                        CDDM_calc_normals(dm);
@@ -7828,9 +7829,10 @@ static void shrinkwrapModifier_deformVertsEM(ModifierData *md, Object *ob, EditM
        {
                if(derivedData) dm = CDDM_copy(derivedData);
                else if(ob->type==OB_MESH) dm = CDDM_from_editmesh(editData, ob->data);
+               else if(ob->type==OB_LATTICE) dm = NULL;
                else return;
 
-               if(dataMask & CD_MVERT)
+               if(dm != NULL && (dataMask & CD_MVERT))
                {
                        CDDM_apply_vert_coords(dm, vertexCos);
                        CDDM_calc_normals(dm);
@@ -7916,9 +7918,10 @@ static void simpledeformModifier_deformVerts(ModifierData *md, Object *ob, Deriv
        {
                if(derivedData) dm = CDDM_copy(derivedData);
                else if(ob->type==OB_MESH) dm = CDDM_from_mesh(ob->data, ob);
+               else if(ob->type==OB_LATTICE) dm = NULL;
                else return;
 
-               if(dataMask & CD_MVERT)
+               if(dm != NULL && (dataMask & CD_MVERT))
                {
                        CDDM_apply_vert_coords(dm, vertexCos);
                        CDDM_calc_normals(dm);
@@ -7942,9 +7945,10 @@ static void simpledeformModifier_deformVertsEM(ModifierData *md, Object *ob, Edi
        {
                if(derivedData) dm = CDDM_copy(derivedData);
                else if(ob->type==OB_MESH) dm = CDDM_from_editmesh(editData, ob->data);
+               else if(ob->type==OB_LATTICE) dm = NULL;
                else return;
 
-               if(dataMask & CD_MVERT)
+               if(dm != NULL && (dataMask & CD_MVERT))
                {
                        CDDM_apply_vert_coords(dm, vertexCos);
                        CDDM_calc_normals(dm);
index 28bf7aee88439578c05e1400f213920ec020b4e4..ab98fb1f0078c79a915351189aca2d0bdddec291 100644 (file)
@@ -41,6 +41,7 @@
 
 #include "BKE_shrinkwrap.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_lattice.h"
 #include "BKE_utildefines.h"
 #include "BKE_deform.h"
 #include "BKE_cdderivedmesh.h"
@@ -161,6 +162,18 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM
        calc.numVerts = numVerts;
        calc.vertexCos = vertexCos;
 
+       //DeformVertex
+       calc.vgroup = get_named_vertexgroup_num(calc.ob, calc.smd->vgroup_name);
+       if(calc.original)
+       {
+               calc.dvert = calc.original->getVertDataArray(calc.original, CD_MDEFORMVERT);
+       }
+       else if(calc.ob->type == OB_LATTICE)
+       {
+               calc.dvert = lattice_get_deform_verts(calc.ob);
+       }
+
+
        if(smd->target)
        {
                //TODO currently we need a copy in case object_get_derived_final returns an emDM that does not defines getVertArray or getFace array
@@ -207,8 +220,6 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM
 void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc)
 {
        int i;
-       const int vgroup                 = get_named_vertexgroup_num(calc->ob, calc->smd->vgroup_name);
-       MDeformVert *const dvert = calc->original ? calc->original->getVertDataArray(calc->original, CD_MDEFORMVERT) : NULL;
 
        BVHTreeFromMesh treeData = NULL_BVHTreeFromMesh;
        BVHTreeNearest  nearest  = NULL_BVHTreeNearest;
@@ -230,7 +241,7 @@ void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc)
        {
                float *co = calc->vertexCos[i];
                float tmp_co[3];
-               float weight = vertexgroup_get_vertex_weight(dvert, i, vgroup);
+               float weight = vertexgroup_get_vertex_weight(calc->dvert, i, calc->vgroup);
                if(weight == 0.0f) continue;
 
                VECCOPY(tmp_co, co);
@@ -342,11 +353,6 @@ void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc)
        MVert *vert  = NULL; //Needed in case of vertex normal
        DerivedMesh* ss_mesh = NULL;
 
-       //Vertex group data
-       const int vgroup                   = get_named_vertexgroup_num(calc->ob, calc->smd->vgroup_name);
-       const MDeformVert *dvert = calc->original ? calc->original->getVertDataArray(calc->original, CD_MDEFORMVERT) : NULL;
-
-
        //Raycast and tree stuff
        BVHTreeRayHit hit;
        BVHTreeFromMesh treeData = NULL_BVHTreeFromMesh;        //target
@@ -441,7 +447,7 @@ do
                float *co = calc->vertexCos[i];
                float tmp_co[3], tmp_no[3];
                float lim = 10000.0f; //TODO: we should use FLT_MAX here, but sweepsphere code isnt prepared for that
-               float weight = vertexgroup_get_vertex_weight(dvert, i, vgroup);
+               float weight = vertexgroup_get_vertex_weight(calc->dvert, i, calc->vgroup);
 
                if(weight == 0.0f) continue;
 
@@ -520,9 +526,6 @@ void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc)
 {
        int i;
 
-       const int vgroup = get_named_vertexgroup_num(calc->ob, calc->smd->vgroup_name);
-       const MDeformVert *const dvert = calc->original ? calc->original->getVertDataArray(calc->original, CD_MDEFORMVERT) : NULL;
-
        BVHTreeFromMesh treeData = NULL_BVHTreeFromMesh;
        BVHTreeNearest  nearest  = NULL_BVHTreeNearest;
 
@@ -547,7 +550,7 @@ void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc)
        {
                float *co = calc->vertexCos[i];
                float tmp_co[3];
-               float weight = vertexgroup_get_vertex_weight(dvert, i, vgroup);
+               float weight = vertexgroup_get_vertex_weight(calc->dvert, i, calc->vgroup);
                if(weight == 0.0f) continue;
 
                //Convert the vertex to tree coordinates
index 0eb710fa48ec31ddc59a1c55f81bbc0d9a5d7286..2978a6f7f01972e01dfb4aae0985f22174835e1b 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "BKE_simple_deform.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_lattice.h"
 #include "BKE_deform.h"
 #include "BKE_utildefines.h"
 #include "BLI_arithb.h"
@@ -204,7 +205,14 @@ void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, s
 
 
        if(dm)
-               dvert   = dm->getVertDataArray(dm, CD_MDEFORMVERT);
+       {
+               dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
+       }
+       else if(ob->type == OB_LATTICE)
+       {
+               dvert = lattice_get_deform_verts(ob);
+       }
+
 
 
        switch(smd->mode)