54 for (
const int i : displacement_factors.
index_range()) {
55 displacement_factors[i] += factors[i] * strength * (1.05f - std::abs(displacement_factors[i]));
72 for (
const int i : displacement_factors.
index_range()) {
73 displacement_factors[i] += std::abs(factors[i] * strength * displacement_factors[i]) *
74 (displacement_factors[i] > 0.0f ? -1.0f : 1.0f);
83 for (
const int i : displacement_factors.
index_range()) {
84 displacement_factors[i] = std::clamp(displacement_factors[i], -1.0f, 1.0f);
88 for (
const int i : displacement_factors.
index_range()) {
89 const float clamp_mask = 1.0f - masks[i];
90 displacement_factors[i] = std::clamp(displacement_factors[i], -clamp_mask, clamp_mask);
105 const float3 offset = orig_normals[i] * height * displacement_factors[i];
106 const float3 translation = orig_positions[i] + offset - positions[i];
107 r_translations[i] = translation * factors[i];
122 const float3 offset = base_normals[verts[i]] * height * displacement_factors[i];
123 const float3 translation = base_positions[verts[i]] + offset - positions[i];
124 r_translations[i] = translation * factors[i];
133 const bool use_persistent_base,
176 if (use_persistent_base) {
189 persistent_base_normals,
192 displacement_factors,
198 position_data.deform(translations, verts);
210 displacement_factors,
216 position_data.deform(translations, verts);
224 const bool use_persistent_base,
263 tls.masks.resize(positions.
size());
269 subdiv_ccg, layer_displacement_factor.
as_span(), grids, tls.displacement_factors);
271 if (use_persistent_base) {
281 subdiv_ccg, displacement_factors.
as_span(), grids, layer_displacement_factor);
286 gather_data_grids(subdiv_ccg, persistent_base_positions, grids, tls.persistent_positions),
287 gather_data_grids(subdiv_ccg, persistent_base_normals, grids, tls.persistent_normals),
289 displacement_factors,
302 subdiv_ccg, displacement_factors.
as_span(), grids, layer_displacement_factor);
309 displacement_factors,
358 layer_displacement_factor.
as_span(), verts, tls.displacement_factors);
362 tls.masks.resize(verts.
size());
374 displacement_factors,
396 switch (
pbvh.type()) {
410 bool use_persistent_base =
false;
413 if (!persistent_position.
is_empty() && !persistent_normal.is_empty()) {
416 if (persistent_disp_attr) {
417 use_persistent_base =
true;
418 displacement = persistent_disp_attr.span;
448 persistent_disp_attr.finish();
452 SubdivCCG &subdiv_ccg = *
object.runtime->sculpt_session->subdiv_ccg;
455 const std::optional<PersistentMultiresData> persistent_multires_data =
461 bool use_persistent_base =
false;
464 if (persistent_multires_data) {
465 use_persistent_base =
true;
466 persistent_position = persistent_multires_data->positions;
467 persistent_normal = persistent_multires_data->normals;
468 displacement = persistent_multires_data->displacements;
514 pbvh.tag_positions_changed(node_mask);
515 pbvh.flush_bounds_to_parents();
A BVH for high poly meshes.
Object is a sort of wrapper for general info.
#define PRF_scope(category)
Span< T > as_span() const
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr Span< T > as_span() const
constexpr IndexRange index_range() const
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
GAttributeReader lookup(const StringRef name) const
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
constexpr bool is_empty() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
pbvh::Tree * pbvh_get(Object &object)
void update_node_bounds_bmesh(BMeshNode &node)
void update_node_bounds_mesh(Span< float3 > positions, MeshNode &node)
Span< float3 > vert_normals_eval(const Depsgraph &depsgraph, const Object &object_orig)
void update_node_bounds_grids(int grid_area, Span< float3 > positions, GridsNode &node)
void calc_vert_factors(const Depsgraph &depsgraph, const Object &object, const Cache &automasking, const bke::pbvh::MeshNode &node, Span< int > verts, MutableSpan< float > factors)
void calc_grids_factors(const Depsgraph &depsgraph, const Object &object, const Cache &automasking, const bke::pbvh::GridsNode &node, Span< int > grids, MutableSpan< float > factors)
static BLI_NOINLINE void reset_displacement_factors(const MutableSpan< float > displacement_factors, const Span< float > factors, const float strength)
static BLI_NOINLINE void clamp_displacement_factors(const MutableSpan< float > displacement_factors, const Span< float > masks)
static void calc_bmesh(const Depsgraph &depsgraph, const Sculpt &sd, const Brush &brush, Object &object, bke::pbvh::BMeshNode &node, LocalData &tls, MutableSpan< float > layer_displacement_factor)
static void calc_grids(const Depsgraph &depsgraph, const Sculpt &sd, const Brush &brush, Object &object, const bool use_persistent_base, const Span< float3 > persistent_base_positions, const Span< float3 > persistent_base_normals, bke::pbvh::GridsNode &node, LocalData &tls, MutableSpan< float > layer_displacement_factor)
static BLI_NOINLINE void offset_displacement_factors(const MutableSpan< float > displacement_factors, const Span< float > factors, const float strength)
static BLI_NOINLINE void calc_translations(const Span< float3 > orig_positions, const Span< float3 > orig_normals, const Span< float3 > positions, const Span< float > displacement_factors, const Span< float > factors, const float height, const MutableSpan< float3 > r_translations)
static void calc_faces(const Depsgraph &depsgraph, const Sculpt &sd, const Brush &brush, const MeshAttributeData &attribute_data, const Span< float3 > vert_normals, const bool use_persistent_base, const Span< float3 > persistent_base_positions, const Span< float3 > persistent_base_normals, Object &object, bke::pbvh::MeshNode &node, MutableSpan< float > layer_displacement_factor, const PositionDeformData &position_data)
void do_layer_brush(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const IndexMask &node_mask)
void gather_mask_bmesh(const BMesh &bm, const Set< BMVert *, 0 > &verts, const MutableSpan< float > r_mask)
void fill_factor_from_hide_and_mask(Span< bool > hide_vert, Span< float > mask, Span< int > verts, MutableSpan< float > r_factors)
MutableSpan< float3 > gather_grids_positions(const SubdivCCG &subdiv_ccg, const Span< int > grids, Vector< float3 > &positions)
void scatter_data_bmesh(Span< T > node_data, const Set< BMVert *, 0 > &verts, MutableSpan< T > dst)
void gather_bmesh_positions(const Set< BMVert *, 0 > &verts, MutableSpan< float3 > positions)
void calc_brush_strength_factors(const StrokeCache &cache, const Brush &brush, Span< float > distances, MutableSpan< float > factors)
void gather_data_grids(const SubdivCCG &subdiv_ccg, Span< T > src, Span< int > grids, MutableSpan< T > node_data)
void apply_hardness_to_distances(float radius, float hardness, MutableSpan< float > distances)
void filter_distances_with_radius(float radius, Span< float > distances, MutableSpan< float > factors)
int vertex_count_get(const Object &object)
void filter_region_clip_factors(const SculptSession &ss, Span< float3 > vert_positions, Span< int > verts, MutableSpan< float > factors)
void gather_data_bmesh(Span< T > src, const Set< BMVert *, 0 > &verts, MutableSpan< T > node_data)
void orig_position_data_gather_bmesh(const BMLog &bm_log, const Set< BMVert *, 0 > &verts, MutableSpan< float3 > positions, MutableSpan< float3 > normals)
void clip_and_lock_translations(const Sculpt &sd, const SculptSession &ss, Span< float3 > positions, Span< int > verts, MutableSpan< float3 > translations)
void scatter_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
void calc_brush_distances(const SculptSession &ss, Span< float3 > vert_positions, Span< int > vert, eBrushFalloffShape falloff_shape, MutableSpan< float > r_distances)
void apply_translations(Span< float3 > translations, Span< int > verts, MutableSpan< float3 > positions)
OrigPositionData orig_position_data_get_mesh(const Object &object, const bke::pbvh::MeshNode &node)
void gather_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
OrigPositionData orig_position_data_get_grids(const Object &object, const bke::pbvh::GridsNode &node)
void calc_front_face(const float3 &view_normal, Span< float3 > normals, MutableSpan< float > factors)
void calc_brush_texture_factors(PaintMode paint_mode, const SculptSession &ss, const Brush &brush, Span< float3 > vert_positions, Span< int > vert, MutableSpan< float > factors)
void scatter_data_grids(const SubdivCCG &subdiv_ccg, Span< T > node_data, Span< int > grids, MutableSpan< T > dst)
constexpr ParallelGrainSize grain_size(int grain_size)
BMesh const char void * data
const Brush * BKE_paint_brush_for_read(const Paint *paint)
VecBase< float, 3 > float3
const Set< BMVert *, 0 > & BKE_pbvh_bmesh_node_unique_verts(bke::pbvh::BMeshNode *node)
ed::sculpt_paint::StrokeCache * cache
std::optional< PersistentMultiresData > persistent_multires_data()
Array< float3 > positions
VArraySpan< bool > hide_vert
StrokeToggleSettings toggle_settings
Array< float > layer_displacement_factor
std::unique_ptr< auto_mask::Cache > automasking
Vector< float > distances
Vector< float3 > positions
Vector< float3 > translations
Vector< float3 > persistent_positions
Vector< float > distances
Vector< float > displacement_factors
Vector< float3 > persistent_normals
Vector< float3 > positions
Vector< float3 > translations
void resize(int new_size)