diff options
Diffstat (limited to 'source/blender/modifiers/intern/MOD_build.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_build.c | 89 |
1 files changed, 46 insertions, 43 deletions
diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c index e877d5649d4..902a9e7f14f 100644 --- a/source/blender/modifiers/intern/MOD_build.c +++ b/source/blender/modifiers/intern/MOD_build.c @@ -41,18 +41,16 @@ #include "BLI_ghash.h" #include "DNA_meshdata_types.h" +#include "DNA_mesh_types.h" +#include "DNA_object_types.h" -#include "BKE_cdderivedmesh.h" +#include "DEG_depsgraph_query.h" + +#include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_particle.h" #include "BKE_scene.h" - - -#ifdef _OPENMP -# include "BKE_mesh.h" /* BKE_MESH_OMP_LIMIT */ -#endif - static void initData(ModifierData *md) { BuildModifierData *bmd = (BuildModifierData *) md; @@ -66,13 +64,11 @@ static bool dependsOnTime(ModifierData *UNUSED(md)) return true; } -static DerivedMesh *applyModifier( - ModifierData *md, Object *UNUSED(ob), - DerivedMesh *derivedData, - ModifierApplyFlag UNUSED(flag)) +static Mesh *applyModifier( + ModifierData *md, const ModifierEvalContext *ctx, + struct Mesh *mesh) { - DerivedMesh *dm = derivedData; - DerivedMesh *result; + Mesh *result; BuildModifierData *bmd = (BuildModifierData *) md; int i, j, k; int numFaces_dst, numEdges_dst, numLoops_dst = 0; @@ -85,16 +81,16 @@ static DerivedMesh *applyModifier( GHash *vertHash = BLI_ghash_int_new("build ve apply gh"); /* maps edge indices in new mesh to indices in old mesh */ GHash *edgeHash = BLI_ghash_int_new("build ed apply gh"); + /* maps edge indices in old mesh to indices in new mesh */ GHash *edgeHash2 = BLI_ghash_int_new("build ed apply gh"); - const int numVert_src = dm->getNumVerts(dm); - const int numEdge_src = dm->getNumEdges(dm); - const int numPoly_src = dm->getNumPolys(dm); - MPoly *mpoly_src = dm->getPolyArray(dm); - MLoop *mloop_src = dm->getLoopArray(dm); - MEdge *medge_src = dm->getEdgeArray(dm); - MVert *mvert_src = dm->getVertArray(dm); - + const int numVert_src = mesh->totvert; + const int numEdge_src = mesh->totedge; + const int numPoly_src = mesh->totpoly; + MPoly *mpoly_src = mesh->mpoly; + MLoop *mloop_src = mesh->mloop; + MEdge *medge_src = mesh->medge; + MVert *mvert_src = mesh->mvert; vertMap = MEM_malloc_arrayN(numVert_src, sizeof(*vertMap), "build modifier vertMap"); edgeMap = MEM_malloc_arrayN(numEdge_src, sizeof(*edgeMap), "build modifier edgeMap"); @@ -104,9 +100,9 @@ static DerivedMesh *applyModifier( range_vn_i(edgeMap, numEdge_src, 0); range_vn_i(faceMap, numPoly_src, 0); - frac = (BKE_scene_frame_get(md->scene) - bmd->start) / bmd->length; + struct Scene *scene = DEG_get_input_scene(ctx->depsgraph); + frac = (BKE_scene_frame_get(scene) - bmd->start) / bmd->length; CLAMP(frac, 0.0f, 1.0f); - if (bmd->flag & MOD_BUILD_FLAG_REVERSE) { frac = 1.0f - frac; } @@ -118,7 +114,6 @@ static DerivedMesh *applyModifier( if (numFaces_dst) { MPoly *mpoly, *mp; MLoop *ml, *mloop; - MEdge *medge; uintptr_t hash_num, hash_num_alt; if (bmd->flag & MOD_BUILD_FLAG_RANDOMIZE) { @@ -151,11 +146,10 @@ static DerivedMesh *applyModifier( /* get the set of edges that will be in the new mesh (i.e. all edges * that have both verts in the new mesh) */ - medge = medge_src; hash_num = 0; hash_num_alt = 0; for (i = 0; i < numEdge_src; i++, hash_num_alt++) { - MEdge *me = medge + i; + MEdge *me = medge_src + i; if (BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v1)) && BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v2))) @@ -165,6 +159,7 @@ static DerivedMesh *applyModifier( hash_num++; } } + BLI_assert(hash_num == BLI_ghash_len(edgeHash)); } else if (numEdges_dst) { MEdge *medge, *me; @@ -221,11 +216,10 @@ static DerivedMesh *applyModifier( } } - /* now we know the number of verts, edges and faces, we can create - * the mesh - */ - result = CDDM_from_template(dm, BLI_ghash_len(vertHash), - BLI_ghash_len(edgeHash), 0, numLoops_dst, numFaces_dst); + /* now we know the number of verts, edges and faces, we can create the mesh. */ + result = BKE_mesh_new_nomain_from_template( + mesh, BLI_ghash_len(vertHash), BLI_ghash_len(edgeHash), + 0, numLoops_dst, numFaces_dst); /* copy the vertices across */ GHASH_ITER (gh_iter, vertHash) { @@ -235,9 +229,9 @@ static DerivedMesh *applyModifier( int newIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(&gh_iter)); source = mvert_src[oldIndex]; - dest = CDDM_get_vert(result, newIndex); + dest = &result->mvert[newIndex]; - DM_copy_vert_data(dm, result, oldIndex, newIndex, 1); + CustomData_copy_data(&mesh->vdata, &result->vdata, oldIndex, newIndex, 1); *dest = source; } @@ -248,17 +242,17 @@ static DerivedMesh *applyModifier( int oldIndex = GET_INT_FROM_POINTER(BLI_ghash_lookup(edgeHash, SET_INT_IN_POINTER(i))); source = medge_src[oldIndex]; - dest = CDDM_get_edge(result, i); + dest = &result->medge[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); + CustomData_copy_data(&mesh->edata, &result->edata, oldIndex, i, 1); *dest = source; } - mpoly_dst = CDDM_get_polys(result); - /* mloop_dst = */ ml_dst = CDDM_get_loops(result); + mpoly_dst = result->mpoly; + ml_dst = result->mloop; /* copy the faces across, remapping indices */ k = 0; @@ -268,12 +262,11 @@ static DerivedMesh *applyModifier( source = mpoly_src + faceMap[i]; dest = mpoly_dst + i; - DM_copy_poly_data(dm, result, faceMap[i], i, 1); + CustomData_copy_data(&mesh->pdata, &result->pdata, faceMap[i], i, 1); *dest = *source; dest->loopstart = k; - - DM_copy_loop_data(dm, result, source->loopstart, dest->loopstart, dest->totloop); + CustomData_copy_data(&mesh->ldata, &result->ldata, source->loopstart, dest->loopstart, dest->totloop); ml_src = mloop_src + source->loopstart; for (j = 0; j < source->totloop; j++, k++, ml_src++, ml_dst++) { @@ -290,10 +283,11 @@ static DerivedMesh *applyModifier( MEM_freeN(edgeMap); MEM_freeN(faceMap); - if (dm->dirty & DM_DIRTY_NORMALS) { - result->dirty |= DM_DIRTY_NORMALS; + if (mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL) { + result->runtime.cd_dirty_vert |= CD_MASK_NORMAL; } + /* TODO(sybren): also copy flags & tags? */ return result; } @@ -305,18 +299,27 @@ ModifierTypeInfo modifierType_Build = { /* type */ eModifierTypeType_Nonconstructive, /* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_AcceptsCVs, + /* copyData */ modifier_copyData_generic, + + /* deformVerts_DM */ NULL, + /* deformMatrices_DM */ NULL, + /* deformVertsEM_DM */ NULL, + /* deformMatricesEM_DM*/NULL, + /* applyModifier_DM */ NULL, + /* applyModifierEM_DM */NULL, + /* deformVerts */ NULL, /* deformMatrices */ NULL, /* deformVertsEM */ NULL, /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, /* applyModifierEM */ NULL, + /* initData */ initData, /* requiredDataMask */ NULL, /* freeData */ NULL, /* isDisabled */ NULL, - /* updateDepgraph */ NULL, /* updateDepsgraph */ NULL, /* dependsOnTime */ dependsOnTime, /* dependsOnNormals */ NULL, |