53#include "RNA_prototypes.hh"
124 if (
nodes.is_empty()) {
137 const float max_edge_len = 1.0f /
178 ot->
name =
"Detail Flood Fill";
179 ot->
idname =
"SCULPT_OT_detail_flood_fill";
180 ot->
description =
"Flood fill the mesh with the selected detail setting";
203 {0,
nullptr, 0,
nullptr,
nullptr},
220 const float mval_fl[2] = {
float(mval[0]),
float(mval[1])};
227 const int active_vert = std::get<int>(ss.
active_vert());
228 const float3 active_vert_position = positions[active_vert];
229 float edge_length = 0.0f;
232 faces, corner_verts, vert_to_face_map, hide_poly, active_vert, neighbors))
234 edge_length +=
math::distance(active_vert_position, positions[neighbor]);
236 mesh.remesh_voxel_size = edge_length /
float(neighbors.
size());
264 float depth =
raycast_init(vc, mval_fl, ray_start, ray_end, ray_normal,
false);
291 const int event_xy[2],
298 if (region ==
nullptr) {
327 const int mval[2] = {
383 switch (event->
type) {
415 ot->
name =
"Sample Detail Size";
416 ot->
idname =
"SCULPT_OT_sample_detail_size";
417 ot->
description =
"Sample the mesh detail on clicked point";
435 "Screen coordinates of sampling",
444 "Target sculpting workflow that is going to use the sampled size");
455#define DETAIL_SIZE_DELTA_SPEED 0.08f
456#define DETAIL_SIZE_DELTA_ACCURATE_SPEED 0.004f
497 const float start_co[3],
498 const float end_co[3],
502 float object_space_constant_detail;
521 object_space_constant_detail *= 0.7f;
524 const int tot_lines = int(total_len / object_space_constant_detail) + 1;
525 const float tot_lines_fl = total_len / object_space_constant_detail;
526 float spacing_disp[3];
533 mul_v3_fl(spacing_disp, total_len / tot_lines_fl);
536 for (
int i = 0; i < tot_lines; i++) {
539 line_length = total_len * (
float(i) /
float(tot_lines_fl));
542 line_length = total_len * (1.0f - (
float(i) /
float(tot_lines_fl)));
640 if (std::holds_alternative<std::monostate>(active_vert)) {
643 BMVert *active_vertex = std::get<BMVert *>(active_vert);
648 len_accum +=
len_v3v3(active_vertex->
co, neighbor->co);
650 const int num_neighbors = neighbors.
size();
652 if (num_neighbors > 0) {
653 const float avg_edge_len = len_accum / num_neighbors;
678 float detail_size_delta;
686 detail_size_delta = mval[0] - cd->
init_mval[0];
712 const char *format_string;
713 const char *property_name;
715 property_name =
"constant_detail_resolution";
716 format_string =
"%s: %0.4f";
719 property_name =
"detail_percent";
720 format_string =
"%s: %3.1f%%";
723 property_name =
"detail_size";
724 format_string =
"%s: %0.4f";
733 status.
item(
IFACE_(
"Confirm"), ICON_EVENT_RETURN, ICON_MOUSE_LMB);
734 status.
item(
IFACE_(
"Cancel"), ICON_EVENT_ESC, ICON_MOUSE_RMB);
735 status.
item(
IFACE_(
"Change Size"), ICON_MOUSE_MOVE);
868 float cursor_trans[4][4], cursor_rot[4][4];
869 const float z_axis[4] = {0.0f, 0.0f, 1.0f, 0.0f};
871 copy_m4_m4(cursor_trans, active_object.object_to_world().ptr());
874 float cursor_normal[3];
888 const float y_axis[3] = {0.0f, cd->
radius, 0.0f};
889 for (
int i = 0; i < 3; i++) {
901 const char *status_str =
IFACE_(
902 "Move the mouse to change the dyntopo detail size. LMB: confirm size, ESC/RMB: cancel, "
903 "SHIFT: precision mode, CTRL: sample detail size");
914 ot->
name =
"Edit Dyntopo Detail Size";
915 ot->
description =
"Modify the detail size of dyntopo interactively";
916 ot->
idname =
"SCULPT_OT_dyntopo_detail_size_edit";
933 return 1.0f / (constant_detail *
mat4_to_scale(ob.object_to_world().ptr()));
938 return brush_radius * brush_percent / 100.0f;
942 const float brush_radius,
943 const float pixel_radius,
944 const float pixel_size)
950 const float brush_radius,
953 const float object_scale =
mat4_to_scale(ob.object_to_world().ptr());
955 return 100.0f / (constant_detail * brush_radius * object_scale);
959 const float brush_radius,
960 const float pixel_radius,
961 const float pixel_size,
964 const float object_scale =
mat4_to_scale(ob.object_to_world().ptr());
967 (1.0f / (constant_detail * object_scale));
A BVH for high poly meshes.
#define SNPRINTF_UTF8(dst, format,...)
Platform independent time functions.
#define CLOG_DEBUG(clg_ref,...)
#define REGION_DRAW_POST_VIEW
Read Blender memory allocation and freeing.
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
void item(std::string text, int icon1, int icon2=0)
void item_bool(std::string text, bool inverted, int icon1, int icon2=0)
GAttributeReader lookup(const StringRef name) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
float distance(float, float) RET
float2x2 invert(float2x2 mat)
pbvh::Tree * pbvh_get(Object &object)
void raycast(Tree &pbvh, FunctionRef< void(Node &node, float *tmin)> hit_fn, const float3 &ray_start, const float3 &ray_normal, bool original)
IndexMask all_leaf_nodes(const Tree &pbvh, IndexMaskMemory &memory)
Bounds< float3 > bounds_get(const Tree &pbvh)
bool bmesh_update_topology(BMesh &bm, Tree &pbvh, BMLog &bm_log, PBVHTopologyUpdateMode mode, float min_edge_len, float max_edge_len, const float3 ¢er, const std::optional< float3 > &view_normal, float radius, bool use_frontface, bool use_projected)
bool raycast_node_detail_bmesh(const BMeshNode &node, const float3 &ray_start, const IsectRayPrecalc *isect_precalc, float *depth, float *r_edge_length)
Span< float3 > vert_positions_eval(const Depsgraph &depsgraph, const Object &object_orig)
float relative_to_detail_size(const float relative_detail, const float brush_radius, const float pixel_radius, const float pixel_size)
float constant_to_detail_size(const float constant_detail, const Object &ob)
float constant_to_relative_detail(const float constant_detail, const float brush_radius, const float pixel_radius, const float pixel_size, const Object &ob)
float constant_to_brush_detail(const float constant_detail, const float brush_radius, const Object &ob)
float brush_to_detail_size(const float brush_percent, const float brush_radius)
constexpr float RELATIVE_SCALE_FACTOR
constexpr float EDGE_LENGTH_MIN_FACTOR
void SCULPT_OT_detail_flood_fill(wmOperatorType *ot)
static EnumPropertyItem prop_sculpt_sample_detail_mode_types[]
static void dyntopo_detail_size_edit_cancel(bContext *C, wmOperator *op)
static float dyntopo_detail_size_initial_value(const Sculpt *sd, const eDyntopoDetailingMode mode)
static wmOperatorStatus sculpt_sample_detail_size_exec(bContext *C, wmOperator *op)
static void dyntopo_detail_size_update_header(bContext *C, const DyntopoDetailSizeEditCustomData *cd)
static wmOperatorStatus dyntopo_detail_size_edit_modal(bContext *C, wmOperator *op, const wmEvent *event)
void SCULPT_OT_sample_detail_size(wmOperatorType *ot)
static void sample_detail_dyntopo(bContext *C, ViewContext *vc, const int mval[2])
static void dyntopo_detail_size_parallel_lines_draw(uint pos3d, DyntopoDetailSizeEditCustomData *cd, const float start_co[3], const float end_co[3], bool flip, const float angle)
static wmOperatorStatus dyntopo_detail_size_edit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void dyntopo_detail_size_update_from_mouse_delta(DyntopoDetailSizeEditCustomData *cd, const wmEvent *event)
static void dyntopo_detail_size_sample_from_surface(Object &ob, DyntopoDetailSizeEditCustomData *cd)
static void dyntopo_detail_size_edit_draw(const bContext *, ARegion *, void *arg)
static bool sample_detail_voxel(bContext *C, ViewContext *vc, const int mval[2])
void SCULPT_OT_dyntopo_detail_size_edit(wmOperatorType *ot)
static wmOperatorStatus sculpt_sample_detail_size_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void dyntopo_detail_size_bounds(DyntopoDetailSizeEditCustomData *cd)
static wmOperatorStatus sample_detail(bContext *C, const int event_xy[2], const SampleDetailModeType mode)
static void sculpt_raycast_detail_cb(bke::pbvh::BMeshNode &node, SculptDetailRaycastData &srd, float *distance)
static wmOperatorStatus sculpt_sample_detail_size_invoke(bContext *C, wmOperator *op, const wmEvent *)
@ DETAILING_MODE_BRUSH_PERCENT
@ DETAILING_MODE_DETAIL_SIZE
@ DETAILING_MODE_RESOLUTION
static bool sculpt_and_dynamic_topology_poll(bContext *C)
static bool sculpt_and_constant_or_manual_detail_poll(bContext *C)
static wmOperatorStatus sculpt_detail_flood_fill_exec(bContext *C, wmOperator *op)
void push_end(Object &ob)
void push_node(const Depsgraph &depsgraph, const Object &object, const bke::pbvh::Node *node, const Type type)
void push_begin(const Scene &scene, Object &ob, const wmOperator *op)
void vert_random_access_ensure(Object &object)
Vector< BMVert *, 64 > BMeshNeighborVerts
void stroke_modifiers_check(Depsgraph &depsgraph, Object &ob, const Brush *brush)
bool sculpt_mode_poll(bContext *C)
float raycast_init(ViewContext *vc, const float2 &mval, float3 &r_ray_start, float3 &r_ray_end, float3 &r_ray_normal, bool original)
Span< BMVert * > vert_neighbors_get_bmesh(BMVert &vert, BMeshNeighborVerts &r_neighbors)
float object_space_radius_get(const ViewContext &vc, const Paint &paint, const Brush &brush, const float3 &location, const float scale_factor)
std::optional< CursorGeometryInfo > cursor_geometry_info_update(bContext *C, const float2 &mval, const bool use_sampled_normal)
Span< int > vert_neighbors_get_mesh(const OffsetIndices< int > faces, const Span< int > corner_verts, const GroupedSpan< int > vert_to_face, const Span< bool > hide_poly, const int vert, Vector< int > &r_neighbors)
T reduce_max(const VecBase< T, Size > &a)
T distance(const T &a, const T &b)
T midpoint(const T &a, const T &b)
void WM_main_add_notifier(uint type, void *reference)
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
ScrArea * CTX_wm_area(const bContext *C)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
std::variant< std::monostate, int, BMVert * > ActiveVert
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
MINLINE void copy_v3_v3(float r[3], const float a[3])
bool BKE_base_is_visible(const View3D *v3d, const Base *base)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
float mat4_to_scale(const float mat[4][4])
MINLINE void copy_v2_v2(float r[2], const float a[2])
GPUVertFormat * immVertexFormat()
float BKE_brush_radius_get(const Paint *paint, const Brush *brush)
void WM_cursor_modal_set(wmWindow *win, int val)
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)
wmWindow * CTX_wm_window(const bContext *C)
void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3])
void translate_m4(float mat[4][4], float Tx, float Ty, float Tz)
void immUniformColor4fv(const float rgba[4])
void ED_region_tag_redraw(ARegion *region)
Base * CTX_data_active_base(const bContext *C)
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 immBindBuiltinProgram(GPUBuiltinShader shader_id)
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
VecBase< float, 2 > float2
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 rotate_v2_v2fl(float r[2], const float p[2], float angle)
void DEG_id_tag_update(ID *id, unsigned int flags)
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
@ GPU_SHADER_3D_UNIFORM_COLOR
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
void WM_cursor_modal_restore(wmWindow *win)
void immUniformColor4f(float r, float g, float b, float a)
@ SCULPT_DYNTOPO_DETAIL_CONSTANT
@ SCULPT_DYNTOPO_DETAIL_MANUAL
@ SCULPT_DYNTOPO_DETAIL_BRUSH
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void isect_ray_tri_watertight_v3_precalc(struct IsectRayPrecalc *isect_precalc, const float ray_direction[3])
void ED_area_status_text(ScrArea *area, const char *str)
ToolSettings * CTX_data_tool_settings(const bContext *C)
MINLINE void zero_v3(float r[3])
ScrArea ScrArea * BKE_screen_find_area_xy(const bScreen *screen, int spacetype, const int xy[2]) ATTR_NONNULL(1
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
const Brush * BKE_paint_brush_for_read(const Paint *paint)
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)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void mul_m4_m4_post(float R[4][4], const float B[4][4])
PropertyRNA * RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void BKE_sculptsession_update_for_edit(Depsgraph *depsgraph, Object *ob_orig, bool is_paint_tool)
Brush * BKE_paint_brush(Paint *paint)
double BLI_time_now_seconds()
Scene * CTX_data_scene(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
MINLINE void copy_v4_v4(float r[4], const float a[4])
void GPU_blend(GPUBlend blend)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
VecBase< float, 3 > float3
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void imm_draw_circle_wire_3d(uint pos, float x, float y, float radius, int nsegments)
void BKE_pbvh_node_mark_topology_update(bke::pbvh::Node &node)
Object * CTX_data_active_object(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
void ED_workspace_status_text(bContext *C, const char *str)
View3D * CTX_wm_view3d(const bContext *C)
const char * RNA_property_ui_name(const PropertyRNA *prop, const PointerRNA *ptr)
void quat_to_mat4(float m[4][4], const float q[4])
MINLINE float clamp_f(float value, float min, float max)
void CTX_wm_area_set(bContext *C, ScrArea *area)
ARegion * BKE_area_find_region_xy(const ScrArea *area, int regiontype, const int xy[2]) ATTR_NONNULL(3)
#define DETAIL_SIZE_DELTA_ACCURATE_SPEED
#define DETAIL_SIZE_DELTA_SPEED
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::ARegionRuntime * runtime
bke::ObjectRuntime * runtime
struct ToolSettings * toolsettings
std::optional< float3 > cursor_sampled_normal
ActiveVert active_vert() const
struct ARegionType * type
SculptSession * sculpt_session
eDyntopoDetailingMode mode
IsectRayPrecalc isect_precalc
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
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