diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-01-20 14:20:30 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-01-20 14:21:34 +0300 |
commit | 4425e0cd64ff23b77c553041858a150665a32ba3 (patch) | |
tree | 45c76d67d99499377dc719679c22e87effc86d8f /source/blender/editors/transform | |
parent | 9b4c017031f94237d75320349e933462772d773e (diff) |
Subdivision: add support for vertex creasing
This adds vertex creasing support for OpenSubDiv for modeling, rendering,
Alembic and USD I/O.
For modeling, vertex creasing follows the edge creasing implementation with an
operator accessible through the Vertex menu in Edit Mode, and some parameter in
the properties panel. The option in the Subsurf and Multires to use edge
creasing also affects vertex creasing.
The vertex crease data is stored as a CustomData layer, unlike edge creases
which for now are stored in `MEdge`, but will in the future also be moved to
a `CustomData` layer. See comments for details on the difference in behavior
for the `CD_CREASE` layer between egdes and vertices.
For Cycles this adds sockets on the Mesh node to hold data about which vertices
are creased (one socket for the indices, one for the weigths).
Viewport rendering of vertex creasing reuses the same color scheme as for edges
and creased vertices are drawn bigger than uncreased vertices.
For Alembic and USD, vertex crease support follows the edge crease
implementation, they are always read, but only exported if a `Subsurf` modifier
is present on the Mesh.
Reviewed By: brecht, fclem, sergey, sybren, campbellbarton
Differential Revision: https://developer.blender.org/D10145
Diffstat (limited to 'source/blender/editors/transform')
7 files changed, 58 insertions, 11 deletions
diff --git a/source/blender/editors/transform/transform_convert_mesh.c b/source/blender/editors/transform/transform_convert_mesh.c index c3d95e1ad98..55f2bfd37db 100644 --- a/source/blender/editors/transform/transform_convert_mesh.c +++ b/source/blender/editors/transform/transform_convert_mesh.c @@ -1465,7 +1465,7 @@ static void VertsToTransData(TransInfo *t, td->ext = NULL; td->val = NULL; td->extra = eve; - if (t->mode == TFM_BWEIGHT) { + if (t->mode == TFM_BWEIGHT || t->mode == TFM_VERT_CREASE) { td->val = bweight; td->ival = *bweight; } @@ -1606,10 +1606,15 @@ void createTransEditVerts(TransInfo *t) } int cd_vert_bweight_offset = -1; + int cd_vert_crease_offset = -1; if (t->mode == TFM_BWEIGHT) { BM_mesh_cd_flag_ensure(bm, BKE_mesh_from_object(tc->obedit), ME_CDFLAG_VERT_BWEIGHT); cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT); } + else if (t->mode == TFM_VERT_CREASE) { + BM_mesh_cd_flag_ensure(bm, BKE_mesh_from_object(tc->obedit), ME_CDFLAG_VERT_CREASE); + cd_vert_crease_offset = CustomData_get_offset(&bm->vdata, CD_CREASE); + } TransData *tob = tc->data; TransDataMirror *td_mirror = tc->data_mirror; @@ -1645,6 +1650,8 @@ void createTransEditVerts(TransInfo *t) else if (prop_mode || BM_elem_flag_test(eve, BM_ELEM_SELECT)) { float *bweight = (cd_vert_bweight_offset != -1) ? BM_ELEM_CD_GET_VOID_P(eve, cd_vert_bweight_offset) : + (cd_vert_crease_offset != -1) ? + BM_ELEM_CD_GET_VOID_P(eve, cd_vert_crease_offset) : NULL; /* Do not use the island center in case we are using islands diff --git a/source/blender/editors/transform/transform_convert_mesh_edge.c b/source/blender/editors/transform/transform_convert_mesh_edge.c index 2db3e259153..2243f66cc7f 100644 --- a/source/blender/editors/transform/transform_convert_mesh_edge.c +++ b/source/blender/editors/transform/transform_convert_mesh_edge.c @@ -86,8 +86,8 @@ void createTransEdge(TransInfo *t) BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(tc->obedit), ME_CDFLAG_EDGE_BWEIGHT); cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_BWEIGHT); } - else { /* if (t->mode == TFM_CREASE) { */ - BLI_assert(t->mode == TFM_CREASE); + else { /* if (t->mode == TFM_EDGE_CREASE) { */ + BLI_assert(t->mode == TFM_EDGE_CREASE); BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(tc->obedit), ME_CDFLAG_EDGE_CREASE); cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_CREASE); } diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 43d894d60f2..d1cbab9ff8a 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -260,7 +260,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve } /* Crease needs edge flag */ - if (ELEM(t->mode, TFM_CREASE, TFM_BWEIGHT)) { + if (ELEM(t->mode, TFM_EDGE_CREASE, TFM_BWEIGHT)) { t->options |= CTX_EDGE_DATA; } diff --git a/source/blender/editors/transform/transform_mode.c b/source/blender/editors/transform/transform_mode.c index 2ab4cdff5e6..e1fea62ae54 100644 --- a/source/blender/editors/transform/transform_mode.c +++ b/source/blender/editors/transform/transform_mode.c @@ -1135,8 +1135,11 @@ void transform_mode_init(TransInfo *t, wmOperator *op, const int mode) case TFM_PUSHPULL: initPushPull(t); break; - case TFM_CREASE: - initCrease(t); + case TFM_EDGE_CREASE: + initEgdeCrease(t); + break; + case TFM_VERT_CREASE: + initVertCrease(t); break; case TFM_BONESIZE: initBoneSize(t); diff --git a/source/blender/editors/transform/transform_mode.h b/source/blender/editors/transform/transform_mode.h index cdcda5a8648..16b26724c67 100644 --- a/source/blender/editors/transform/transform_mode.h +++ b/source/blender/editors/transform/transform_mode.h @@ -106,7 +106,8 @@ void initCurveShrinkFatten(TransInfo *t); void initBevelWeight(TransInfo *t); /* transform_mode_edge_crease.c */ -void initCrease(TransInfo *t); +void initEgdeCrease(TransInfo *t); +void initVertCrease(TransInfo *t); /* transform_mode_edge_rotate_normal.c */ void initNormalRotation(TransInfo *t); diff --git a/source/blender/editors/transform/transform_mode_edge_crease.c b/source/blender/editors/transform/transform_mode_edge_crease.c index debc2a1be3e..60b95a1d2da 100644 --- a/source/blender/editors/transform/transform_mode_edge_crease.c +++ b/source/blender/editors/transform/transform_mode_edge_crease.c @@ -157,9 +157,9 @@ static void applyCrease(TransInfo *t, const int UNUSED(mval[2])) ED_area_status_text(t->area, str); } -void initCrease(TransInfo *t) +static void initCrease_ex(TransInfo *t, int mode) { - t->mode = TFM_CREASE; + t->mode = mode; t->transform = applyCrease; initMouseInputMode(t, &t->mouse, INPUT_SPRING_DELTA); @@ -176,4 +176,13 @@ void initCrease(TransInfo *t) t->flag |= T_NO_CONSTRAINT | T_NO_PROJECT; } +void initEgdeCrease(TransInfo *t) +{ + initCrease_ex(t, TFM_EDGE_CREASE); +} + +void initVertCrease(TransInfo *t) +{ + initCrease_ex(t, TFM_VERT_CREASE); +} /** \} */ diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 5ed340abf97..80feb934f1a 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -78,6 +78,7 @@ static const char OP_BONE_SIZE[] = "TRANSFORM_OT_bbone_resize"; static const char OP_EDGE_SLIDE[] = "TRANSFORM_OT_edge_slide"; static const char OP_VERT_SLIDE[] = "TRANSFORM_OT_vert_slide"; static const char OP_EDGE_CREASE[] = "TRANSFORM_OT_edge_crease"; +static const char OP_VERT_CREASE[] = "TRANSFORM_OT_vert_crease"; static const char OP_EDGE_BWEIGHT[] = "TRANSFORM_OT_edge_bevelweight"; static const char OP_SEQ_SLIDE[] = "TRANSFORM_OT_seq_slide"; static const char OP_NORMAL_ROTATION[] = "TRANSFORM_OT_rotate_normal"; @@ -98,6 +99,7 @@ static void TRANSFORM_OT_bbone_resize(struct wmOperatorType *ot); static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot); static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot); static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot); +static void TRANSFORM_OT_vert_crease(struct wmOperatorType *ot); static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot); static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot); static void TRANSFORM_OT_rotate_normal(struct wmOperatorType *ot); @@ -118,7 +120,8 @@ static TransformModeItem transform_modes[] = { {OP_BONE_SIZE, TFM_BONESIZE, TRANSFORM_OT_bbone_resize}, {OP_EDGE_SLIDE, TFM_EDGE_SLIDE, TRANSFORM_OT_edge_slide}, {OP_VERT_SLIDE, TFM_VERT_SLIDE, TRANSFORM_OT_vert_slide}, - {OP_EDGE_CREASE, TFM_CREASE, TRANSFORM_OT_edge_crease}, + {OP_EDGE_CREASE, TFM_EDGE_CREASE, TRANSFORM_OT_edge_crease}, + {OP_VERT_CREASE, TFM_VERT_CREASE, TRANSFORM_OT_vert_crease}, {OP_EDGE_BWEIGHT, TFM_BWEIGHT, TRANSFORM_OT_edge_bevelweight}, {OP_SEQ_SLIDE, TFM_SEQ_SLIDE, TRANSFORM_OT_seq_slide}, {OP_NORMAL_ROTATION, TFM_NORMAL_ROTATION, TRANSFORM_OT_rotate_normal}, @@ -139,7 +142,8 @@ const EnumPropertyItem rna_enum_transform_mode_types[] = { {TFM_TILT, "TILT", 0, "Tilt", ""}, {TFM_TRACKBALL, "TRACKBALL", 0, "Trackball", ""}, {TFM_PUSHPULL, "PUSHPULL", 0, "Push/Pull", ""}, - {TFM_CREASE, "CREASE", 0, "Crease", ""}, + {TFM_EDGE_CREASE, "CREASE", 0, "Crease", ""}, + {TFM_VERT_CREASE, "VERTEX_CREASE", 0, "Vertex Crease", ""}, {TFM_MIRROR, "MIRROR", 0, "Mirror", ""}, {TFM_BONESIZE, "BONE_SIZE", 0, "Bone Size", ""}, {TFM_BONE_ENVELOPE, "BONE_ENVELOPE", 0, "Bone Envelope", ""}, @@ -1196,6 +1200,29 @@ static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot) Transform_Properties(ot, P_SNAP); } +static void TRANSFORM_OT_vert_crease(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Vertex Crease"; + ot->description = "Change the crease of vertices"; + ot->idname = OP_VERT_CREASE; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; + + /* api callbacks */ + ot->invoke = transform_invoke; + ot->exec = transform_exec; + ot->modal = transform_modal; + ot->cancel = transform_cancel; + ot->poll = ED_operator_editmesh; + ot->poll_property = transform_poll_property; + + RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f); + + WM_operatortype_props_advanced_begin(ot); + + Transform_Properties(ot, P_SNAP); +} + static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot) { /* identifiers */ |