Modifiers: add minimum number of vertices to triangulate modifier.
This lets you only triangulate n-gons when setting the number to 5 or more. Differential Revision: https://developer.blender.org/D4367
This commit is contained in:
parent
c89dcc89e6
commit
da5b6ed75b
|
@ -1368,6 +1368,8 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
|
|||
col = row.column()
|
||||
col.label(text="Ngon Method:")
|
||||
col.prop(md, "ngon_method", text="")
|
||||
col.label(text="Minimum Vertices:")
|
||||
col.prop(md, "min_vertices", text="")
|
||||
|
||||
def UV_WARP(self, layout, ob, md):
|
||||
split = layout.split()
|
||||
|
|
|
@ -552,7 +552,7 @@ Mesh *AbcGenericMeshWriter::getFinalMesh(bool &r_needsfree)
|
|||
struct BMeshFromMeshParams bmfmp = {true, false, false, 0};
|
||||
BMesh *bm = BKE_mesh_to_bmesh_ex(mesh, &bmcp, &bmfmp);
|
||||
|
||||
BM_mesh_triangulate(bm, quad_method, ngon_method, tag_only, NULL, NULL, NULL);
|
||||
BM_mesh_triangulate(bm, quad_method, ngon_method, 4, tag_only, NULL, NULL, NULL);
|
||||
|
||||
Mesh *result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL);
|
||||
BM_mesh_free(bm);
|
||||
|
|
|
@ -2920,5 +2920,16 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
|
|||
part->draw_as = PART_DRAW_NOT;
|
||||
}
|
||||
}
|
||||
|
||||
if (!DNA_struct_elem_find(fd->filesdna, "TriangulateModifierData", "int", "min_vertices")) {
|
||||
for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
|
||||
for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
|
||||
if (md->type == eModifierType_Triangulate) {
|
||||
TriangulateModifierData *smd = (TriangulateModifierData *)md;
|
||||
smd->min_vertices = 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ void bmo_triangulate_exec(BMesh *bm, BMOperator *op)
|
|||
BM_mesh_elem_hflag_disable_all(bm, BM_FACE | BM_EDGE, BM_ELEM_TAG, false);
|
||||
BMO_slot_buffer_hflag_enable(bm, op->slots_in, "faces", BM_FACE, BM_ELEM_TAG, false);
|
||||
|
||||
BM_mesh_triangulate(bm, quad_method, ngon_method, true, op, slot_facemap_out, slot_facemap_double_out);
|
||||
BM_mesh_triangulate(bm, quad_method, ngon_method, 4, true, op, slot_facemap_out, slot_facemap_double_out);
|
||||
|
||||
BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "edges.out", BM_EDGE, BM_ELEM_TAG);
|
||||
BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG);
|
||||
|
|
|
@ -83,8 +83,9 @@ static void bm_face_triangulate_mapping(
|
|||
|
||||
|
||||
void BM_mesh_triangulate(
|
||||
BMesh *bm, const int quad_method, const int ngon_method, const bool tag_only,
|
||||
BMOperator *op, BMOpSlot *slot_facemap_out, BMOpSlot *slot_facemap_double_out)
|
||||
BMesh *bm, const int quad_method, const int ngon_method, const int min_vertices,
|
||||
const bool tag_only, BMOperator *op, BMOpSlot *slot_facemap_out,
|
||||
BMOpSlot *slot_facemap_double_out)
|
||||
{
|
||||
BMIter iter;
|
||||
BMFace *face;
|
||||
|
@ -103,7 +104,7 @@ void BM_mesh_triangulate(
|
|||
if (slot_facemap_out) {
|
||||
/* same as below but call: bm_face_triangulate_mapping() */
|
||||
BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
|
||||
if (face->len > 3) {
|
||||
if (face->len >= min_vertices) {
|
||||
if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) {
|
||||
bm_face_triangulate_mapping(
|
||||
bm, face,
|
||||
|
@ -118,7 +119,7 @@ void BM_mesh_triangulate(
|
|||
LinkNode *faces_double = NULL;
|
||||
|
||||
BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
|
||||
if (face->len > 3) {
|
||||
if (face->len >= min_vertices) {
|
||||
if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) {
|
||||
BM_face_triangulate(
|
||||
bm, face,
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
#define __BMESH_TRIANGULATE_H__
|
||||
|
||||
void BM_mesh_triangulate(
|
||||
BMesh *bm, const int quad_method, const int ngon_method, const bool tag_only,
|
||||
BMesh *bm, const int quad_method, const int ngon_method,
|
||||
const int min_vertices, const bool tag_only,
|
||||
BMOperator *op, BMOpSlot *slot_facemap_out, BMOpSlot *slot_doubles_out);
|
||||
|
||||
#endif /* __BMESH_TRIANGULATE_H__ */
|
||||
|
|
|
@ -5423,7 +5423,7 @@ static void SCULPT_OT_set_persistent_base(wmOperatorType *ot)
|
|||
static void sculpt_dynamic_topology_triangulate(BMesh *bm)
|
||||
{
|
||||
if (bm->totloop != bm->totface * 3) {
|
||||
BM_mesh_triangulate(bm, MOD_TRIANGULATE_QUAD_BEAUTY, MOD_TRIANGULATE_NGON_EARCLIP, false, NULL, NULL, NULL);
|
||||
BM_mesh_triangulate(bm, MOD_TRIANGULATE_QUAD_BEAUTY, MOD_TRIANGULATE_NGON_EARCLIP, 4, false, NULL, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1551,7 +1551,7 @@ typedef struct TriangulateModifierData {
|
|||
int flag;
|
||||
int quad_method;
|
||||
int ngon_method;
|
||||
char _pad[4];
|
||||
int min_vertices;
|
||||
} TriangulateModifierData;
|
||||
|
||||
/* TriangulateModifierData.flag */
|
||||
|
|
|
@ -4359,6 +4359,12 @@ static void rna_def_modifier_triangulate(BlenderRNA *brna)
|
|||
RNA_def_property_ui_text(prop, "Polygon Method", "Method for splitting the polygons into triangles");
|
||||
RNA_def_property_update(prop, 0, "rna_Modifier_update");
|
||||
|
||||
prop = RNA_def_property(srna, "min_vertices", PROP_INT, PROP_UNSIGNED);
|
||||
RNA_def_property_int_sdna(prop, NULL, "min_vertices");
|
||||
RNA_def_property_range(prop, 4, INT_MAX);
|
||||
RNA_def_property_ui_text(prop, "Minimum Vertices", "Triangulate only polygons with vertex count greater than or equal to this number");
|
||||
RNA_def_property_update(prop, 0, "rna_Modifier_update");
|
||||
|
||||
prop = RNA_def_property(srna, "keep_custom_normals", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_TRIANGULATE_KEEP_CUSTOMLOOP_NORMALS);
|
||||
RNA_def_property_ui_text(prop, "Keep Normals",
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
#include "MOD_modifiertypes.h"
|
||||
|
||||
static Mesh *triangulate_mesh(Mesh *mesh, const int quad_method, const int ngon_method, const int flag)
|
||||
static Mesh *triangulate_mesh(Mesh *mesh, const int quad_method, const int ngon_method, const int min_vertices, const int flag)
|
||||
{
|
||||
Mesh *result;
|
||||
BMesh *bm;
|
||||
|
@ -59,7 +59,7 @@ static Mesh *triangulate_mesh(Mesh *mesh, const int quad_method, const int ngon_
|
|||
.cd_mask_extra = cddata_masks,
|
||||
}));
|
||||
|
||||
BM_mesh_triangulate(bm, quad_method, ngon_method, false, NULL, NULL, NULL);
|
||||
BM_mesh_triangulate(bm, quad_method, ngon_method, min_vertices, false, NULL, NULL, NULL);
|
||||
|
||||
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, &cddata_masks);
|
||||
BM_mesh_free(bm);
|
||||
|
@ -98,6 +98,7 @@ static void initData(ModifierData *md)
|
|||
md->mode |= eModifierMode_Editmode;
|
||||
tmd->quad_method = MOD_TRIANGULATE_QUAD_SHORTEDGE;
|
||||
tmd->ngon_method = MOD_TRIANGULATE_NGON_BEAUTY;
|
||||
tmd->min_vertices = 4;
|
||||
}
|
||||
|
||||
static Mesh *applyModifier(
|
||||
|
@ -107,7 +108,7 @@ static Mesh *applyModifier(
|
|||
{
|
||||
TriangulateModifierData *tmd = (TriangulateModifierData *)md;
|
||||
Mesh *result;
|
||||
if (!(result = triangulate_mesh(mesh, tmd->quad_method, tmd->ngon_method, tmd->flag))) {
|
||||
if (!(result = triangulate_mesh(mesh, tmd->quad_method, tmd->ngon_method, tmd->min_vertices, tmd->flag))) {
|
||||
return mesh;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue