Commit: 0e94c8258ecdcd2802c3eeb12d2f6c5c356f94de Author: Sebastian Parborg Date: Wed Sep 11 16:03:13 2019 +0200 Branches: quadriflow https://developer.blender.org/rB0e94c8258ecdcd2802c3eeb12d2f6c5c356f94de
Make quadriflow not freeze blender while it is processing =================================================================== M intern/quadriflow/quadriflow_capi.cpp M intern/quadriflow/quadriflow_capi.hpp M release/scripts/startup/bl_ui/properties_data_mesh.py M source/blender/blenkernel/BKE_mesh_remesh_voxel.h M source/blender/blenkernel/intern/mesh_remesh_voxel.c M source/blender/blenloader/intern/versioning_280.c M source/blender/editors/object/object_remesh.c M source/blender/makesdna/DNA_mesh_types.h M source/blender/makesrna/intern/rna_mesh.c M source/blender/windowmanager/WM_api.h =================================================================== diff --git a/intern/quadriflow/quadriflow_capi.cpp b/intern/quadriflow/quadriflow_capi.cpp index 3d3aac2e4f4..302c7a0ae30 100644 --- a/intern/quadriflow/quadriflow_capi.cpp +++ b/intern/quadriflow/quadriflow_capi.cpp @@ -61,7 +61,18 @@ struct ObjVertexHash : std::unary_function<ObjVertex, size_t> { typedef std::unordered_map<ObjVertex, uint32_t, ObjVertexHash> VertexMap; -void QFLOW_quadriflow_remesh(QuadriflowRemeshData *qrd) +static int check_if_canceled(float progress, + void (*update_cb)(void *, float progress, int *cancel), + void *update_cb_data) +{ + int cancel = 0; + update_cb(update_cb_data, progress, &cancel); + return cancel; +} + +void QFLOW_quadriflow_remesh(QuadriflowRemeshData *qrd, + void (*update_cb)(void *, float progress, int *cancel), + void *update_cb_data) { Parametrizer field; VertexMap vertexMap; @@ -88,6 +99,10 @@ void QFLOW_quadriflow_remesh(QuadriflowRemeshData *qrd) field.hierarchy.rng_seed = qrd->rng_seed; } + if (check_if_canceled(0.0f, update_cb, update_cb_data) != 0) { + return; + } + /* Copy mesh to quadriflow data structures. */ std::vector<Vector3d> positions; std::vector<uint32_t> indices; @@ -130,10 +145,18 @@ void QFLOW_quadriflow_remesh(QuadriflowRemeshData *qrd) field.V.col(i) = positions.at(vertices[i].p); } + if (check_if_canceled(0.1f, update_cb, update_cb_data)) { + return; + } + /* Start processing the input mesh data */ field.NormalizeMesh(); field.Initialize(faces); + if (check_if_canceled(0.2f, update_cb, update_cb_data)) { + return; + } + /* Setup mesh boundary constraints if needed */ if (field.flag_preserve_boundary) { Hierarchy &mRes = field.hierarchy; @@ -160,19 +183,36 @@ void QFLOW_quadriflow_remesh(QuadriflowRemeshData *qrd) Optimizer::optimize_orientations(field.hierarchy); field.ComputeOrientationSingularities(); + if (check_if_canceled(0.3f, update_cb, update_cb_data)) { + return; + } + if (field.flag_adaptive_scale == 1) { field.EstimateSlope(); } + if (check_if_canceled(0.4f, update_cb, update_cb_data)) { + return; + } + Optimizer::optimize_scale(field.hierarchy, field.rho, field.flag_adaptive_scale); field.flag_adaptive_scale = 1; Optimizer::optimize_positions(field.hierarchy, field.flag_adaptive_scale); field.ComputePositionSingularities(); + + if (check_if_canceled(0.5f, update_cb, update_cb_data)) { + return; + } + /* Compute the final quad geomtry using a maxflow solver */ field.ComputeIndexMap(); + if (check_if_canceled(0.9f, update_cb, update_cb_data)) { + return; + } + /* Get the output mesh data */ qrd->out_totverts = field.O_compact.size(); qrd->out_totfaces = field.F_compact.size(); diff --git a/intern/quadriflow/quadriflow_capi.hpp b/intern/quadriflow/quadriflow_capi.hpp index 0c6ae1d20e2..c31fd6eff95 100644 --- a/intern/quadriflow/quadriflow_capi.hpp +++ b/intern/quadriflow/quadriflow_capi.hpp @@ -43,7 +43,9 @@ typedef struct QuadriflowRemeshData { int rng_seed; } QuadriflowRemeshData; -void QFLOW_quadriflow_remesh(QuadriflowRemeshData *qrd); +void QFLOW_quadriflow_remesh(QuadriflowRemeshData *qrd, + void (*update_cb)(void *, float progress, int *cancel), + void *update_cb_data); #ifdef __cplusplus } diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py index 74869c2c812..8031690970d 100644 --- a/release/scripts/startup/bl_ui/properties_data_mesh.py +++ b/release/scripts/startup/bl_ui/properties_data_mesh.py @@ -467,16 +467,18 @@ class DATA_PT_remesh(MeshButtonsPanel, Panel): def draw(self, context): layout = self.layout layout.use_property_split = True - col = layout.column() + row = layout.row() mesh = context.mesh - col.prop(mesh, "remesh_voxel_size") - col.prop(mesh, "remesh_smooth_normals") - col.prop(mesh, "remesh_preserve_paint_mask") - col.operator("object.voxel_remesh", text="Voxel Remesh") - - col.separator() - col.operator("object.quadriflow_remesh", text="QuadriFlow Remesh") + row.prop(mesh, "remesh_mode", text="Mode") + col = layout.column() + if (mesh.remesh_mode == 'VOXEL'): + col.prop(mesh, "remesh_voxel_size") + col.prop(mesh, "remesh_smooth_normals") + col.prop(mesh, "remesh_preserve_paint_mask") + col.operator("object.voxel_remesh", text="Voxel Remesh") + else: + col.operator("object.quadriflow_remesh", text="QuadriFlow Remesh") class DATA_PT_customdata(MeshButtonsPanel, Panel): bl_label = "Geometry Data" diff --git a/source/blender/blenkernel/BKE_mesh_remesh_voxel.h b/source/blender/blenkernel/BKE_mesh_remesh_voxel.h index 302bae0b5d8..6b275e11cf7 100644 --- a/source/blender/blenkernel/BKE_mesh_remesh_voxel.h +++ b/source/blender/blenkernel/BKE_mesh_remesh_voxel.h @@ -44,7 +44,9 @@ struct Mesh *BKE_mesh_remesh_quadriflow_to_mesh_nomain(struct Mesh *mesh, int seed, bool preserve_sharp, bool preserve_boundary, - bool adaptive_scale); + bool adaptive_scale, + void *update_cb, + void *update_cb_data); /* Data reprojection functions */ void BKE_remesh_reproject_paint_mask(struct Mesh *target, struct Mesh *source); diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.c b/source/blender/blenkernel/intern/mesh_remesh_voxel.c index 22fbdd35dfb..48ccca8213d 100644 --- a/source/blender/blenkernel/intern/mesh_remesh_voxel.c +++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.c @@ -156,7 +156,9 @@ static Mesh *BKE_mesh_remesh_quadriflow(Mesh *input_mesh, int seed, bool preserve_sharp, bool preserve_boundary, - bool adaptive_scale) + bool adaptive_scale, + void *update_cb, + void *update_cb_data) { /* Ensure that the triangulated mesh data is up to data */ BKE_mesh_runtime_looptri_recalc(input_mesh); @@ -204,8 +206,19 @@ static Mesh *BKE_mesh_remesh_quadriflow(Mesh *input_mesh, qrd.aggresive_sat = 0; qrd.rng_seed = seed; + qrd.out_faces = NULL; + /* Run the remesher */ - QFLOW_quadriflow_remesh(&qrd); + QFLOW_quadriflow_remesh(&qrd, update_cb, update_cb_data); + + MEM_freeN(verts); + MEM_freeN(faces); + MEM_freeN(verttri); + + if (qrd.out_faces == NULL) { + /* The remeshing was canceled */ + return NULL; + } /* Construct the new output mesh */ Mesh *mesh = BKE_mesh_new_nomain( @@ -230,10 +243,6 @@ static Mesh *BKE_mesh_remesh_quadriflow(Mesh *input_mesh, BKE_mesh_calc_edges(mesh, false, false); BKE_mesh_calc_normals(mesh); - MEM_freeN(verts); - MEM_freeN(faces); - MEM_freeN(verttri); - MEM_freeN(qrd.out_faces); MEM_freeN(qrd.out_verts); @@ -246,17 +255,32 @@ Mesh *BKE_mesh_remesh_quadriflow_to_mesh_nomain(Mesh *mesh, int seed, bool preserve_sharp, bool preserve_boundary, - bool adaptive_scale) + bool adaptive_scale, + void *update_cb, + void *update_cb_data) { Mesh *new_mesh = NULL; #ifdef WITH_QUADRIFLOW if (target_faces <= 0) { target_faces = -1; } - new_mesh = BKE_mesh_remesh_quadriflow( - mesh, target_faces, seed, preserve_sharp, preserve_boundary, adaptive_scale); + new_mesh = BKE_mesh_remesh_quadriflow(mesh, + target_faces, + seed, + preserve_sharp, + preserve_boundary, + adaptive_scale, + update_cb, + update_cb_data); #else - UNUSED_VARS(mesh, target_faces, seed, preserve_sharp, adaptive_scale); + UNUSED_VARS(mesh, + target_faces, + seed, + preserve_sharp, + preserve_boundary, + adaptive_scale, + update_cb, + update_cb_data); #endif return new_mesh; } diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index d06da062d49..11e45c5395b 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -3844,5 +3844,8 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) { /* Versioning code until next subversion bump goes here. */ + for (Mesh *mesh = bmain->meshes.first; mesh; mesh = mesh->id.next) { + mesh->remesh_mode = REMESH_VOXEL; + } } } diff --git a/source/blender/editors/object/object_remesh.c b/source/blender/editors/object/object_remesh.c index 3899b93b3c2..a2615ffb660 100644 --- a/source/blender/editors/object/object_remesh.c +++ b/source/blender/editors/object/object_remesh.c @@ -88,7 +88,6 @@ static bool object_remesh_poll(bContext *C) static int voxel_remesh_exec(bContext *C, wmOperator *op) { Object *ob = CTX_data_active_object(C); - Main *bmain = CTX_data_main(C); Mesh *mesh = ob->data; Mesh *new_mesh; @@ -134,7 +133,6 @@ static int voxel_remesh_exec(bCon @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs