diff options
Diffstat (limited to 'source/blender/modifiers/intern/MOD_skin.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_skin.c | 131 |
1 files changed, 68 insertions, 63 deletions
diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c index a1d952c12ec..586a0b57350 100644 --- a/source/blender/modifiers/intern/MOD_skin.c +++ b/source/blender/modifiers/intern/MOD_skin.c @@ -59,20 +59,20 @@ #include "MEM_guardedalloc.h" +#include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_modifier_types.h" #include "BLI_utildefines.h" #include "BLI_array.h" -#include "BLI_heap.h" +#include "BLI_heap_simple.h" #include "BLI_math.h" #include "BLI_stack.h" #include "BLI_bitmap.h" -#include "BKE_cdderivedmesh.h" #include "BKE_deform.h" -#include "BKE_DerivedMesh.h" +#include "BKE_library.h" #include "BKE_mesh.h" #include "BKE_mesh_mapping.h" #include "BKE_modifier.h" @@ -826,11 +826,11 @@ static int calc_edge_subdivisions( #undef NUM_SUBDIVISIONS_MAX } -/* Take a DerivedMesh and subdivide its edges to keep skin nodes +/* Take a Mesh and subdivide its edges to keep skin nodes * reasonably close. */ -static DerivedMesh *subdivide_base(DerivedMesh *orig) +static Mesh *subdivide_base(Mesh *orig) { - DerivedMesh *dm; + Mesh *result; MVertSkin *orignode, *outnode; MVert *origvert, *outvert; MEdge *origedge, *outedge, *e; @@ -840,12 +840,12 @@ static DerivedMesh *subdivide_base(DerivedMesh *orig) int i, j, k, u, v; float radrat; - orignode = CustomData_get_layer(&orig->vertData, CD_MVERT_SKIN); - origvert = orig->getVertArray(orig); - origedge = orig->getEdgeArray(orig); - origdvert = orig->getVertDataArray(orig, CD_MDEFORMVERT); - totorigvert = orig->getNumVerts(orig); - totorigedge = orig->getNumEdges(orig); + orignode = CustomData_get_layer(&orig->vdata, CD_MVERT_SKIN); + origvert = orig->mvert; + origedge = orig->medge; + origdvert = orig->dvert; + totorigvert = orig->totvert; + totorigedge = orig->totedge; /* Get degree of all vertices */ degree = MEM_calloc_arrayN(totorigvert, sizeof(int), "degree"); @@ -859,25 +859,27 @@ static DerivedMesh *subdivide_base(DerivedMesh *orig) for (i = 0, totsubd = 0; i < totorigedge; i++) { edge_subd[i] += calc_edge_subdivisions(origvert, orignode, &origedge[i], degree); + BLI_assert(edge_subd[i] >= 0); totsubd += edge_subd[i]; } MEM_freeN(degree); - /* Allocate output derivedmesh */ - dm = CDDM_from_template(orig, - totorigvert + totsubd, - totorigedge + totsubd, - 0, 0, 0); + /* Allocate output mesh */ + result = BKE_mesh_new_nomain_from_template( + orig, + totorigvert + totsubd, + totorigedge + totsubd, + 0, 0, 0); - outvert = dm->getVertArray(dm); - outedge = dm->getEdgeArray(dm); - outnode = CustomData_get_layer(&dm->vertData, CD_MVERT_SKIN); - outdvert = CustomData_get_layer(&dm->vertData, CD_MDEFORMVERT); + outvert = result->mvert; + outedge = result->medge; + outnode = CustomData_get_layer(&result->vdata, CD_MVERT_SKIN); + outdvert = result->dvert; /* Copy original vertex data */ - CustomData_copy_data(&orig->vertData, - &dm->vertData, + CustomData_copy_data(&orig->vdata, + &result->vdata, 0, 0, totorigvert); /* Subdivide edges */ @@ -961,7 +963,7 @@ static DerivedMesh *subdivide_base(DerivedMesh *orig) MEM_freeN(edge_subd); - return dm; + return result; } /******************************* Output *******************************/ @@ -1430,10 +1432,10 @@ static void hull_merge_triangles(SkinOutput *so, const SkinModifierData *smd) { BMIter iter; BMEdge *e; - Heap *heap; + HeapSimple *heap; float score; - heap = BLI_heap_new(); + heap = BLI_heapsimple_new(); BM_mesh_elem_hflag_disable_all(so->bm, BM_FACE, BM_ELEM_TAG, false); @@ -1476,15 +1478,15 @@ static void hull_merge_triangles(SkinOutput *so, const SkinModifierData *smd) continue; } - BLI_heap_insert(heap, -score, e); + BLI_heapsimple_insert(heap, -score, e); } } } - while (!BLI_heap_is_empty(heap)) { + while (!BLI_heapsimple_is_empty(heap)) { BMFace *adj[2]; - e = BLI_heap_pop_min(heap); + e = BLI_heapsimple_pop_min(heap); if (BM_edge_face_pair(e, &adj[0], &adj[1])) { /* If both triangles still free, and if they don't already @@ -1501,7 +1503,7 @@ static void hull_merge_triangles(SkinOutput *so, const SkinModifierData *smd) } } - BLI_heap_free(heap, NULL); + BLI_heapsimple_free(heap, NULL); BM_mesh_delete_hflag_tagged(so->bm, BM_ELEM_TAG, BM_EDGE | BM_FACE); @@ -1819,12 +1821,12 @@ static BMesh *build_skin(SkinNode *skin_nodes, return so.bm; } -static void skin_set_orig_indices(DerivedMesh *dm) +static void skin_set_orig_indices(Mesh *mesh) { int *orig, totpoly; - totpoly = dm->getNumPolys(dm); - orig = CustomData_add_layer(&dm->polyData, CD_ORIGINDEX, + totpoly = mesh->totpoly; + orig = CustomData_add_layer(&mesh->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, totpoly); copy_vn_i(orig, totpoly, ORIGINDEX_NONE); } @@ -1835,10 +1837,10 @@ static void skin_set_orig_indices(DerivedMesh *dm) * 2) Generate node frames * 3) Output vertices and polygons from frames, connections, and hulls */ -static DerivedMesh *base_skin(DerivedMesh *origdm, - SkinModifierData *smd) +static Mesh *base_skin(Mesh *origmesh, + SkinModifierData *smd) { - DerivedMesh *result; + Mesh *result; MVertSkin *nodes; BMesh *bm; EMat *emat; @@ -1851,13 +1853,13 @@ static DerivedMesh *base_skin(DerivedMesh *origdm, int totvert, totedge; bool has_valid_root = false; - nodes = CustomData_get_layer(&origdm->vertData, CD_MVERT_SKIN); + nodes = CustomData_get_layer(&origmesh->vdata, CD_MVERT_SKIN); - mvert = origdm->getVertArray(origdm); - dvert = origdm->getVertDataArray(origdm, CD_MDEFORMVERT); - medge = origdm->getEdgeArray(origdm); - totvert = origdm->getNumVerts(origdm); - totedge = origdm->getNumEdges(origdm); + mvert = origmesh->mvert; + dvert = origmesh->dvert; + medge = origmesh->medge; + totvert = origmesh->totvert; + totedge = origmesh->totedge; BKE_mesh_vert_edge_map_create(&emap, &emapmem, medge, totvert, totedge); @@ -1879,31 +1881,29 @@ static DerivedMesh *base_skin(DerivedMesh *origdm, if (!bm) return NULL; - result = CDDM_from_bmesh(bm, false); + result = BKE_mesh_from_bmesh_for_eval_nomain(bm, 0); BM_mesh_free(bm); - result->dirty |= DM_DIRTY_NORMALS; + result->runtime.cd_dirty_vert |= CD_MASK_NORMAL; skin_set_orig_indices(result); return result; } -static DerivedMesh *final_skin(SkinModifierData *smd, - DerivedMesh *origdm) +static Mesh *final_skin(SkinModifierData *smd, Mesh *mesh) { - DerivedMesh *dm; + Mesh *result; /* Skin node layer is required */ - if (!CustomData_get_layer(&origdm->vertData, CD_MVERT_SKIN)) - return origdm; - - origdm = subdivide_base(origdm); - dm = base_skin(origdm, smd); + if (!CustomData_get_layer(&mesh->vdata, CD_MVERT_SKIN)) + return mesh; - origdm->release(origdm); + mesh = subdivide_base(mesh); + result = base_skin(mesh, smd); - return dm; + BKE_id_free(NULL, mesh); + return result; } @@ -1921,15 +1921,14 @@ static void initData(ModifierData *md) smd->symmetry_axes = MOD_SKIN_SYMM_X; } -static DerivedMesh *applyModifier(ModifierData *md, - Object *UNUSED(ob), - DerivedMesh *dm, - ModifierApplyFlag UNUSED(flag)) +static Mesh *applyModifier(ModifierData *md, + const ModifierEvalContext *UNUSED(ctx), + Mesh *mesh) { - DerivedMesh *result; + Mesh *result; - if (!(result = final_skin((SkinModifierData *)md, dm))) - return dm; + if (!(result = final_skin((SkinModifierData *)md, mesh))) + return mesh; return result; } @@ -1947,17 +1946,23 @@ ModifierTypeInfo modifierType_Skin = { /* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsEditmode, /* copyData */ modifier_copyData_generic, + + /* deformVerts_DM */ NULL, + /* deformMatrices_DM */ NULL, + /* deformVertsEM_DM */ NULL, + /* deformMatricesEM_DM*/NULL, + /* applyModifier_DM */ NULL, + /* deformVerts */ NULL, /* deformMatrices */ NULL, /* deformVertsEM */ NULL, /* deformMatricesEM */ NULL, /* applyModifier */ applyModifier, - /* applyModifierEM */ NULL, + /* initData */ initData, /* requiredDataMask */ requiredDataMask, /* freeData */ NULL, /* isDisabled */ NULL, - /* updateDepgraph */ NULL, /* updateDepsgraph */ NULL, /* dependsOnTime */ NULL, /* dependsOnNormals */ NULL, |