diff options
Diffstat (limited to 'source/blender/modifiers/intern/MOD_meshdeform.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_meshdeform.c | 224 |
1 files changed, 112 insertions, 112 deletions
diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index 1bcafc2918e..c6f53b49175 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -57,14 +57,14 @@ static void initData(ModifierData *md) { - MeshDeformModifierData *mmd = (MeshDeformModifierData*) md; + MeshDeformModifierData *mmd = (MeshDeformModifierData *) md; - mmd->gridsize= 5; + mmd->gridsize = 5; } static void freeData(ModifierData *md) { - MeshDeformModifierData *mmd = (MeshDeformModifierData*) md; + MeshDeformModifierData *mmd = (MeshDeformModifierData *) md; if (mmd->bindinfluences) MEM_freeN(mmd->bindinfluences); if (mmd->bindoffsets) MEM_freeN(mmd->bindoffsets); @@ -72,14 +72,14 @@ static void freeData(ModifierData *md) if (mmd->dyngrid) MEM_freeN(mmd->dyngrid); if (mmd->dyninfluences) MEM_freeN(mmd->dyninfluences); if (mmd->dynverts) MEM_freeN(mmd->dynverts); - if (mmd->bindweights) MEM_freeN(mmd->bindweights); /* deprecated */ - if (mmd->bindcos) MEM_freeN(mmd->bindcos); /* deprecated */ + if (mmd->bindweights) MEM_freeN(mmd->bindweights); /* deprecated */ + if (mmd->bindcos) MEM_freeN(mmd->bindcos); /* deprecated */ } static void copyData(ModifierData *md, ModifierData *target) { - MeshDeformModifierData *mmd = (MeshDeformModifierData*) md; - MeshDeformModifierData *tmmd = (MeshDeformModifierData*) target; + MeshDeformModifierData *mmd = (MeshDeformModifierData *) md; + MeshDeformModifierData *tmmd = (MeshDeformModifierData *) target; tmmd->gridsize = mmd->gridsize; tmmd->object = mmd->object; @@ -98,34 +98,34 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) static int isDisabled(ModifierData *md, int UNUSED(useRenderParams)) { - MeshDeformModifierData *mmd = (MeshDeformModifierData*) md; + MeshDeformModifierData *mmd = (MeshDeformModifierData *) md; return !mmd->object; } static void foreachObjectLink( - ModifierData *md, Object *ob, - void (*walk)(void *userData, Object *ob, Object **obpoin), - void *userData) + ModifierData *md, Object *ob, + void (*walk)(void *userData, Object *ob, Object **obpoin), + void *userData) { - MeshDeformModifierData *mmd = (MeshDeformModifierData*) md; + MeshDeformModifierData *mmd = (MeshDeformModifierData *) md; walk(userData, ob, &mmd->object); } static void updateDepgraph(ModifierData *md, DagForest *forest, - struct Scene *UNUSED(scene), - Object *UNUSED(ob), - DagNode *obNode) + struct Scene *UNUSED(scene), + Object *UNUSED(ob), + DagNode *obNode) { - MeshDeformModifierData *mmd = (MeshDeformModifierData*) md; + MeshDeformModifierData *mmd = (MeshDeformModifierData *) md; if (mmd->object) { DagNode *curNode = dag_get_node(forest, mmd->object); dag_add_relation(forest, curNode, obNode, - DAG_RL_DATA_DATA|DAG_RL_OB_DATA|DAG_RL_DATA_OB|DAG_RL_OB_OB, - "Mesh Deform Modifier"); + DAG_RL_DATA_DATA | DAG_RL_OB_DATA | DAG_RL_DATA_OB | DAG_RL_OB_OB, + "Mesh Deform Modifier"); } } @@ -138,40 +138,40 @@ static float meshdeform_dynamic_bind(MeshDeformModifierData *mmd, float (*dco)[3 int i, j, a, x, y, z, size; zero_v3(co); - totweight= 0.0f; - size= mmd->dyngridsize; + totweight = 0.0f; + size = mmd->dyngridsize; - for (i=0; i<3; i++) { - gridvec[i] = (vec[i] - mmd->dyncellmin[i] - mmd->dyncellwidth*0.5f)/mmd->dyncellwidth; + for (i = 0; i < 3; i++) { + gridvec[i] = (vec[i] - mmd->dyncellmin[i] - mmd->dyncellwidth * 0.5f) / mmd->dyncellwidth; ivec[i] = (int)gridvec[i]; dvec[i] = gridvec[i] - ivec[i]; } - for (i=0; i<8; i++) { + for (i = 0; i < 8; i++) { if (i & 1) { x = ivec[0] + 1; wx = dvec[0]; } - else { x = ivec[0]; wx = 1.0f - dvec[0]; } + else { x = ivec[0]; wx = 1.0f - dvec[0]; } if (i & 2) { y = ivec[1] + 1; wy = dvec[1]; } - else { y = ivec[1]; wy = 1.0f - dvec[1]; } + else { y = ivec[1]; wy = 1.0f - dvec[1]; } if (i & 4) { z = ivec[2] + 1; wz = dvec[2]; } - else { z = ivec[2]; wz = 1.0f - dvec[2]; } + else { z = ivec[2]; wz = 1.0f - dvec[2]; } CLAMP(x, 0, size - 1); CLAMP(y, 0, size - 1); CLAMP(z, 0, size - 1); - a= x + y*size + z*size*size; - weight= wx*wy*wz; - - cell= &mmd->dyngrid[a]; - inf= mmd->dyninfluences + cell->offset; - for (j=0; j<cell->totinfluence; j++, inf++) { - cageco= dco[inf->vertex]; - cageweight= weight*inf->weight; - co[0] += cageweight*cageco[0]; - co[1] += cageweight*cageco[1]; - co[2] += cageweight*cageco[2]; + a = x + y * size + z * size * size; + weight = wx * wy * wz; + + cell = &mmd->dyngrid[a]; + inf = mmd->dyninfluences + cell->offset; + for (j = 0; j < cell->totinfluence; j++, inf++) { + cageco = dco[inf->vertex]; + cageweight = weight * inf->weight; + co[0] += cageweight * cageco[0]; + co[1] += cageweight * cageco[1]; + co[2] += cageweight * cageco[2]; totweight += cageweight; } } @@ -182,11 +182,11 @@ static float meshdeform_dynamic_bind(MeshDeformModifierData *mmd, float (*dco)[3 } static void meshdeformModifier_do( - ModifierData *md, Object *ob, DerivedMesh *dm, - float (*vertexCos)[3], int numVerts) + ModifierData *md, Object *ob, DerivedMesh *dm, + float (*vertexCos)[3], int numVerts) { - MeshDeformModifierData *mmd = (MeshDeformModifierData*) md; - struct Mesh *me= (mmd->object)? mmd->object->data: NULL; + MeshDeformModifierData *mmd = (MeshDeformModifierData *) md; + struct Mesh *me = (mmd->object) ? mmd->object->data : NULL; BMEditMesh *em = me ? me->edit_btmesh : NULL; DerivedMesh *tmpdm, *cagedm; MDeformVert *dvert = NULL; @@ -202,19 +202,19 @@ static void meshdeformModifier_do( /* get cage derivedmesh */ if (em) { - tmpdm= editbmesh_get_derived_cage_and_final(md->scene, ob, em, &cagedm, 0); + tmpdm = editbmesh_get_derived_cage_and_final(md->scene, ob, em, &cagedm, 0); if (tmpdm) tmpdm->release(tmpdm); } else - cagedm= mmd->object->derivedFinal; + cagedm = mmd->object->derivedFinal; /* if we don't have one computed, use derivedmesh from data * without any modifiers */ if (!cagedm) { - cagedm= get_dm(mmd->object, NULL, NULL, NULL, 0); + cagedm = get_dm(mmd->object, NULL, NULL, NULL, 0); if (cagedm) - cagedm->needsFree= 1; + cagedm->needsFree = 1; } if (!cagedm) { @@ -236,14 +236,14 @@ static void meshdeformModifier_do( /* progress bar redraw can make this recursive .. */ if (!recursive) { recursive = 1; - mmd->bindfunc(md->scene, mmd, (float*)vertexCos, numVerts, cagemat); + mmd->bindfunc(md->scene, mmd, (float *)vertexCos, numVerts, cagemat); recursive = 0; } } /* verify we have compatible weights */ - totvert= numVerts; - totcagevert= cagedm->getNumVerts(cagedm); + totvert = numVerts; + totcagevert = cagedm->getNumVerts(cagedm); if (mmd->totvert != totvert) { modifier_setError(md, TIP_("Verts changed from %d to %d."), mmd->totvert, totvert); @@ -261,16 +261,16 @@ static void meshdeformModifier_do( return; } - cagecos= MEM_callocN(sizeof(*cagecos)*totcagevert, "meshdeformModifier vertCos"); + cagecos = MEM_callocN(sizeof(*cagecos) * totcagevert, "meshdeformModifier vertCos"); /* setup deformation data */ cagedm->getVertCos(cagedm, cagecos); - influences= mmd->bindinfluences; - offsets= mmd->bindoffsets; - bindcagecos= (float(*)[3])mmd->bindcagecos; + influences = mmd->bindinfluences; + offsets = mmd->bindoffsets; + bindcagecos = (float(*)[3])mmd->bindcagecos; - dco= MEM_callocN(sizeof(*dco)*totcagevert, "MDefDco"); - for (a=0; a<totcagevert; a++) { + dco = MEM_callocN(sizeof(*dco) * totcagevert, "MDefDco"); + for (a = 0; a < totcagevert; a++) { /* get cage vertex in world space with binding transform */ copy_v3_v3(co, cagecos[a]); @@ -286,18 +286,18 @@ static void meshdeformModifier_do( modifier_get_vgroup(ob, dm, mmd->defgrp_name, &dvert, &defgrp_index); /* do deformation */ - fac= 1.0f; + fac = 1.0f; - for (b=0; b<totvert; b++) { + for (b = 0; b < totvert; b++) { if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) if (!mmd->dynverts[b]) continue; if (dvert) { - fac= defvert_find_weight(&dvert[b], defgrp_index); + fac = defvert_find_weight(&dvert[b], defgrp_index); if (mmd->flag & MOD_MDEF_INVERT_VGROUP) { - fac= 1.0f - fac; + fac = 1.0f - fac; } if (fac <= 0.0f) { @@ -308,14 +308,14 @@ static void meshdeformModifier_do( if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) { /* transform coordinate into cage's local space */ mul_v3_m4v3(co, cagemat, vertexCos[b]); - totweight= meshdeform_dynamic_bind(mmd, dco, co); + totweight = meshdeform_dynamic_bind(mmd, dco, co); } else { - totweight= 0.0f; + totweight = 0.0f; zero_v3(co); for (a = offsets[b]; a < offsets[b + 1]; a++) { - weight= influences[a].weight; + weight = influences[a].weight; madd_v3_v3fl(co, dco[influences[a].vertex], weight); totweight += weight; } @@ -338,13 +338,13 @@ static void meshdeformModifier_do( } static void deformVerts(ModifierData *md, Object *ob, - DerivedMesh *derivedData, - float (*vertexCos)[3], - int numVerts, - int UNUSED(useRenderParams), - int UNUSED(isFinalCalc)) + DerivedMesh *derivedData, + float (*vertexCos)[3], + int numVerts, + int UNUSED(useRenderParams), + int UNUSED(isFinalCalc)) { - DerivedMesh *dm= get_dm(ob, NULL, derivedData, NULL, 0); + DerivedMesh *dm = get_dm(ob, NULL, derivedData, NULL, 0); modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */ @@ -355,12 +355,12 @@ static void deformVerts(ModifierData *md, Object *ob, } static void deformVertsEM(ModifierData *md, Object *ob, - struct BMEditMesh *UNUSED(editData), - DerivedMesh *derivedData, - float (*vertexCos)[3], - int numVerts) + struct BMEditMesh *UNUSED(editData), + DerivedMesh *derivedData, + float (*vertexCos)[3], + int numVerts) { - DerivedMesh *dm= get_dm(ob, NULL, derivedData, NULL, 0); + DerivedMesh *dm = get_dm(ob, NULL, derivedData, NULL, 0); meshdeformModifier_do(md, ob, dm, vertexCos, numVerts); @@ -372,21 +372,21 @@ static void deformVertsEM(ModifierData *md, Object *ob, void modifier_mdef_compact_influences(ModifierData *md) { - MeshDeformModifierData *mmd= (MeshDeformModifierData*)md; + MeshDeformModifierData *mmd = (MeshDeformModifierData *)md; float weight, *weights, totweight; int totinfluence, totvert, totcagevert, a, b; - weights= mmd->bindweights; + weights = mmd->bindweights; if (!weights) return; - totvert= mmd->totvert; - totcagevert= mmd->totcagevert; + totvert = mmd->totvert; + totcagevert = mmd->totcagevert; /* count number of influences above threshold */ - for (b=0; b<totvert; b++) { - for (a=0; a<totcagevert; a++) { - weight= weights[a + b*totcagevert]; + for (b = 0; b < totvert; b++) { + for (a = 0; a < totcagevert; a++) { + weight = weights[a + b * totcagevert]; if (weight > MESHDEFORM_MIN_INFLUENCE) mmd->totinfluence++; @@ -398,23 +398,23 @@ void modifier_mdef_compact_influences(ModifierData *md) mmd->bindoffsets = MEM_callocN(sizeof(int) * (totvert + 1), "MDefBindOffset"); /* write influences */ - totinfluence= 0; + totinfluence = 0; - for (b=0; b<totvert; b++) { - mmd->bindoffsets[b]= totinfluence; - totweight= 0.0f; + for (b = 0; b < totvert; b++) { + mmd->bindoffsets[b] = totinfluence; + totweight = 0.0f; /* sum total weight */ - for (a=0; a<totcagevert; a++) { - weight= weights[a + b*totcagevert]; + for (a = 0; a < totcagevert; a++) { + weight = weights[a + b * totcagevert]; if (weight > MESHDEFORM_MIN_INFLUENCE) totweight += weight; } /* assign weights normalized */ - for (a=0; a<totcagevert; a++) { - weight= weights[a + b*totcagevert]; + for (a = 0; a < totcagevert; a++) { + weight = weights[a + b * totcagevert]; if (weight > MESHDEFORM_MIN_INFLUENCE) { mmd->bindinfluences[totinfluence].weight = weight / totweight; @@ -424,36 +424,36 @@ void modifier_mdef_compact_influences(ModifierData *md) } } - mmd->bindoffsets[b]= totinfluence; + mmd->bindoffsets[b] = totinfluence; /* free */ MEM_freeN(mmd->bindweights); - mmd->bindweights= NULL; + mmd->bindweights = NULL; } ModifierTypeInfo modifierType_MeshDeform = { - /* name */ "MeshDeform", - /* structName */ "MeshDeformModifierData", - /* structSize */ sizeof(MeshDeformModifierData), - /* type */ eModifierTypeType_OnlyDeform, - /* flags */ eModifierTypeFlag_AcceptsCVs - | eModifierTypeFlag_SupportsEditmode, - - /* copyData */ copyData, - /* deformVerts */ deformVerts, - /* deformMatrices */ NULL, - /* deformVertsEM */ deformVertsEM, - /* deformMatricesEM */ NULL, - /* applyModifier */ NULL, - /* applyModifierEM */ NULL, - /* initData */ initData, - /* requiredDataMask */ requiredDataMask, - /* freeData */ freeData, - /* isDisabled */ isDisabled, - /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ NULL, - /* dependsOnNormals */ NULL, + /* name */ "MeshDeform", + /* structName */ "MeshDeformModifierData", + /* structSize */ sizeof(MeshDeformModifierData), + /* type */ eModifierTypeType_OnlyDeform, + /* flags */ eModifierTypeFlag_AcceptsCVs | + eModifierTypeFlag_SupportsEditmode, + + /* copyData */ copyData, + /* deformVerts */ deformVerts, + /* deformMatrices */ NULL, + /* deformVertsEM */ deformVertsEM, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, + /* initData */ initData, + /* requiredDataMask */ requiredDataMask, + /* freeData */ freeData, + /* isDisabled */ isDisabled, + /* updateDepgraph */ updateDepgraph, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ NULL, - /* foreachTexLink */ NULL, + /* foreachIDLink */ NULL, + /* foreachTexLink */ NULL, }; |