diff options
author | Nick Samarin <nicks1987@bigmir.net> | 2011-05-17 00:30:59 +0400 |
---|---|---|
committer | Nick Samarin <nicks1987@bigmir.net> | 2011-05-17 00:30:59 +0400 |
commit | a918040902bdeb7c9793168710871e4a3b7777a3 (patch) | |
tree | 7380f00bce5448d777d09f4be4d7127e8eecec49 /source/blender/modifiers | |
parent | daeca2f8262884c436c5678225704b594ce5347b (diff) | |
parent | 99ee18c684da65ba774175c0b57a086e8222464a (diff) |
synched with trunk at revision 36569
Diffstat (limited to 'source/blender/modifiers')
45 files changed, 2367 insertions, 1600 deletions
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt index 31adba0b63f..3222b4cf9e2 100644 --- a/source/blender/modifiers/CMakeLists.txt +++ b/source/blender/modifiers/CMakeLists.txt @@ -27,6 +27,7 @@ set(INC . ./intern ../blenlib + ../blenloader ../makesdna ../blenkernel ../blenkernel/intern @@ -37,6 +38,7 @@ set(INC ../../../intern/elbeem/extern ../../../extern/recastnavigation/Recast/Include ${ZLIB_INCLUDE_DIRS} + ${GLEW_INCLUDE_PATH} ) set(SRC @@ -77,6 +79,7 @@ set(SRC intern/MOD_surface.c intern/MOD_util.c intern/MOD_uvproject.c + intern/MOD_warp.c intern/MOD_wave.c MOD_modifiertypes.h diff --git a/source/blender/modifiers/MOD_modifiertypes.h b/source/blender/modifiers/MOD_modifiertypes.h index b76a0f85ca5..3d8ad7b4128 100644 --- a/source/blender/modifiers/MOD_modifiertypes.h +++ b/source/blender/modifiers/MOD_modifiertypes.h @@ -1,4 +1,4 @@ -/** +/* * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** @@ -25,6 +25,10 @@ * ***** END GPL LICENSE BLOCK ***** */ +/** \file MOD_modifiertypes.h + * \ingroup modifiers + */ + #ifndef MOD_MODIFIERTYPES_H #define MOD_MODIFIERTYPES_H @@ -67,6 +71,7 @@ extern ModifierTypeInfo modifierType_Smoke; extern ModifierTypeInfo modifierType_ShapeKey; extern ModifierTypeInfo modifierType_Solidify; extern ModifierTypeInfo modifierType_Screw; +extern ModifierTypeInfo modifierType_Warp; extern ModifierTypeInfo modifierType_NavMesh; /* MOD_util.c */ diff --git a/source/blender/modifiers/SConscript b/source/blender/modifiers/SConscript index 659cd1ffcb1..5d40803fb59 100644 --- a/source/blender/modifiers/SConscript +++ b/source/blender/modifiers/SConscript @@ -4,8 +4,8 @@ Import ('env') sources = env.Glob('intern/*.c') + env.Glob('intern/*.cpp') incs = '. ./intern' -incs += ' #/intern/guardedalloc #/intern/decimation/extern #/intern/bsp/extern #/intern/elbeem/extern' -incs += ' ../render/extern/include' +incs += ' #/intern/guardedalloc #/intern/decimation/extern #/intern/bsp/extern #/intern/elbeem/extern #/extern/glew/include' +incs += ' ../render/extern/include ../blenloader' incs += ' ../include ../blenlib ../makesdna ../blenkernel ../blenkernel/intern' incs += ' ../editors/include ../gpu' incs += ' #extern/recastnavigation/Recast/Include' @@ -23,4 +23,4 @@ if env['BF_NO_ELBEEM']: env.BlenderLib ( libname = 'bf_modifiers', sources = sources, includes = Split(incs), defines=defs, - libtype=['core','player'], priority = [180, 40] ) + libtype=['core','player'], priority = [80, 40] ) diff --git a/source/blender/modifiers/intern/MOD_armature.c b/source/blender/modifiers/intern/MOD_armature.c index ac25987871d..95579147dbb 100644 --- a/source/blender/modifiers/intern/MOD_armature.c +++ b/source/blender/modifiers/intern/MOD_armature.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_armature.c + * \ingroup modifiers + */ + + #include <string.h> #include "DNA_armature_types.h" @@ -189,15 +194,15 @@ ModifierTypeInfo modifierType_Armature = { /* deformMatrices */ deformMatrices, /* deformVertsEM */ deformVertsEM, /* deformMatricesEM */ deformMatricesEM, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, + /* freeData */ NULL, /* isDisabled */ isDisabled, /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c index 9b49066d623..90954fef1c7 100644 --- a/source/blender/modifiers/intern/MOD_array.c +++ b/source/blender/modifiers/intern/MOD_array.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_array.c + * \ingroup modifiers + */ + + /* Array modifier: duplicates the object multiple times along an axis */ #include "MEM_guardedalloc.h" @@ -51,6 +56,8 @@ #include "depsgraph_private.h" +#include "MOD_util.h" + static void initData(ModifierData *md) { ArrayModifierData *amd = (ArrayModifierData*) md; @@ -306,60 +313,60 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, else /* if the offset has no translation, just make one copy */ count = 1; - } + } - if(count < 1) - count = 1; + if(count < 1) + count = 1; /* allocate memory for count duplicates (including original) plus * start and end caps */ - finalVerts = dm->getNumVerts(dm) * count; - finalEdges = dm->getNumEdges(dm) * count; - finalFaces = dm->getNumFaces(dm) * count; - if(start_cap) { - finalVerts += start_cap->getNumVerts(start_cap); - finalEdges += start_cap->getNumEdges(start_cap); - finalFaces += start_cap->getNumFaces(start_cap); - } - if(end_cap) { - finalVerts += end_cap->getNumVerts(end_cap); - finalEdges += end_cap->getNumEdges(end_cap); - finalFaces += end_cap->getNumFaces(end_cap); - } - result = CDDM_from_template(dm, finalVerts, finalEdges, finalFaces); - - /* calculate the offset matrix of the final copy (for merging) */ - unit_m4(final_offset); - - for(j=0; j < count - 1; j++) { - mul_m4_m4m4(tmp_mat, final_offset, offset); - copy_m4_m4(final_offset, tmp_mat); - } - - numVerts = numEdges = numFaces = 0; - mvert = CDDM_get_verts(result); - - for (i = 0; i < maxVerts; i++) { - indexMap[i].merge = -1; /* default to no merge */ - indexMap[i].merge_final = 0; /* default to no merge */ - } - - for (i = 0; i < maxVerts; i++) { - MVert *inMV; - MVert *mv = &mvert[numVerts]; - MVert *mv2; - float co[3]; - - inMV = &src_mvert[i]; - - DM_copy_vert_data(dm, result, i, numVerts, 1); - *mv = *inMV; - numVerts++; - - indexMap[i].new = numVerts - 1; - - copy_v3_v3(co, mv->co); + finalVerts = dm->getNumVerts(dm) * count; + finalEdges = dm->getNumEdges(dm) * count; + finalFaces = dm->getNumFaces(dm) * count; + if(start_cap) { + finalVerts += start_cap->getNumVerts(start_cap); + finalEdges += start_cap->getNumEdges(start_cap); + finalFaces += start_cap->getNumFaces(start_cap); + } + if(end_cap) { + finalVerts += end_cap->getNumVerts(end_cap); + finalEdges += end_cap->getNumEdges(end_cap); + finalFaces += end_cap->getNumFaces(end_cap); + } + result = CDDM_from_template(dm, finalVerts, finalEdges, finalFaces); + + /* calculate the offset matrix of the final copy (for merging) */ + unit_m4(final_offset); + + for(j=0; j < count - 1; j++) { + mul_m4_m4m4(tmp_mat, final_offset, offset); + copy_m4_m4(final_offset, tmp_mat); + } + + numVerts = numEdges = numFaces = 0; + mvert = CDDM_get_verts(result); + + for (i = 0; i < maxVerts; i++) { + indexMap[i].merge = -1; /* default to no merge */ + indexMap[i].merge_final = 0; /* default to no merge */ + } + + for (i = 0; i < maxVerts; i++) { + MVert *inMV; + MVert *mv = &mvert[numVerts]; + MVert *mv2; + float co[3]; + + inMV = &src_mvert[i]; + + DM_copy_vert_data(dm, result, i, numVerts, 1); + *mv = *inMV; + numVerts++; + + indexMap[i].new = numVerts - 1; + + copy_v3_v3(co, mv->co); /* Attempts to merge verts from one duplicate with verts from the * next duplicate which are closer than amd->merge_dist. @@ -367,405 +374,405 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, * If verts are merged in the first duplicate pair, they are merged * in all pairs. */ - if((count > 1) && (amd->flags & MOD_ARR_MERGE)) { - float tmp_co[3]; - mul_v3_m4v3(tmp_co, offset, mv->co); - - for(j = 0; j < maxVerts; j++) { - /* if vertex already merged, don't use it */ - if( indexMap[j].merge != -1 ) continue; - - inMV = &src_mvert[j]; - /* if this vert is within merge limit, merge */ - if(compare_len_v3v3(tmp_co, inMV->co, amd->merge_dist)) { - indexMap[i].merge = j; - - /* test for merging with final copy of merge target */ - if(amd->flags & MOD_ARR_MERGEFINAL) { - copy_v3_v3(tmp_co, inMV->co); - inMV = &src_mvert[i]; - mul_m4_v3(final_offset, tmp_co); - if(compare_len_v3v3(tmp_co, inMV->co, amd->merge_dist)) - indexMap[i].merge_final = 1; - } - break; - } - } - } - - /* if no merging, generate copies of this vert */ - if(indexMap[i].merge < 0) { - for(j=0; j < count - 1; j++) { - mv2 = &mvert[numVerts]; - - DM_copy_vert_data(result, result, numVerts - 1, numVerts, 1); - *mv2 = *mv; - numVerts++; - - mul_m4_v3(offset, co); - copy_v3_v3(mv2->co, co); - } - } else if(indexMap[i].merge != i && indexMap[i].merge_final) { + if((count > 1) && (amd->flags & MOD_ARR_MERGE)) { + float tmp_co[3]; + mul_v3_m4v3(tmp_co, offset, mv->co); + + for(j = 0; j < maxVerts; j++) { + /* if vertex already merged, don't use it */ + if( indexMap[j].merge != -1 ) continue; + + inMV = &src_mvert[j]; + /* if this vert is within merge limit, merge */ + if(compare_len_v3v3(tmp_co, inMV->co, amd->merge_dist)) { + indexMap[i].merge = j; + + /* test for merging with final copy of merge target */ + if(amd->flags & MOD_ARR_MERGEFINAL) { + copy_v3_v3(tmp_co, inMV->co); + inMV = &src_mvert[i]; + mul_m4_v3(final_offset, tmp_co); + if(compare_len_v3v3(tmp_co, inMV->co, amd->merge_dist)) + indexMap[i].merge_final = 1; + } + break; + } + } + } + + /* if no merging, generate copies of this vert */ + if(indexMap[i].merge < 0) { + for(j=0; j < count - 1; j++) { + mv2 = &mvert[numVerts]; + + DM_copy_vert_data(result, result, numVerts - 1, numVerts, 1); + *mv2 = *mv; + numVerts++; + + mul_m4_v3(offset, co); + copy_v3_v3(mv2->co, co); + } + } else if(indexMap[i].merge != i && indexMap[i].merge_final) { /* if this vert is not merging with itself, and it is merging * with the final copy of its merge target, remove the first copy */ - numVerts--; - DM_free_vert_data(result, numVerts, 1); - } - } + numVerts--; + DM_free_vert_data(result, numVerts, 1); + } + } - /* make a hashtable so we can avoid duplicate edges from merging */ - edges = BLI_edgehash_new(); + /* make a hashtable so we can avoid duplicate edges from merging */ + edges = BLI_edgehash_new(); - maxEdges = dm->getNumEdges(dm); - medge = CDDM_get_edges(result); - for(i = 0; i < maxEdges; i++) { - MEdge inMED; - MEdge med; - MEdge *med2; - int vert1, vert2; + maxEdges = dm->getNumEdges(dm); + medge = CDDM_get_edges(result); + for(i = 0; i < maxEdges; i++) { + MEdge inMED; + MEdge med; + MEdge *med2; + int vert1, vert2; - dm->getEdge(dm, i, &inMED); + dm->getEdge(dm, i, &inMED); - med = inMED; - med.v1 = indexMap[inMED.v1].new; - med.v2 = indexMap[inMED.v2].new; + med = inMED; + med.v1 = indexMap[inMED.v1].new; + med.v2 = indexMap[inMED.v2].new; /* if vertices are to be merged with the final copies of their * merge targets, calculate that final copy */ - if(indexMap[inMED.v1].merge_final) { - med.v1 = calc_mapping(indexMap, indexMap[inMED.v1].merge, - count - 1); - } - if(indexMap[inMED.v2].merge_final) { - med.v2 = calc_mapping(indexMap, indexMap[inMED.v2].merge, - count - 1); - } - - if(med.v1 == med.v2) continue; - - /* XXX Unfortunately the calc_mapping returns sometimes numVerts... leads to bad crashes */ - if(med.v1 >= numVerts) - med.v1= numVerts-1; - if(med.v2 >= numVerts) - med.v2= numVerts-1; - - if (initFlags) { - med.flag |= ME_EDGEDRAW | ME_EDGERENDER; - } - - if(!BLI_edgehash_haskey(edges, med.v1, med.v2)) { - DM_copy_edge_data(dm, result, i, numEdges, 1); - medge[numEdges] = med; - numEdges++; - - BLI_edgehash_insert(edges, med.v1, med.v2, NULL); - } - - for(j = 1; j < count; j++) - { - vert1 = calc_mapping(indexMap, inMED.v1, j); - vert2 = calc_mapping(indexMap, inMED.v2, j); - - /* edge could collapse to single point after mapping */ - if(vert1 == vert2) continue; - - /* XXX Unfortunately the calc_mapping returns sometimes numVerts... leads to bad crashes */ - if(vert1 >= numVerts) - vert1= numVerts-1; - if(vert2 >= numVerts) - vert2= numVerts-1; - - /* avoid duplicate edges */ - if(!BLI_edgehash_haskey(edges, vert1, vert2)) { - med2 = &medge[numEdges]; - - DM_copy_edge_data(dm, result, i, numEdges, 1); - *med2 = med; - numEdges++; - - med2->v1 = vert1; - med2->v2 = vert2; - - BLI_edgehash_insert(edges, med2->v1, med2->v2, NULL); - } - } - } - - maxFaces = dm->getNumFaces(dm); - mface = CDDM_get_faces(result); - for (i=0; i < maxFaces; i++) { - MFace inMF; - MFace *mf = &mface[numFaces]; - - dm->getFace(dm, i, &inMF); - - DM_copy_face_data(dm, result, i, numFaces, 1); - *mf = inMF; - - mf->v1 = indexMap[inMF.v1].new; - mf->v2 = indexMap[inMF.v2].new; - mf->v3 = indexMap[inMF.v3].new; - if(inMF.v4) - mf->v4 = indexMap[inMF.v4].new; + if(indexMap[inMED.v1].merge_final) { + med.v1 = calc_mapping(indexMap, indexMap[inMED.v1].merge, + count - 1); + } + if(indexMap[inMED.v2].merge_final) { + med.v2 = calc_mapping(indexMap, indexMap[inMED.v2].merge, + count - 1); + } + + if(med.v1 == med.v2) continue; + + /* XXX Unfortunately the calc_mapping returns sometimes numVerts... leads to bad crashes */ + if(med.v1 >= numVerts) + med.v1= numVerts-1; + if(med.v2 >= numVerts) + med.v2= numVerts-1; + + if (initFlags) { + med.flag |= ME_EDGEDRAW | ME_EDGERENDER; + } + + if(!BLI_edgehash_haskey(edges, med.v1, med.v2)) { + DM_copy_edge_data(dm, result, i, numEdges, 1); + medge[numEdges] = med; + numEdges++; + + BLI_edgehash_insert(edges, med.v1, med.v2, NULL); + } + + for(j = 1; j < count; j++) + { + vert1 = calc_mapping(indexMap, inMED.v1, j); + vert2 = calc_mapping(indexMap, inMED.v2, j); + + /* edge could collapse to single point after mapping */ + if(vert1 == vert2) continue; + + /* XXX Unfortunately the calc_mapping returns sometimes numVerts... leads to bad crashes */ + if(vert1 >= numVerts) + vert1= numVerts-1; + if(vert2 >= numVerts) + vert2= numVerts-1; + + /* avoid duplicate edges */ + if(!BLI_edgehash_haskey(edges, vert1, vert2)) { + med2 = &medge[numEdges]; + + DM_copy_edge_data(dm, result, i, numEdges, 1); + *med2 = med; + numEdges++; + + med2->v1 = vert1; + med2->v2 = vert2; + + BLI_edgehash_insert(edges, med2->v1, med2->v2, NULL); + } + } + } + + maxFaces = dm->getNumFaces(dm); + mface = CDDM_get_faces(result); + for (i=0; i < maxFaces; i++) { + MFace inMF; + MFace *mf = &mface[numFaces]; + + dm->getFace(dm, i, &inMF); + + DM_copy_face_data(dm, result, i, numFaces, 1); + *mf = inMF; + + mf->v1 = indexMap[inMF.v1].new; + mf->v2 = indexMap[inMF.v2].new; + mf->v3 = indexMap[inMF.v3].new; + if(inMF.v4) + mf->v4 = indexMap[inMF.v4].new; /* if vertices are to be merged with the final copies of their * merge targets, calculate that final copy */ - if(indexMap[inMF.v1].merge_final) - mf->v1 = calc_mapping(indexMap, indexMap[inMF.v1].merge, count-1); - if(indexMap[inMF.v2].merge_final) - mf->v2 = calc_mapping(indexMap, indexMap[inMF.v2].merge, count-1); - if(indexMap[inMF.v3].merge_final) - mf->v3 = calc_mapping(indexMap, indexMap[inMF.v3].merge, count-1); - if(inMF.v4 && indexMap[inMF.v4].merge_final) - mf->v4 = calc_mapping(indexMap, indexMap[inMF.v4].merge, count-1); - - if(test_index_face_maxvert(mf, &result->faceData, numFaces, inMF.v4?4:3, numVerts) < 3) - continue; - - numFaces++; - - /* if the face has fewer than 3 vertices, don't create it */ - if(mf->v3 == 0 || (mf->v1 && (mf->v1 == mf->v3 || mf->v1 == mf->v4))) { - numFaces--; - DM_free_face_data(result, numFaces, 1); - } - - for(j = 1; j < count; j++) - { - MFace *mf2 = &mface[numFaces]; - - DM_copy_face_data(dm, result, i, numFaces, 1); - *mf2 = *mf; - - mf2->v1 = calc_mapping(indexMap, inMF.v1, j); - mf2->v2 = calc_mapping(indexMap, inMF.v2, j); - mf2->v3 = calc_mapping(indexMap, inMF.v3, j); - if (inMF.v4) - mf2->v4 = calc_mapping(indexMap, inMF.v4, j); - - numFaces++; - - /* if the face has fewer than 3 vertices, don't create it */ - if(test_index_face_maxvert(mf2, &result->faceData, numFaces-1, inMF.v4?4:3, numVerts) < 3) { - numFaces--; - DM_free_face_data(result, numFaces, 1); - } - } - } - - /* add start and end caps */ - if(start_cap) { - float startoffset[4][4]; - MVert *cap_mvert; - MEdge *cap_medge; - MFace *cap_mface; - int *origindex; - int *vert_map; - int capVerts, capEdges, capFaces; - - capVerts = start_cap->getNumVerts(start_cap); - capEdges = start_cap->getNumEdges(start_cap); - capFaces = start_cap->getNumFaces(start_cap); - cap_mvert = start_cap->getVertArray(start_cap); - cap_medge = start_cap->getEdgeArray(start_cap); - cap_mface = start_cap->getFaceArray(start_cap); - - invert_m4_m4(startoffset, offset); - - vert_map = MEM_callocN(sizeof(*vert_map) * capVerts, - "arrayModifier_doArray vert_map"); - - origindex = result->getVertDataArray(result, CD_ORIGINDEX); - for(i = 0; i < capVerts; i++) { - MVert *mv = &cap_mvert[i]; - short merged = 0; - - if(amd->flags & MOD_ARR_MERGE) { - float tmp_co[3]; - MVert *in_mv; - int j; - - copy_v3_v3(tmp_co, mv->co); - mul_m4_v3(startoffset, tmp_co); - - for(j = 0; j < maxVerts; j++) { - in_mv = &src_mvert[j]; - /* if this vert is within merge limit, merge */ - if(compare_len_v3v3(tmp_co, in_mv->co, amd->merge_dist)) { - vert_map[i] = calc_mapping(indexMap, j, 0); - merged = 1; - break; - } - } - } - - if(!merged) { - DM_copy_vert_data(start_cap, result, i, numVerts, 1); - mvert[numVerts] = *mv; - mul_m4_v3(startoffset, mvert[numVerts].co); - origindex[numVerts] = ORIGINDEX_NONE; - - vert_map[i] = numVerts; - - numVerts++; - } - } - origindex = result->getEdgeDataArray(result, CD_ORIGINDEX); - for(i = 0; i < capEdges; i++) { - int v1, v2; - - v1 = vert_map[cap_medge[i].v1]; - v2 = vert_map[cap_medge[i].v2]; - - if(!BLI_edgehash_haskey(edges, v1, v2)) { - DM_copy_edge_data(start_cap, result, i, numEdges, 1); - medge[numEdges] = cap_medge[i]; - medge[numEdges].v1 = v1; - medge[numEdges].v2 = v2; - origindex[numEdges] = ORIGINDEX_NONE; - - numEdges++; - } - } - origindex = result->getFaceDataArray(result, CD_ORIGINDEX); - for(i = 0; i < capFaces; i++) { - DM_copy_face_data(start_cap, result, i, numFaces, 1); - mface[numFaces] = cap_mface[i]; - mface[numFaces].v1 = vert_map[mface[numFaces].v1]; - mface[numFaces].v2 = vert_map[mface[numFaces].v2]; - mface[numFaces].v3 = vert_map[mface[numFaces].v3]; - if(mface[numFaces].v4) { - mface[numFaces].v4 = vert_map[mface[numFaces].v4]; - - test_index_face_maxvert(&mface[numFaces], &result->faceData, - numFaces, 4, numVerts); - } - else - { - test_index_face(&mface[numFaces], &result->faceData, - numFaces, 3); - } - - origindex[numFaces] = ORIGINDEX_NONE; - - numFaces++; - } - - MEM_freeN(vert_map); - start_cap->release(start_cap); - } - - if(end_cap) { - float endoffset[4][4]; - MVert *cap_mvert; - MEdge *cap_medge; - MFace *cap_mface; - int *origindex; - int *vert_map; - int capVerts, capEdges, capFaces; - - capVerts = end_cap->getNumVerts(end_cap); - capEdges = end_cap->getNumEdges(end_cap); - capFaces = end_cap->getNumFaces(end_cap); - cap_mvert = end_cap->getVertArray(end_cap); - cap_medge = end_cap->getEdgeArray(end_cap); - cap_mface = end_cap->getFaceArray(end_cap); - - mul_m4_m4m4(endoffset, final_offset, offset); - - vert_map = MEM_callocN(sizeof(*vert_map) * capVerts, - "arrayModifier_doArray vert_map"); - - origindex = result->getVertDataArray(result, CD_ORIGINDEX); - for(i = 0; i < capVerts; i++) { - MVert *mv = &cap_mvert[i]; - short merged = 0; - - if(amd->flags & MOD_ARR_MERGE) { - float tmp_co[3]; - MVert *in_mv; - int j; - - copy_v3_v3(tmp_co, mv->co); - mul_m4_v3(offset, tmp_co); - - for(j = 0; j < maxVerts; j++) { - in_mv = &src_mvert[j]; - /* if this vert is within merge limit, merge */ - if(compare_len_v3v3(tmp_co, in_mv->co, amd->merge_dist)) { - vert_map[i] = calc_mapping(indexMap, j, count - 1); - merged = 1; - break; - } - } - } - - if(!merged) { - DM_copy_vert_data(end_cap, result, i, numVerts, 1); - mvert[numVerts] = *mv; - mul_m4_v3(endoffset, mvert[numVerts].co); - origindex[numVerts] = ORIGINDEX_NONE; - - vert_map[i] = numVerts; - - numVerts++; - } - } - origindex = result->getEdgeDataArray(result, CD_ORIGINDEX); - for(i = 0; i < capEdges; i++) { - int v1, v2; - - v1 = vert_map[cap_medge[i].v1]; - v2 = vert_map[cap_medge[i].v2]; - - if(!BLI_edgehash_haskey(edges, v1, v2)) { - DM_copy_edge_data(end_cap, result, i, numEdges, 1); - medge[numEdges] = cap_medge[i]; - medge[numEdges].v1 = v1; - medge[numEdges].v2 = v2; - origindex[numEdges] = ORIGINDEX_NONE; - - numEdges++; - } - } - origindex = result->getFaceDataArray(result, CD_ORIGINDEX); - for(i = 0; i < capFaces; i++) { - DM_copy_face_data(end_cap, result, i, numFaces, 1); - mface[numFaces] = cap_mface[i]; - mface[numFaces].v1 = vert_map[mface[numFaces].v1]; - mface[numFaces].v2 = vert_map[mface[numFaces].v2]; - mface[numFaces].v3 = vert_map[mface[numFaces].v3]; - if(mface[numFaces].v4) { - mface[numFaces].v4 = vert_map[mface[numFaces].v4]; - - test_index_face(&mface[numFaces], &result->faceData, - numFaces, 4); - } - else - { - test_index_face(&mface[numFaces], &result->faceData, - numFaces, 3); - } - origindex[numFaces] = ORIGINDEX_NONE; - - numFaces++; - } - - MEM_freeN(vert_map); - end_cap->release(end_cap); - } - - BLI_edgehash_free(edges, NULL); - MEM_freeN(indexMap); - - CDDM_lower_num_verts(result, numVerts); - CDDM_lower_num_edges(result, numEdges); - CDDM_lower_num_faces(result, numFaces); - - return result; + if(indexMap[inMF.v1].merge_final) + mf->v1 = calc_mapping(indexMap, indexMap[inMF.v1].merge, count-1); + if(indexMap[inMF.v2].merge_final) + mf->v2 = calc_mapping(indexMap, indexMap[inMF.v2].merge, count-1); + if(indexMap[inMF.v3].merge_final) + mf->v3 = calc_mapping(indexMap, indexMap[inMF.v3].merge, count-1); + if(inMF.v4 && indexMap[inMF.v4].merge_final) + mf->v4 = calc_mapping(indexMap, indexMap[inMF.v4].merge, count-1); + + if(test_index_face_maxvert(mf, &result->faceData, numFaces, inMF.v4?4:3, numVerts) < 3) + continue; + + numFaces++; + + /* if the face has fewer than 3 vertices, don't create it */ + if(mf->v3 == 0 || (mf->v1 && (mf->v1 == mf->v3 || mf->v1 == mf->v4))) { + numFaces--; + DM_free_face_data(result, numFaces, 1); + } + + for(j = 1; j < count; j++) + { + MFace *mf2 = &mface[numFaces]; + + DM_copy_face_data(dm, result, i, numFaces, 1); + *mf2 = *mf; + + mf2->v1 = calc_mapping(indexMap, inMF.v1, j); + mf2->v2 = calc_mapping(indexMap, inMF.v2, j); + mf2->v3 = calc_mapping(indexMap, inMF.v3, j); + if (inMF.v4) + mf2->v4 = calc_mapping(indexMap, inMF.v4, j); + + numFaces++; + + /* if the face has fewer than 3 vertices, don't create it */ + if(test_index_face_maxvert(mf2, &result->faceData, numFaces-1, inMF.v4?4:3, numVerts) < 3) { + numFaces--; + DM_free_face_data(result, numFaces, 1); + } + } + } + + /* add start and end caps */ + if(start_cap) { + float startoffset[4][4]; + MVert *cap_mvert; + MEdge *cap_medge; + MFace *cap_mface; + int *origindex; + int *vert_map; + int capVerts, capEdges, capFaces; + + capVerts = start_cap->getNumVerts(start_cap); + capEdges = start_cap->getNumEdges(start_cap); + capFaces = start_cap->getNumFaces(start_cap); + cap_mvert = start_cap->getVertArray(start_cap); + cap_medge = start_cap->getEdgeArray(start_cap); + cap_mface = start_cap->getFaceArray(start_cap); + + invert_m4_m4(startoffset, offset); + + vert_map = MEM_callocN(sizeof(*vert_map) * capVerts, + "arrayModifier_doArray vert_map"); + + origindex = result->getVertDataArray(result, CD_ORIGINDEX); + for(i = 0; i < capVerts; i++) { + MVert *mv = &cap_mvert[i]; + short merged = 0; + + if(amd->flags & MOD_ARR_MERGE) { + float tmp_co[3]; + MVert *in_mv; + int j; + + copy_v3_v3(tmp_co, mv->co); + mul_m4_v3(startoffset, tmp_co); + + for(j = 0; j < maxVerts; j++) { + in_mv = &src_mvert[j]; + /* if this vert is within merge limit, merge */ + if(compare_len_v3v3(tmp_co, in_mv->co, amd->merge_dist)) { + vert_map[i] = calc_mapping(indexMap, j, 0); + merged = 1; + break; + } + } + } + + if(!merged) { + DM_copy_vert_data(start_cap, result, i, numVerts, 1); + mvert[numVerts] = *mv; + mul_m4_v3(startoffset, mvert[numVerts].co); + origindex[numVerts] = ORIGINDEX_NONE; + + vert_map[i] = numVerts; + + numVerts++; + } + } + origindex = result->getEdgeDataArray(result, CD_ORIGINDEX); + for(i = 0; i < capEdges; i++) { + int v1, v2; + + v1 = vert_map[cap_medge[i].v1]; + v2 = vert_map[cap_medge[i].v2]; + + if(!BLI_edgehash_haskey(edges, v1, v2)) { + DM_copy_edge_data(start_cap, result, i, numEdges, 1); + medge[numEdges] = cap_medge[i]; + medge[numEdges].v1 = v1; + medge[numEdges].v2 = v2; + origindex[numEdges] = ORIGINDEX_NONE; + + numEdges++; + } + } + origindex = result->getFaceDataArray(result, CD_ORIGINDEX); + for(i = 0; i < capFaces; i++) { + DM_copy_face_data(start_cap, result, i, numFaces, 1); + mface[numFaces] = cap_mface[i]; + mface[numFaces].v1 = vert_map[mface[numFaces].v1]; + mface[numFaces].v2 = vert_map[mface[numFaces].v2]; + mface[numFaces].v3 = vert_map[mface[numFaces].v3]; + if(mface[numFaces].v4) { + mface[numFaces].v4 = vert_map[mface[numFaces].v4]; + + test_index_face_maxvert(&mface[numFaces], &result->faceData, + numFaces, 4, numVerts); + } + else + { + test_index_face(&mface[numFaces], &result->faceData, + numFaces, 3); + } + + origindex[numFaces] = ORIGINDEX_NONE; + + numFaces++; + } + + MEM_freeN(vert_map); + start_cap->release(start_cap); + } + + if(end_cap) { + float endoffset[4][4]; + MVert *cap_mvert; + MEdge *cap_medge; + MFace *cap_mface; + int *origindex; + int *vert_map; + int capVerts, capEdges, capFaces; + + capVerts = end_cap->getNumVerts(end_cap); + capEdges = end_cap->getNumEdges(end_cap); + capFaces = end_cap->getNumFaces(end_cap); + cap_mvert = end_cap->getVertArray(end_cap); + cap_medge = end_cap->getEdgeArray(end_cap); + cap_mface = end_cap->getFaceArray(end_cap); + + mul_m4_m4m4(endoffset, final_offset, offset); + + vert_map = MEM_callocN(sizeof(*vert_map) * capVerts, + "arrayModifier_doArray vert_map"); + + origindex = result->getVertDataArray(result, CD_ORIGINDEX); + for(i = 0; i < capVerts; i++) { + MVert *mv = &cap_mvert[i]; + short merged = 0; + + if(amd->flags & MOD_ARR_MERGE) { + float tmp_co[3]; + MVert *in_mv; + int j; + + copy_v3_v3(tmp_co, mv->co); + mul_m4_v3(offset, tmp_co); + + for(j = 0; j < maxVerts; j++) { + in_mv = &src_mvert[j]; + /* if this vert is within merge limit, merge */ + if(compare_len_v3v3(tmp_co, in_mv->co, amd->merge_dist)) { + vert_map[i] = calc_mapping(indexMap, j, count - 1); + merged = 1; + break; + } + } + } + + if(!merged) { + DM_copy_vert_data(end_cap, result, i, numVerts, 1); + mvert[numVerts] = *mv; + mul_m4_v3(endoffset, mvert[numVerts].co); + origindex[numVerts] = ORIGINDEX_NONE; + + vert_map[i] = numVerts; + + numVerts++; + } + } + origindex = result->getEdgeDataArray(result, CD_ORIGINDEX); + for(i = 0; i < capEdges; i++) { + int v1, v2; + + v1 = vert_map[cap_medge[i].v1]; + v2 = vert_map[cap_medge[i].v2]; + + if(!BLI_edgehash_haskey(edges, v1, v2)) { + DM_copy_edge_data(end_cap, result, i, numEdges, 1); + medge[numEdges] = cap_medge[i]; + medge[numEdges].v1 = v1; + medge[numEdges].v2 = v2; + origindex[numEdges] = ORIGINDEX_NONE; + + numEdges++; + } + } + origindex = result->getFaceDataArray(result, CD_ORIGINDEX); + for(i = 0; i < capFaces; i++) { + DM_copy_face_data(end_cap, result, i, numFaces, 1); + mface[numFaces] = cap_mface[i]; + mface[numFaces].v1 = vert_map[mface[numFaces].v1]; + mface[numFaces].v2 = vert_map[mface[numFaces].v2]; + mface[numFaces].v3 = vert_map[mface[numFaces].v3]; + if(mface[numFaces].v4) { + mface[numFaces].v4 = vert_map[mface[numFaces].v4]; + + test_index_face(&mface[numFaces], &result->faceData, + numFaces, 4); + } + else + { + test_index_face(&mface[numFaces], &result->faceData, + numFaces, 3); + } + origindex[numFaces] = ORIGINDEX_NONE; + + numFaces++; + } + + MEM_freeN(vert_map); + end_cap->release(end_cap); + } + + BLI_edgehash_free(edges, NULL); + MEM_freeN(indexMap); + + CDDM_lower_num_verts(result, numVerts); + CDDM_lower_num_edges(result, numEdges); + CDDM_lower_num_faces(result, numFaces); + + return result; } static DerivedMesh *applyModifier(ModifierData *md, Object *ob, @@ -804,19 +811,19 @@ ModifierTypeInfo modifierType_Array = { | eModifierTypeFlag_AcceptsCVs, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, /* applyModifierEM */ applyModifierEM, /* initData */ initData, - /* requiredDataMask */ 0, - /* freeData */ 0, - /* isDisabled */ 0, + /* requiredDataMask */ NULL, + /* freeData */ NULL, + /* isDisabled */ NULL, /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c index effc376943e..323ed71dd74 100644 --- a/source/blender/modifiers/intern/MOD_bevel.c +++ b/source/blender/modifiers/intern/MOD_bevel.c @@ -29,6 +29,11 @@ * ***** END GPL LICENSE BLOCK ***** * */ + +/** \file blender/modifiers/intern/MOD_bevel.c + * \ingroup modifiers + */ + #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" @@ -38,6 +43,8 @@ #include "BKE_modifier.h" #include "BKE_particle.h" +#include "MOD_util.h" + static void initData(ModifierData *md) { @@ -128,19 +135,19 @@ ModifierTypeInfo modifierType_Bevel = { | eModifierTypeFlag_EnableInEditmode, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, /* applyModifierEM */ applyModifierEM, /* initData */ initData, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, - /* isDisabled */ 0, - /* updateDepgraph */ 0, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* freeData */ NULL, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c index c40d6cfb79e..ec6387f44af 100644 --- a/source/blender/modifiers/intern/MOD_boolean.c +++ b/source/blender/modifiers/intern/MOD_boolean.c @@ -30,6 +30,12 @@ * */ +/** \file blender/modifiers/intern/MOD_boolean.c + * \ingroup modifiers + */ + +#include <stdio.h> + #include "DNA_object_types.h" #include "BLI_utildefines.h" @@ -41,6 +47,7 @@ #include "depsgraph_private.h" #include "MOD_boolean_util.h" +#include "MOD_util.h" static void copyData(ModifierData *md, ModifierData *target) @@ -138,19 +145,19 @@ ModifierTypeInfo modifierType_Boolean = { | eModifierTypeFlag_UsesPointCache, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, - /* applyModifierEM */ 0, - /* initData */ 0, + /* applyModifierEM */ NULL, + /* initData */ NULL, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, + /* freeData */ NULL, /* isDisabled */ isDisabled, /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_boolean_util.c b/source/blender/modifiers/intern/MOD_boolean_util.c index 900a94487e5..9d83e351b2b 100644 --- a/source/blender/modifiers/intern/MOD_boolean_util.c +++ b/source/blender/modifiers/intern/MOD_boolean_util.c @@ -1,4 +1,4 @@ -/** +/* * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** @@ -28,6 +28,11 @@ * CSG operations. */ +/** \file blender/modifiers/intern/MOD_boolean_util.c + * \ingroup modifiers + */ + + #include "DNA_material_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" @@ -48,6 +53,8 @@ #include "CSG_BooleanOps.h" +#include "MOD_boolean_util.h" + /** * Here's the vertex iterator structure used to walk through * the blender vertex structure. @@ -451,7 +458,7 @@ static void FreeMeshDescriptors( FaceIt_Destruct(face_it); } -DerivedMesh *NewBooleanDerivedMesh_intern( +static DerivedMesh *NewBooleanDerivedMesh_intern( DerivedMesh *dm, struct Object *ob, DerivedMesh *dm_select, struct Object *ob_select, int int_op_type, Material **mat, int *totmat) { diff --git a/source/blender/modifiers/intern/MOD_boolean_util.h b/source/blender/modifiers/intern/MOD_boolean_util.h index e415b368a85..2a4191de407 100644 --- a/source/blender/modifiers/intern/MOD_boolean_util.h +++ b/source/blender/modifiers/intern/MOD_boolean_util.h @@ -1,4 +1,4 @@ -/** +/* * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** @@ -27,6 +27,11 @@ * ***** END GPL LICENSE BLOCK ***** */ +/** \file blender/modifiers/intern/MOD_boolean_util.h + * \ingroup modifiers + */ + + #ifndef MOD_BOOLEAN_UTILS_H #define MOD_BOOLEAN_UTILS_H diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c index 704caf0aff8..e293be5886d 100644 --- a/source/blender/modifiers/intern/MOD_build.c +++ b/source/blender/modifiers/intern/MOD_build.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_build.c + * \ingroup modifiers + */ + + #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" @@ -46,6 +51,7 @@ #include "BKE_particle.h" #include "BKE_scene.h" +#include "MOD_util.h" static void initData(ModifierData *md) { @@ -81,7 +87,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, BuildModifierData *bmd = (BuildModifierData*) md; int i; int numFaces, numEdges; - int maxVerts, maxEdges, maxFaces; int *vertMap, *edgeMap, *faceMap; float frac; GHashIterator *hashIter; @@ -92,19 +97,15 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, GHash *edgeHash = BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp, "build ed apply gh"); - maxVerts = dm->getNumVerts(dm); - vertMap = MEM_callocN(sizeof(*vertMap) * maxVerts, - "build modifier vertMap"); - for(i = 0; i < maxVerts; ++i) vertMap[i] = i; + const int maxVerts= dm->getNumVerts(dm); + const int maxEdges= dm->getNumEdges(dm); + const int maxFaces= dm->getNumFaces(dm); - maxEdges = dm->getNumEdges(dm); - edgeMap = MEM_callocN(sizeof(*edgeMap) * maxEdges, - "build modifier edgeMap"); + vertMap = MEM_callocN(sizeof(*vertMap) * maxVerts, "build modifier vertMap"); + for(i = 0; i < maxVerts; ++i) vertMap[i] = i; + edgeMap = MEM_callocN(sizeof(*edgeMap) * maxEdges, "build modifier edgeMap"); for(i = 0; i < maxEdges; ++i) edgeMap[i] = i; - - maxFaces = dm->getNumFaces(dm); - faceMap = MEM_callocN(sizeof(*faceMap) * maxFaces, - "build modifier faceMap"); + faceMap = MEM_callocN(sizeof(*faceMap) * maxFaces, "build modifier faceMap"); for(i = 0; i < maxFaces; ++i) faceMap[i] = i; if (ob) { @@ -113,15 +114,13 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, } else { frac = BKE_curframe(md->scene) - bmd->start / bmd->length; } - CLAMP(frac, 0.0, 1.0); + CLAMP(frac, 0.0f, 1.0f); numFaces = dm->getNumFaces(dm) * frac; numEdges = dm->getNumEdges(dm) * frac; /* if there's at least one face, build based on faces */ if(numFaces) { - int maxEdges; - if(bmd->randomize) BLI_array_randomize(faceMap, sizeof(*faceMap), maxFaces, bmd->seed); @@ -150,7 +149,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, /* get the set of edges that will be in the new mesh (i.e. all edges * that have both verts in the new mesh) */ - maxEdges = dm->getNumEdges(dm); for(i = 0; i < maxEdges; ++i) { MEdge me; dm->getEdge(dm, i, &me); @@ -210,71 +208,72 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, BLI_ghash_size(edgeHash), numFaces); /* copy the vertices across */ - for(hashIter = BLI_ghashIterator_new(vertHash); - !BLI_ghashIterator_isDone(hashIter); - BLI_ghashIterator_step(hashIter)) { - MVert source; - MVert *dest; - int oldIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(hashIter)); - int newIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(hashIter)); - - dm->getVert(dm, oldIndex, &source); - dest = CDDM_get_vert(result, newIndex); - - DM_copy_vert_data(dm, result, oldIndex, newIndex, 1); - *dest = source; - } - BLI_ghashIterator_free(hashIter); - - /* copy the edges across, remapping indices */ - for(i = 0; i < BLI_ghash_size(edgeHash); ++i) { - MEdge source; - MEdge *dest; - int oldIndex = GET_INT_FROM_POINTER(BLI_ghash_lookup(edgeHash, SET_INT_IN_POINTER(i))); - - dm->getEdge(dm, oldIndex, &source); - dest = CDDM_get_edge(result, i); - - source.v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v1))); - source.v2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v2))); - - DM_copy_edge_data(dm, result, oldIndex, i, 1); - *dest = source; - } - - /* copy the faces across, remapping indices */ - for(i = 0; i < numFaces; ++i) { - MFace source; - MFace *dest; - int orig_v4; - - dm->getFace(dm, faceMap[i], &source); - dest = CDDM_get_face(result, i); - - orig_v4 = source.v4; - - source.v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v1))); - source.v2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v2))); - source.v3 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v3))); - if(source.v4) - source.v4 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v4))); - - DM_copy_face_data(dm, result, faceMap[i], i, 1); - *dest = source; - - test_index_face(dest, &result->faceData, i, (orig_v4 ? 4 : 3)); - } - - CDDM_calc_normals(result); - - BLI_ghash_free(vertHash, NULL, NULL); - BLI_ghash_free(edgeHash, NULL, NULL); + for( hashIter = BLI_ghashIterator_new(vertHash); + !BLI_ghashIterator_isDone(hashIter); + BLI_ghashIterator_step(hashIter) + ) { + MVert source; + MVert *dest; + int oldIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(hashIter)); + int newIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(hashIter)); + + dm->getVert(dm, oldIndex, &source); + dest = CDDM_get_vert(result, newIndex); + + DM_copy_vert_data(dm, result, oldIndex, newIndex, 1); + *dest = source; + } + BLI_ghashIterator_free(hashIter); + + /* copy the edges across, remapping indices */ + for(i = 0; i < BLI_ghash_size(edgeHash); ++i) { + MEdge source; + MEdge *dest; + int oldIndex = GET_INT_FROM_POINTER(BLI_ghash_lookup(edgeHash, SET_INT_IN_POINTER(i))); + + dm->getEdge(dm, oldIndex, &source); + dest = CDDM_get_edge(result, i); + + source.v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v1))); + source.v2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v2))); + + DM_copy_edge_data(dm, result, oldIndex, i, 1); + *dest = source; + } - MEM_freeN(vertMap); - MEM_freeN(edgeMap); - MEM_freeN(faceMap); + /* copy the faces across, remapping indices */ + for(i = 0; i < numFaces; ++i) { + MFace source; + MFace *dest; + int orig_v4; + + dm->getFace(dm, faceMap[i], &source); + dest = CDDM_get_face(result, i); + + orig_v4 = source.v4; + + source.v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v1))); + source.v2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v2))); + source.v3 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v3))); + if(source.v4) + source.v4 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v4))); + + DM_copy_face_data(dm, result, faceMap[i], i, 1); + *dest = source; + + test_index_face(dest, &result->faceData, i, (orig_v4 ? 4 : 3)); + } - return result; + CDDM_calc_normals(result); + + BLI_ghash_free(vertHash, NULL, NULL); + BLI_ghash_free(edgeHash, NULL, NULL); + + MEM_freeN(vertMap); + MEM_freeN(edgeMap); + MEM_freeN(faceMap); + + return result; } @@ -286,19 +285,19 @@ ModifierTypeInfo modifierType_Build = { /* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_AcceptsCVs, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, - /* applyModifierEM */ 0, + /* applyModifierEM */ NULL, /* initData */ initData, - /* requiredDataMask */ 0, - /* freeData */ 0, - /* isDisabled */ 0, - /* updateDepgraph */ 0, + /* requiredDataMask */ NULL, + /* freeData */ NULL, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, /* dependsOnTime */ dependsOnTime, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL }; diff --git a/source/blender/modifiers/intern/MOD_cast.c b/source/blender/modifiers/intern/MOD_cast.c index 17c2ec40b7e..5cb352ef482 100644 --- a/source/blender/modifiers/intern/MOD_cast.c +++ b/source/blender/modifiers/intern/MOD_cast.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_cast.c + * \ingroup modifiers + */ + + #include "DNA_meshdata_types.h" #include "DNA_object_types.h" @@ -422,9 +427,9 @@ static void cuboid_do( } if (has_radius) { - if (fabs(tmp_co[0]) > cmd->radius || - fabs(tmp_co[1]) > cmd->radius || - fabs(tmp_co[2]) > cmd->radius) continue; + if (fabsf(tmp_co[0]) > cmd->radius || + fabsf(tmp_co[1]) > cmd->radius || + fabsf(tmp_co[2]) > cmd->radius) continue; } for (j = 0; j < dvert[i].totweight; ++j) { @@ -474,7 +479,7 @@ static void cuboid_do( /* ok, now we know which coordinate of the vertex to use */ - if (fabs(tmp_co[coord]) < FLT_EPSILON) /* avoid division by zero */ + if (fabsf(tmp_co[coord]) < FLT_EPSILON) /* avoid division by zero */ continue; /* finally, this is the factor we wanted, to project the vertex @@ -518,9 +523,9 @@ static void cuboid_do( } if (has_radius) { - if (fabs(tmp_co[0]) > cmd->radius || - fabs(tmp_co[1]) > cmd->radius || - fabs(tmp_co[2]) > cmd->radius) continue; + if (fabsf(tmp_co[0]) > cmd->radius || + fabsf(tmp_co[1]) > cmd->radius || + fabsf(tmp_co[2]) > cmd->radius) continue; } octant = 0; @@ -545,7 +550,7 @@ static void cuboid_do( coord = 2; } - if (fabs(tmp_co[coord]) < FLT_EPSILON) + if (fabsf(tmp_co[coord]) < FLT_EPSILON) continue; fbb = apex[coord] / tmp_co[coord]; @@ -619,18 +624,18 @@ ModifierTypeInfo modifierType_Cast = { /* copyData */ copyData, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, + /* deformMatrices */ NULL, /* deformVertsEM */ deformVertsEM, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, + /* freeData */ NULL, /* isDisabled */ isDisabled, /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c index 1cb46c0992f..30ddb3f7b9c 100644 --- a/source/blender/modifiers/intern/MOD_cloth.c +++ b/source/blender/modifiers/intern/MOD_cloth.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_cloth.c + * \ingroup modifiers + */ + + #include "DNA_cloth_types.h" #include "DNA_scene_types.h" #include "DNA_object_types.h" @@ -47,6 +52,7 @@ #include "depsgraph_private.h" +#include "MOD_util.h" static void initData(ModifierData *md) { @@ -195,19 +201,19 @@ ModifierTypeInfo modifierType_Cloth = { | eModifierTypeFlag_Single, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, - /* applyModifierEM */ 0, + /* applyModifierEM */ NULL, /* initData */ initData, /* requiredDataMask */ requiredDataMask, /* freeData */ freeData, - /* isDisabled */ 0, + /* isDisabled */ NULL, /* updateDepgraph */ updateDepgraph, /* dependsOnTime */ dependsOnTime, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c index 8decb460d6a..83ba8a12163 100644 --- a/source/blender/modifiers/intern/MOD_collision.c +++ b/source/blender/modifiers/intern/MOD_collision.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_collision.c + * \ingroup modifiers + */ + + #include "DNA_scene_types.h" #include "DNA_object_types.h" #include "DNA_meshdata_types.h" @@ -48,6 +53,7 @@ #include "BKE_pointcache.h" #include "BKE_scene.h" +#include "MOD_util.h" static void initData(ModifierData *md) { @@ -58,7 +64,7 @@ static void initData(ModifierData *md) collmd->current_x = NULL; collmd->current_xnew = NULL; collmd->current_v = NULL; - collmd->time = -1000; + collmd->time_x = collmd->time_xnew = -1000; collmd->numverts = 0; collmd->bvhtree = NULL; } @@ -89,7 +95,7 @@ static void freeData(ModifierData *md) collmd->current_x = NULL; collmd->current_xnew = NULL; collmd->current_v = NULL; - collmd->time = -1000; + collmd->time_x = collmd->time_xnew = -1000; collmd->numverts = 0; collmd->bvhtree = NULL; collmd->mfaces = NULL; @@ -110,8 +116,6 @@ static void deformVerts(ModifierData *md, Object *ob, { CollisionModifierData *collmd = (CollisionModifierData*) md; DerivedMesh *dm = NULL; - float current_time = 0; - unsigned int numverts = 0, i = 0; MVert *tempVert = NULL; /* if possible use/create DerivedMesh */ @@ -126,23 +130,28 @@ static void deformVerts(ModifierData *md, Object *ob, if(dm) { + float current_time = 0; + unsigned int numverts = 0; + CDDM_apply_vert_coords(dm, vertexCos); CDDM_calc_normals(dm); current_time = BKE_curframe(md->scene); if(G.rt > 0) - printf("current_time %f, collmd->time %f\n", current_time, collmd->time); + printf("current_time %f, collmd->time_xnew %f\n", current_time, collmd->time_xnew); numverts = dm->getNumVerts ( dm ); - if((current_time > collmd->time)|| (BKE_ptcache_get_continue_physics())) - { + if((current_time > collmd->time_xnew)|| (BKE_ptcache_get_continue_physics())) + { + unsigned int i; + // check if mesh has changed if(collmd->x && (numverts != collmd->numverts)) freeData((ModifierData *)collmd); - if(collmd->time == -1000) // first time + if(collmd->time_xnew == -1000) // first time { collmd->x = dm->dupVertArray(dm); // frame start position @@ -165,7 +174,7 @@ static void deformVerts(ModifierData *md, Object *ob, // create bounding box hierarchy collmd->bvhtree = bvhtree_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->x, numverts, ob->pd->pdef_sboft); - collmd->time = current_time; + collmd->time_x = collmd->time_xnew = current_time; } else if(numverts == collmd->numverts) { @@ -173,6 +182,7 @@ static void deformVerts(ModifierData *md, Object *ob, tempVert = collmd->x; collmd->x = collmd->xnew; collmd->xnew = tempVert; + collmd->time_x = collmd->time_xnew; memcpy(collmd->xnew, dm->getVertArray(dm), numverts*sizeof(MVert)); @@ -207,7 +217,7 @@ static void deformVerts(ModifierData *md, Object *ob, bvhtree_update_from_mvert ( collmd->bvhtree, collmd->mfaces, collmd->numfaces, collmd->current_x, collmd->current_xnew, collmd->numverts, 1 ); } - collmd->time = current_time; + collmd->time_xnew = current_time; } else if(numverts != collmd->numverts) { @@ -215,7 +225,7 @@ static void deformVerts(ModifierData *md, Object *ob, } } - else if(current_time < collmd->time) + else if(current_time < collmd->time_xnew) { freeData((ModifierData *)collmd); } @@ -241,20 +251,20 @@ ModifierTypeInfo modifierType_Collision = { /* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_Single, - /* copyData */ 0, + /* copyData */ NULL, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, - /* requiredDataMask */ 0, + /* requiredDataMask */ NULL, /* freeData */ freeData, - /* isDisabled */ 0, - /* updateDepgraph */ 0, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, /* dependsOnTime */ dependsOnTime, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_curve.c b/source/blender/modifiers/intern/MOD_curve.c index c4e41941acc..ecd10250c00 100644 --- a/source/blender/modifiers/intern/MOD_curve.c +++ b/source/blender/modifiers/intern/MOD_curve.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_curve.c + * \ingroup modifiers + */ + + #include <string.h> #include "DNA_scene_types.h" @@ -44,6 +49,7 @@ #include "depsgraph_private.h" +#include "MOD_util.h" static void initData(ModifierData *md) { @@ -142,18 +148,18 @@ ModifierTypeInfo modifierType_Curve = { /* copyData */ copyData, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, + /* deformMatrices */ NULL, /* deformVertsEM */ deformVertsEM, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, + /* freeData */ NULL, /* isDisabled */ isDisabled, /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c index 2f1723cf9bb..ba9dbfc31ad 100644 --- a/source/blender/modifiers/intern/MOD_decimate.c +++ b/source/blender/modifiers/intern/MOD_decimate.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_decimate.c + * \ingroup modifiers + */ + + #include "DNA_meshdata_types.h" #include "BLI_math.h" @@ -47,6 +52,8 @@ #include "LOD_decimation.h" #endif +#include "MOD_util.h" + static void initData(ModifierData *md) { DecimateModifierData *dmd = (DecimateModifierData*) md; @@ -196,19 +203,19 @@ ModifierTypeInfo modifierType_Decimate = { /* type */ eModifierTypeType_Nonconstructive, /* flags */ eModifierTypeFlag_AcceptsMesh, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, - /* applyModifierEM */ 0, + /* applyModifierEM */ NULL, /* initData */ initData, - /* requiredDataMask */ 0, - /* freeData */ 0, - /* isDisabled */ 0, - /* updateDepgraph */ 0, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* requiredDataMask */ NULL, + /* freeData */ NULL, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c index 919814edf59..3288c1b5da1 100644 --- a/source/blender/modifiers/intern/MOD_displace.c +++ b/source/blender/modifiers/intern/MOD_displace.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_displace.c + * \ingroup modifiers + */ + + #include "DNA_meshdata_types.h" #include "DNA_object_types.h" @@ -157,92 +162,6 @@ static void updateDepgraph(ModifierData *md, DagForest *forest, } -static void get_texture_coords(DisplaceModifierData *dmd, Object *ob, - DerivedMesh *dm, - float (*co)[3], float (*texco)[3], - int numVerts) -{ - int i; - int texmapping = dmd->texmapping; - float mapob_imat[4][4]; - - if(texmapping == MOD_DISP_MAP_OBJECT) { - if(dmd->map_object) - invert_m4_m4(mapob_imat, dmd->map_object->obmat); - else /* if there is no map object, default to local */ - texmapping = MOD_DISP_MAP_LOCAL; - } - - /* UVs need special handling, since they come from faces */ - if(texmapping == MOD_DISP_MAP_UV) { - if(CustomData_has_layer(&dm->faceData, CD_MTFACE)) { - MFace *mface = dm->getFaceArray(dm); - MFace *mf; - char *done = MEM_callocN(sizeof(*done) * numVerts, - "get_texture_coords done"); - int numFaces = dm->getNumFaces(dm); - char uvname[32]; - MTFace *tf; - - validate_layer_name(&dm->faceData, CD_MTFACE, dmd->uvlayer_name, uvname); - tf = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, uvname); - - /* verts are given the UV from the first face that uses them */ - for(i = 0, mf = mface; i < numFaces; ++i, ++mf, ++tf) { - if(!done[mf->v1]) { - texco[mf->v1][0] = tf->uv[0][0]; - texco[mf->v1][1] = tf->uv[0][1]; - texco[mf->v1][2] = 0; - done[mf->v1] = 1; - } - if(!done[mf->v2]) { - texco[mf->v2][0] = tf->uv[1][0]; - texco[mf->v2][1] = tf->uv[1][1]; - texco[mf->v2][2] = 0; - done[mf->v2] = 1; - } - if(!done[mf->v3]) { - texco[mf->v3][0] = tf->uv[2][0]; - texco[mf->v3][1] = tf->uv[2][1]; - texco[mf->v3][2] = 0; - done[mf->v3] = 1; - } - if(!done[mf->v4]) { - texco[mf->v4][0] = tf->uv[3][0]; - texco[mf->v4][1] = tf->uv[3][1]; - texco[mf->v4][2] = 0; - done[mf->v4] = 1; - } - } - - /* remap UVs from [0, 1] to [-1, 1] */ - for(i = 0; i < numVerts; ++i) { - texco[i][0] = texco[i][0] * 2 - 1; - texco[i][1] = texco[i][1] * 2 - 1; - } - - MEM_freeN(done); - return; - } else /* if there are no UVs, default to local */ - texmapping = MOD_DISP_MAP_LOCAL; - } - - for(i = 0; i < numVerts; ++i, ++co, ++texco) { - switch(texmapping) { - case MOD_DISP_MAP_LOCAL: - copy_v3_v3(*texco, *co); - break; - case MOD_DISP_MAP_GLOBAL: - mul_v3_m4v3(*texco, ob->obmat, *co); - break; - case MOD_DISP_MAP_OBJECT: - mul_v3_m4v3(*texco, ob->obmat, *co); - mul_m4_v3(mapob_imat, *texco); - break; - } - } -} - /* dm must be a CDDerivedMesh */ static void displaceModifier_do( DisplaceModifierData *dmd, Object *ob, @@ -255,6 +174,7 @@ static void displaceModifier_do( float (*tex_co)[3]; if(!dmd->texture) return; + if(dmd->strength == 0.0f) return; defgrp_index = defgroup_name_index(ob, dmd->defgrp_name); @@ -264,7 +184,7 @@ static void displaceModifier_do( tex_co = MEM_callocN(sizeof(*tex_co) * numVerts, "displaceModifier_do tex_co"); - get_texture_coords(dmd, ob, dm, vertexCos, tex_co, numVerts); + get_texture_coords((MappingInfoModifierData *)dmd, ob, dm, vertexCos, tex_co, numVerts); for(i = 0; i < numVerts; ++i) { TexResult texres; @@ -279,7 +199,7 @@ static void displaceModifier_do( break; } } - if(!def_weight) continue; + if(!def_weight || def_weight->weight==0.0f) continue; } texres.nor = NULL; @@ -357,14 +277,14 @@ ModifierTypeInfo modifierType_Displace = { /* copyData */ copyData, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, + /* deformMatrices */ NULL, /* deformVertsEM */ deformVertsEM, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, + /* freeData */ NULL, /* isDisabled */ isDisabled, /* updateDepgraph */ updateDepgraph, /* dependsOnTime */ dependsOnTime, diff --git a/source/blender/modifiers/intern/MOD_edgesplit.c b/source/blender/modifiers/intern/MOD_edgesplit.c index 56138552000..8d0aea41b5c 100644 --- a/source/blender/modifiers/intern/MOD_edgesplit.c +++ b/source/blender/modifiers/intern/MOD_edgesplit.c @@ -30,9 +30,16 @@ * */ +/** \file blender/modifiers/intern/MOD_edgesplit.c + * \ingroup modifiers + */ + + /* EdgeSplit modifier: Splits edges in the mesh according to sharpness flag * or edge angle (can be used to achieve autosmoothing) */ +#include <assert.h> + #include "DNA_meshdata_types.h" #include "BLI_listbase.h" @@ -48,6 +55,7 @@ #include "MEM_guardedalloc.h" +#include "MOD_util.h" #if 0 #define EDGESPLIT_DEBUG_3 @@ -119,6 +127,8 @@ static SmoothVert *smoothvert_copy(SmoothVert *vert, SmoothMesh *mesh) { SmoothVert *copy = &mesh->verts[mesh->num_verts]; + assert(vert != NULL); + if(mesh->num_verts >= mesh->max_verts) { printf("Attempted to add a SmoothMesh vert beyond end of array\n"); return NULL; @@ -169,11 +179,11 @@ static SmoothMesh *smoothmesh_new(int num_verts, int num_edges, int num_faces, { SmoothMesh *mesh = MEM_callocN(sizeof(*mesh), "smoothmesh"); mesh->verts = MEM_callocN(sizeof(*mesh->verts) * max_verts, - "SmoothMesh.verts"); + "SmoothMesh.verts"); mesh->edges = MEM_callocN(sizeof(*mesh->edges) * max_edges, - "SmoothMesh.edges"); + "SmoothMesh.edges"); mesh->faces = MEM_callocN(sizeof(*mesh->faces) * max_faces, - "SmoothMesh.faces"); + "SmoothMesh.faces"); mesh->num_verts = num_verts; mesh->num_edges = num_edges; @@ -274,8 +284,8 @@ static void smoothmesh_print(SmoothMesh *mesh) dm->getVert(dm, vert->oldIndex, &mv); printf("%3d: ind={%3d, %3d}, pos={% 5.1f, % 5.1f, % 5.1f}", - i, vert->oldIndex, vert->newIndex, - mv.co[0], mv.co[1], mv.co[2]); + i, vert->oldIndex, vert->newIndex, + mv.co[0], mv.co[1], mv.co[2]); printf(", faces={"); for(node = vert->faces; node != NULL; node = node->next) { printf(" %d", ((SmoothFace *)node->link)->newIndex); @@ -289,9 +299,9 @@ static void smoothmesh_print(SmoothMesh *mesh) LinkNode *node; printf("%4d: indices={%4d, %4d}, verts={%4d, %4d}", - i, - edge->oldIndex, edge->newIndex, - edge->verts[0]->newIndex, edge->verts[1]->newIndex); + i, + edge->oldIndex, edge->newIndex, + edge->verts[0]->newIndex, edge->verts[1]->newIndex); if(edge->verts[0] == edge->verts[1]) printf(" <- DUPLICATE VERTEX"); printf(", faces={"); for(node = edge->faces; node != NULL; node = node->next) { @@ -305,7 +315,7 @@ static void smoothmesh_print(SmoothMesh *mesh) SmoothFace *face = &mesh->faces[i]; printf("%4d: indices={%4d, %4d}, edges={", i, - face->oldIndex, face->newIndex); + face->oldIndex, face->newIndex); for(j = 0; j < SMOOTHFACE_MAX_EDGES && face->edges[j]; j++) { if(face->flip[j]) printf(" -%-2d", face->edges[j]->newIndex); @@ -333,7 +343,7 @@ static SmoothMesh *smoothmesh_from_derivedmesh(DerivedMesh *dm) totface = dm->getNumFaces(dm); mesh = smoothmesh_new(totvert, totedge, totface, - totvert, totedge, totface); + totvert, totedge, totface); mesh->dm = dm; @@ -404,8 +414,8 @@ static DerivedMesh *CDDM_from_smoothmesh(SmoothMesh *mesh) { DerivedMesh *result = CDDM_from_template(mesh->dm, mesh->num_verts, - mesh->num_edges, - mesh->num_faces); + mesh->num_edges, + mesh->num_faces); MVert *new_verts = CDDM_get_verts(result); MEdge *new_edges = CDDM_get_edges(result); MFace *new_faces = CDDM_get_faces(result); @@ -416,7 +426,7 @@ static DerivedMesh *CDDM_from_smoothmesh(SmoothMesh *mesh) MVert *newMV = &new_verts[vert->newIndex]; DM_copy_vert_data(mesh->dm, result, - vert->oldIndex, vert->newIndex, 1); + vert->oldIndex, vert->newIndex, 1); mesh->dm->getVert(mesh->dm, vert->oldIndex, newMV); } @@ -425,7 +435,7 @@ static DerivedMesh *CDDM_from_smoothmesh(SmoothMesh *mesh) MEdge *newME = &new_edges[edge->newIndex]; DM_copy_edge_data(mesh->dm, result, - edge->oldIndex, edge->newIndex, 1); + edge->oldIndex, edge->newIndex, 1); mesh->dm->getEdge(mesh->dm, edge->oldIndex, newME); newME->v1 = edge->verts[0]->newIndex; newME->v2 = edge->verts[1]->newIndex; @@ -436,7 +446,7 @@ static DerivedMesh *CDDM_from_smoothmesh(SmoothMesh *mesh) MFace *newMF = &new_faces[face->newIndex]; DM_copy_face_data(mesh->dm, result, - face->oldIndex, face->newIndex, 1); + face->oldIndex, face->newIndex, 1); mesh->dm->getFace(mesh->dm, face->oldIndex, newMF); newMF->v1 = face->edges[0]->verts[face->flip[0]]->newIndex; @@ -508,18 +518,18 @@ static void linklist_copy(LinkNode **target, LinkNode *source) for(; source; source = source->next) { if(node) { node->next = MEM_mallocN(sizeof(*node->next), "nlink_copy"); - node = node->next; -} else { - node = *target = MEM_mallocN(sizeof(**target), "nlink_copy"); -} - node->link = source->link; - node->next = NULL; -} + node = node->next; + } else { + node = *target = MEM_mallocN(sizeof(**target), "nlink_copy"); + } + node->link = source->link; + node->next = NULL; + } } #endif - /* appends source to target if it's not already in target */ - static void linklist_append_unique(LinkNode **target, void *source) +/* appends source to target if it's not already in target */ +static void linklist_append_unique(LinkNode **target, void *source) { LinkNode *node; LinkNode *prev = NULL; @@ -553,7 +563,7 @@ static void linklist_prepend_linklist(LinkNode **list, LinkNode *prepend) node->next = *list; *list = prepend; -} + } } #endif @@ -660,7 +670,7 @@ static void edge_replace_vert(void *ptr, void *userdata) #ifdef EDGESPLIT_DEBUG_3 printf("replacing vert %4d with %4d in edge %4d", - find->newIndex, replace->newIndex, edge->newIndex); + find->newIndex, replace->newIndex, edge->newIndex); printf(": {%4d, %4d}", edge->verts[0]->newIndex, edge->verts[1]->newIndex); #endif @@ -696,15 +706,15 @@ static void face_replace_edge(void *ptr, void *userdata) #ifdef EDGESPLIT_DEBUG_3 printf("replacing edge %4d with %4d in face %4d", - find->newIndex, replace->newIndex, face->newIndex); + find->newIndex, replace->newIndex, face->newIndex); if(face->edges[3]) printf(": {%2d %2d %2d %2d}", - face->edges[0]->newIndex, face->edges[1]->newIndex, - face->edges[2]->newIndex, face->edges[3]->newIndex); + face->edges[0]->newIndex, face->edges[1]->newIndex, + face->edges[2]->newIndex, face->edges[3]->newIndex); else printf(": {%2d %2d %2d}", - face->edges[0]->newIndex, face->edges[1]->newIndex, - face->edges[2]->newIndex); + face->edges[0]->newIndex, face->edges[1]->newIndex, + face->edges[2]->newIndex); #endif for(i = 0; i < SMOOTHFACE_MAX_EDGES && face->edges[i]; i++) { @@ -718,12 +728,12 @@ static void face_replace_edge(void *ptr, void *userdata) #ifdef EDGESPLIT_DEBUG_3 if(face->edges[3]) printf(" -> {%2d %2d %2d %2d}\n", - face->edges[0]->newIndex, face->edges[1]->newIndex, - face->edges[2]->newIndex, face->edges[3]->newIndex); + face->edges[0]->newIndex, face->edges[1]->newIndex, + face->edges[2]->newIndex, face->edges[3]->newIndex); else printf(" -> {%2d %2d %2d}\n", - face->edges[0]->newIndex, face->edges[1]->newIndex, - face->edges[2]->newIndex); + face->edges[0]->newIndex, face->edges[1]->newIndex, + face->edges[2]->newIndex); #endif } @@ -770,7 +780,7 @@ static SmoothEdge *find_other_sharp_edge(SmoothVert *vert, SmoothEdge *edge, Lin LinkNode *visited_edges = NULL; #ifdef EDGESPLIT_DEBUG_1 printf("=== START === find_other_sharp_edge(edge = %4d, vert = %4d)\n", - edge->newIndex, vert->newIndex); + edge->newIndex, vert->newIndex); #endif /* get a face on which to start */ @@ -794,7 +804,7 @@ static SmoothEdge *find_other_sharp_edge(SmoothVert *vert, SmoothEdge *edge, Lin && !linklist_contains(visited_edges, edge2)) { #ifdef EDGESPLIT_DEBUG_3 printf("current face %4d; current edge %4d\n", face->newIndex, - edge2->newIndex); + edge2->newIndex); #endif /* get the next face */ face = other_face(edge2, face); @@ -812,26 +822,26 @@ static SmoothEdge *find_other_sharp_edge(SmoothVert *vert, SmoothEdge *edge, Lin edge2 = other_edge(face, vert, edge2); #ifdef EDGESPLIT_DEBUG_3 printf("next face %4d; next edge %4d\n", - face->newIndex, edge2->newIndex); + face->newIndex, edge2->newIndex); } else { printf("loose edge: %4d\n", edge2->newIndex); #endif } - } + } - /* either we came back to the start edge or we found a sharp/loose edge */ - if(linklist_contains(visited_edges, edge2)) - /* we came back to the start edge */ - edge2 = NULL; + /* either we came back to the start edge or we found a sharp/loose edge */ + if(linklist_contains(visited_edges, edge2)) + /* we came back to the start edge */ + edge2 = NULL; - BLI_linklist_free(visited_edges, NULL); + BLI_linklist_free(visited_edges, NULL); #ifdef EDGESPLIT_DEBUG_1 - printf("=== END === find_other_sharp_edge(edge = %4d, vert = %4d), " - "returning edge %d\n", - edge->newIndex, vert->newIndex, edge2 ? edge2->newIndex : -1); + printf("=== END === find_other_sharp_edge(edge = %4d, vert = %4d), " + "returning edge %d\n", + edge->newIndex, vert->newIndex, edge2 ? edge2->newIndex : -1); #endif - return edge2; + return edge2; } static void split_single_vert(SmoothVert *vert, SmoothFace *face, @@ -842,6 +852,12 @@ static void split_single_vert(SmoothVert *vert, SmoothFace *face, copy_vert = smoothvert_copy(vert, mesh); + if(copy_vert == NULL) { + /* bug [#26316], this prevents a segfault + * but this still needs fixing */ + return; + } + repdata.find = vert; repdata.replace = copy_vert; face_replace_vert(face, &repdata); @@ -899,7 +915,7 @@ static void propagate_split(SmoothEdge *edge, SmoothVert *vert, LinkNode *visited_faces = NULL; #ifdef EDGESPLIT_DEBUG_1 printf("=== START === propagate_split(edge = %4d, vert = %4d)\n", - edge->newIndex, vert->newIndex); + edge->newIndex, vert->newIndex); #endif edge2 = find_other_sharp_edge(vert, edge, &visited_faces); @@ -930,10 +946,13 @@ static void propagate_split(SmoothEdge *edge, SmoothVert *vert, /* vert has more than one fan of faces attached; split it */ vert2 = smoothvert_copy(vert, mesh); - /* replace vert with its copy in visited_faces */ - repdata.find = vert; - repdata.replace = vert2; - BLI_linklist_apply(visited_faces, face_replace_vert, &repdata); + /* fails in rare cases, see [#26993] */ + if(vert2) { + /* replace vert with its copy in visited_faces */ + repdata.find = vert; + repdata.replace = vert2; + BLI_linklist_apply(visited_faces, face_replace_vert, &repdata); + } } } else { /* edge is not loose, so it must be sharp; split it */ @@ -944,7 +963,7 @@ static void propagate_split(SmoothEdge *edge, SmoothVert *vert, BLI_linklist_free(visited_faces, NULL); #ifdef EDGESPLIT_DEBUG_1 printf("=== END === propagate_split(edge = %4d, vert = %4d)\n", - edge->newIndex, vert->newIndex); + edge->newIndex, vert->newIndex); #endif } @@ -957,7 +976,7 @@ static void split_edge(SmoothEdge *edge, SmoothVert *vert, SmoothMesh *mesh) LinkNode *visited_faces = NULL; #ifdef EDGESPLIT_DEBUG_1 printf("=== START === split_edge(edge = %4d, vert = %4d)\n", - edge->newIndex, vert->newIndex); + edge->newIndex, vert->newIndex); #endif edge2 = find_other_sharp_edge(vert, edge, &visited_faces); @@ -1030,7 +1049,7 @@ static void split_edge(SmoothEdge *edge, SmoothVert *vert, SmoothMesh *mesh) BLI_linklist_free(visited_faces, NULL); #ifdef EDGESPLIT_DEBUG_1 printf("=== END === split_edge(edge = %4d, vert = %4d)\n", - edge->newIndex, vert->newIndex); + edge->newIndex, vert->newIndex); #endif } @@ -1040,7 +1059,7 @@ static void tag_and_count_extra_edges(SmoothMesh *mesh, float split_angle, /* if normal1 dot normal2 < threshold, angle is greater, so split */ /* FIXME not sure if this always works */ /* 0.00001 added for floating-point rounding */ - float threshold = cos((split_angle + 0.00001) * M_PI / 180.0); + float threshold = cos((split_angle + 0.00001f) * (float)M_PI / 180.0f); int i; *extra_edges = 0; @@ -1066,31 +1085,31 @@ static void tag_and_count_extra_edges(SmoothMesh *mesh, float split_angle, /* (the edge can only be sharp if we're checking angle or flag, * and it has at least 2 faces) */ - /* if we're checking the sharp flag and it's set, good */ - if((flags & MOD_EDGESPLIT_FROMFLAG) && (edge->flag & ME_SHARP)) { - /* this edge is sharp */ - sharp = 1; - - (*extra_edges)++; - } else if(flags & MOD_EDGESPLIT_FROMANGLE) { - /* we know the edge has 2 faces, so check the angle */ - SmoothFace *face1 = edge->faces->link; - SmoothFace *face2 = edge->faces->next->link; - float edge_angle_cos = dot_v3v3(face1->normal, - face2->normal); - - if(edge_angle_cos < threshold) { - /* this edge is sharp */ - sharp = 1; - - (*extra_edges)++; - } - } - } + /* if we're checking the sharp flag and it's set, good */ + if((flags & MOD_EDGESPLIT_FROMFLAG) && (edge->flag & ME_SHARP)) { + /* this edge is sharp */ + sharp = 1; + + (*extra_edges)++; + } else if(flags & MOD_EDGESPLIT_FROMANGLE) { + /* we know the edge has 2 faces, so check the angle */ + SmoothFace *face1 = edge->faces->link; + SmoothFace *face2 = edge->faces->next->link; + float edge_angle_cos = dot_v3v3(face1->normal, + face2->normal); + + if(edge_angle_cos < threshold) { + /* this edge is sharp */ + sharp = 1; + + (*extra_edges)++; + } + } + } - /* set/clear sharp flag appropriately */ - if(sharp) edge->flag |= ME_SHARP; - else edge->flag &= ~ME_SHARP; + /* set/clear sharp flag appropriately */ + if(sharp) edge->flag |= ME_SHARP; + else edge->flag &= ~ME_SHARP; } } @@ -1101,7 +1120,7 @@ static void split_sharp_edges(SmoothMesh *mesh, float split_angle, int flags) /* if normal1 dot normal2 < threshold, angle is greater, so split */ /* FIXME not sure if this always works */ /* 0.00001 added for floating-point rounding */ - mesh->threshold = cos((split_angle + 0.00001) * M_PI / 180.0); + mesh->threshold = cosf((split_angle + 0.00001f) * (float)M_PI / 180.0f); mesh->flags = flags; /* loop through edges, splitting sharp ones */ @@ -1231,8 +1250,8 @@ static DerivedMesh *edgesplitModifier_do(EdgeSplitModifierData *emd, DerivedMesh #ifdef EDGESPLIT_DEBUG_0 printf("Edgesplit: Estimated %d verts & %d edges, " - "found %d verts & %d edges\n", max_verts, max_edges, - mesh->num_verts, mesh->num_edges); + "found %d verts & %d edges\n", max_verts, max_edges, + mesh->num_verts, mesh->num_edges); #endif result = CDDM_from_smoothmesh(mesh); @@ -1277,19 +1296,19 @@ ModifierTypeInfo modifierType_EdgeSplit = { | eModifierTypeFlag_EnableInEditmode, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, /* applyModifierEM */ applyModifierEM, /* initData */ initData, - /* requiredDataMask */ 0, - /* freeData */ 0, - /* isDisabled */ 0, - /* updateDepgraph */ 0, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* requiredDataMask */ NULL, + /* freeData */ NULL, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c index a0765b56808..f1bc0d33fd8 100644 --- a/source/blender/modifiers/intern/MOD_explode.c +++ b/source/blender/modifiers/intern/MOD_explode.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_explode.c + * \ingroup modifiers + */ + + #include "DNA_meshdata_types.h" #include "DNA_scene_types.h" @@ -51,12 +56,13 @@ #include "MEM_guardedalloc.h" +#include "MOD_util.h" static void initData(ModifierData *md) { ExplodeModifierData *emd= (ExplodeModifierData*) md; - emd->facepa=0; + emd->facepa= NULL; emd->flag |= eExplodeFlag_Unborn+eExplodeFlag_Alive+eExplodeFlag_Dead; } static void freeData(ModifierData *md) @@ -70,7 +76,7 @@ static void copyData(ModifierData *md, ModifierData *target) ExplodeModifierData *emd= (ExplodeModifierData*) md; ExplodeModifierData *temd= (ExplodeModifierData*) target; - temd->facepa = 0; + temd->facepa = NULL; temd->flag = emd->flag; temd->protect = emd->protect; temd->vgroup = emd->vgroup; @@ -95,12 +101,12 @@ static void createFacepa(ExplodeModifierData *emd, DerivedMesh *dm) { ParticleSystem *psys=psmd->psys; - MFace *fa=0, *mface=0; - MVert *mvert = 0; + MFace *fa=NULL, *mface=NULL; + MVert *mvert = NULL; ParticleData *pa; KDTree *tree; float center[3], co[3]; - int *facepa=0,*vertpa=0,totvert=0,totface=0,totpart=0; + int *facepa=NULL,*vertpa=NULL,totvert=0,totface=0,totpart=0; int i,p,v1,v2,v3,v4=0; mvert = dm->getVertArray(dm); @@ -128,11 +134,10 @@ static void createFacepa(ExplodeModifierData *emd, /* set protected verts */ if(emd->vgroup){ MDeformVert *dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); - float val; if(dvert){ - int defgrp_index= emd->vgroup-1; + const int defgrp_index= emd->vgroup-1; for(i=0; i<totvert; i++, dvert++){ - val = BLI_frand(); + float val = BLI_frand(); val = (1.0f-emd->protect)*val + emd->protect*0.5f; if(val < defvert_find_weight(dvert, defgrp_index)) vertpa[i] = -1; @@ -143,7 +148,7 @@ static void createFacepa(ExplodeModifierData *emd, /* make tree of emitter locations */ tree=BLI_kdtree_new(totpart); for(p=0,pa=psys->particles; p<totpart; p++,pa++){ - psys_particle_on_dm(psmd->dm,psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,0,0,0,0,0); + psys_particle_on_emitter(psmd,psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,NULL,NULL,NULL,NULL,NULL); BLI_kdtree_insert(tree, p, co, NULL); } BLI_kdtree_balance(tree); @@ -180,14 +185,367 @@ static void createFacepa(ExplodeModifierData *emd, BLI_kdtree_free(tree); } -static int edgesplit_get(EdgeHash *edgehash, int v1, int v2) +static int edgecut_get(EdgeHash *edgehash, int v1, int v2) { return GET_INT_FROM_POINTER(BLI_edgehash_lookup(edgehash, v1, v2)); } -static DerivedMesh * splitEdges(ExplodeModifierData *emd, DerivedMesh *dm){ + +static const short add_faces[24] = { + 0, + 0, 0, 2, 0, 1, 2, 2, 0, 2, 1, + 2, 2, 2, 2, 3, 0, 0, 0, 1, 0, + 1, 1, 2 + }; + +static MFace *get_dface(DerivedMesh *dm, DerivedMesh *split, int cur, int i, MFace *mf) +{ + MFace *df = CDDM_get_face(split, cur); + DM_copy_face_data(dm, split, i, cur, 1); + *df = *mf; + return df; +} + +#define SET_VERTS(a, b, c, d) \ + v[0]=mf->v##a; uv[0]=a-1; \ + v[1]=mf->v##b; uv[1]=b-1; \ + v[2]=mf->v##c; uv[2]=c-1; \ + v[3]=mf->v##d; uv[3]=d-1; + +#define GET_ES(v1, v2) edgecut_get(eh, v1, v2); +#define INT_UV(uvf, c0, c1) interp_v2_v2v2(uvf, mf->uv[c0], mf->uv[c1], 0.5f); + +static void remap_faces_3_6_9_12(DerivedMesh *dm, DerivedMesh *split, MFace *mf, int *facepa, int *vertpa, int i, EdgeHash *eh, int cur, int v1, int v2, int v3, int v4) +{ + MFace *df1 = get_dface(dm, split, cur, i, mf); + MFace *df2 = get_dface(dm, split, cur+1, i, mf); + MFace *df3 = get_dface(dm, split, cur+2, i, mf); + + facepa[cur] = vertpa[v1]; + df1->v1 = v1; + df1->v2 = GET_ES(v1, v2) + df1->v3 = GET_ES(v2, v3) + df1->v4 = v3; + df1->flag |= ME_FACE_SEL; + + facepa[cur+1] = vertpa[v2]; + df2->v1 = GET_ES(v1, v2) + df2->v2 = v2; + df2->v3 = GET_ES(v2, v3) + df2->v4 = 0; + df2->flag &= ~ME_FACE_SEL; + + facepa[cur+2] = vertpa[v1]; + df3->v1 = v1; + df3->v2 = v3; + df3->v3 = v4; + df3->v4 = 0; + df3->flag &= ~ME_FACE_SEL; +} + +static void remap_uvs_3_6_9_12(DerivedMesh *dm, DerivedMesh *split, int numlayer, int i, int cur, int c0, int c1, int c2, int c3) +{ + MTFace *mf, *df1, *df2, *df3; + int l; + + for(l=0; l<numlayer; l++) { + mf = CustomData_get_layer_n(&split->faceData, CD_MTFACE, l); + df1 = mf+cur; + df2 = df1 + 1; + df3 = df1 + 2; + mf = CustomData_get_layer_n(&dm->faceData, CD_MTFACE, l); + mf += i; + + copy_v2_v2(df1->uv[0], mf->uv[c0]); + INT_UV(df1->uv[1], c0, c1) + INT_UV(df1->uv[2], c1, c2) + copy_v2_v2(df1->uv[3], mf->uv[c2]); + + INT_UV(df2->uv[0], c0, c1) + copy_v2_v2(df2->uv[1], mf->uv[c1]); + INT_UV(df2->uv[2], c1, c2) + + copy_v2_v2(df3->uv[0], mf->uv[c0]); + copy_v2_v2(df3->uv[1], mf->uv[c2]); + copy_v2_v2(df3->uv[2], mf->uv[c3]); + } +} + +static void remap_faces_5_10(DerivedMesh *dm, DerivedMesh *split, MFace *mf, int *facepa, int *vertpa, int i, EdgeHash *eh, int cur, int v1, int v2, int v3, int v4) +{ + MFace *df1 = get_dface(dm, split, cur, i, mf); + MFace *df2 = get_dface(dm, split, cur+1, i, mf); + + facepa[cur] = vertpa[v1]; + df1->v1 = v1; + df1->v2 = v2; + df1->v3 = GET_ES(v2, v3) + df1->v4 = GET_ES(v1, v4) + df1->flag |= ME_FACE_SEL; + + facepa[cur+1] = vertpa[v3]; + df2->v1 = GET_ES(v1, v4) + df2->v2 = GET_ES(v2, v3) + df2->v3 = v3; + df2->v4 = v4; + df2->flag |= ME_FACE_SEL; +} + +static void remap_uvs_5_10(DerivedMesh *dm, DerivedMesh *split, int numlayer, int i, int cur, int c0, int c1, int c2, int c3) +{ + MTFace *mf, *df1, *df2; + int l; + + for(l=0; l<numlayer; l++) { + mf = CustomData_get_layer_n(&split->faceData, CD_MTFACE, l); + df1 = mf+cur; + df2 = df1 + 1; + mf = CustomData_get_layer_n(&dm->faceData, CD_MTFACE, l); + mf += i; + + copy_v2_v2(df1->uv[0], mf->uv[c0]); + copy_v2_v2(df1->uv[1], mf->uv[c1]); + INT_UV(df1->uv[2], c1, c2) + INT_UV(df1->uv[3], c0, c3) + + INT_UV(df2->uv[0], c0, c3) + INT_UV(df2->uv[1], c1, c2) + copy_v2_v2(df2->uv[2], mf->uv[c2]); + copy_v2_v2(df2->uv[3], mf->uv[c3]); + + } +} + +static void remap_faces_15(DerivedMesh *dm, DerivedMesh *split, MFace *mf, int *facepa, int *vertpa, int i, EdgeHash *eh, int cur, int v1, int v2, int v3, int v4) +{ + MFace *df1 = get_dface(dm, split, cur, i, mf); + MFace *df2 = get_dface(dm, split, cur+1, i, mf); + MFace *df3 = get_dface(dm, split, cur+2, i, mf); + MFace *df4 = get_dface(dm, split, cur+3, i, mf); + + facepa[cur] = vertpa[v1]; + df1->v1 = v1; + df1->v2 = GET_ES(v1, v2) + df1->v3 = GET_ES(v1, v3) + df1->v4 = GET_ES(v1, v4) + df1->flag |= ME_FACE_SEL; + + facepa[cur+1] = vertpa[v2]; + df2->v1 = GET_ES(v1, v2) + df2->v2 = v2; + df2->v3 = GET_ES(v2, v3) + df2->v4 = GET_ES(v1, v3) + df2->flag |= ME_FACE_SEL; + + facepa[cur+2] = vertpa[v3]; + df3->v1 = GET_ES(v1, v3) + df3->v2 = GET_ES(v2, v3) + df3->v3 = v3; + df3->v4 = GET_ES(v3, v4) + df3->flag |= ME_FACE_SEL; + + facepa[cur+3] = vertpa[v4]; + df4->v1 = GET_ES(v1, v4) + df4->v2 = GET_ES(v1, v3) + df4->v3 = GET_ES(v3, v4) + df4->v4 = v4; + df4->flag |= ME_FACE_SEL; +} + +static void remap_uvs_15(DerivedMesh *dm, DerivedMesh *split, int numlayer, int i, int cur, int c0, int c1, int c2, int c3) +{ + MTFace *mf, *df1, *df2, *df3, *df4; + int l; + + for(l=0; l<numlayer; l++) { + mf = CustomData_get_layer_n(&split->faceData, CD_MTFACE, l); + df1 = mf+cur; + df2 = df1 + 1; + df3 = df1 + 2; + df4 = df1 + 3; + mf = CustomData_get_layer_n(&dm->faceData, CD_MTFACE, l); + mf += i; + + copy_v2_v2(df1->uv[0], mf->uv[c0]); + INT_UV(df1->uv[1], c0, c1) + INT_UV(df1->uv[2], c0, c2) + INT_UV(df1->uv[3], c0, c3) + + INT_UV(df2->uv[0], c0, c1) + copy_v2_v2(df2->uv[1], mf->uv[c1]); + INT_UV(df2->uv[2], c1, c2) + INT_UV(df2->uv[3], c0, c2) + + INT_UV(df3->uv[0], c0, c2) + INT_UV(df3->uv[1], c1, c2) + copy_v2_v2(df3->uv[2], mf->uv[c2]); + INT_UV(df3->uv[3], c2, c3) + + INT_UV(df4->uv[0], c0, c3) + INT_UV(df4->uv[1], c0, c2) + INT_UV(df4->uv[2], c2, c3) + copy_v2_v2(df4->uv[3], mf->uv[c3]); + } +} + +static void remap_faces_7_11_13_14(DerivedMesh *dm, DerivedMesh *split, MFace *mf, int *facepa, int *vertpa, int i, EdgeHash *eh, int cur, int v1, int v2, int v3, int v4) +{ + MFace *df1 = get_dface(dm, split, cur, i, mf); + MFace *df2 = get_dface(dm, split, cur+1, i, mf); + MFace *df3 = get_dface(dm, split, cur+2, i, mf); + + facepa[cur] = vertpa[v1]; + df1->v1 = v1; + df1->v2 = GET_ES(v1, v2) + df1->v3 = GET_ES(v2, v3) + df1->v4 = GET_ES(v1, v4) + df1->flag |= ME_FACE_SEL; + + facepa[cur+1] = vertpa[v2]; + df2->v1 = GET_ES(v1, v2) + df2->v2 = v2; + df2->v3 = GET_ES(v2, v3) + df2->v4 = 0; + df2->flag &= ~ME_FACE_SEL; + + facepa[cur+2] = vertpa[v4]; + df3->v1 = GET_ES(v1, v4) + df3->v2 = GET_ES(v2, v3) + df3->v3 = v3; + df3->v4 = v4; + df3->flag |= ME_FACE_SEL; +} + +static void remap_uvs_7_11_13_14(DerivedMesh *dm, DerivedMesh *split, int numlayer, int i, int cur, int c0, int c1, int c2, int c3) +{ + MTFace *mf, *df1, *df2, *df3; + int l; + + for(l=0; l<numlayer; l++) { + mf = CustomData_get_layer_n(&split->faceData, CD_MTFACE, l); + df1 = mf+cur; + df2 = df1 + 1; + df3 = df1 + 2; + mf = CustomData_get_layer_n(&dm->faceData, CD_MTFACE, l); + mf += i; + + copy_v2_v2(df1->uv[0], mf->uv[c0]); + INT_UV(df1->uv[1], c0, c1) + INT_UV(df1->uv[2], c1, c2) + INT_UV(df1->uv[3], c0, c3) + + INT_UV(df2->uv[0], c0, c1) + copy_v2_v2(df2->uv[1], mf->uv[c1]); + INT_UV(df2->uv[2], c1, c2) + + INT_UV(df3->uv[0], c0, c3) + INT_UV(df3->uv[1], c1, c2) + copy_v2_v2(df3->uv[2], mf->uv[c2]); + copy_v2_v2(df3->uv[3], mf->uv[c3]); + } +} + +static void remap_faces_19_21_22(DerivedMesh *dm, DerivedMesh *split, MFace *mf, int *facepa, int *vertpa, int i, EdgeHash *eh, int cur, int v1, int v2, int v3) +{ + MFace *df1 = get_dface(dm, split, cur, i, mf); + MFace *df2 = get_dface(dm, split, cur+1, i, mf); + + facepa[cur] = vertpa[v1]; + df1->v1 = v1; + df1->v2 = GET_ES(v1, v2) + df1->v3 = GET_ES(v1, v3) + df1->v4 = 0; + df1->flag &= ~ME_FACE_SEL; + + facepa[cur+1] = vertpa[v2]; + df2->v1 = GET_ES(v1, v2) + df2->v2 = v2; + df2->v3 = v3; + df2->v4 = GET_ES(v1, v3) + df2->flag |= ME_FACE_SEL; +} + +static void remap_uvs_19_21_22(DerivedMesh *dm, DerivedMesh *split, int numlayer, int i, int cur, int c0, int c1, int c2) +{ + MTFace *mf, *df1, *df2; + int l; + + for(l=0; l<numlayer; l++) { + mf = CustomData_get_layer_n(&split->faceData, CD_MTFACE, l); + df1 = mf+cur; + df2 = df1 + 1; + mf = CustomData_get_layer_n(&dm->faceData, CD_MTFACE, l); + mf += i; + + copy_v2_v2(df1->uv[0], mf->uv[c0]); + INT_UV(df1->uv[1], c0, c1) + INT_UV(df1->uv[2], c0, c2) + + INT_UV(df2->uv[0], c0, c1) + copy_v2_v2(df2->uv[1], mf->uv[c1]); + copy_v2_v2(df2->uv[2], mf->uv[c2]); + INT_UV(df2->uv[3], c0, c2) + } +} + +static void remap_faces_23(DerivedMesh *dm, DerivedMesh *split, MFace *mf, int *facepa, int *vertpa, int i, EdgeHash *eh, int cur, int v1, int v2, int v3) +{ + MFace *df1 = get_dface(dm, split, cur, i, mf); + MFace *df2 = get_dface(dm, split, cur+1, i, mf); + MFace *df3 = get_dface(dm, split, cur+2, i, mf); + + facepa[cur] = vertpa[v1]; + df1->v1 = v1; + df1->v2 = GET_ES(v1, v2) + df1->v3 = GET_ES(v2, v3) + df1->v4 = GET_ES(v1, v3) + df1->flag |= ME_FACE_SEL; + + facepa[cur+1] = vertpa[v2]; + df2->v1 = GET_ES(v1, v2) + df2->v2 = v2; + df2->v3 = GET_ES(v2, v3) + df2->v4 = 0; + df2->flag &= ~ME_FACE_SEL; + + facepa[cur+2] = vertpa[v3]; + df3->v1 = GET_ES(v1, v3) + df3->v2 = GET_ES(v2, v3) + df3->v3 = v3; + df3->v4 = 0; + df3->flag &= ~ME_FACE_SEL; +} + +static void remap_uvs_23(DerivedMesh *dm, DerivedMesh *split, int numlayer, int i, int cur, int c0, int c1, int c2) +{ + MTFace *mf, *df1, *df2; + int l; + + for(l=0; l<numlayer; l++) { + mf = CustomData_get_layer_n(&split->faceData, CD_MTFACE, l); + df1 = mf+cur; + df2 = df1 + 1; + mf = CustomData_get_layer_n(&dm->faceData, CD_MTFACE, l); + mf += i; + + copy_v2_v2(df1->uv[0], mf->uv[c0]); + INT_UV(df1->uv[1], c0, c1) + INT_UV(df1->uv[2], c1, c2) + INT_UV(df1->uv[3], c0, c2) + + INT_UV(df2->uv[0], c0, c1) + copy_v2_v2(df2->uv[1], mf->uv[c1]); + INT_UV(df2->uv[2], c1, c2) + + INT_UV(df2->uv[0], c0, c2) + INT_UV(df2->uv[1], c1, c2) + copy_v2_v2(df2->uv[2], mf->uv[c2]); + } +} + +static DerivedMesh * cutEdges(ExplodeModifierData *emd, DerivedMesh *dm){ DerivedMesh *splitdm; - MFace *mf=0,*df1=0,*df2=0,*df3=0; + MFace *mf=NULL,*df1=NULL; MFace *mface=dm->getFaceArray(dm); MVert *dupve, *mv; EdgeHash *edgehash; @@ -198,8 +556,9 @@ static DerivedMesh * splitEdges(ExplodeModifierData *emd, DerivedMesh *dm){ int *facesplit = MEM_callocN(sizeof(int)*totface,"explode_facesplit"); int *vertpa = MEM_callocN(sizeof(int)*totvert,"explode_vertpa2"); int *facepa = emd->facepa; - int *fs, totesplit=0,totfsplit=0,totin=0,curdupface=0,curdupin=0; - int i,j,v1,v2,v3,v4,esplit; + int *fs, totesplit=0,totfsplit=0,curdupface=0; + int i,j,v1,v2,v3,v4,esplit, v[4], uv[4]; + int numlayer; edgehash= BLI_edgehash_new(); @@ -214,52 +573,48 @@ static DerivedMesh * splitEdges(ExplodeModifierData *emd, DerivedMesh *dm){ /* mark edges for splitting and how to split faces */ for (i=0,mf=mface,fs=facesplit; i<totface; i++,mf++,fs++) { - if(mf->v4){ - v1=vertpa[mf->v1]; - v2=vertpa[mf->v2]; - v3=vertpa[mf->v3]; - v4=vertpa[mf->v4]; + v1=vertpa[mf->v1]; + v2=vertpa[mf->v2]; + v3=vertpa[mf->v3]; - if(v1!=v2){ - BLI_edgehash_insert(edgehash, mf->v1, mf->v2, NULL); - (*fs)++; - } + if(v1!=v2){ + BLI_edgehash_insert(edgehash, mf->v1, mf->v2, NULL); + (*fs) |= 1; + } - if(v2!=v3){ - BLI_edgehash_insert(edgehash, mf->v2, mf->v3, NULL); - (*fs)++; - } + if(v2!=v3){ + BLI_edgehash_insert(edgehash, mf->v2, mf->v3, NULL); + (*fs) |= 2; + } + + if(mf->v4){ + v4=vertpa[mf->v4]; if(v3!=v4){ BLI_edgehash_insert(edgehash, mf->v3, mf->v4, NULL); - (*fs)++; + (*fs) |= 4; } if(v1!=v4){ BLI_edgehash_insert(edgehash, mf->v1, mf->v4, NULL); - (*fs)++; + (*fs) |= 8; } - if(*fs==2){ - if((v1==v2 && v3==v4) || (v1==v4 && v2==v3)) - *fs=1; - else if(v1!=v2){ - if(v1!=v4) - BLI_edgehash_insert(edgehash, mf->v2, mf->v3, NULL); - else - BLI_edgehash_insert(edgehash, mf->v3, mf->v4, NULL); - } - else{ - if(v1!=v4) - BLI_edgehash_insert(edgehash, mf->v1, mf->v2, NULL); - else - BLI_edgehash_insert(edgehash, mf->v1, mf->v4, NULL); - } + /* mark center vertex as a fake edge split */ + if(*fs == 15) + BLI_edgehash_insert(edgehash, mf->v1, mf->v3, NULL); + } + else { + (*fs) |= 16; /* mark face as tri */ + + if(v1!=v3){ + BLI_edgehash_insert(edgehash, mf->v1, mf->v3, NULL); + (*fs) |= 4; } } } - /* count splits & reindex */ + /* count splits & create indexes for new verts */ ehi= BLI_edgehashIterator_new(edgehash); totesplit=totvert; for(; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) { @@ -269,24 +624,11 @@ static DerivedMesh * splitEdges(ExplodeModifierData *emd, DerivedMesh *dm){ BLI_edgehashIterator_free(ehi); /* count new faces due to splitting */ - for(i=0,fs=facesplit; i<totface; i++,fs++){ - if(*fs==1) - totfsplit+=1; - else if(*fs==2) - totfsplit+=2; - else if(*fs==3) - totfsplit+=3; - else if(*fs==4){ - totfsplit+=3; - - mf=dm->getFaceData(dm,i,CD_MFACE);//CDDM_get_face(dm,i); - - if(vertpa[mf->v1]!=vertpa[mf->v2] && vertpa[mf->v2]!=vertpa[mf->v3]) - totin++; - } - } + for(i=0,fs=facesplit; i<totface; i++,fs++) + totfsplit += add_faces[*fs]; - splitdm= CDDM_from_template(dm, totesplit+totin, dm->getNumEdges(dm),totface+totfsplit); + splitdm= CDDM_from_template(dm, totesplit, 0, totface+totfsplit); + numlayer = CustomData_number_of_layers(&splitdm->faceData, CD_MTFACE); /* copy new faces & verts (is it really this painful with custom data??) */ for(i=0; i<totvert; i++){ @@ -298,19 +640,10 @@ static DerivedMesh * splitEdges(ExplodeModifierData *emd, DerivedMesh *dm){ DM_copy_vert_data(dm, splitdm, i, i, 1); *dest = source; } - for(i=0; i<totface; i++){ - MFace source; - MFace *dest; - dm->getFace(dm, i, &source); - dest = CDDM_get_face(splitdm, i); - - DM_copy_face_data(dm, splitdm, i, i, 1); - *dest = source; - } /* override original facepa (original pointer is saved in caller function) */ facepa= MEM_callocN(sizeof(int)*(totface+totfsplit),"explode_facepa"); - memcpy(facepa,emd->facepa,totface*sizeof(int)); + //memcpy(facepa,emd->facepa,totface*sizeof(int)); emd->facepa=facepa; /* create new verts */ @@ -333,320 +666,101 @@ static DerivedMesh * splitEdges(ExplodeModifierData *emd, DerivedMesh *dm){ BLI_edgehashIterator_free(ehi); /* create new faces */ - curdupface=totface; - curdupin=totesplit; + curdupface=0;//=totface; + //curdupin=totesplit; for(i=0,fs=facesplit; i<totface; i++,fs++){ - if(*fs){ - mf=CDDM_get_face(splitdm,i); - - v1=vertpa[mf->v1]; - v2=vertpa[mf->v2]; - v3=vertpa[mf->v3]; - v4=vertpa[mf->v4]; - /* ouch! creating new faces & remapping them to new verts is no fun */ - if(*fs==1){ - df1=CDDM_get_face(splitdm,curdupface); - DM_copy_face_data(splitdm,splitdm,i,curdupface,1); - *df1=*mf; - curdupface++; - - if(v1==v2){ - df1->v1=edgesplit_get(edgehash, mf->v1, mf->v4); - df1->v2=edgesplit_get(edgehash, mf->v2, mf->v3); - mf->v3=df1->v2; - mf->v4=df1->v1; - } - else{ - df1->v1=edgesplit_get(edgehash, mf->v1, mf->v2); - df1->v4=edgesplit_get(edgehash, mf->v3, mf->v4); - mf->v2=df1->v1; - mf->v3=df1->v4; - } - - facepa[i]=v1; - facepa[curdupface-1]=v3; - - test_index_face(df1, &splitdm->faceData, curdupface, (df1->v4 ? 4 : 3)); - } - if(*fs==2){ - df1=CDDM_get_face(splitdm,curdupface); - DM_copy_face_data(splitdm,splitdm,i,curdupface,1); - *df1=*mf; - curdupface++; - - df2=CDDM_get_face(splitdm,curdupface); - DM_copy_face_data(splitdm,splitdm,i,curdupface,1); - *df2=*mf; - curdupface++; - - if(v1!=v2){ - if(v1!=v4){ - df1->v1=edgesplit_get(edgehash, mf->v1, mf->v4); - df1->v2=edgesplit_get(edgehash, mf->v1, mf->v2); - df2->v1=df1->v3=mf->v2; - df2->v3=df1->v4=mf->v4; - df2->v2=mf->v3; - - mf->v2=df1->v2; - mf->v3=df1->v1; - - df2->v4=mf->v4=0; - - facepa[i]=v1; - } - else{ - df1->v2=edgesplit_get(edgehash, mf->v1, mf->v2); - df1->v3=edgesplit_get(edgehash, mf->v2, mf->v3); - df1->v4=mf->v3; - df2->v2=mf->v3; - df2->v3=mf->v4; - - mf->v1=df1->v2; - mf->v3=df1->v3; - - df2->v4=mf->v4=0; - - facepa[i]=v2; - } - facepa[curdupface-1]=facepa[curdupface-2]=v3; - } - else{ - if(v1!=v4){ - df1->v3=edgesplit_get(edgehash, mf->v3, mf->v4); - df1->v4=edgesplit_get(edgehash, mf->v1, mf->v4); - df1->v2=mf->v3; - - mf->v1=df1->v4; - mf->v2=df1->v3; - mf->v3=mf->v4; - - df2->v4=mf->v4=0; - - facepa[i]=v4; - } - else{ - df1->v3=edgesplit_get(edgehash, mf->v2, mf->v3); - df1->v4=edgesplit_get(edgehash, mf->v3, mf->v4); - df1->v1=mf->v4; - df1->v2=mf->v2; - df2->v3=mf->v4; - - mf->v1=df1->v4; - mf->v2=df1->v3; - - df2->v4=mf->v4=0; - - facepa[i]=v3; - } - - facepa[curdupface-1]=facepa[curdupface-2]=v1; - } - - test_index_face(df1, &splitdm->faceData, curdupface-2, (df1->v4 ? 4 : 3)); - test_index_face(df1, &splitdm->faceData, curdupface-1, (df1->v4 ? 4 : 3)); - } - else if(*fs==3){ - df1=CDDM_get_face(splitdm,curdupface); - DM_copy_face_data(splitdm,splitdm,i,curdupface,1); - *df1=*mf; - curdupface++; - - df2=CDDM_get_face(splitdm,curdupface); - DM_copy_face_data(splitdm,splitdm,i,curdupface,1); - *df2=*mf; - curdupface++; - - df3=CDDM_get_face(splitdm,curdupface); - DM_copy_face_data(splitdm,splitdm,i,curdupface,1); - *df3=*mf; - curdupface++; - - if(v1==v2){ - df2->v1=df1->v1=edgesplit_get(edgehash, mf->v1, mf->v4); - df3->v1=df1->v2=edgesplit_get(edgehash, mf->v2, mf->v3); - df3->v3=df2->v2=df1->v3=edgesplit_get(edgehash, mf->v3, mf->v4); - df3->v2=mf->v3; - df2->v3=mf->v4; - df1->v4=df2->v4=df3->v4=0; - - mf->v3=df1->v2; - mf->v4=df1->v1; - - facepa[i]=facepa[curdupface-3]=v1; - facepa[curdupface-1]=v3; - facepa[curdupface-2]=v4; - } - else if(v2==v3){ - df3->v1=df2->v3=df1->v1=edgesplit_get(edgehash, mf->v1, mf->v4); - df2->v2=df1->v2=edgesplit_get(edgehash, mf->v1, mf->v2); - df3->v2=df1->v3=edgesplit_get(edgehash, mf->v3, mf->v4); - - df3->v3=mf->v4; - df2->v1=mf->v1; - df1->v4=df2->v4=df3->v4=0; - - mf->v1=df1->v2; - mf->v4=df1->v3; - - facepa[i]=facepa[curdupface-3]=v2; - facepa[curdupface-1]=v4; - facepa[curdupface-2]=v1; - } - else if(v3==v4){ - df3->v2=df2->v1=df1->v1=edgesplit_get(edgehash, mf->v1, mf->v2); - df2->v3=df1->v2=edgesplit_get(edgehash, mf->v2, mf->v3); - df3->v3=df1->v3=edgesplit_get(edgehash, mf->v1, mf->v4); - - df3->v1=mf->v1; - df2->v2=mf->v2; - df1->v4=df2->v4=df3->v4=0; - - mf->v1=df1->v3; - mf->v2=df1->v2; - - facepa[i]=facepa[curdupface-3]=v3; - facepa[curdupface-1]=v1; - facepa[curdupface-2]=v2; - } - else{ - df3->v1=df1->v1=edgesplit_get(edgehash, mf->v1, mf->v2); - df3->v3=df2->v1=df1->v2=edgesplit_get(edgehash, mf->v2, mf->v3); - df2->v3=df1->v3=edgesplit_get(edgehash, mf->v3, mf->v4); - - df3->v2=mf->v2; - df2->v2=mf->v3; - df1->v4=df2->v4=df3->v4=0; - - mf->v2=df1->v1; - mf->v3=df1->v3; - - facepa[i]=facepa[curdupface-3]=v1; - facepa[curdupface-1]=v2; - facepa[curdupface-2]=v3; - } - - test_index_face(df1, &splitdm->faceData, curdupface-3, (df1->v4 ? 4 : 3)); - test_index_face(df1, &splitdm->faceData, curdupface-2, (df1->v4 ? 4 : 3)); - test_index_face(df1, &splitdm->faceData, curdupface-1, (df1->v4 ? 4 : 3)); - } - else if(*fs==4){ - if(v1!=v2 && v2!=v3){ - - /* set new vert to face center */ - mv=CDDM_get_vert(splitdm,mf->v1); - dupve=CDDM_get_vert(splitdm,curdupin); - DM_copy_vert_data(splitdm,splitdm,mf->v1,curdupin,1); - *dupve=*mv; - - mv=CDDM_get_vert(splitdm,mf->v2); - VECADD(dupve->co,dupve->co,mv->co); - mv=CDDM_get_vert(splitdm,mf->v3); - VECADD(dupve->co,dupve->co,mv->co); - mv=CDDM_get_vert(splitdm,mf->v4); - VECADD(dupve->co,dupve->co,mv->co); - mul_v3_fl(dupve->co,0.25); - - - df1=CDDM_get_face(splitdm,curdupface); - DM_copy_face_data(splitdm,splitdm,i,curdupface,1); - *df1=*mf; - curdupface++; - - df2=CDDM_get_face(splitdm,curdupface); - DM_copy_face_data(splitdm,splitdm,i,curdupface,1); - *df2=*mf; - curdupface++; - - df3=CDDM_get_face(splitdm,curdupface); - DM_copy_face_data(splitdm,splitdm,i,curdupface,1); - *df3=*mf; - curdupface++; - - df1->v1=edgesplit_get(edgehash, mf->v1, mf->v2); - df3->v2=df1->v3=edgesplit_get(edgehash, mf->v2, mf->v3); - - df2->v1=edgesplit_get(edgehash, mf->v1, mf->v4); - df3->v4=df2->v3=edgesplit_get(edgehash, mf->v3, mf->v4); - - df3->v1=df2->v2=df1->v4=curdupin; - - mf->v2=df1->v1; - mf->v3=curdupin; - mf->v4=df2->v1; - - curdupin++; - - facepa[i]=v1; - facepa[curdupface-3]=v2; - facepa[curdupface-2]=v3; - facepa[curdupface-1]=v4; - - test_index_face(df1, &splitdm->faceData, curdupface-3, (df1->v4 ? 4 : 3)); - - test_index_face(df1, &splitdm->faceData, curdupface-2, (df1->v4 ? 4 : 3)); - test_index_face(df1, &splitdm->faceData, curdupface-1, (df1->v4 ? 4 : 3)); - } - else{ - df1=CDDM_get_face(splitdm,curdupface); - DM_copy_face_data(splitdm,splitdm,i,curdupface,1); - *df1=*mf; - curdupface++; - - df2=CDDM_get_face(splitdm,curdupface); - DM_copy_face_data(splitdm,splitdm,i,curdupface,1); - *df2=*mf; - curdupface++; - - df3=CDDM_get_face(splitdm,curdupface); - DM_copy_face_data(splitdm,splitdm,i,curdupface,1); - *df3=*mf; - curdupface++; - - if(v2==v3){ - df1->v1=edgesplit_get(edgehash, mf->v1, mf->v2); - df3->v1=df1->v2=df1->v3=edgesplit_get(edgehash, mf->v2, mf->v3); - df2->v1=df1->v4=edgesplit_get(edgehash, mf->v1, mf->v4); - - df3->v3=df2->v3=edgesplit_get(edgehash, mf->v3, mf->v4); - - df3->v2=mf->v3; - df3->v4=0; - - mf->v2=df1->v1; - mf->v3=df1->v4; - mf->v4=0; - - facepa[i]=v1; - facepa[curdupface-3]=facepa[curdupface-2]=v2; - facepa[curdupface-1]=v3; - } - else{ - df3->v1=df2->v1=df1->v2=edgesplit_get(edgehash, mf->v1, mf->v2); - df2->v4=df1->v3=edgesplit_get(edgehash, mf->v3, mf->v4); - df1->v4=edgesplit_get(edgehash, mf->v1, mf->v4); - - df3->v3=df2->v2=edgesplit_get(edgehash, mf->v2, mf->v3); - - df3->v4=0; - - mf->v1=df1->v4; - mf->v2=df1->v3; - mf->v3=mf->v4; - mf->v4=0; - - facepa[i]=v4; - facepa[curdupface-3]=facepa[curdupface-2]=v1; - facepa[curdupface-1]=v2; - } - - test_index_face(df1, &splitdm->faceData, curdupface-3, (df1->v4 ? 4 : 3)); - test_index_face(df1, &splitdm->faceData, curdupface-2, (df1->v4 ? 4 : 3)); - test_index_face(df1, &splitdm->faceData, curdupface-1, (df1->v4 ? 4 : 3)); - } - } + mf = dm->getFaceData(dm, i, CD_MFACE); + + switch(*fs) { + case 3: + case 10: + case 11: + case 15: + SET_VERTS(1, 2, 3, 4) + break; + case 5: + case 6: + case 7: + SET_VERTS(2, 3, 4, 1) + break; + case 9: + case 13: + SET_VERTS(4, 1, 2, 3) + break; + case 12: + case 14: + SET_VERTS(3, 4, 1, 2) + break; + case 21: + case 23: + SET_VERTS(1, 2, 3, 4) + break; + case 19: + SET_VERTS(2, 3, 1, 4) + break; + case 22: + SET_VERTS(3, 1, 2, 4) + break; + } - test_index_face(df1, &splitdm->faceData, i, (df1->v4 ? 4 : 3)); + switch(*fs) { + case 3: + case 6: + case 9: + case 12: + remap_faces_3_6_9_12(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]); + if(numlayer) + remap_uvs_3_6_9_12(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2], uv[3]); + break; + case 5: + case 10: + remap_faces_5_10(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]); + if(numlayer) + remap_uvs_5_10(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2], uv[3]); + break; + case 15: + remap_faces_15(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]); + if(numlayer) + remap_uvs_15(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2], uv[3]); + break; + case 7: + case 11: + case 13: + case 14: + remap_faces_7_11_13_14(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]); + if(numlayer) + remap_uvs_7_11_13_14(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2], uv[3]); + break; + case 19: + case 21: + case 22: + remap_faces_19_21_22(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2]); + if(numlayer) + remap_uvs_19_21_22(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2]); + break; + case 23: + remap_faces_23(dm, splitdm, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2]); + if(numlayer) + remap_uvs_23(dm, splitdm, numlayer, i, curdupface, uv[0], uv[1], uv[2]); + break; + case 0: + case 16: + df1 = get_dface(dm, splitdm, curdupface, i, mf); + facepa[curdupface] = vertpa[mf->v1]; + + if(df1->v4) + df1->flag |= ME_FACE_SEL; + else + df1->flag &= ~ME_FACE_SEL; + break; } + + curdupface += add_faces[*fs]+1; + } + + for(i=0; i<curdupface; i++) { + mf = CDDM_get_face(splitdm, i); + test_index_face(mf, &splitdm->faceData, i, (mf->flag & ME_FACE_SEL ? 4 : 3)); } BLI_edgehash_free(edgehash, NULL); @@ -661,20 +775,21 @@ static DerivedMesh * explodeMesh(ExplodeModifierData *emd, DerivedMesh *to_explode) { DerivedMesh *explode, *dm=to_explode; - MFace *mf=0, *mface; + MFace *mf= NULL, *mface; ParticleSettings *part=psmd->psys->part; - ParticleSimulationData sim= {0}; + ParticleSimulationData sim= {NULL}; ParticleData *pa=NULL, *pars=psmd->psys->particles; ParticleKey state; EdgeHash *vertpahash; EdgeHashIterator *ehi; - float *vertco=0, imat[4][4]; + float *vertco= NULL, imat[4][4]; float loc0[3], nor[3]; float cfra; /* float timestep; */ int *facepa=emd->facepa; int totdup=0,totvert=0,totface=0,totpart=0; int i, j, v, mindex=0; + MTFace *mtface = NULL, *mtf; totface= dm->getNumFaces(dm); totvert= dm->getNumVerts(dm); @@ -724,6 +839,7 @@ static DerivedMesh * explodeMesh(ExplodeModifierData *emd, /* the final duplicated vertices */ explode= CDDM_from_template(dm, totdup, 0,totface); + mtface = CustomData_get_layer_named(&explode->faceData, CD_MTFACE, emd->uvname); /*dupvert= CDDM_get_verts(explode);*/ /* getting back to object space */ @@ -753,7 +869,7 @@ static DerivedMesh * explodeMesh(ExplodeModifierData *emd, pa= pars+i; /* get particle state */ - psys_particle_on_emitter(psmd,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,loc0,nor,0,0,0,0); + psys_particle_on_emitter(psmd,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,loc0,nor,NULL,NULL,NULL,NULL); mul_m4_v3(ob->obmat,loc0); state.time=cfra; @@ -800,16 +916,28 @@ static DerivedMesh * explodeMesh(ExplodeModifierData *emd, else mindex = totvert+facepa[i]; - source.v1 = edgesplit_get(vertpahash, source.v1, mindex); - source.v2 = edgesplit_get(vertpahash, source.v2, mindex); - source.v3 = edgesplit_get(vertpahash, source.v3, mindex); + source.v1 = edgecut_get(vertpahash, source.v1, mindex); + source.v2 = edgecut_get(vertpahash, source.v2, mindex); + source.v3 = edgecut_get(vertpahash, source.v3, mindex); if(source.v4) - source.v4 = edgesplit_get(vertpahash, source.v4, mindex); + source.v4 = edgecut_get(vertpahash, source.v4, mindex); DM_copy_face_data(dm,explode,i,i,1); *mf = source; + /* override uv channel for particle age */ + if(mtface) { + float age = (cfra - pa->time)/pa->lifetime; + /* Clamp to this range to avoid flipping to the other side of the coordinates. */ + CLAMP(age, 0.001f, 0.999f); + + mtf = mtface + i; + + mtf->uv[0][0] = mtf->uv[1][0] = mtf->uv[2][0] = mtf->uv[3][0] = age; + mtf->uv[0][1] = mtf->uv[1][1] = mtf->uv[2][1] = mtf->uv[3][1] = 0.5f; + } + test_index_face(mf, &explode->faceData, i, (orig_v4 ? 4 : 3)); } @@ -831,7 +959,7 @@ static DerivedMesh * explodeMesh(ExplodeModifierData *emd, static ParticleSystemModifierData * findPrecedingParticlesystem(Object *ob, ModifierData *emd) { ModifierData *md; - ParticleSystemModifierData *psmd=0; + ParticleSystemModifierData *psmd= NULL; for (md=ob->modifiers.first; emd!=md; md=md->next){ if(md->type==eModifierType_ParticleSystem) @@ -851,12 +979,12 @@ static DerivedMesh * applyModifier(ModifierData *md, Object *ob, if(psmd){ ParticleSystem * psys=psmd->psys; - if(psys==0 || psys->totpart==0) return derivedData; - if(psys->part==0 || psys->particles==0) return derivedData; - if(psmd->dm==0) return derivedData; + if(psys==NULL || psys->totpart==0) return derivedData; + if(psys->part==NULL || psys->particles==NULL) return derivedData; + if(psmd->dm==NULL) return derivedData; /* 1. find faces to be exploded if needed */ - if(emd->facepa==0 + if(emd->facepa == NULL || psmd->flag&eParticleSystemFlag_Pars || emd->flag&eExplodeFlag_CalcFaces || MEM_allocN_len(emd->facepa)/sizeof(int) != dm->getNumFaces(dm)) @@ -869,19 +997,19 @@ static DerivedMesh * applyModifier(ModifierData *md, Object *ob, createFacepa(emd,psmd,derivedData); } - /* 2. create new mesh */ - if(emd->flag & eExplodeFlag_EdgeSplit){ - int *facepa = emd->facepa; - DerivedMesh *splitdm=splitEdges(emd,dm); - DerivedMesh *explode=explodeMesh(emd, psmd, md->scene, ob, splitdm); - - MEM_freeN(emd->facepa); - emd->facepa=facepa; - splitdm->release(splitdm); - return explode; - } - else - return explodeMesh(emd, psmd, md->scene, ob, derivedData); + /* 2. create new mesh */ + if(emd->flag & eExplodeFlag_EdgeCut){ + int *facepa = emd->facepa; + DerivedMesh *splitdm=cutEdges(emd,dm); + DerivedMesh *explode=explodeMesh(emd, psmd, md->scene, ob, splitdm); + + MEM_freeN(emd->facepa); + emd->facepa=facepa; + splitdm->release(splitdm); + return explode; + } + else + return explodeMesh(emd, psmd, md->scene, ob, derivedData); } return derivedData; } @@ -891,22 +1019,22 @@ ModifierTypeInfo modifierType_Explode = { /* name */ "Explode", /* structName */ "ExplodeModifierData", /* structSize */ sizeof(ExplodeModifierData), - /* type */ eModifierTypeType_Nonconstructive, + /* type */ eModifierTypeType_Constructive, /* flags */ eModifierTypeFlag_AcceptsMesh, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, - /* applyModifierEM */ 0, + /* applyModifierEM */ NULL, /* initData */ initData, /* requiredDataMask */ requiredDataMask, /* freeData */ freeData, - /* isDisabled */ 0, - /* updateDepgraph */ 0, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, /* dependsOnTime */ dependsOnTime, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_fluidsim.c b/source/blender/modifiers/intern/MOD_fluidsim.c index 19111b0cafc..354dc33ffe0 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim.c +++ b/source/blender/modifiers/intern/MOD_fluidsim.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_fluidsim.c + * \ingroup modifiers + */ + + #include "DNA_scene_types.h" #include "DNA_object_fluidsim.h" #include "DNA_object_types.h" @@ -42,6 +47,7 @@ #include "depsgraph_private.h" +#include "MOD_util.h" #include "MOD_fluidsim_util.h" #include "MEM_guardedalloc.h" @@ -141,19 +147,19 @@ ModifierTypeInfo modifierType_Fluidsim = { | eModifierTypeFlag_Single, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, - /* applyModifierEM */ 0, + /* applyModifierEM */ NULL, /* initData */ initData, - /* requiredDataMask */ 0, + /* requiredDataMask */ NULL, /* freeData */ freeData, - /* isDisabled */ 0, + /* isDisabled */ NULL, /* updateDepgraph */ updateDepgraph, /* dependsOnTime */ dependsOnTime, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index eb556e31aba..02912e38204 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_fluidsim_util.c + * \ingroup modifiers + */ + + #include <stddef.h> #include <zlib.h> @@ -45,11 +50,13 @@ #include "BLI_utildefines.h" #include "BKE_main.h" +#include "BKE_fluidsim.h" /* ensure definitions here match */ #include "BKE_cdderivedmesh.h" #include "BKE_mesh.h" #include "BKE_utildefines.h" #include "BKE_global.h" /* G.main->name only */ +#include "MOD_fluidsim_util.h" #include "MOD_modifiertypes.h" #include "MEM_guardedalloc.h" @@ -167,7 +174,7 @@ void fluidsim_free(FluidsimModifierData *fluidmd) #ifndef DISABLE_ELBEEM /* read .bobj.gz file into a fluidsimDerivedMesh struct */ -DerivedMesh *fluidsim_read_obj(char *filename) +static DerivedMesh *fluidsim_read_obj(const char *filename) { int wri = 0,i; int gotBytes; @@ -379,7 +386,7 @@ void fluid_estimate_memory(Object *ob, FluidsimSettings *fss, char *value) /* read zipped fluidsim velocities into the co's of the fluidsimsettings normals struct */ -void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, char *filename) +static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, char *filename) { int wri, i, j; float wrf; @@ -442,7 +449,7 @@ void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, cha gzclose(gzf); } -DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluidmd, int framenr, int useRenderParams) +static DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluidmd, int framenr, int useRenderParams) { int displaymode = 0; int curFrame = framenr - 1 /*scene->r.sfra*/; /* start with 0 at start frame */ @@ -459,7 +466,7 @@ DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluid displaymode = fss->renderDisplayMode; } - strncpy(targetDir, fss->surfdataPath, FILE_MAXDIR); + BLI_strncpy(targetDir, fss->surfdataPath, sizeof(targetDir)); // use preview or final mesh? if(displaymode==1) @@ -479,8 +486,7 @@ DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluid BLI_path_abs(targetDir, G.main->name); BLI_path_frame(targetDir, curFrame, 0); // fixed #frame-no - strcpy(targetFile,targetDir); - strcat(targetFile, ".bobj.gz"); + BLI_snprintf(targetFile, sizeof(targetFile), "%s.bobj.gz", targetDir); dm = fluidsim_read_obj(targetFile); @@ -538,7 +544,7 @@ DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluid DerivedMesh *fluidsimModifier_do(FluidsimModifierData *fluidmd, Scene *scene, Object *UNUSED(ob), DerivedMesh *dm, - int useRenderParams) + int useRenderParams, int UNUSED(isFinalCalc)) { #ifndef DISABLE_ELBEEM DerivedMesh *result = NULL; diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.h b/source/blender/modifiers/intern/MOD_fluidsim_util.h index a06c74cb8dd..f8af8e6f583 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.h +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.h @@ -1,4 +1,4 @@ -/** +/* * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** @@ -27,6 +27,11 @@ * ***** END GPL LICENSE BLOCK ***** */ +/** \file blender/modifiers/intern/MOD_fluidsim_util.h + * \ingroup modifiers + */ + + #ifndef MOD_FLUIDSIM_UTIL_H #define MOD_FLUIDSIM_UTIL_H @@ -42,6 +47,6 @@ void fluidsim_free(struct FluidsimModifierData *fluidmd); struct DerivedMesh *fluidsimModifier_do(struct FluidsimModifierData *fluidmd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, int useRenderParams, int isFinalCalc); - + #endif diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c index 79493d2c549..082c199b16f 100644 --- a/source/blender/modifiers/intern/MOD_hook.c +++ b/source/blender/modifiers/intern/MOD_hook.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_hook.c + * \ingroup modifiers + */ + + #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_object_types.h" @@ -46,6 +51,7 @@ #include "depsgraph_private.h" #include "MEM_guardedalloc.h" +#include "MOD_util.h" static void initData(ModifierData *md) { @@ -130,8 +136,8 @@ static float hook_falloff(float *co_1, float *co_2, const float falloff_squared, if(len_squared > falloff_squared) { return 0.0f; } - else if(len_squared > 0.0) { - return fac * (1.0 - (len_squared / falloff_squared)); + else if(len_squared > 0.0f) { + return fac * (1.0f - (len_squared / falloff_squared)); } } @@ -243,7 +249,6 @@ static void deformVerts(ModifierData *md, Object *ob, } } else if(dvert) { /* vertex group hook */ - int i; const float fac_orig= hmd->force; for(i = 0; i < max_dvert; i++, dvert++) { @@ -284,18 +289,18 @@ ModifierTypeInfo modifierType_Hook = { | eModifierTypeFlag_SupportsEditmode, /* copyData */ copyData, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, + /* deformMatrices */ NULL, /* deformVertsEM */ deformVertsEM, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, /* requiredDataMask */ requiredDataMask, /* freeData */ freeData, /* isDisabled */ isDisabled, /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_lattice.c b/source/blender/modifiers/intern/MOD_lattice.c index c5fb87c8ffc..694f8fb3e52 100644 --- a/source/blender/modifiers/intern/MOD_lattice.c +++ b/source/blender/modifiers/intern/MOD_lattice.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_lattice.c + * \ingroup modifiers + */ + + #include <string.h> #include "DNA_object_types.h" @@ -137,18 +142,18 @@ ModifierTypeInfo modifierType_Lattice = { | eModifierTypeFlag_SupportsEditmode, /* copyData */ copyData, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, + /* deformMatrices */ NULL, /* deformVertsEM */ deformVertsEM, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, - /* initData */ 0, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, + /* initData */ NULL, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, + /* freeData */ NULL, /* isDisabled */ isDisabled, /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_mask.c b/source/blender/modifiers/intern/MOD_mask.c index b2f2c86c46d..b36d6848533 100644 --- a/source/blender/modifiers/intern/MOD_mask.c +++ b/source/blender/modifiers/intern/MOD_mask.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_mask.c + * \ingroup modifiers + */ + + #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" @@ -47,13 +52,14 @@ #include "depsgraph_private.h" +#include "MOD_util.h" static void copyData(ModifierData *md, ModifierData *target) { MaskModifierData *mmd = (MaskModifierData*) md; MaskModifierData *tmmd = (MaskModifierData*) target; - strcpy(tmmd->vgroup, mmd->vgroup); + BLI_strncpy(tmmd->vgroup, mmd->vgroup, sizeof(tmmd->vgroup)); tmmd->flag = mmd->flag; } @@ -398,19 +404,19 @@ ModifierTypeInfo modifierType_Mask = { /* flags */ eModifierTypeFlag_AcceptsMesh|eModifierTypeFlag_SupportsMapping|eModifierTypeFlag_SupportsEditmode, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, - /* applyModifierEM */ 0, - /* initData */ 0, + /* applyModifierEM */ NULL, + /* initData */ NULL, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, - /* isDisabled */ 0, + /* freeData */ NULL, + /* isDisabled */ NULL, /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index 61e7f950e0f..ba73f3fa0d1 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_meshdeform.c + * \ingroup modifiers + */ + + #include "DNA_meshdata_types.h" #include "DNA_object_types.h" @@ -372,7 +377,7 @@ static void deformVertsEM(ModifierData *md, Object *ob, dm->release(dm); } -#define MESHDEFORM_MIN_INFLUENCE 0.00001 +#define MESHDEFORM_MIN_INFLUENCE 0.00001f void modifier_mdef_compact_influences(ModifierData *md) { @@ -445,18 +450,18 @@ ModifierTypeInfo modifierType_MeshDeform = { /* copyData */ copyData, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, + /* deformMatrices */ NULL, /* deformVertsEM */ deformVertsEM, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, /* requiredDataMask */ requiredDataMask, /* freeData */ freeData, /* isDisabled */ isDisabled, /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/modifiers/intern/MOD_mirror.c index 5c73b2f0866..b1c765e5c9b 100644 --- a/source/blender/modifiers/intern/MOD_mirror.c +++ b/source/blender/modifiers/intern/MOD_mirror.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_mirror.c + * \ingroup modifiers + */ + + #include "DNA_meshdata_types.h" #include "DNA_object_types.h" @@ -45,6 +50,8 @@ #include "MEM_guardedalloc.h" #include "depsgraph_private.h" +#include "MOD_util.h" + static void initData(ModifierData *md) { MirrorModifierData *mmd = (MirrorModifierData*) md; @@ -341,19 +348,19 @@ ModifierTypeInfo modifierType_Mirror = { | eModifierTypeFlag_AcceptsCVs, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, /* applyModifierEM */ applyModifierEM, /* initData */ initData, - /* requiredDataMask */ 0, - /* freeData */ 0, - /* isDisabled */ 0, + /* requiredDataMask */ NULL, + /* freeData */ NULL, + /* isDisabled */ NULL, /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_multires.c b/source/blender/modifiers/intern/MOD_multires.c index 10b135aaa77..134574ae6c4 100644 --- a/source/blender/modifiers/intern/MOD_multires.c +++ b/source/blender/modifiers/intern/MOD_multires.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_multires.c + * \ingroup modifiers + */ + + #include <stddef.h> #include "BKE_cdderivedmesh.h" @@ -40,6 +45,8 @@ #include "DNA_mesh_types.h" +#include "MOD_util.h" + static void initData(ModifierData *md) { MultiresModifierData *mmd = (MultiresModifierData*)md; @@ -105,22 +112,23 @@ ModifierTypeInfo modifierType_Multires = { /* structSize */ sizeof(MultiresModifierData), /* type */ eModifierTypeType_Constructive, /* flags */ eModifierTypeFlag_AcceptsMesh + | eModifierTypeFlag_SupportsMapping | eModifierTypeFlag_RequiresOriginalData, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, - /* applyModifierEM */ 0, + /* applyModifierEM */ NULL, /* initData */ initData, - /* requiredDataMask */ 0, - /* freeData */ 0, - /* isDisabled */ 0, - /* updateDepgraph */ 0, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* requiredDataMask */ NULL, + /* freeData */ NULL, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_none.c b/source/blender/modifiers/intern/MOD_none.c index c08335d638a..489733c8480 100644 --- a/source/blender/modifiers/intern/MOD_none.c +++ b/source/blender/modifiers/intern/MOD_none.c @@ -1,4 +1,4 @@ -/** +/* * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** @@ -34,7 +34,11 @@ * ***** END GPL LICENSE BLOCK ***** */ +/** \file blender/modifiers/intern/MOD_none.c + * \ingroup modifiers + */ +#include <stdio.h> #include "BLI_utildefines.h" @@ -57,20 +61,20 @@ ModifierTypeInfo modifierType_None = { /* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_AcceptsCVs, - /* copyData */ 0, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, - /* initData */ 0, - /* requiredDataMask */ 0, - /* freeData */ 0, + /* copyData */ NULL, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, + /* initData */ NULL, + /* requiredDataMask */ NULL, + /* freeData */ NULL, /* isDisabled */ isDisabled, - /* updateDepgraph */ 0, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* updateDepgraph */ NULL, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c index c36581d9317..46d53e0db15 100644 --- a/source/blender/modifiers/intern/MOD_particleinstance.c +++ b/source/blender/modifiers/intern/MOD_particleinstance.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_particleinstance.c + * \ingroup modifiers + */ + + #include "DNA_meshdata_types.h" #include "MEM_guardedalloc.h" @@ -45,6 +50,7 @@ #include "BKE_particle.h" #include "BKE_pointcache.h" +#include "MOD_util.h" #include "depsgraph_private.h" @@ -109,8 +115,8 @@ static DerivedMesh * applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm = derivedData, *result; ParticleInstanceModifierData *pimd= (ParticleInstanceModifierData*) md; ParticleSimulationData sim; - ParticleSystem * psys=0; - ParticleData *pa=0, *pars=0; + ParticleSystem *psys= NULL; + ParticleData *pa= NULL, *pars= NULL; MFace *mface, *orig_mface; MVert *mvert, *orig_mvert; int i,totvert, totpart=0, totface, maxvert, maxface, first_particle=0; @@ -121,13 +127,13 @@ static DerivedMesh * applyModifier(ModifierData *md, Object *ob, trackneg=((ob->trackflag>2)?1:0); if(pimd->ob==ob){ - pimd->ob=0; + pimd->ob= NULL; return derivedData; } if(pimd->ob){ psys = BLI_findlink(&pimd->ob->particlesystem,pimd->psys-1); - if(psys==0 || psys->totpart==0) + if(psys==NULL || psys->totpart==0) return derivedData; } else return derivedData; @@ -230,7 +236,7 @@ static DerivedMesh * applyModifier(ModifierData *md, Object *ob, normalize_v3(state.vel); /* TODO: incremental rotations somehow */ - if(state.vel[axis] < -0.9999 || state.vel[axis] > 0.9999) { + if(state.vel[axis] < -0.9999f || state.vel[axis] > 0.9999f) { state.rot[0] = 1; state.rot[1] = state.rot[2] = state.rot[3] = 0.0f; } @@ -268,7 +274,7 @@ static DerivedMesh * applyModifier(ModifierData *md, Object *ob, if(psys->part->childtype==PART_CHILD_PARTICLES) pa=psys->particles+(psys->child+i/totface-psys->totpart)->parent; else - pa=0; + pa= NULL; } else pa=pars+i/totface; @@ -277,7 +283,7 @@ static DerivedMesh * applyModifier(ModifierData *md, Object *ob, if(psys->part->childtype==PART_CHILD_PARTICLES) pa=psys->particles+(psys->child+i/totface)->parent; else - pa=0; + pa= NULL; } if(pa){ @@ -329,19 +335,19 @@ ModifierTypeInfo modifierType_ParticleInstance = { | eModifierTypeFlag_EnableInEditmode, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, /* applyModifierEM */ applyModifierEM, /* initData */ initData, - /* requiredDataMask */ 0, - /* freeData */ 0, - /* isDisabled */ 0, + /* requiredDataMask */ NULL, + /* freeData */ NULL, + /* isDisabled */ NULL, /* updateDepgraph */ updateDepgraph, /* dependsOnTime */ dependsOnTime, - /* dependsOnNormals */ 0, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_particlesystem.c b/source/blender/modifiers/intern/MOD_particlesystem.c index c7638afbbcc..533bfd203b5 100644 --- a/source/blender/modifiers/intern/MOD_particlesystem.c +++ b/source/blender/modifiers/intern/MOD_particlesystem.c @@ -30,7 +30,12 @@ * */ -#include "stddef.h" +/** \file blender/modifiers/intern/MOD_particlesystem.c + * \ingroup modifiers + */ + + +#include <stddef.h> #include "DNA_material_types.h" @@ -48,8 +53,8 @@ static void initData(ModifierData *md) { ParticleSystemModifierData *psmd= (ParticleSystemModifierData*) md; - psmd->psys= 0; - psmd->dm=0; + psmd->psys= NULL; + psmd->dm= NULL; psmd->totdmvert= psmd->totdmedge= psmd->totdmface= 0; } static void freeData(ModifierData *md) @@ -59,7 +64,7 @@ static void freeData(ModifierData *md) if(psmd->dm){ psmd->dm->needsFree = 1; psmd->dm->release(psmd->dm); - psmd->dm=0; + psmd->dm = NULL; } /* ED_object_modifier_remove may have freed this first before calling @@ -72,7 +77,7 @@ static void copyData(ModifierData *md, ModifierData *target) ParticleSystemModifierData *psmd= (ParticleSystemModifierData*) md; ParticleSystemModifierData *tpsmd= (ParticleSystemModifierData*) target; - tpsmd->dm = 0; + tpsmd->dm = NULL; tpsmd->totdmvert = tpsmd->totdmedge = tpsmd->totdmface = 0; //tpsmd->facepa = 0; tpsmd->flag = psmd->flag; @@ -80,28 +85,23 @@ static void copyData(ModifierData *md, ModifierData *target) tpsmd->psys = psmd->psys; } -static CustomDataMask requiredDataMask(Object *ob, ModifierData *md) +static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) { ParticleSystemModifierData *psmd= (ParticleSystemModifierData*) md; CustomDataMask dataMask = 0; - Material *ma; MTex *mtex; int i; if(!psmd->psys->part) return 0; - ma= give_current_material(ob, psmd->psys->part->omat); - if(ma) { - for(i=0; i<MAX_MTEX; i++) { - mtex=ma->mtex[i]; - if(mtex && (ma->septex & (1<<i))==0) - if(mtex->pmapto && (mtex->texco & TEXCO_UV)) - dataMask |= CD_MASK_MTFACE; - } + for(i=0; i<MAX_MTEX; i++) { + mtex = psmd->psys->part->mtex[i]; + if(mtex && mtex->mapto && (mtex->texco & TEXCO_UV)) + dataMask |= CD_MASK_MTFACE; } - if(psmd->psys->part->tanfac!=0.0) + if(psmd->psys->part->tanfac != 0.0f) dataMask |= CD_MASK_MTFACE; /* ask for vertexgroups if we need them */ @@ -131,7 +131,7 @@ static void deformVerts(ModifierData *md, Object *ob, { DerivedMesh *dm = derivedData; ParticleSystemModifierData *psmd= (ParticleSystemModifierData*) md; - ParticleSystem * psys=0; + ParticleSystem * psys= NULL; int needsFree=0; if(ob->particlesystem.first) @@ -142,7 +142,7 @@ static void deformVerts(ModifierData *md, Object *ob, if(!psys_check_enabled(ob, psys)) return; - if(dm==0) { + if(dm==NULL) { dm= get_dm(ob, NULL, NULL, vertexCos, 1); if(!dm) @@ -228,18 +228,18 @@ ModifierTypeInfo modifierType_ParticleSystem = { /* copyData */ copyData, /* deformVerts */ deformVerts, - /* deformVertsEM */ 0 /* deformVertsEM */ , - /* deformMatrices */ 0, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* deformVertsEM */ NULL /* deformVertsEM */ , + /* deformMatrices */ NULL, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, /* requiredDataMask */ requiredDataMask, /* freeData */ freeData, - /* isDisabled */ 0, - /* updateDepgraph */ 0, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c index 7e8fad2801e..17e350482f0 100644 --- a/source/blender/modifiers/intern/MOD_screw.c +++ b/source/blender/modifiers/intern/MOD_screw.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_screw.c + * \ingroup modifiers + */ + + /* Screw modifier: revolves the edges about an axis */ #include "DNA_meshdata_types.h" @@ -267,7 +272,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, /* will the screw be closed? * Note! smaller then FLT_EPSILON*100 gives problems with float precision so its never closed. */ - if (fabs(screw_ofs) <= (FLT_EPSILON*100) && fabs(fabs(angle) - (M_PI * 2)) <= (FLT_EPSILON*100)) { + if (fabsf(screw_ofs) <= (FLT_EPSILON*100.0f) && fabsf(fabsf(angle) - ((float)M_PI * 2.0f)) <= (FLT_EPSILON*100.0f)) { close= 1; step_tot--; if(step_tot < 2) step_tot= 2; @@ -433,15 +438,15 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, /* find the first vert */ vc= vert_connect; for (i=0; i < totvert; i++, vc++) { - int v_best=-1, ed_loop_closed=0; /* vert and vert new */ - int ed_loop_flip= 0; /* compiler complains if not initialized, but it should be initialized below */ - float fl= -1.0f; - ScrewVertIter lt_iter; - /* Now do search for connected verts, order all edges and flip them * so resulting faces are flipped the right way */ vc_tot_linked= 0; /* count the number of linked verts for this loop */ if (vc->flag == 0) { + int v_best=-1, ed_loop_closed=0; /* vert and vert new */ + ScrewVertIter lt_iter; + int ed_loop_flip= 0; /* compiler complains if not initialized, but it should be initialized below */ + float fl= -1.0f; + /*printf("Loop on connected vert: %i\n", i);*/ for(j=0; j<2; j++) { @@ -883,19 +888,19 @@ ModifierTypeInfo modifierType_Screw = { | eModifierTypeFlag_EnableInEditmode, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, /* applyModifierEM */ applyModifierEM, /* initData */ initData, - /* requiredDataMask */ 0, - /* freeData */ 0, - /* isDisabled */ 0, + /* requiredDataMask */ NULL, + /* freeData */ NULL, + /* isDisabled */ NULL, /* updateDepgraph */ updateDepgraph, /* dependsOnTime */ dependsOnTime, - /* dependsOnNormals */ 0, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_shapekey.c b/source/blender/modifiers/intern/MOD_shapekey.c index e03783e8eeb..94d23de6573 100644 --- a/source/blender/modifiers/intern/MOD_shapekey.c +++ b/source/blender/modifiers/intern/MOD_shapekey.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_shapekey.c + * \ingroup modifiers + */ + + #include "BLI_math.h" #include "DNA_key_types.h" @@ -70,11 +75,12 @@ static void deformMatrices(ModifierData *md, Object *ob, DerivedMesh *derivedDat Key *key= ob_get_key(ob); KeyBlock *kb= ob_get_keyblock(ob); float scale[3][3]; - int a; (void)vertexCos; /* unused */ if(kb && kb->totelem==numVerts && kb!=key->refkey) { + int a; + if(ob->shapeflag & OB_SHAPE_LOCK) scale_m3_fl(scale, 1); else scale_m3_fl(scale, kb->curval); @@ -107,11 +113,11 @@ static void deformMatricesEM(ModifierData *UNUSED(md), Object *ob, Key *key= ob_get_key(ob); KeyBlock *kb= ob_get_keyblock(ob); float scale[3][3]; - int a; (void)vertexCos; /* unused */ if(kb && kb->totelem==numVerts && kb!=key->refkey) { + int a; scale_m3_fl(scale, kb->curval); for(a=0; a<numVerts; a++) @@ -127,20 +133,20 @@ ModifierTypeInfo modifierType_ShapeKey = { /* flags */ eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_SupportsEditmode, - /* copyData */ 0, + /* copyData */ NULL, /* deformVerts */ deformVerts, /* deformMatrices */ deformMatrices, /* deformVertsEM */ deformVertsEM, /* deformMatricesEM */ deformMatricesEM, - /* applyModifier */ 0, - /* applyModifierEM */ 0, - /* initData */ 0, - /* requiredDataMask */ 0, - /* freeData */ 0, - /* isDisabled */ 0, - /* updateDepgraph */ 0, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, + /* initData */ NULL, + /* requiredDataMask */ NULL, + /* freeData */ NULL, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL }; diff --git a/source/blender/modifiers/intern/MOD_shrinkwrap.c b/source/blender/modifiers/intern/MOD_shrinkwrap.c index 56a5b4b8577..e1fc4bc969f 100644 --- a/source/blender/modifiers/intern/MOD_shrinkwrap.c +++ b/source/blender/modifiers/intern/MOD_shrinkwrap.c @@ -30,11 +30,16 @@ * */ +/** \file blender/modifiers/intern/MOD_shrinkwrap.c + * \ingroup modifiers + */ + + #include <string.h> +#include "BLI_string.h" #include "BLI_utildefines.h" - #include "BKE_cdderivedmesh.h" #include "BKE_modifier.h" #include "BKE_shrinkwrap.h" @@ -65,7 +70,7 @@ static void copyData(ModifierData *md, ModifierData *target) tsmd->target = smd->target; tsmd->auxTarget = smd->auxTarget; - strcpy(tsmd->vgroup_name, smd->vgroup_name); + BLI_strncpy(tsmd->vgroup_name, smd->vgroup_name, sizeof(tsmd->vgroup_name)); tsmd->keepDist = smd->keepDist; tsmd->shrinkType= smd->shrinkType; @@ -167,18 +172,18 @@ ModifierTypeInfo modifierType_Shrinkwrap = { /* copyData */ copyData, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, + /* deformMatrices */ NULL, /* deformVertsEM */ deformVertsEM, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, + /* freeData */ NULL, /* isDisabled */ isDisabled, /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_simpledeform.c b/source/blender/modifiers/intern/MOD_simpledeform.c index 1c3e40a4193..ea4771b679a 100644 --- a/source/blender/modifiers/intern/MOD_simpledeform.c +++ b/source/blender/modifiers/intern/MOD_simpledeform.c @@ -30,10 +30,16 @@ * */ +/** \file blender/modifiers/intern/MOD_simpledeform.c + * \ingroup modifiers + */ + + #include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "BLI_math.h" +#include "BLI_string.h" #include "BLI_utildefines.h" #include "BKE_cdderivedmesh.h" @@ -50,7 +56,7 @@ /* Clamps/Limits the given coordinate to: limits[0] <= co[axis] <= limits[1] - * The ammount of clamp is saved on dcut */ + * The amount of clamp is saved on dcut */ static void axis_limit(int axis, const float limits[2], float co[3], float dcut[3]) { float val = co[axis]; @@ -83,11 +89,11 @@ static void simpleDeform_stretch(const float factor, const float dcut[3], float float x = co[0], y = co[1], z = co[2]; float scale; - scale = (z*z*factor-factor + 1.0); + scale = (z*z*factor-factor + 1.0f); co[0] = x*scale; co[1] = y*scale; - co[2] = z*(1.0+factor); + co[2] = z*(1.0f+factor); if(dcut) @@ -128,7 +134,7 @@ static void simpleDeform_bend(const float factor, const float dcut[3], float *co sint = sin(theta); cost = cos(theta); - if(fabs(factor) > 1e-7f) + if(fabsf(factor) > 1e-7f) { co[0] = -(y-1.0f/factor)*sint; co[1] = (y-1.0f/factor)*cost + 1.0f/factor; @@ -147,7 +153,7 @@ static void simpleDeform_bend(const float factor, const float dcut[3], float *co /* simple deform modifier */ -void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3], int numVerts) +static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3], int numVerts) { static const float lock_axis[2] = {0.0f, 0.0f}; @@ -162,8 +168,8 @@ void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, s //Safe-check if(smd->origin == ob) smd->origin = NULL; //No self references - if(smd->limit[0] < 0.0) smd->limit[0] = 0.0f; - if(smd->limit[0] > 1.0) smd->limit[0] = 1.0f; + if(smd->limit[0] < 0.0f) smd->limit[0] = 0.0f; + if(smd->limit[0] > 1.0f) smd->limit[0] = 1.0f; smd->limit[0] = MIN2(smd->limit[0], smd->limit[1]); //Upper limit >= than lower limit @@ -288,7 +294,7 @@ static void copyData(ModifierData *md, ModifierData *target) tsmd->originOpts= smd->originOpts; tsmd->factor= smd->factor; memcpy(tsmd->limit, smd->limit, sizeof(tsmd->limit)); - strcpy(tsmd->vgroup_name, smd->vgroup_name); + BLI_strncpy(tsmd->vgroup_name, smd->vgroup_name, sizeof(tsmd->vgroup_name)); } static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) @@ -375,18 +381,18 @@ ModifierTypeInfo modifierType_SimpleDeform = { /* copyData */ copyData, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, + /* deformMatrices */ NULL, /* deformVertsEM */ deformVertsEM, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, - /* isDisabled */ 0, + /* freeData */ NULL, + /* isDisabled */ NULL, /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, - /* foreachIDLink */ 0, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_smoke.c b/source/blender/modifiers/intern/MOD_smoke.c index 0227d2008e5..d8e94e92bfa 100644 --- a/source/blender/modifiers/intern/MOD_smoke.c +++ b/source/blender/modifiers/intern/MOD_smoke.c @@ -30,7 +30,12 @@ * */ -#include "stddef.h" +/** \file blender/modifiers/intern/MOD_smoke.c + * \ingroup modifiers + */ + + +#include <stddef.h> #include "MEM_guardedalloc.h" @@ -142,6 +147,17 @@ static void updateDepgraph(ModifierData *md, DagForest *forest, } } +static void foreachIDLink(ModifierData *md, Object *ob, + IDWalkFunc walk, void *userData) +{ + SmokeModifierData *smd = (SmokeModifierData*) md; + + if(smd->type==MOD_SMOKE_TYPE_DOMAIN && smd->domain) { + walk(userData, ob, (ID **)&smd->domain->coll_group); + walk(userData, ob, (ID **)&smd->domain->fluid_group); + walk(userData, ob, (ID **)&smd->domain->eff_group); + } +} ModifierTypeInfo modifierType_Smoke = { /* name */ "Smoke", @@ -154,18 +170,18 @@ ModifierTypeInfo modifierType_Smoke = { /* copyData */ copyData, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, - /* requiredDataMask */ 0, + /* requiredDataMask */ NULL, /* freeData */ freeData, - /* isDisabled */ 0, + /* isDisabled */ NULL, /* updateDepgraph */ updateDepgraph, /* dependsOnTime */ dependsOnTime, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ foreachIDLink, }; diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c index 7761995a419..5f76fad14b1 100644 --- a/source/blender/modifiers/intern/MOD_smooth.c +++ b/source/blender/modifiers/intern/MOD_smooth.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_smooth.c + * \ingroup modifiers + */ + + #include "DNA_meshdata_types.h" #include "BLI_math.h" @@ -137,9 +142,7 @@ static void smoothModifier_do( v1 = vertexCos[idx1]; v2 = vertexCos[idx2]; - fvec[0] = (v1[0] + v2[0]) / 2.0; - fvec[1] = (v1[1] + v2[1]) / 2.0; - fvec[2] = (v1[2] + v2[2]) / 2.0; + mid_v3_v3v3(fvec, v1, v2); v1 = &ftmp[idx1*3]; v2 = &ftmp[idx2*3]; @@ -256,18 +259,18 @@ ModifierTypeInfo modifierType_Smooth = { /* copyData */ copyData, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, + /* deformMatrices */ NULL, /* deformVertsEM */ deformVertsEM, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, + /* freeData */ NULL, /* isDisabled */ isDisabled, - /* updateDepgraph */ 0, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* updateDepgraph */ NULL, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_softbody.c b/source/blender/modifiers/intern/MOD_softbody.c index 7322628267c..25996286735 100644 --- a/source/blender/modifiers/intern/MOD_softbody.c +++ b/source/blender/modifiers/intern/MOD_softbody.c @@ -30,11 +30,16 @@ * */ +/** \file blender/modifiers/intern/MOD_softbody.c + * \ingroup modifiers + */ + +#include <stdio.h> + #include "DNA_scene_types.h" #include "BLI_utildefines.h" - #include "BKE_cdderivedmesh.h" #include "BKE_particle.h" #include "BKE_softbody.h" @@ -66,20 +71,20 @@ ModifierTypeInfo modifierType_Softbody = { | eModifierTypeFlag_RequiresOriginalData | eModifierTypeFlag_Single, - /* copyData */ 0, + /* copyData */ NULL, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, - /* initData */ 0, - /* requiredDataMask */ 0, - /* freeData */ 0, - /* isDisabled */ 0, - /* updateDepgraph */ 0, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, + /* initData */ NULL, + /* requiredDataMask */ NULL, + /* freeData */ NULL, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, /* dependsOnTime */ dependsOnTime, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c index 4faf955b953..1b7b724835c 100644 --- a/source/blender/modifiers/intern/MOD_solidify.c +++ b/source/blender/modifiers/intern/MOD_solidify.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_solidify.c + * \ingroup modifiers + */ + + #include "DNA_meshdata_types.h" #include "BLI_math.h" @@ -209,6 +214,11 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, const int numEdges = dm->getNumEdges(dm); const int numFaces = dm->getNumFaces(dm); + /* only use material offsets if we have 2 or more materials */ + const short mat_nr_max= ob->totcol > 1 ? ob->totcol - 1 : 0; + const short mat_ofs= mat_nr_max ? smd->mat_ofs : 0; + const short mat_ofs_rim= mat_nr_max ? smd->mat_ofs_rim : 0; + /* use for edges */ int *new_vert_arr= NULL; int newFaces = 0; @@ -291,7 +301,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, ehi= BLI_edgehashIterator_new(edgehash); for(; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) { - int eidx= GET_INT_FROM_POINTER(BLI_edgehashIterator_getValue(ehi)); + eidx= GET_INT_FROM_POINTER(BLI_edgehashIterator_getValue(ehi)); if(edge_users[eidx] >= 0) { BLI_edgehashIterator_getKey(ehi, &v1, &v2); orig_mvert[v1].flag |= ME_VERT_TMP_TAG; @@ -355,6 +365,11 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DM_swap_face_data(result, i+numFaces, corner_indices); test_index_face(mf, &result->faceData, numFaces, is_quad ? 4:3); } + + if(mat_ofs) { + mf->mat_nr += mat_ofs; + CLAMP(mf->mat_nr, 0, mat_nr_max); + } } } @@ -408,7 +423,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, float *vert_angles= MEM_callocN(sizeof(float) * numVerts * 2, "mod_solid_pair"); /* 2 in 1 */ float *vert_accum= vert_angles + numVerts; float face_angles[4]; - int i, j, vidx; + int j, vidx; face_nors = CustomData_get_layer(&dm->faceData, CD_NORMAL); if(!face_nors) { @@ -515,9 +530,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, float (*edge_vert_nos)[3]= MEM_callocN(sizeof(float) * numVerts * 3, "solidify_edge_nos"); float nor[3]; #endif - /* maximum value -1, so we have room to increase */ - const short mat_nr_shift= (smd->flag & MOD_SOLIDIFY_RIM_MATERIAL) ? ob->totcol-1 : -1; - const unsigned char crease_rim= smd->crease_rim * 255.0f; const unsigned char crease_outer= smd->crease_outer * 255.0f; const unsigned char crease_inner= smd->crease_inner * 255.0f; @@ -577,14 +589,22 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, } /* use the next material index if option enabled */ - if(mf->mat_nr < mat_nr_shift) - mf->mat_nr++; - - if(crease_outer) - ed->crease= crease_outer; + if(mat_ofs_rim) { + mf->mat_nr += mat_ofs_rim; + CLAMP(mf->mat_nr, 0, mat_nr_max); + } + if(crease_outer) { + /* crease += crease_outer; without wrapping */ + unsigned char *cr= (unsigned char *)&(ed->crease); + int tcr= *cr + crease_outer; + *cr= tcr > 255 ? 255 : tcr; + } if(crease_inner) { - medge[numEdges + eidx].crease= crease_inner; + /* crease += crease_inner; without wrapping */ + unsigned char *cr= (unsigned char *)&(medge[numEdges + eidx].crease); + int tcr= *cr + crease_inner; + *cr= tcr > 255 ? 255 : tcr; } #ifdef SOLIDIFY_SIDE_NORMALS @@ -623,6 +643,11 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, MEM_freeN(edge_order); } + /* must recalculate normals with vgroups since they can displace unevenly [#26888] */ + if(dvert) { + CDDM_calc_normals(result); + } + return result; } @@ -650,19 +675,19 @@ ModifierTypeInfo modifierType_Solidify = { | eModifierTypeFlag_EnableInEditmode, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, /* applyModifierEM */ applyModifierEM, /* initData */ initData, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, - /* isDisabled */ 0, - /* updateDepgraph */ 0, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* freeData */ NULL, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL }; diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c index 4ba139305d8..fc9958b08d0 100644 --- a/source/blender/modifiers/intern/MOD_subsurf.c +++ b/source/blender/modifiers/intern/MOD_subsurf.c @@ -30,7 +30,12 @@ * */ -#include "stddef.h" +/** \file blender/modifiers/intern/MOD_subsurf.c + * \ingroup modifiers + */ + + +#include <stddef.h> #include "DNA_scene_types.h" #include "DNA_object_types.h" @@ -132,19 +137,19 @@ ModifierTypeInfo modifierType_Subsurf = { | eModifierTypeFlag_AcceptsCVs, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, /* applyModifierEM */ applyModifierEM, /* initData */ initData, - /* requiredDataMask */ 0, + /* requiredDataMask */ NULL, /* freeData */ freeData, /* isDisabled */ isDisabled, - /* updateDepgraph */ 0, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* updateDepgraph */ NULL, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c index 8d6f6954e18..382358b179e 100644 --- a/source/blender/modifiers/intern/MOD_surface.c +++ b/source/blender/modifiers/intern/MOD_surface.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_surface.c + * \ingroup modifiers + */ + + #include "DNA_scene_types.h" #include "DNA_object_types.h" #include "DNA_meshdata_types.h" @@ -91,7 +96,6 @@ static void deformVerts(ModifierData *md, Object *ob, int UNUSED(isFinalCalc)) { SurfaceModifierData *surmd = (SurfaceModifierData*) md; - unsigned int numverts = 0, i = 0; if(surmd->dm) surmd->dm->release(surmd->dm); @@ -108,6 +112,7 @@ static void deformVerts(ModifierData *md, Object *ob, if(surmd->dm) { + unsigned int numverts = 0, i = 0; int init = 0; float *vec; MVert *x, *v; @@ -171,20 +176,20 @@ ModifierTypeInfo modifierType_Surface = { /* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_NoUserAdd, - /* copyData */ 0, + /* copyData */ NULL, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, - /* requiredDataMask */ 0, + /* requiredDataMask */ NULL, /* freeData */ freeData, - /* isDisabled */ 0, - /* updateDepgraph */ 0, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, /* dependsOnTime */ dependsOnTime, - /* dependsOnNormals */ 0, - /* foreachObjectLink */ 0, - /* foreachIDLink */ 0, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, }; diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c index c697dafb6fc..d008fcfc929 100644 --- a/source/blender/modifiers/intern/MOD_util.c +++ b/source/blender/modifiers/intern/MOD_util.c @@ -1,4 +1,4 @@ -/** +/* * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** @@ -30,13 +30,21 @@ * ***** END GPL LICENSE BLOCK ***** */ +/** \file blender/modifiers/intern/MOD_util.c + * \ingroup modifiers + */ + + #include <string.h> #include "DNA_modifier_types.h" #include "DNA_object_types.h" #include "DNA_curve_types.h" +#include "DNA_meshdata_types.h" #include "BLI_utildefines.h" +#include "BLI_math_vector.h" +#include "BLI_math_matrix.h" #include "BKE_cdderivedmesh.h" #include "BKE_mesh.h" @@ -69,6 +77,92 @@ void get_texture_value(Tex *texture, float *tex_co, TexResult *texres) texres->tr = texres->tg = texres->tb = texres->tin; } +void get_texture_coords(MappingInfoModifierData *dmd, Object *ob, + DerivedMesh *dm, + float (*co)[3], float (*texco)[3], + int numVerts) +{ + int i; + int texmapping = dmd->texmapping; + float mapob_imat[4][4]; + + if(texmapping == MOD_DISP_MAP_OBJECT) { + if(dmd->map_object) + invert_m4_m4(mapob_imat, dmd->map_object->obmat); + else /* if there is no map object, default to local */ + texmapping = MOD_DISP_MAP_LOCAL; + } + + /* UVs need special handling, since they come from faces */ + if(texmapping == MOD_DISP_MAP_UV) { + if(CustomData_has_layer(&dm->faceData, CD_MTFACE)) { + MFace *mface = dm->getFaceArray(dm); + MFace *mf; + char *done = MEM_callocN(sizeof(*done) * numVerts, + "get_texture_coords done"); + int numFaces = dm->getNumFaces(dm); + char uvname[32]; + MTFace *tf; + + validate_layer_name(&dm->faceData, CD_MTFACE, dmd->uvlayer_name, uvname); + tf = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, uvname); + + /* verts are given the UV from the first face that uses them */ + for(i = 0, mf = mface; i < numFaces; ++i, ++mf, ++tf) { + if(!done[mf->v1]) { + texco[mf->v1][0] = tf->uv[0][0]; + texco[mf->v1][1] = tf->uv[0][1]; + texco[mf->v1][2] = 0; + done[mf->v1] = 1; + } + if(!done[mf->v2]) { + texco[mf->v2][0] = tf->uv[1][0]; + texco[mf->v2][1] = tf->uv[1][1]; + texco[mf->v2][2] = 0; + done[mf->v2] = 1; + } + if(!done[mf->v3]) { + texco[mf->v3][0] = tf->uv[2][0]; + texco[mf->v3][1] = tf->uv[2][1]; + texco[mf->v3][2] = 0; + done[mf->v3] = 1; + } + if(!done[mf->v4]) { + texco[mf->v4][0] = tf->uv[3][0]; + texco[mf->v4][1] = tf->uv[3][1]; + texco[mf->v4][2] = 0; + done[mf->v4] = 1; + } + } + + /* remap UVs from [0, 1] to [-1, 1] */ + for(i = 0; i < numVerts; ++i) { + texco[i][0] = texco[i][0] * 2 - 1; + texco[i][1] = texco[i][1] * 2 - 1; + } + + MEM_freeN(done); + return; + } else /* if there are no UVs, default to local */ + texmapping = MOD_DISP_MAP_LOCAL; + } + + for(i = 0; i < numVerts; ++i, ++co, ++texco) { + switch(texmapping) { + case MOD_DISP_MAP_LOCAL: + copy_v3_v3(*texco, *co); + break; + case MOD_DISP_MAP_GLOBAL: + mul_v3_m4v3(*texco, ob->obmat, *co); + break; + case MOD_DISP_MAP_OBJECT: + mul_v3_m4v3(*texco, ob->obmat, *co); + mul_m4_v3(mapob_imat, *texco); + break; + } + } +} + void modifier_vgroup_cache(ModifierData *md, float (*vertexCos)[3]) { while((md=md->next) && md->type==eModifierType_Armature) { @@ -148,7 +242,6 @@ DerivedMesh *get_dm(Object *ob, struct EditMesh *em, DerivedMesh *dm, float (*ve /* only called by BKE_modifier.h/modifier.c */ void modifier_type_init(ModifierTypeInfo *types[]) { - memset(types, 0, sizeof(types)); #define INIT_TYPE(typeName) (types[eModifierType_##typeName] = &modifierType_##typeName) INIT_TYPE(None); INIT_TYPE(Curve); @@ -185,6 +278,7 @@ void modifier_type_init(ModifierTypeInfo *types[]) INIT_TYPE(ShapeKey); INIT_TYPE(Solidify); INIT_TYPE(Screw); + INIT_TYPE(Warp); INIT_TYPE(NavMesh); #undef INIT_TYPE } diff --git a/source/blender/modifiers/intern/MOD_util.h b/source/blender/modifiers/intern/MOD_util.h index 0ba35ad23e6..b7862403459 100644 --- a/source/blender/modifiers/intern/MOD_util.h +++ b/source/blender/modifiers/intern/MOD_util.h @@ -1,4 +1,4 @@ -/** +/* * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** @@ -25,9 +25,17 @@ * ***** END GPL LICENSE BLOCK ***** */ +/** \file blender/modifiers/intern/MOD_util.h + * \ingroup modifiers + */ + + #ifndef MOD_UTIL_H #define MOD_UTIL_H +/* so modifier types match their defines */ +#include "MOD_modifiertypes.h" + struct Tex; struct TexResult; struct CustomData; @@ -38,6 +46,7 @@ struct EditMesh; struct ModifierData; void get_texture_value(struct Tex *texture, float *tex_co, struct TexResult *texres); +void get_texture_coords(struct MappingInfoModifierData *dmd, struct Object *ob, struct DerivedMesh *dm, float (*co)[3], float (*texco)[3], int numVerts); void modifier_vgroup_cache(struct ModifierData *md, float (*vertexCos)[3]); void validate_layer_name(const struct CustomData *data, int type, char *name, char *outname); struct DerivedMesh *get_cddm(struct Object *ob, struct EditMesh *em, struct DerivedMesh *dm, float (*vertexCos)[3]); diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c index 8eaf0d5fbcb..b054a5b0a6e 100644 --- a/source/blender/modifiers/intern/MOD_uvproject.c +++ b/source/blender/modifiers/intern/MOD_uvproject.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_uvproject.c + * \ingroup modifiers + */ + + /* UV Project modifier: Generates UVs projected from an object */ #include "DNA_meshdata_types.h" @@ -189,7 +194,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, free_uci= 1; } else { - float scale= (cam->type == CAM_PERSP) ? cam->clipsta * 32.0 / cam->lens : cam->ortho_scale; + float scale= (cam->type == CAM_PERSP) ? cam->clipsta * 32.0f / cam->lens : cam->ortho_scale; float xmax, xmin, ymax, ymin; if(aspect > 1.0f) { @@ -412,19 +417,19 @@ ModifierTypeInfo modifierType_UVProject = { | eModifierTypeFlag_EnableInEditmode, /* copyData */ copyData, - /* deformVerts */ 0, - /* deformMatrices */ 0, - /* deformVertsEM */ 0, - /* deformMatricesEM */ 0, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, /* applyModifierEM */ applyModifierEM, /* initData */ initData, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, - /* isDisabled */ 0, + /* freeData */ NULL, + /* isDisabled */ NULL, /* updateDepgraph */ updateDepgraph, - /* dependsOnTime */ 0, - /* dependsOnNormals */ 0, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, /* foreachIDLink */ foreachIDLink, }; diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c new file mode 100644 index 00000000000..27add27deb1 --- /dev/null +++ b/source/blender/modifiers/intern/MOD_warp.c @@ -0,0 +1,365 @@ +/* +* $Id$ +* +* ***** BEGIN GPL LICENSE BLOCK ***** +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +* Contributor(s): Campbell Barton +* +* ***** END GPL LICENSE BLOCK ***** +* +*/ + +#include <string.h> + +#include "MEM_guardedalloc.h" + +#include "BLI_math.h" +#include "BLI_utildefines.h" + +#include "BKE_cdderivedmesh.h" +#include "BKE_modifier.h" +#include "BKE_deform.h" +#include "BKE_texture.h" +#include "BKE_colortools.h" + +#include "DNA_object_types.h" +#include "DNA_meshdata_types.h" + +#include "depsgraph_private.h" + +#include "RE_shader_ext.h" + +#include "MOD_util.h" + + +static void initData(ModifierData *md) +{ + WarpModifierData *wmd = (WarpModifierData*) md; + + wmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + wmd->texture = NULL; + wmd->strength = 1.0f; + wmd->falloff_radius = 1.0f; + wmd->falloff_type = eWarp_Falloff_Smooth; + wmd->flag = 0; +} + +static void copyData(ModifierData *md, ModifierData *target) +{ + WarpModifierData *wmd = (WarpModifierData*) md; + WarpModifierData *twmd = (WarpModifierData*) target; + + twmd->object_from = wmd->object_from; + twmd->object_to = wmd->object_to; + + twmd->strength = wmd->strength; + twmd->falloff_radius = wmd->falloff_radius; + twmd->falloff_type = wmd->falloff_type; + strncpy(twmd->defgrp_name, wmd->defgrp_name, sizeof(twmd->defgrp_name)); + twmd->curfalloff = curvemapping_copy(wmd->curfalloff); + + /* map info */ + twmd->texture = wmd->texture; + twmd->map_object = wmd->map_object; + strncpy(twmd->uvlayer_name, wmd->uvlayer_name, sizeof(twmd->uvlayer_name)); + twmd->texmapping= wmd->texmapping; +} + +static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) +{ + WarpModifierData *wmd = (WarpModifierData *)md; + CustomDataMask dataMask = 0; + + /* ask for vertexgroups if we need them */ + if(wmd->defgrp_name[0]) dataMask |= (1 << CD_MDEFORMVERT); + dataMask |= (1 << CD_MDEFORMVERT); + + /* ask for UV coordinates if we need them */ + if(wmd->texmapping == MOD_DISP_MAP_UV) dataMask |= (1 << CD_MTFACE); + + return dataMask; +} + +static int dependsOnTime(ModifierData *md) +{ + WarpModifierData *wmd = (WarpModifierData *)md; + + if(wmd->texture) { + return BKE_texture_dependsOnTime(wmd->texture); + } + else { + return 0; + } +} + +static void freeData(ModifierData *md) +{ + WarpModifierData *wmd = (WarpModifierData *) md; + curvemapping_free(wmd->curfalloff); +} + + +static int isDisabled(ModifierData *md, int UNUSED(userRenderParams)) +{ + WarpModifierData *wmd = (WarpModifierData*) md; + + return !(wmd->object_from && wmd->object_to); +} + +static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData) +{ + WarpModifierData *wmd = (WarpModifierData*) md; + + walk(userData, ob, &wmd->object_from); + walk(userData, ob, &wmd->object_to); + walk(userData, ob, &wmd->map_object); +} + +static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData) +{ + WarpModifierData *wmd = (WarpModifierData*) md; + + walk(userData, ob, (ID **)&wmd->texture); + + walk(userData, ob, (ID **)&wmd->object_from); + walk(userData, ob, (ID **)&wmd->object_to); + walk(userData, ob, (ID **)&wmd->map_object); +} + +static void updateDepgraph(ModifierData *md, DagForest *forest, struct Scene *UNUSED(scene), + Object *UNUSED(ob), DagNode *obNode) +{ + WarpModifierData *wmd = (WarpModifierData*) md; + + if(wmd->object_from && wmd->object_to) { + DagNode *fromNode = dag_get_node(forest, wmd->object_from); + DagNode *toNode = dag_get_node(forest, wmd->object_to); + + dag_add_relation(forest, fromNode, obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Warp Modifier1"); + dag_add_relation(forest, toNode, obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Warp Modifier2"); + } + + if((wmd->texmapping == MOD_DISP_MAP_OBJECT) && wmd->map_object) { + DagNode *curNode = dag_get_node(forest, wmd->map_object); + dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Warp Modifier3"); + } +} + +static void warpModifier_do(WarpModifierData *wmd, Object *ob, + DerivedMesh *dm, float (*vertexCos)[3], int numVerts) +{ + float obinv[4][4]; + float mat_from[4][4]; + float mat_from_inv[4][4]; + float mat_to[4][4]; + float mat_unit[4][4]; + float mat_final[4][4]; + + float tmat[4][4]; + + float strength = wmd->strength; + float fac = 1.0f, weight; + int i; + int defgrp_index = defgroup_name_index(ob, wmd->defgrp_name); + MDeformVert *dv= NULL; + + float (*tex_co)[3]= NULL; + + if(!(wmd->object_from && wmd->object_to)) + return; + + if(wmd->curfalloff==NULL) /* should never happen, but bad lib linking could cause it */ + wmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + + invert_m4_m4(obinv, ob->obmat); + + mul_m4_m4m4(mat_from, wmd->object_from->obmat, obinv); + mul_m4_m4m4(mat_to, wmd->object_to->obmat, obinv); + + invert_m4_m4(tmat, mat_from); // swap? + mul_m4_m4m4(mat_final, mat_to, tmat); + + invert_m4_m4(mat_from_inv, mat_from); + + unit_m4(mat_unit); + + if(strength < 0.0f) { + float loc[3]; + strength = -strength; + + /* inverted location is not useful, just use the negative */ + copy_v3_v3(loc, mat_final[3]); + invert_m4(mat_final); + negate_v3_v3(mat_final[3], loc); + + } + weight= strength; + + if(wmd->texture) { + tex_co = MEM_mallocN(sizeof(*tex_co) * numVerts, "warpModifier_do tex_co"); + get_texture_coords((MappingInfoModifierData *)wmd, ob, dm, vertexCos, tex_co, numVerts); + } + + for(i = 0; i < numVerts; i++) { + float *co = vertexCos[i]; + + if(wmd->falloff_type==eWarp_Falloff_None || + ((fac=len_v3v3(co, mat_from[3])) < wmd->falloff_radius && (fac=(wmd->falloff_radius-fac)/wmd->falloff_radius)) ) { + + /* skip if no vert group found */ + if(defgrp_index >= 0) { + dv = dm->getVertData(dm, i, CD_MDEFORMVERT); + + if(dv) { + weight = defvert_find_weight(dv, defgrp_index) * wmd->strength; + if(weight <= 0.0f) + continue; + } + } + + + /* closely match PROP_SMOOTH and similar */ + switch(wmd->falloff_type) { + case eWarp_Falloff_None: + fac = 1.0f; + break; + case eWarp_Falloff_Curve: + fac = curvemapping_evaluateF(wmd->curfalloff, 0, fac); + break; + case eWarp_Falloff_Sharp: + fac = fac*fac; + break; + case eWarp_Falloff_Smooth: + fac = 3.0f*fac*fac - 2.0f*fac*fac*fac; + break; + case eWarp_Falloff_Root: + fac = (float)sqrt(fac); + break; + case eWarp_Falloff_Linear: + /* pass */ + break; + case eWarp_Falloff_Const: + fac = 1.0f; + break; + case eWarp_Falloff_Sphere: + fac = (float)sqrt(2*fac - fac * fac); + break; + } + + fac *= weight; + + if(tex_co) { + TexResult texres; + texres.nor = NULL; + get_texture_value(wmd->texture, tex_co[i], &texres); + fac *= texres.tin; + } + + /* into the 'from' objects space */ + mul_m4_v3(mat_from_inv, co); + + if(fac >= 1.0f) { + mul_m4_v3(mat_final, co); + } + else if(fac > 0.0f) { + if(wmd->flag & MOD_WARP_VOLUME_PRESERVE) { + /* interpolate the matrix for nicer locations */ + blend_m4_m4m4(tmat, mat_unit, mat_final, fac); + mul_m4_v3(tmat, co); + } + else { + float tvec[3]; + mul_v3_m4v3(tvec, mat_final, co); + interp_v3_v3v3(co, co, tvec, fac); + } + } + + /* out of the 'from' objects space */ + mul_m4_v3(mat_from, co); + } + } + + if(tex_co) + MEM_freeN(tex_co); + +} + +static int warp_needs_dm(WarpModifierData *wmd) +{ + return wmd->texture || wmd->defgrp_name[0]; +} + +static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, + float (*vertexCos)[3], int numVerts, int UNUSED(useRenderParams), int UNUSED(isFinalCalc)) +{ + DerivedMesh *dm= NULL; + int use_dm= warp_needs_dm((WarpModifierData *)md); + + if(use_dm) { + dm= get_cddm(ob, NULL, derivedData, vertexCos); + } + + warpModifier_do((WarpModifierData *)md, ob, dm, vertexCos, numVerts); + + if(use_dm) { + if(dm != derivedData) dm->release(dm); + } +} + +static void deformVertsEM(ModifierData *md, Object *ob, struct EditMesh *editData, + DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) +{ + DerivedMesh *dm = derivedData; + int use_dm= warp_needs_dm((WarpModifierData *)md); + + if(use_dm) { + if(!derivedData) + dm = CDDM_from_editmesh(editData, ob->data); + } + + deformVerts(md, ob, dm, vertexCos, numVerts, 0, 0); + + if(use_dm) { + if(!derivedData) dm->release(dm); + } +} + + +ModifierTypeInfo modifierType_Warp = { + /* name */ "Warp", + /* structName */ "WarpModifierData", + /* structSize */ sizeof(WarpModifierData), + /* type */ eModifierTypeType_OnlyDeform, + /* flags */ eModifierTypeFlag_AcceptsCVs + | eModifierTypeFlag_SupportsEditmode, + /* copyData */ copyData, + /* deformVerts */ deformVerts, + /* deformMatrices */ NULL, + /* deformVertsEM */ deformVertsEM, + /* deformMatricesEM */ NULL, + /* applyModifier */ 0, + /* applyModifierEM */ 0, + /* initData */ initData, + /* requiredDataMask */ requiredDataMask, + /* freeData */ freeData, + /* isDisabled */ isDisabled, + /* updateDepgraph */ updateDepgraph, + /* dependsOnTime */ dependsOnTime, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ foreachObjectLink, + /* foreachIDLink */ foreachIDLink, +}; diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c index dae9fc471cd..6dfe5314131 100644 --- a/source/blender/modifiers/intern/MOD_wave.c +++ b/source/blender/modifiers/intern/MOD_wave.c @@ -30,6 +30,11 @@ * */ +/** \file blender/modifiers/intern/MOD_wave.c + * \ingroup modifiers + */ + + #include "BLI_math.h" #include "DNA_meshdata_types.h" @@ -258,6 +263,9 @@ static void waveModifier_do(WaveModifierData *md, (float)(1.0 / exp(wmd->width * wmd->narrow * wmd->width * wmd->narrow)); float lifefac = wmd->height; float (*tex_co)[3] = NULL; + const int wmd_axis= wmd->flag & (MOD_WAVE_X|MOD_WAVE_Y); + const float falloff= wmd->falloff; + float falloff_fac= 1.0f; /* when falloff == 0.0f this stays at 1.0f */ if(wmd->flag & MOD_WAVE_NORM && ob->type == OB_MESH) mvert = dm->getVertArray(dm); @@ -281,7 +289,7 @@ static void waveModifier_do(WaveModifierData *md, if(wmd->damp == 0) wmd->damp = 10.0f; - if(wmd->lifetime != 0.0) { + if(wmd->lifetime != 0.0f) { float x = ctime - wmd->timeoffs; if(x > wmd->lifetime) { @@ -289,7 +297,7 @@ static void waveModifier_do(WaveModifierData *md, if(lifefac > wmd->damp) lifefac = 0.0; else lifefac = - (float)(wmd->height * (1.0 - sqrt(lifefac / wmd->damp))); + (float)(wmd->height * (1.0f - sqrtf(lifefac / wmd->damp))); } } @@ -299,9 +307,9 @@ static void waveModifier_do(WaveModifierData *md, wavemod_get_texture_coords(wmd, ob, dm, vertexCos, tex_co, numVerts); } - if(lifefac != 0.0) { + if(lifefac != 0.0f) { /* avoid divide by zero checks within the loop */ - float falloff_inv= wmd->falloff ? 1.0f / wmd->falloff : 1.0; + float falloff_inv= falloff ? 1.0f / falloff : 1.0f; int i; for(i = 0; i < numVerts; i++) { @@ -309,76 +317,72 @@ static void waveModifier_do(WaveModifierData *md, float x = co[0] - wmd->startx; float y = co[1] - wmd->starty; float amplit= 0.0f; - float dist = 0.0f; - float falloff_fac = 0.0f; - TexResult texres; - MDeformWeight *def_weight = NULL; + float def_weight= 1.0f; /* get weights */ if(dvert) { - int j; - for(j = 0; j < dvert[i].totweight; ++j) { - if(dvert[i].dw[j].def_nr == defgrp_index) { - def_weight = &dvert[i].dw[j]; - break; - } - } + def_weight= defvert_find_weight(&dvert[i], defgrp_index); /* if this vert isn't in the vgroup, don't deform it */ - if(!def_weight) continue; - } - - if(wmd->texture) { - texres.nor = NULL; - get_texture_value(wmd->texture, tex_co[i], &texres); - } - - /*get dist*/ - if(wmd->flag & MOD_WAVE_X) { - if(wmd->flag & MOD_WAVE_Y){ - dist = (float)sqrt(x*x + y*y); + if(def_weight == 0.0f) { + continue; } - else{ - dist = fabs(x); - } - } - else if(wmd->flag & MOD_WAVE_Y) { - dist = fabs(y); } - falloff_fac = (1.0f - (dist * falloff_inv)); - - if(wmd->flag & MOD_WAVE_X) { - if(wmd->flag & MOD_WAVE_Y) amplit = (float)sqrt(x*x + y*y); - else amplit = x; + switch(wmd_axis) { + case MOD_WAVE_X|MOD_WAVE_Y: + amplit = sqrtf(x*x + y*y); + break; + case MOD_WAVE_X: + amplit = x; + break; + case MOD_WAVE_Y: + amplit = y; + break; } - else if(wmd->flag & MOD_WAVE_Y) - amplit= y; /* this way it makes nice circles */ amplit -= (ctime - wmd->timeoffs) * wmd->speed; if(wmd->flag & MOD_WAVE_CYCL) { - amplit = (float)fmod(amplit - wmd->width, 2.0 * wmd->width) + amplit = (float)fmodf(amplit - wmd->width, 2.0f * wmd->width) + wmd->width; } + if(falloff != 0.0f) { + float dist = 0.0f; + + switch(wmd_axis) { + case MOD_WAVE_X|MOD_WAVE_Y: + dist = sqrtf(x*x + y*y); + break; + case MOD_WAVE_X: + dist = fabsf(x); + break; + case MOD_WAVE_Y: + dist = fabsf(y); + break; + } + + falloff_fac = (1.0f - (dist * falloff_inv)); + CLAMP(falloff_fac, 0.0f, 1.0f); + } + /* GAUSSIAN */ - if(amplit > -wmd->width && amplit < wmd->width) { + if((falloff_fac != 0.0f) && (amplit > -wmd->width) && (amplit < wmd->width)) { amplit = amplit * wmd->narrow; - amplit = (float)(1.0 / exp(amplit * amplit) - minfac); + amplit = (float)(1.0f / expf(amplit * amplit) - minfac); /*apply texture*/ - if(wmd->texture) - amplit = amplit * texres.tin; - - /*apply weight*/ - if(def_weight) - amplit = amplit * def_weight->weight; + if(wmd->texture) { + TexResult texres; + texres.nor = NULL; + get_texture_value(wmd->texture, tex_co[i], &texres); + amplit *= texres.tin; + } - /*apply falloff*/ - if (wmd->falloff > 0) - amplit = amplit * falloff_fac; + /*apply weight & falloff */ + amplit *= def_weight * falloff_fac; if(mvert) { /* move along normals */ @@ -452,18 +456,18 @@ ModifierTypeInfo modifierType_Wave = { | eModifierTypeFlag_SupportsEditmode, /* copyData */ copyData, /* deformVerts */ deformVerts, - /* deformMatrices */ 0, + /* deformMatrices */ NULL, /* deformVertsEM */ deformVertsEM, - /* deformMatricesEM */ 0, - /* applyModifier */ 0, - /* applyModifierEM */ 0, + /* deformMatricesEM */ NULL, + /* applyModifier */ NULL, + /* applyModifierEM */ NULL, /* initData */ initData, /* requiredDataMask */ requiredDataMask, - /* freeData */ 0, - /* isDisabled */ 0, + /* freeData */ NULL, + /* isDisabled */ NULL, /* updateDepgraph */ updateDepgraph, /* dependsOnTime */ dependsOnTime, - /* dependsOnNormals */ 0, + /* dependsOnNormals */ NULL, /* foreachObjectLink */ foreachObjectLink, /* foreachIDLink */ foreachIDLink, }; |