82 if (ob ==
nullptr || ob->
data ==
nullptr) {
103 C,
"The remesher cannot run with a Multires modifier in the modifier stack");
117 if (
mesh->remesh_voxel_size <= 0.0f) {
122 if (
mesh->faces_num == 0) {
126 float isovalue = 0.0f;
128 isovalue =
mesh->remesh_voxel_size * 0.3f;
146 new_mesh = mesh_fixed_poles;
157 const VArray<bool> sharp_face = *
mesh->attributes().lookup_or_default<
bool>(
180 ot->
name =
"Voxel Remesh";
182 "Calculates a new manifold mesh based on the volume of the current mesh. All data layers "
184 ot->
idname =
"OBJECT_OT_voxel_remesh";
199#define VOXEL_SIZE_EDIT_MAX_GRIDS_LINES 500
200#define VOXEL_SIZE_EDIT_MAX_STR_LEN 20
223 const float initial_co[3],
224 const float end_co[3],
225 const float length_co[3],
228 const float total_len =
len_v3v3(initial_co, end_co);
229 const int tot_lines = int(total_len / spacing);
230 const int tot_lines_half = (tot_lines / 2) + 1;
231 float spacing_dir[3], lines_start[3];
245 for (
int i = 0; i < tot_lines_half; i++) {
248 madd_v3_v3v3fl(line_start, lines_start, spacing_dir, spacing * i);
258 for (
int i = 1; i < tot_lines_half; i++) {
261 madd_v3_v3v3fl(line_start, lines_start, spacing_dir, spacing * i);
304 const int tot_lines = int(total_len / cd->
voxel_size);
309 const float x =
clamp_f((tot_lines - a) / (
b - a), 0.0f, 1.0);
310 const float alpha_factor = 1.0f - (
x *
x * (3.0f - 2.0f *
x));
322 float strwidth, strheight;
323 short fstyle_points = fstyle->
points;
325 short strdrawlen = 0;
338 BLF_size(fontid, 10.0f * fstyle_points);
341 BLF_position(fontid, -0.5f * strwidth, -0.5f * strheight, 0.0f);
367 status.
item(
IFACE_(
"Confirm"), ICON_EVENT_RETURN, ICON_MOUSE_LMB);
368 status.
item(
IFACE_(
"Cancel"), ICON_EVENT_ESC, ICON_MOUSE_RMB);
369 status.
item(
IFACE_(
"Change Size"), ICON_MOUSE_MOVE);
446 "Voxel Size Edit OP Custom Data");
462 const int BB_faces[6][4] = {
479 float current_normal[3];
480 float view_normal[3] = {0.0f, 0.0f, 1.0f};
484 active_object->object_to_world().ptr());
487 copy_m3_m4(mat, active_object->world_to_object().ptr());
493 float min_dot =
dot_v3v3(current_normal, view_normal);
494 float current_dot = 1;
497 for (
int i = 0; i < 6; i++) {
499 bounds_box[BB_faces[i][0]],
500 bounds_box[BB_faces[i][1]],
501 bounds_box[BB_faces[i][2]]);
502 current_dot =
dot_v3v3(current_normal, view_normal);
504 if (current_dot < min_dot) {
505 min_dot = current_dot;
525 float scale_mat[4][4];
527 float d_a[3], d_b[3];
528 float d_a_proj[2], d_b_proj[2];
529 float preview_plane_proj[4][2];
530 const float y_axis_proj[2] = {0.0f, 1.0f};
535 for (
int i = 0; i < 4; i++) {
536 float preview_plane_world_space[3];
538 preview_plane_world_space, active_object->object_to_world().ptr(), cd->
preview_plane[i]);
549 sub_v2_v2v2(d_a_proj, preview_plane_proj[1], preview_plane_proj[0]);
550 sub_v2_v2v2(d_b_proj, preview_plane_proj[3], preview_plane_proj[0]);
562 if (d_b_proj[0] < 0.0f) {
565 if (d_a_proj[1] < 0.0f) {
572 if (d_a_proj[0] < 0.0f) {
575 if (d_b_proj[1] < 0.0f) {
595 float text_pos_word_space[3];
596 mul_v3_m4v3(text_pos_word_space, active_object->object_to_world().ptr(), text_pos);
618 ot->
name =
"Edit Voxel Size";
619 ot->
description =
"Modify the mesh voxel size interactively used in the voxel remesher";
620 ot->
idname =
"OBJECT_OT_voxel_size_edit";
637#define QUADRIFLOW_MIRROR_BISECT_TOLERANCE 0.005f
692 bool is_manifold_consistent =
true;
696 for (
uint i = 0; i <
mesh->edges_num; i++) {
700 for (
const int corner_i : corner_verts.
index_range()) {
701 const int vert = corner_verts[corner_i];
702 const int edge = corner_edges[corner_i];
703 edge_faces[edge] += 1;
704 if (edge_faces[edge] > 2) {
705 is_manifold_consistent =
false;
709 if (edge_vert[edge] == -1) {
710 edge_vert[edge] = vert;
712 else if (edge_vert[edge] == vert) {
714 is_manifold_consistent =
false;
719 if (is_manifold_consistent) {
722 if (edge_faces[i] == 0) {
723 is_manifold_consistent =
false;
727 if (
compare_v3v3(positions[edges[i][0]], positions[edges[i][1]], 1e-4f)) {
728 is_manifold_consistent =
false;
734 MEM_delete(edge_faces);
735 MEM_delete(edge_vert);
737 return is_manifold_consistent;
755 bool should_break =
false;
758 bool should_break = (
G.is_break);
788 Mesh *mesh_bisect, *mesh_bisect_temp;
792 float plane_co[3], plane_no[3];
795 for (
char i = 0; i < 3; i++) {
797 if (symmetry_axes & symm_it) {
802 plane_no[axis] = -1.0f;
803 mesh_bisect_temp = mesh_bisect;
805 &mmd, mesh_bisect, axis, plane_co, plane_no);
806 if (mesh_bisect_temp != mesh_bisect) {
821 Mesh *mesh_mirror, *mesh_mirror_temp;
827 for (
char i = 0; i < 3; i++) {
829 if (symmetry_axes & symm_it) {
833 mesh_mirror_temp = mesh_mirror;
835 &mmd, ob, mesh_mirror, axis,
true,
nullptr,
nullptr);
836 if (mesh_mirror_temp != mesh_mirror) {
880#ifdef USE_MESH_CURVATURE
886 static_cast<void *
>(qj));
890 if (new_mesh ==
nullptr) {
892 worker_status->
stop =
false;
922 worker_status->
stop =
false;
952 "QuadriFlow: The mesh needs to be manifold and have face normals that point in a "
953 "consistent direction");
974#ifdef USE_MESH_CURVATURE
986 for (
char i = 0; i < 3; i++) {
1017 "Remeshing with QuadriFlow...",
1051 faces_num = area / (edge_len * edge_len);
1061 faces_num =
mesh->faces_num * ratio;
1080 if (
STREQ(prop_id,
"target_faces")) {
1111 "Specify target number of faces relative to the current mesh"},
1116 "Input target edge length in the new mesh"},
1118 {0,
nullptr, 0,
nullptr,
nullptr},
1124 C, op, event,
IFACE_(
"QuadriFlow Remesh the Selected Mesh"),
IFACE_(
"Remesh"));
1130 ot->
name =
"QuadriFlow Remesh";
1132 "Create a new quad based mesh using the surface data of the current mesh. All data "
1133 "layers will be lost";
1134 ot->
idname =
"OBJECT_OT_quadriflow_remesh";
1149 "use_mesh_symmetry",
1151 "Use Mesh Symmetry",
1152 "Generates a symmetrical mesh using the mesh symmetry configuration");
1155 "use_preserve_sharp",
1158 "Try to preserve sharp features on the mesh");
1161 "use_preserve_boundary",
1163 "Preserve Mesh Boundary",
1164 "Try to preserve mesh boundary on the mesh");
1165#ifdef USE_MESH_CURVATURE
1167 "use_mesh_curvature",
1169 "Use Mesh Curvature",
1170 "Take the mesh curvature into account when remeshing");
1173 "preserve_attributes",
1175 "Preserve Attributes",
1176 "Reproject attributes onto the new mesh");
1182 "Set the output mesh normals to smooth");
1189 "How to specify the amount of detail for the new mesh");
1197 "Relative number of faces compared to the current mesh",
1202 "target_edge_length",
1207 "Target edge length in the new mesh",
1217 "Approximate number of faces (quads) in the new mesh",
1227 "Old Object Face Area",
1228 "This property is only used to cache the object area for later calculations",
1239 "Random seed to use with the solver. Different seeds will cause the remesher to "
1240 "come up with different quad layouts on the mesh",
General operations, lookup, etc. for blender objects.
#define ID_IS_EDITABLE(_id)
#define ID_IS_OVERRIDE_LIBRARY(_id)
Object is a sort of wrapper for general info.
#define REGION_DRAW_POST_VIEW
Read Blender memory allocation and freeing.
constexpr IndexRange index_range() const
void item(std::string text, int icon1, int icon2=0)
void item_bool(std::string text, bool inverted, int icon1, int icon2=0)
float3x3 scale(float3x3 mat, float2 scale)
void mesh_remesh_reproject_attributes(const Mesh &src, Mesh &dst)
void mesh_smooth_set(Mesh &mesh, bool use_smooth, bool keep_sharp_edges=false)
void mesh_apply_spatial_organization(Mesh &mesh)
std::array< VecBase< T, 3 >, 8 > corners(const Bounds< VecBase< T, 3 > > &bounds)
static bool object_remesh_poll(bContext *C)
static Mesh * remesh_symmetry_bisect(Mesh *mesh, eSymmetryAxes symmetry_axes)
static void quadriflow_end_job(void *customdata)
static void quadriflow_update_job(void *customdata, float progress, int *cancel)
static wmOperatorStatus voxel_size_edit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static int quadriflow_break_job(void *customdata)
static void voxel_size_edit_cancel(bContext *C, wmOperator *op)
static bool mesh_is_manifold_consistent(Mesh *mesh)
static bool voxel_size_edit_poll(bContext *C)
static bool quadriflow_check(bContext *C, wmOperator *op)
void OBJECT_OT_voxel_size_edit(wmOperatorType *ot)
static const EnumPropertyItem mode_type_items[]
static void voxel_size_parallel_lines_draw(uint pos3d, const float initial_co[3], const float end_co[3], const float length_co[3], const float spacing)
static void voxel_size_edit_update_header(wmOperator *op, bContext *C)
static void voxel_size_edit_draw(const bContext *C, ARegion *, void *arg)
void OBJECT_OT_voxel_remesh(wmOperatorType *ot)
static wmOperatorStatus voxel_remesh_exec(bContext *C, wmOperator *op)
static wmOperatorStatus quadriflow_remesh_exec(bContext *C, wmOperator *op)
static Mesh * remesh_symmetry_mirror(Object *ob, Mesh *mesh, eSymmetryAxes symmetry_axes)
static void quadriflow_free_job(void *customdata)
@ QUADRIFLOW_STATUS_NONMANIFOLD
@ QUADRIFLOW_STATUS_SUCCESS
@ QUADRIFLOW_STATUS_CANCELED
@ QUADRIFLOW_REMESH_FACES
@ QUADRIFLOW_REMESH_RATIO
@ QUADRIFLOW_REMESH_EDGE_LENGTH
void OBJECT_OT_quadriflow_remesh(wmOperatorType *ot)
static void quadriflow_start_job(void *customdata, wmJobWorkerStatus *worker_status)
static wmOperatorStatus voxel_size_edit_modal(bContext *C, wmOperator *op, const wmEvent *event)
static bool quadriflow_poll_property(const bContext *C, wmOperator *op, const PropertyRNA *prop)
static wmOperatorStatus quadriflow_remesh_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void geometry_begin(const Scene &scene, Object &ob, const wmOperator *op)
void geometry_end(Object &ob)
const uiStyle * style_get()
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void mul_m3_v3(const float M[3][3], float r[3])
int RNA_enum_get(PointerRNA *ptr, const char *name)
void BLF_position(int fontid, float x, float y, float z)
void WM_jobs_callbacks(wmJob *wm_job, wm_jobs_start_callback startjob, void(*initjob)(void *), void(*update)(void *), void(*endjob)(void *))
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void copy_m3_m4(float m1[3][3], const float m2[4][4])
void mul_m4_m4_pre(float R[4][4], const float A[4][4])
Mesh * BKE_mesh_remesh_quadriflow(const Mesh *mesh, int target_faces, int seed, bool preserve_sharp, bool preserve_boundary, bool adaptive_scale, void(*update_cb)(void *, float progress, int *cancel), void *update_cb_data)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
Mesh * BKE_mesh_copy_for_eval(const Mesh &source)
const char * RNA_property_identifier(const PropertyRNA *prop)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
MINLINE void copy_v2_v2(float r[2], const float a[2])
GPUVertFormat * immVertexFormat()
MINLINE void invert_v3(float r[3])
@ WM_JOB_TYPE_QUADRIFLOW_REMESH
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, bool process_shape_keys=true)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void immBegin(GPUPrimType, uint vertex_len)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void GPU_line_smooth(bool enable)
int RNA_int_get(PointerRNA *ptr, const char *name)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
wmWindow * CTX_wm_window(const bContext *C)
MINLINE float normalize_v2(float n[2])
void WM_jobs_customdata_set(wmJob *wm_job, void *customdata, void(*free)(void *customdata))
void ED_view3d_project_v2(const ARegion *region, const float world[3], float r_region_co[2])
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
void ED_region_tag_redraw(ARegion *region)
void BKE_shrinkwrap_remesh_target_project(Mesh *src_me, Mesh *target_me, Object *ob_target)
void BKE_sculptsession_free_pbvh(Object &object)
void GPU_matrix_mul(const float m[4][4])
MINLINE void mul_v3_fl(float r[3], float f)
void GPU_line_width(float width)
void WM_jobs_start(wmWindowManager *wm, wmJob *wm_job)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
void WM_locked_interface_set(wmWindowManager *wm, bool lock)
float BKE_mesh_calc_area(const Mesh *mesh)
void BLF_size(int fontid, float size)
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
void size_to_mat4(float R[4][4], const float size[3])
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Mesh * BKE_mesh_mirror_bisect_on_mirror_plane_for_modifier(MirrorModifierData *mmd, const Mesh *mesh, int axis, const float plane_co[3], float plane_no[3])
Mesh * BKE_mesh_from_object(Object *ob)
void BKE_mesh_batch_cache_dirty_tag(Mesh *mesh, eMeshBatchDirtyMode mode)
@ GPU_SHADER_3D_UNIFORM_COLOR
wmWindowManager * CTX_wm_manager(const bContext *C)
void immUniformColor4f(float r, float g, float b, float a)
Mesh * BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd, Object *ob, const Mesh *mesh, int axis, bool use_correct_order_on_merge, int **r_vert_merge_map, int *r_vert_merge_map_len)
void unit_m4(float m[4][4])
RegionView3D * CTX_wm_region_view3d(const bContext *C)
Mesh * BKE_mesh_remesh_voxel(const Mesh *mesh, float voxel_size, float adaptivity, float isovalue, const Object *object, ModifierData *modifier_data)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
size_t BKE_unit_value_as_string_scaled(char *str, int str_maxncpy, double value, int prec, int type, const UnitSettings &settings, bool pad, bool do_unit_suffix)
MINLINE void zero_v3(float r[3])
@ ME_REMESH_REPROJECT_ATTRIBUTES
@ ME_REMESH_REPROJECT_VOLUME
void BKE_id_free(Main *bmain, void *idv)
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
bool BKE_modifiers_uses_multires(Object *ob)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
Mesh * BKE_mesh_remesh_voxel_fix_poles(const Mesh *mesh)
void mat4_to_size(float size[3], const float M[4][4])
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
bool BKE_object_is_in_editmode(const Object *ob)
wmOperatorStatus WM_operator_props_popup_confirm_ex(bContext *C, wmOperator *op, const wmEvent *, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message)
MINLINE float normalize_v3(float n[3])
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void immVertex3fv(uint attr_id, const float data[3])
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE bool compare_v3v3(const float v1[3], const float v2[3], float limit) ATTR_WARN_UNUSED_RESULT
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BLF_color3f(int fontid, float r, float g, float b)
float ED_view3d_pixel_size_no_ui_scale(const RegionView3D *rv3d, const float co[3])
wmJob * WM_jobs_get(wmWindowManager *wm, wmWindow *win, const void *owner, const char *name, const eWM_JobFlag flag, const eWM_JobType job_type)
MINLINE float max_ff(float a, float b)
void mul_m4_m4_post(float R[4][4], const float B[4][4])
Scene * CTX_data_scene(const bContext *C)
void GPU_blend(GPUBlend blend)
void scale_m4_fl(float R[4][4], float scale)
size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void BLF_width_and_height(int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL()
bool ED_operator_object_active_editable_mesh(bContext *C)
@ BKE_MESH_BATCH_DIRTY_ALL
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
Object * CTX_data_active_object(const bContext *C)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
ARegion * CTX_wm_region(const bContext *C)
void WM_jobs_timer(wmJob *wm_job, double time_step, uint note, uint endnote, void(*timer_step)(void *))
void ED_workspace_status_text(bContext *C, const char *str)
float RNA_float_get(PointerRNA *ptr, const char *name)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
MINLINE float clamp_f(float value, float min, float max)
#define VOXEL_SIZE_EDIT_MAX_GRIDS_LINES
#define VOXEL_SIZE_EDIT_MAX_STR_LEN
#define QUADRIFLOW_MIRROR_BISECT_TOLERANCE
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::ARegionRuntime * runtime
const c_style_mat & ptr() const
bke::ObjectRuntime * runtime
struct ARegionType * type
SculptSession * sculpt_session
eSymmetryAxes symmetry_axes
wmJobWorkerStatus * worker_status
bool use_preserve_boundary
float preview_plane[4][3]
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) poll_property(const bContext *C, wmOperator *op, const PropertyRNA *prop) ATTR_WARN_UNUSED_RESULT
bool(*) check(bContext *C, wmOperator *op)
void(*) cancel(bContext *C, wmOperator *op)
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports