56using bke::CurvesGeometry;
61 std::unique_ptr<KDTreeNew<float3>> curve_roots_kdtree_;
121 const Mesh &surface_orig = *id_cast<const Mesh *>(surface_ob_orig.
data);
195 const Span<int3> surface_corner_tris_orig = surface_orig.corner_tris();
196 const Span<float3> corner_normals_su = surface_orig.corner_normals();
200 add_inputs.
uvs = sampled_uvs;
216 add_inputs.
surface = &surface_orig;
260 float3 ray_start_wo, ray_end_wo;
269 for (
const float4x4 &brush_transform : symmetry_brush_transforms) {
278 const float3 &ray_start_su,
281 const float3 ray_direction_su = ray_end_su - ray_start_su;
287 const int tri_index = ray_hit->index;
289 const float3 brush_pos_su = ray_hit->position(ray);
305 for (
const float4x4 &brush_transform : symmetry_brush_transforms) {
314 const int old_amount = r_sampled_uvs.
size();
315 const int max_iterations = 100;
316 int current_iteration = 0;
318 if (current_iteration++ >= max_iterations) {
325 const int missing_amount =
add_amount_ + old_amount - r_sampled_uvs.
size();
371 if (!brush_3d.has_value()) {
375 float3 view_ray_start_wo, view_ray_end_wo;
391 for (
const float4x4 &brush_transform : symmetry_brush_transforms) {
399 transform, brush_3d->position_cu, brush_3d->radius_cu);
401 this->
sample_spherical(rng, r_sampled_uvs, brush_pos_su, brush_radius_su, view_direction_su);
407 const float3 &brush_pos_su,
408 const float brush_radius_su,
409 const float3 &view_direction_su)
411 const float brush_radius_sq_su =
pow2f(brush_radius_su);
423 if (
math::dot(normal_su, view_direction_su) >= 0.0f) {
440 const float brush_plane_area_su =
M_PI * brush_radius_sq_su;
441 const float approximate_density_su =
add_amount_ / brush_plane_area_su;
444 const int max_iterations = 5;
445 int current_iteration = 0;
447 const int old_amount = r_sampled_uvs.
size();
449 if (current_iteration++ >= max_iterations) {
458 selected_tri_indices,
461 approximate_density_su,
481 if (
self_->curve_roots_kdtree_ ==
nullptr) {
488 self_->curve_roots_kdtree_ = std::make_unique<KDTreeNew<float3>>(
498 executor.
execute(*
this, stroke_extension);
503 return std::make_unique<AddOperation>();
Low-level operations for curves.
General operations, lookup, etc. for blender objects.
Object is a sort of wrapper for general info.
#define BLI_assert_unreachable()
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
void reinitialize(const int64_t new_size)
constexpr IndexRange()=default
static RandomNumberGenerator from_random_seed()
constexpr Span take_front(int64_t n) const
void remove_and_reorder(const int64_t index)
void append(const T &value)
bool contains(StringRef name) const
AttributeAccessor attributes() const
Span< float3 > positions() const
Span< int > offsets() const
MutableAttributeAccessor attributes_for_write()
GSpanAttributeWriter lookup_for_write_span(StringRef name)
std::optional< RayHit > ray_intersect(const Ray &ray) const
void range_query(const float3 &point, const float radius, FunctionRef< bool(int)> fn) const
constexpr bool is_empty() const
void on_stroke_extended(const PaintStroke &stroke, const StrokeExtension &stroke_extension) override
friend struct AddOperationExecutor
const Depsgraph * depsgraph
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
int sample_surface_points_spherical(RandomNumberGenerator &rng, const Mesh &mesh, Span< int > tris_to_sample, const float3 &sample_pos, float sample_radius, float approximate_density, Vector< float3 > &r_bary_coords, Vector< int > &r_tri_indices, Vector< float3 > &r_positions)
int sample_surface_points_projected(RandomNumberGenerator &rng, const Mesh &mesh, const bke::bvh::Tree &mesh_bvhtree, const float2 &sample_pos_re, float sample_radius_re, FunctionRef< void(const float2 &pos_re, float3 &r_start, float3 &r_end)> region_position_to_ray, bool front_face_only, int tries_num, int max_points, Vector< float3 > &r_bary_coords, Vector< int > &r_tri_indices, Vector< float3 > &r_positions)
float3 compute_bary_coord_in_triangle(Span< float3 > vert_positions, Span< int > corner_verts, const int3 &corner_tri, const float3 &position)
T sample_corner_attribute_with_bary_coords(const float3 &bary_weights, const int3 &corner_tri, const Span< T > corner_attribute)
std::optional< Bounds< T > > min_max(const std::optional< Bounds< T > > &a, const T &b)
void fill_selection_true(GMutableSpan selection)
std::unique_ptr< CurvesSculptStrokeOperation > new_add_operation()
void report_invalid_uv_map(ReportList *reports)
void report_empty_evaluated_surface(ReportList *reports)
std::optional< CurvesBrush3D > sample_curves_surface_3d_brush(const Depsgraph &depsgraph, const ARegion ®ion, const View3D &v3d, const CurvesSurfaceTransforms &transforms, const bke::bvh::Tree &surface_bvh, const float2 &brush_pos_re, const float brush_radius_re)
void report_missing_uv_map_on_original_surface(ReportList *reports)
void remember_stroke_position(CurvesSculpt &curves_sculpt, const float3 &brush_position_wo)
void report_missing_uv_map_on_evaluated_surface(ReportList *reports)
void report_missing_surface(ReportList *reports)
float brush_radius_get(const Paint &paint, const Brush &brush, const StrokeExtension &stroke_extension)
void report_empty_original_surface(ReportList *reports)
Vector< float4x4 > get_symmetry_brush_transforms(const eCurvesSymmetryType symmetry)
float transform_brush_radius(const float4x4 &transform, const float3 &brush_position, const float old_radius)
AddCurvesOnMeshOutputs add_curves_on_mesh(bke::CurvesGeometry &curves, const AddCurvesOnMeshInputs &inputs)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
void WM_main_add_notifier(uint type, void *reference)
@ PAINT_FALLOFF_SHAPE_SPHERE
@ PAINT_FALLOFF_SHAPE_TUBE
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
MatBase< float, 4, 4 > float4x4
void ED_region_tag_redraw(ARegion *region)
MINLINE float pow2f(float x)
@ BRUSH_CURVES_SCULPT_FLAG_INTERPOLATE_RADIUS
@ BRUSH_CURVES_SCULPT_FLAG_INTERPOLATE_LENGTH
@ BRUSH_CURVES_SCULPT_FLAG_INTERPOLATE_POINT_COUNT
@ BRUSH_CURVES_SCULPT_FLAG_INTERPOLATE_SHAPE
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
void DEG_id_tag_update(ID *id, unsigned int flags)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
const Brush * BKE_paint_brush_for_read(const Paint *paint)
bool ED_view3d_win_to_segment_clipped(const Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const float mval[2], float r_ray_start[3], float r_ray_end[3], bool do_clip_planes)
VecBase< float, 3 > float3
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
eBrushCurvesSculptFlag flag
eBrushFalloffShape falloff_shape
struct BrushCurvesSculptSettings * curves_sculpt_settings
struct ToolSettings * toolsettings
void ensure_curve_roots_kdtree()
void sample_spherical_with_symmetry(RandomNumberGenerator &rng, Vector< float2 > &r_sampled_uvs)
CurvesSculptCommonContext ctx_
void sample_in_center_with_symmetry(Vector< float2 > &r_sampled_uvs)
Span< float3 > surface_positions_eval_
Span< int3 > surface_corner_tris_eval_
CurvesSurfaceTransforms transforms_
void sample_projected_with_symmetry(RandomNumberGenerator &rng, Vector< float2 > &r_sampled_uvs)
Object * surface_ob_eval_
void sample_in_center(Vector< float2 > &r_sampled_uvs, const float3 &ray_start_su, const float3 &ray_end_su)
VArraySpan< float2 > surface_uv_map_eval_
const bke::bvh::Tree * surface_bvh_eval_
CurvesGeometry * curves_orig_
const BrushCurvesSculptSettings * brush_settings_
Span< int > surface_corner_verts_eval_
AddOperationExecutor(const PaintStroke &stroke)
void sample_spherical(RandomNumberGenerator &rng, Vector< float2 > &r_sampled_uvs, const float3 &brush_pos_su, const float brush_radius_su, const float3 &view_direction_su)
void sample_projected(RandomNumberGenerator &rng, Vector< float2 > &r_sampled_uvs, const float4x4 &brush_transform)
CurvesSculpt * curves_sculpt_
void execute(AddOperation &self, const StrokeExtension &stroke_extension)
IndexRange new_points_range
IndexRange new_curves_range