diff options
Diffstat (limited to 'source/blender/modifiers/intern/MOD_screw.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_screw.c | 109 |
1 files changed, 52 insertions, 57 deletions
diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c index 5c1296d222e..96335707082 100644 --- a/source/blender/modifiers/intern/MOD_screw.c +++ b/source/blender/modifiers/intern/MOD_screw.c @@ -36,6 +36,7 @@ /* Screw modifier: revolves the edges about an axis */ #include <limits.h> +#include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_object_types.h" @@ -43,10 +44,10 @@ #include "BLI_alloca.h" #include "BLI_utildefines.h" -#include "BKE_cdderivedmesh.h" +#include "BKE_library.h" #include "BKE_library_query.h" +#include "BKE_mesh.h" -#include "depsgraph_private.h" #include "DEG_depsgraph_build.h" #include "MOD_modifiertypes.h" @@ -112,8 +113,8 @@ static void screwvert_iter_step(ScrewVertIter *iter) } } -static DerivedMesh *dm_remove_doubles_on_axis( - DerivedMesh *result, MVert *mvert_new, const uint totvert, const uint step_tot, +static Mesh *mesh_remove_doubles_on_axis( + Mesh *result, MVert *mvert_new, const uint totvert, const uint step_tot, const float axis_vec[3], const float axis_offset[3], const float merge_threshold) { const float merge_threshold_sq = SQUARE(merge_threshold); @@ -157,7 +158,7 @@ static DerivedMesh *dm_remove_doubles_on_axis( } } } - result = CDDM_merge_verts(result, full_doubles_map, (int)(tot_doubles * (step_tot - 1)), CDDM_MERGE_VERTS_DUMP_IF_MAPPED); + result = BKE_mesh_merge_verts(result, full_doubles_map, (int)(tot_doubles * (step_tot - 1)), MESH_MERGE_VERTS_DUMP_IF_MAPPED); MEM_freeN(full_doubles_map); } return result; @@ -176,15 +177,14 @@ static void initData(ModifierData *md) ltmd->merge_dist = 0.01f; } -static DerivedMesh *applyModifier( - ModifierData *md, Object *ob, - DerivedMesh *derivedData, - ModifierApplyFlag flag) +static Mesh *applyModifier( + ModifierData *md, const ModifierEvalContext *ctx, + Mesh *meshData) { - DerivedMesh *dm = derivedData; - DerivedMesh *result; + Mesh *mesh = meshData; + Mesh *result; ScrewModifierData *ltmd = (ScrewModifierData *) md; - const bool use_render_params = (flag & MOD_APPLY_RENDER) != 0; + const bool use_render_params = (ctx->flag & MOD_APPLY_RENDER) != 0; int *origindex; int mpoly_index = 0; @@ -208,15 +208,15 @@ static DerivedMesh *applyModifier( }; unsigned int maxVerts = 0, maxEdges = 0, maxPolys = 0; - const unsigned int totvert = (unsigned int)dm->getNumVerts(dm); - const unsigned int totedge = (unsigned int)dm->getNumEdges(dm); - const unsigned int totpoly = (unsigned int)dm->getNumPolys(dm); + const unsigned int totvert = (unsigned int)mesh->totvert; + const unsigned int totedge = (unsigned int)mesh->totedge; + const unsigned int totpoly = (unsigned int)mesh->totpoly; unsigned int *edge_poly_map = NULL; /* orig edge to orig poly */ unsigned int *vert_loop_map = NULL; /* orig vert to orig loop */ /* UV Coords */ - const unsigned int mloopuv_layers_tot = (unsigned int)CustomData_number_of_layers(&dm->loopData, CD_MLOOPUV); + const unsigned int mloopuv_layers_tot = (unsigned int)CustomData_number_of_layers(&mesh->ldata, CD_MLOOPUV); MLoopUV **mloopuv_layers = BLI_array_alloca(mloopuv_layers, mloopuv_layers_tot); float uv_u_scale; float uv_v_minmax[2] = {FLT_MAX, -FLT_MAX}; @@ -251,7 +251,7 @@ static DerivedMesh *applyModifier( /* don't do anything? */ if (!totvert) - return CDDM_from_template(dm, 0, 0, 0, 0, 0); + return BKE_mesh_new_nomain_from_template(mesh, 0, 0, 0, 0, 0); switch (ltmd->axis) { case 0: @@ -272,7 +272,7 @@ static DerivedMesh *applyModifier( if (ltmd->ob_axis) { /* calc the matrix relative to the axis object */ - invert_m4_m4(mtx_tmp_a, ob->obmat); + invert_m4_m4(mtx_tmp_a, ctx->object->obmat); copy_m4_m4(mtx_tx_inv, ltmd->ob_axis->obmat); mul_m4_m4m4(mtx_tx, mtx_tmp_a, mtx_tx_inv); @@ -376,24 +376,24 @@ static DerivedMesh *applyModifier( uv_u_scale = (uv_u_scale / (float)ltmd->iter) * (angle / ((float)M_PI * 2.0f)); } - result = CDDM_from_template(dm, (int)maxVerts, (int)maxEdges, 0, (int)maxPolys * 4, (int)maxPolys); + result = BKE_mesh_new_nomain_from_template(mesh, (int)maxVerts, (int)maxEdges, 0, (int)maxPolys * 4, (int)maxPolys); /* copy verts from mesh */ - mvert_orig = dm->getVertArray(dm); - medge_orig = dm->getEdgeArray(dm); + mvert_orig = mesh->mvert; + medge_orig = mesh->medge; - mvert_new = result->getVertArray(result); - mpoly_new = result->getPolyArray(result); - mloop_new = result->getLoopArray(result); - medge_new = result->getEdgeArray(result); + mvert_new = result->mvert; + mpoly_new = result->mpoly; + mloop_new = result->mloop; + medge_new = result->medge; - if (!CustomData_has_layer(&result->polyData, CD_ORIGINDEX)) { - CustomData_add_layer(&result->polyData, CD_ORIGINDEX, CD_CALLOC, NULL, (int)maxPolys); + if (!CustomData_has_layer(&result->pdata, CD_ORIGINDEX)) { + CustomData_add_layer(&result->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, (int)maxPolys); } - origindex = CustomData_get_layer(&result->polyData, CD_ORIGINDEX); + origindex = CustomData_get_layer(&result->pdata, CD_ORIGINDEX); - DM_copy_vert_data(dm, result, 0, 0, (int)totvert); /* copy first otherwise this overwrites our own vertex normals */ + CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, (int)totvert); if (mloopuv_layers_tot) { float zero_co[3] = {0}; @@ -403,7 +403,7 @@ static DerivedMesh *applyModifier( if (mloopuv_layers_tot) { unsigned int uv_lay; for (uv_lay = 0; uv_lay < mloopuv_layers_tot; uv_lay++) { - mloopuv_layers[uv_lay] = CustomData_get_layer_n(&result->loopData, CD_MLOOPUV, (int)uv_lay); + mloopuv_layers[uv_lay] = CustomData_get_layer_n(&result->ldata, CD_MLOOPUV, (int)uv_lay); } if (ltmd->flag & MOD_SCREW_UV_STRETCH_V) { @@ -439,8 +439,8 @@ static DerivedMesh *applyModifier( if (totpoly) { MPoly *mp_orig; - mpoly_orig = dm->getPolyArray(dm); - mloop_orig = dm->getLoopArray(dm); + mpoly_orig = mesh->mpoly; + mloop_orig = mesh->mloop; edge_poly_map = MEM_malloc_arrayN(totedge, sizeof(*edge_poly_map), __func__); memset(edge_poly_map, 0xff, sizeof(*edge_poly_map) * totedge); @@ -851,7 +851,7 @@ static DerivedMesh *applyModifier( madd_v3_v3fl(mat[3], axis_vec, screw_ofs * ((float)step / (float)(step_tot - 1))); /* copy a slice */ - DM_copy_vert_data(dm, result, 0, (int)varray_stride, (int)totvert); + CustomData_copy_data(&mesh->vdata, &result->vdata, 0, (int)varray_stride, (int)totvert); mv_new_base = mvert_new; mv_new = &mvert_new[varray_stride]; /* advance to the next slice */ @@ -954,7 +954,7 @@ static DerivedMesh *applyModifier( /* Polygon */ if (has_mpoly_orig) { - DM_copy_poly_data(dm, result, (int)mpoly_index_orig, (int)mpoly_index, 1); + CustomData_copy_data(&mesh->pdata, &result->pdata, (int)mpoly_index_orig, (int)mpoly_index, 1); origindex[mpoly_index] = (int)mpoly_index_orig; } else { @@ -969,10 +969,11 @@ static DerivedMesh *applyModifier( /* Loop-Custom-Data */ if (has_mloop_orig) { int l_index = (int)(ml_new - mloop_new); - DM_copy_loop_data(dm, result, (int)mloop_index_orig[0], l_index + 0, 1); - DM_copy_loop_data(dm, result, (int)mloop_index_orig[1], l_index + 1, 1); - DM_copy_loop_data(dm, result, (int)mloop_index_orig[1], l_index + 2, 1); - DM_copy_loop_data(dm, result, (int)mloop_index_orig[0], l_index + 3, 1); + + CustomData_copy_data(&mesh->ldata, &result->ldata, (int)mloop_index_orig[0], l_index + 0, 1); + CustomData_copy_data(&mesh->ldata, &result->ldata, (int)mloop_index_orig[1], l_index + 1, 1); + CustomData_copy_data(&mesh->ldata, &result->ldata, (int)mloop_index_orig[1], l_index + 2, 1); + CustomData_copy_data(&mesh->ldata, &result->ldata, (int)mloop_index_orig[0], l_index + 3, 1); if (mloopuv_layers_tot) { unsigned int uv_lay; @@ -1094,36 +1095,22 @@ static DerivedMesh *applyModifier( } if ((ltmd->flag & MOD_SCREW_MERGE) && (screw_ofs == 0.0f)) { - DerivedMesh *result_prev = result; - result = dm_remove_doubles_on_axis( + Mesh *result_prev = result; + result = mesh_remove_doubles_on_axis( result, mvert_new, totvert, step_tot, axis_vec, ltmd->ob_axis ? mtx_tx[3] : NULL, ltmd->merge_dist); if (result != result_prev) { - result->dirty |= DM_DIRTY_NORMALS; + result->runtime.cd_dirty_vert |= CD_MASK_NORMAL; } } if ((ltmd->flag & MOD_SCREW_NORMAL_CALC) == 0) { - result->dirty |= DM_DIRTY_NORMALS; + result->runtime.cd_dirty_vert |= CD_MASK_NORMAL; } return result; } - -static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx) -{ - ScrewModifierData *ltmd = (ScrewModifierData *) md; - - if (ltmd->ob_axis) { - DagNode *curNode = dag_get_node(ctx->forest, ltmd->ob_axis); - - dag_add_relation(ctx->forest, curNode, ctx->obNode, - DAG_RL_DATA_DATA | DAG_RL_OB_DATA, - "Screw Modifier"); - } -} - static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx) { ScrewModifierData *ltmd = (ScrewModifierData *)md; @@ -1153,17 +1140,25 @@ ModifierTypeInfo modifierType_Screw = { eModifierTypeFlag_EnableInEditmode, /* 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 */ updateDepgraph, /* updateDepsgraph */ updateDepsgraph, /* dependsOnTime */ NULL, /* dependsOnNormals */ NULL, |