[Bf-blender-cvs] [828a5c86bc8] quadriflow: Added three quadriflow face count ui options
Sebastian Parborg
noreply at git.blender.org
Tue Sep 10 18:36:17 CEST 2019
Commit: 828a5c86bc89e9780e17892cdb9e7538746e745f
Author: Sebastian Parborg
Date: Mon Sep 9 19:48:51 2019 +0200
Branches: quadriflow
https://developer.blender.org/rB828a5c86bc89e9780e17892cdb9e7538746e745f
Added three quadriflow face count ui options
===================================================================
M source/blender/editors/object/object_remesh.c
===================================================================
diff --git a/source/blender/editors/object/object_remesh.c b/source/blender/editors/object/object_remesh.c
index 29d249647f5..dab6d9178cb 100644
--- a/source/blender/editors/object/object_remesh.c
+++ b/source/blender/editors/object/object_remesh.c
@@ -157,6 +157,12 @@ void OBJECT_OT_voxel_remesh(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
+enum {
+ QUA_RATIO = 1,
+ QUA_EDGE_LENGTH,
+ QUA_FACES,
+};
+
static int quadriflow_remesh_exec(bContext *C, wmOperator *op)
{
const bool is_frozen = RNA_boolean_get(op->ptr, "use_freeze");
@@ -228,6 +234,79 @@ static int quadriflow_remesh_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
+/* Hide the target variables if they are not active */
+static bool quadriflow_poll_property(const bContext *UNUSED(C),
+ wmOperator *op,
+ const PropertyRNA *prop)
+{
+ const char *prop_id = RNA_property_identifier(prop);
+
+ if (STRPREFIX(prop_id, "target")) {
+ int mode = RNA_enum_get(op->ptr, "mode");
+
+ if (STREQ(prop_id, "target_edge_len") && mode != QUA_EDGE_LENGTH) {
+ return false;
+ }
+ else if (STREQ(prop_id, "target_faces")) {
+ if (mode != QUA_FACES) {
+ /* Only disable input */
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ }
+ else {
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ }
+ }
+ else if (STREQ(prop_id, "target_ratio") && mode != QUA_RATIO) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static bool quadriflow_check(bContext *C, wmOperator *op)
+{
+ int mode = RNA_enum_get(op->ptr, "mode");
+
+ if (mode == QUA_EDGE_LENGTH) {
+ float area = RNA_float_get(op->ptr, "mesh_area");
+ if (area < 0.0f) {
+ Object *ob = CTX_data_active_object(C);
+ area = BKE_mesh_calc_area(ob->data);
+ RNA_float_set(op->ptr, "mesh_area", area);
+ }
+ int num_faces;
+ float edge_len = RNA_float_get(op->ptr, "target_edge_len");
+
+ num_faces = area / (edge_len * edge_len);
+ RNA_int_set(op->ptr, "target_faces", num_faces);
+ }
+ else if (mode == QUA_RATIO) {
+ Object *ob = CTX_data_active_object(C);
+ Mesh *mesh = ob->data;
+
+ int num_faces;
+ float ratio = RNA_float_get(op->ptr, "target_ratio");
+
+ num_faces = mesh->totpoly * ratio;
+
+ RNA_int_set(op->ptr, "target_faces", num_faces);
+ }
+
+ return true;
+}
+
+static const EnumPropertyItem mode_type_items[] = {
+ {QUA_FACES, "FACES", 0, "Faces", "Input the target face count directly"},
+ {QUA_RATIO, "RATIO", 0, "Ratio", "The amount of faces will be specified via a ratio"},
+ {QUA_EDGE_LENGTH,
+ "EDGE",
+ 0,
+ "Edge Length",
+ "The amount of faces is defined with an edge length"},
+ {0, NULL, 0, NULL, NULL},
+};
+
void OBJECT_OT_quadriflow_remesh(wmOperatorType *ot)
{
/* identifiers */
@@ -239,11 +318,15 @@ void OBJECT_OT_quadriflow_remesh(wmOperatorType *ot)
/* api callbacks */
ot->poll = object_remesh_poll;
+ ot->poll_property = quadriflow_poll_property;
+ ot->check = quadriflow_check;
ot->invoke = WM_operator_props_popup_confirm;
ot->exec = quadriflow_remesh_exec;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ PropertyRNA *prop;
+
/* properties */
RNA_def_boolean(ot->srna,
"use_preserve_sharp",
@@ -275,6 +358,33 @@ void OBJECT_OT_quadriflow_remesh(wmOperatorType *ot)
"Smooth normals",
"Set the output mesh normals to smooth");
+ RNA_def_enum(ot->srna,
+ "mode",
+ mode_type_items,
+ 0,
+ "Face Count Mode",
+ "How to calculate the number of output faces");
+
+ prop = RNA_def_float(ot->srna,
+ "target_ratio",
+ 1,
+ 0,
+ FLT_MAX,
+ "Ratio",
+ "The face count ratio in respect to the original mesh",
+ 0.0f,
+ 1.0f);
+
+ prop = RNA_def_float(ot->srna,
+ "target_edge_len",
+ 0.1f,
+ 0.0000001f,
+ FLT_MAX,
+ "Edge Length",
+ "The desired edge length on the output quads",
+ 0.00001f,
+ 1.0f);
+
RNA_def_int(ot->srna,
"target_faces",
0,
@@ -286,6 +396,19 @@ void OBJECT_OT_quadriflow_remesh(wmOperatorType *ot)
"current mesh",
0,
255);
+
+ prop = RNA_def_float(
+ ot->srna,
+ "mesh_area",
+ -1.0f,
+ -FLT_MAX,
+ FLT_MAX,
+ "Old object face area",
+ "This property is only used to cache the object area for later calculations",
+ 0.0f,
+ 10.0f);
+ RNA_def_property_flag(prop, PROP_HIDDEN);
+
RNA_def_int(ot->srna,
"seed",
0,
More information about the Bf-blender-cvs
mailing list