50 displacement_factors[
i] += factors[
i] * strength * (1.05f - std::abs(displacement_factors[
i]));
67 displacement_factors[
i] += std::abs(factors[
i] * strength * displacement_factors[
i]) *
68 (displacement_factors[
i] > 0.0f ? -1.0f : 1.0f);
77 displacement_factors[
i] = std::clamp(displacement_factors[
i], -1.0f, 1.0f);
97 const float3 offset = orig_normals[
i] * height * displacement_factors[
i];
98 const float3 translation = orig_positions[
i] + offset - positions[
i];
99 r_translations[
i] = translation * factors[
i];
113 const float3 offset = base_normals[
verts[
i]] * height * displacement_factors[
i];
114 const float3 translation = base_positions[
verts[
i]] + offset - positions[
i];
115 r_translations[
i] = translation * factors[
i];
124 const bool use_persistent_base,
164 tls.masks.resize(
verts.size());
169 tls.displacement_factors.resize(
verts.size());
173 if (use_persistent_base) {
187 persistent_base_normals,
190 displacement_factors,
196 position_data.deform(translations,
verts);
209 displacement_factors,
215 position_data.deform(translations,
verts);
223 const bool use_persistent_base,
262 tls.masks.resize(positions.
size());
268 subdiv_ccg, layer_displacement_factor.
as_span(), grids, tls.displacement_factors);
270 if (use_persistent_base) {
280 subdiv_ccg, displacement_factors.
as_span(), grids, layer_displacement_factor);
285 gather_data_grids(subdiv_ccg, persistent_base_positions, grids, tls.persistent_positions),
286 gather_data_grids(subdiv_ccg, persistent_base_normals, grids, tls.persistent_normals),
288 displacement_factors,
301 subdiv_ccg, displacement_factors.
as_span(), grids, layer_displacement_factor);
308 displacement_factors,
357 layer_displacement_factor.
as_span(),
verts, tls.displacement_factors);
361 tls.masks.resize(
verts.size());
373 displacement_factors,
394 switch (pbvh.
type()) {
408 bool use_persistent_base =
false;
411 if (!persistent_position.
is_empty() && !persistent_normal.is_empty()) {
414 if (persistent_disp_attr) {
415 use_persistent_base =
true;
416 displacement = persistent_disp_attr.span;
447 persistent_disp_attr.finish();
451 SubdivCCG &subdiv_ccg = *
object.sculpt->subdiv_ccg;
454 const std::optional<PersistentMultiresData> persistent_multires_data =
460 bool use_persistent_base =
false;
463 if (persistent_multires_data) {
464 use_persistent_base =
true;
465 persistent_position = persistent_multires_data->positions;
466 persistent_normal = persistent_multires_data->normals;
467 displacement = persistent_multires_data->displacements;
const Brush * BKE_paint_brush_for_read(const Paint *paint)
A BVH for high poly meshes.
const blender::Set< BMVert *, 0 > & BKE_pbvh_bmesh_node_unique_verts(blender::bke::pbvh::BMeshNode *node)
Object is a sort of wrapper for general info.
BPy_StructRNA * depsgraph
Span< T > as_span() const
constexpr bool is_empty() const
void resize(const int64_t new_size)
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr Span< T > as_span() const
constexpr IndexRange index_range() const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
GAttributeReader lookup(const StringRef attribute_id) const
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef attribute_id, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
void tag_positions_changed(const IndexMask &node_mask)
Span< NodeT > nodes() const
void flush_bounds_to_parents()
void foreach_index(Fn &&fn) 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 void calc_bmesh(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const Brush &brush, const float3 &direction, const float strength, bke::pbvh::BMeshNode &node, LocalData &tls)
static void calc_faces(const Depsgraph &depsgraph, const Sculpt &sd, const Brush &brush, const float4 &test_plane, const float strength, const MeshAttributeData &attribute_data, const Span< float3 > vert_normals, const bke::pbvh::MeshNode &node, Object &object, LocalData &tls, const PositionDeformData &position_data)
static void calc_grids(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const Brush &brush, const float4 &test_plane, const float strength, bke::pbvh::GridsNode &node, LocalData &tls)
static BLI_NOINLINE void fill_factor_from_hide_and_mask(const Mesh &mesh, const Span< int > face_indices, const MutableSpan< float > r_factors)
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, LocalData &tls, MutableSpan< float > layer_displacement_factor, const PositionDeformData &position_data)
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 BLI_NOINLINE void clamp_mask(const MutableSpan< float > masks)
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)
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)
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)
void calc_brush_texture_factors(const SculptSession &ss, const Brush &brush, Span< float3 > vert_positions, Span< int > vert, MutableSpan< float > factors)
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 scatter_data_grids(const SubdivCCG &subdiv_ccg, Span< T > node_data, Span< int > grids, MutableSpan< T > dst)
VecBase< float, 3 > float3
int SCULPT_vertex_count_get(const Object &object)
blender::ed::sculpt_paint::StrokeCache * cache
std::optional< PersistentMultiresData > persistent_multires_data()
blender::Array< float > masks
blender::Array< blender::float3 > positions
Span< int > grids() const
Span< int > verts() const
VArraySpan< bool > hide_vert
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