Commit: 726773588cc15be80f9298bd7f0e4039dddea995 Author: Pablo Dobarro Date: Wed Mar 20 03:34:07 2019 +0100 Branches: sculpt-mode-features https://developer.blender.org/rB726773588cc15be80f9298bd7f0e4039dddea995
Voxel Remesher: Add remesher parameters to mesh datablock I tested several UI integrations: -Running the remesher from an operator and adjusting the parameters with the redo panel freezes the interface with high-res meshes. It looks cool, but it is not that useful. -Integrating it into a tool does not store per object remesh configurations. It also forces the user to switch the tool when he/she is sculpting just to recalculate the topology. Storing the remesher options per mesh is the best option I found. Now, the remesher is found in the properties panel under the mesh tab. The user can assign it to the quick favorites menu or add a keyboard shortcut. Remesher parameters can be adjusted there. They are stored per mesh. This way, remesher parameters of each mesh are preserved when sculpting different objects at different levels of details. In the future, the user will be able to choose different remeshing algorithms (triangulation, quadriflow...) from there and assign them to the mesh. All of them will be executed by the same remesh operator and some of them will share some options (like smooth normals). =================================================================== M release/scripts/startup/bl_ui/properties_data_mesh.py M source/blender/blenloader/intern/versioning_280.c M source/blender/editors/mesh/editmesh_add.c M source/blender/editors/object/object_edit.c M source/blender/makesdna/DNA_mesh_types.h M source/blender/makesrna/intern/rna_mesh.c =================================================================== diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py index eacf027c491..de178496c56 100644 --- a/release/scripts/startup/bl_ui/properties_data_mesh.py +++ b/release/scripts/startup/bl_ui/properties_data_mesh.py @@ -454,6 +454,22 @@ class DATA_PT_vertex_colors(MeshButtonsPanel, Panel): col.operator("mesh.vertex_color_remove", icon='REMOVE', text="") +class DATA_PT_remesh(MeshButtonsPanel, Panel): + bl_label = "Remesh" + bl_options = {'DEFAULT_CLOSED'} + COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'} + + def draw(self, context): + layout = self.layout + layout.use_property_split = True + col = layout.column() + + mesh = context.mesh + col.prop(mesh, "voxel_size") + col.prop(mesh, "smooth_normals") + col.operator("object.remesh", text="Remesh") + + class DATA_PT_customdata(MeshButtonsPanel, Panel): bl_label = "Geometry Data" bl_options = {'DEFAULT_CLOSED'} @@ -503,6 +519,7 @@ classes = ( DATA_PT_uv_texture, DATA_PT_vertex_colors, DATA_PT_face_maps, + DATA_PT_remesh, DATA_PT_normals, DATA_PT_normals_auto_smooth, DATA_PT_texture_space, diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index 47a69ff7f63..ff95e094ea4 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -2927,5 +2927,11 @@ 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, "Mesh", "float", "voxel_size")) { + for (Mesh *me = bmain->meshes.first; me; me = me->id.next) { + me->voxel_size = 0.1f; + } + } } } diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index aca8fac8bf7..7cbd17c0aa7 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -27,11 +27,13 @@ #include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "DNA_mesh_types.h" #include "BLT_translation.h" #include "BKE_context.h" #include "BKE_editmesh.h" +#include "BKE_mesh.h" #include "RNA_define.h" #include "RNA_access.h" @@ -94,6 +96,10 @@ static void make_prim_finish(bContext *C, Object *obedit, const MakePrimitiveDat /* userdef */ if (exit_editmode) { ED_object_editmode_exit(C, EM_FREEDATA); + //TODO: Find a better place to init this + Mesh *me; + me = obedit->data; + me->voxel_size = 0.1f; } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); } diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index ba1c07c24b6..a71718431b3 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -1765,6 +1765,10 @@ static int remesh_exec(bContext *C, wmOperator *op) } if (ob->type == OB_MESH) { + Mesh *mesh = ob->data; + if (mesh->voxel_size <= 0.0f) { + return OPERATOR_CANCELLED; + } if (ob->mode == OB_MODE_SCULPT) { Depsgraph *depsgraph = CTX_data_depsgraph(C); @@ -1779,7 +1783,6 @@ static int remesh_exec(bContext *C, wmOperator *op) sculpt_undo_push_begin("voxel remesh"); sculpt_undo_push_node(ob, nodes[0], SCULPT_UNDO_REMESH); } - Mesh *mesh = ob->data; BKE_mesh_runtime_looptri_recalc(mesh); const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(mesh); MVertTri *verttri = MEM_callocN(sizeof(*verttri) * BKE_mesh_runtime_looptri_len(mesh), "remesh_looptri"); @@ -1789,8 +1792,7 @@ static int remesh_exec(bContext *C, wmOperator *op) rmd.totverts = mesh->totvert; rmd.verts = (float *)MEM_calloc_arrayN(rmd.totverts * 3, sizeof(float), "remesh_input_verts"); rmd.faces = (unsigned int *)MEM_calloc_arrayN(rmd.totfaces * 3, sizeof(unsigned int), "remesh_intput_faces"); - PropertyRNA *prop = RNA_struct_find_property(op->ptr, "voxel_size"); - rmd.voxel_size = RNA_property_float_get(op->ptr, prop); + rmd.voxel_size = mesh->voxel_size; rmd.isovalue = 0.0f; for(int i = 0; i < mesh->totvert; i++) { @@ -1828,7 +1830,7 @@ static int remesh_exec(bContext *C, wmOperator *op) BKE_mesh_calc_normals(newMesh); BKE_mesh_nomain_to_mesh(newMesh, ob->data, ob, &CD_MASK_EVERYTHING, true); - if (RNA_boolean_get(op->ptr, "smooth_normals")) { + if (mesh->flag & ME_REMESH_SMOOTH_NORMALS) { BKE_mesh_smooth_flag_set(ob, true); } if (ob->mode == OB_MODE_SCULPT) { @@ -1853,8 +1855,6 @@ static int remesh_exec(bContext *C, wmOperator *op) void OBJECT_OT_remesh(wmOperatorType *ot) { - PropertyRNA *prop; - /* identifiers */ ot->name = "Voxel remesh"; ot->description = "Run OpenVDB voxel remesher"; @@ -1864,13 +1864,5 @@ void OBJECT_OT_remesh(wmOperatorType *ot) ot->poll = object_mode_set_poll; ot->exec = remesh_exec; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - prop = RNA_def_property(ot->srna, "voxel_size", PROP_FLOAT, PROP_UNSIGNED); - RNA_def_property_range(prop, 0.001, 1.0); - RNA_def_property_float_default(prop, 0.1f); - RNA_def_property_ui_range(prop, 0.0001, 1, 0.01, 4); - RNA_def_property_ui_text(prop, "Voxel Size", "Voxel size used for volume evaluation"); - - prop = RNA_def_boolean(ot->srna, "smooth_normals", false, "Shade smooth", "Smooth normals on the resulting mesh"); + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; } diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h index 15b95104359..098337b6431 100644 --- a/source/blender/makesdna/DNA_mesh_types.h +++ b/source/blender/makesdna/DNA_mesh_types.h @@ -187,6 +187,8 @@ typedef struct Mesh { short totcol; + float voxel_size; + char _pad1[4]; /** Deprecated multiresolution modeling data, only keep for loading old files. */ struct Multires *mr DNA_DEPRECATED; @@ -244,6 +246,7 @@ enum { ME_FLAG_UNUSED_8 = 1 << 8, /* cleared */ ME_DS_EXPAND = 1 << 9, ME_SCULPT_DYNAMIC_TOPOLOGY = 1 << 10, + ME_REMESH_SMOOTH_NORMALS = 1 << 11, }; /* me->cd_flag */ diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index c9a8da51e40..3e7b88207d4 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -2731,6 +2731,23 @@ static void rna_def_mesh(BlenderRNA *brna) rna_def_paint_mask(brna, prop); /* End paint mask */ + /* Remesher */ + prop = RNA_def_property(srna, "voxel_size", PROP_FLOAT, PROP_DISTANCE); + RNA_def_property_float_sdna(prop, NULL, "voxel_size"); + RNA_def_property_float_default(prop, 0.1f); + RNA_def_property_range(prop, 0.001f, 1.0f); + RNA_def_property_ui_range(prop, 0.001f, 1.0f, 0.01, 4); + RNA_def_property_ui_text(prop, "Voxel size", + "Size of the voxel used for OpenVDB evaluation"); + RNA_def_property_update(prop, 0, "rna_Mesh_update_data"); + + prop = RNA_def_property(srna, "smooth_normals", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_REMESH_SMOOTH_NORMALS); + RNA_def_property_ui_text(prop, "Smooth normals", + "Smooth the normals of the remesher result"); + RNA_def_property_update(prop, 0, "rna_Mesh_update_data"); + /* End remesher */ + prop = RNA_def_property(srna, "use_auto_smooth", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_AUTOSMOOTH); RNA_def_property_ui_text(prop, "Auto Smooth", _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs