diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2018-05-02 12:39:23 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2018-05-02 13:15:00 +0300 |
commit | 81175eb40ddbbd8ea9c98eb71f590b148012eb06 (patch) | |
tree | 75c3942ed83873519c60733799e77d4e61953ba1 /source | |
parent | baf0547de57397d2f12404d1cc1e861aa1e90d83 (diff) |
Modifiers: ported Bevel modifier DerivedMesh → Mesh
This introduces `BKE_mesh_to_bmesh_ex()`, which exposes all of the
`BMeshFromMeshParams` parameters to the caller. This is required to enable
the `calc_face_normal` flag, which is required for the Bevel modifier.
This also introduces `BKE_bmesh_to_mesh()`, which allocates a new `Mesh`,
converts the `BMesh` to it, and returns it. The returned mesh is owned by
the caller.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_mesh.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 36 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_armature.c | 10 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_bevel.c | 28 |
4 files changed, 55 insertions, 27 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 386681bf99a..18c518e431f 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -33,6 +33,8 @@ struct ID; struct BMeshCreateParams; +struct BMeshFromMeshParams; +struct BMeshToMeshParams; struct BoundBox; struct Depsgraph; struct EdgeHash; @@ -71,10 +73,16 @@ extern "C" { /* *** mesh.c *** */ +struct BMesh *BKE_mesh_to_bmesh_ex( + struct Mesh *me, + const struct BMeshCreateParams *create_params, + const struct BMeshFromMeshParams *convert_params); struct BMesh *BKE_mesh_to_bmesh( struct Mesh *me, struct Object *ob, const bool add_key_index, const struct BMeshCreateParams *params); +struct Mesh *BKE_bmesh_to_mesh(struct BMesh *me, const struct BMeshToMeshParams *params); + int poly_find_loop_from_vert( const struct MPoly *poly, const struct MLoop *loopstart, unsigned vert); diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 35af7196524..a927377149c 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -666,23 +666,41 @@ Mesh *BKE_mesh_copy(Main *bmain, const Mesh *me) return me_copy; } -BMesh *BKE_mesh_to_bmesh( - Mesh *me, Object *ob, - const bool add_key_index, const struct BMeshCreateParams *params) +BMesh *BKE_mesh_to_bmesh_ex( + Mesh *me, + const struct BMeshCreateParams *create_params, + const struct BMeshFromMeshParams *convert_params) { BMesh *bm; const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(me); - bm = BM_mesh_create(&allocsize, params); - - BM_mesh_bm_from_me( - bm, me, (&(struct BMeshFromMeshParams){ - .add_key_index = add_key_index, .use_shapekey = true, .active_shapekey = ob->shapenr, - })); + bm = BM_mesh_create(&allocsize, create_params); + BM_mesh_bm_from_me(bm, me, convert_params); return bm; } +BMesh *BKE_mesh_to_bmesh( + Mesh *me, Object *ob, + const bool add_key_index, const struct BMeshCreateParams *params) +{ + struct BMeshFromMeshParams convert_params = { + .calc_face_normal = false, + .add_key_index = add_key_index, + .use_shapekey = true, + .active_shapekey = ob->shapenr, + }; + return BKE_mesh_to_bmesh_ex(me, params, &convert_params); +} + +Mesh *BKE_bmesh_to_mesh(BMesh *bm, const struct BMeshToMeshParams *params) +{ + Mesh *mesh = BKE_libblock_alloc_notest(ID_ME); + BKE_mesh_init(mesh); + BM_mesh_bm_to_me(bm, mesh, params); + return mesh; +} + void BKE_mesh_make_local(Main *bmain, Mesh *me, const bool lib_local) { BKE_id_make_local_generic(bmain, &me->id, true, lib_local); diff --git a/source/blender/modifiers/intern/MOD_armature.c b/source/blender/modifiers/intern/MOD_armature.c index f354ed3aada..d48c4e2549d 100644 --- a/source/blender/modifiers/intern/MOD_armature.c +++ b/source/blender/modifiers/intern/MOD_armature.c @@ -136,12 +136,9 @@ static void deformVertsEM( ArmatureModifierData *amd = (ArmatureModifierData *) md; Mesh *mesh_src = mesh; - /* TODO(sybren): possibly lift this code to modifier.c and use it for all modifiers */ if (!mesh) { struct BMeshToMeshParams params = {0}; - mesh_src = BKE_libblock_alloc_notest(ID_ME); - BKE_mesh_init(mesh_src); - BM_mesh_bm_to_me(em->bm, mesh_src, ¶ms); + mesh_src = BKE_bmesh_to_mesh(em->bm, ¶ms); } modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */ @@ -169,12 +166,9 @@ static void deformMatricesEM( ArmatureModifierData *amd = (ArmatureModifierData *) md; Mesh *mesh_src = mesh; - /* TODO(sybren): possibly lift this code to modifier.c and use it for all modifiers */ if (!mesh) { struct BMeshToMeshParams params = {0}; - mesh_src = BKE_libblock_alloc_notest(ID_ME); - BKE_mesh_init(mesh_src); - BM_mesh_bm_to_me(em->bm, mesh_src, ¶ms); + mesh_src = BKE_bmesh_to_mesh(em->bm, ¶ms); } armature_deform_verts(amd->object, ctx->object, mesh_src, vertexCos, defMats, numVerts, diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c index 4134314bd85..325b70ddc5e 100644 --- a/source/blender/modifiers/intern/MOD_bevel.c +++ b/source/blender/modifiers/intern/MOD_bevel.c @@ -33,6 +33,7 @@ */ #include "DNA_object_types.h" +#include "DNA_mesh_types.h" #include "BLI_utildefines.h" #include "BLI_math.h" @@ -40,6 +41,7 @@ #include "BKE_cdderivedmesh.h" #include "BKE_deform.h" +#include "BKE_mesh.h" #include "BKE_modifier.h" #include "MOD_util.h" @@ -86,10 +88,9 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) /* * This calls the new bevel code (added since 2.64) */ -static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, - DerivedMesh *dm) +static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh) { - DerivedMesh *result; + Mesh *result; BMesh *bm; BMIter iter; BMEdge *e; @@ -105,9 +106,17 @@ static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *c const int mat = CLAMPIS(bmd->mat, -1, ctx->object->totcol - 1); const bool loop_slide = (bmd->flags & MOD_BEVEL_EVEN_WIDTHS) == 0; - bm = DM_to_bmesh(dm, true); + const struct BMeshCreateParams bmcp = {0}; + const struct BMeshFromMeshParams bmfmp = { + .calc_face_normal = true, + .add_key_index = false, + .use_shapekey = true, + .active_shapekey = ctx->object->shapenr, + }; + bm = BKE_mesh_to_bmesh_ex(mesh, &bmcp, &bmfmp); + if ((bmd->lim_flags & MOD_BEVEL_VGROUP) && bmd->defgrp_name[0]) - modifier_get_vgroup(ctx->object, dm, bmd->defgrp_name, &dvert, &vgroup); + modifier_get_vgroup_mesh(ctx->object, mesh, bmd->defgrp_name, &dvert, &vgroup); if (vertex_only) { BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { @@ -167,15 +176,14 @@ static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *c vertex_only, bmd->lim_flags & MOD_BEVEL_WEIGHT, do_clamp, dvert, vgroup, mat, loop_slide); - result = CDDM_from_bmesh(bm, true); + struct BMeshToMeshParams bmmp = {0}; + result = BKE_bmesh_to_mesh(bm, &bmmp); BLI_assert(bm->vtoolflagpool == NULL && bm->etoolflagpool == NULL && bm->ftoolflagpool == NULL); /* make sure we never alloc'd these */ BM_mesh_free(bm); - result->dirty |= DM_DIRTY_NORMALS; - return result; } @@ -199,14 +207,14 @@ ModifierTypeInfo modifierType_Bevel = { /* deformMatrices_DM */ NULL, /* deformVertsEM_DM */ NULL, /* deformMatricesEM_DM*/NULL, - /* applyModifier_DM */ applyModifier, + /* applyModifier_DM */ NULL, /* applyModifierEM_DM */NULL, /* deformVerts */ NULL, /* deformMatrices */ NULL, /* deformVertsEM */ NULL, /* deformMatricesEM */ NULL, - /* applyModifier */ NULL, + /* applyModifier */ applyModifier, /* applyModifierEM */ NULL, /* initData */ initData, |