diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_lattice.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_shrinkwrap.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/deform.c | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lattice.c | 12 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 12 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/shrinkwrap.c | 29 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/simple_deform.c | 10 |
7 files changed, 53 insertions, 22 deletions
diff --git a/source/blender/blenkernel/BKE_lattice.h b/source/blender/blenkernel/BKE_lattice.h index 5620674e791..131c8cb5aaf 100644 --- a/source/blender/blenkernel/BKE_lattice.h +++ b/source/blender/blenkernel/BKE_lattice.h @@ -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 diff --git a/source/blender/blenkernel/BKE_shrinkwrap.h b/source/blender/blenkernel/BKE_shrinkwrap.h index e8276238ff2..d016348da3e 100644 --- a/source/blender/blenkernel/BKE_shrinkwrap.h +++ b/source/blender/blenkernel/BKE_shrinkwrap.h @@ -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 diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 3143c5e4df2..47736865273 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -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); } diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 54915058bab..2737cac149e 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -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; +} + diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 13dc2e834f2..6bdd395a2ac 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -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); diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 28bf7aee884..ab98fb1f007 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -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 diff --git a/source/blender/blenkernel/intern/simple_deform.c b/source/blender/blenkernel/intern/simple_deform.c index 0eb710fa48e..2978a6f7f01 100644 --- a/source/blender/blenkernel/intern/simple_deform.c +++ b/source/blender/blenkernel/intern/simple_deform.c @@ -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) |