Blender V4.3
multires_displacement_eraser.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7#include "DNA_brush_types.h"
8#include "DNA_mesh_types.h"
9#include "DNA_object_types.h"
10#include "DNA_scene_types.h"
11
12#include "BKE_paint.hh"
13#include "BKE_pbvh.hh"
14#include "BKE_subdiv_ccg.hh"
15
17#include "BLI_math_matrix.hh"
18#include "BLI_math_vector.hh"
19#include "BLI_task.h"
20#include "BLI_task.hh"
21
25
27
28inline namespace multires_displacement_eraser_cc {
29
36
37static BLI_NOINLINE void calc_limit_positions(const SubdivCCG &subdiv_ccg,
38 const Span<int> grids,
39 const MutableSpan<float3> limit_positions)
40{
41 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
42 for (const int i : grids.index_range()) {
43 const int start = i * key.grid_area;
45 subdiv_ccg, key, grids[i], limit_positions.slice(start, key.grid_area));
46 }
47}
48
49static void calc_node(const Depsgraph &depsgraph,
50 const Sculpt &sd,
51 Object &object,
52 const Brush &brush,
53 const float strength,
55 LocalData &tls)
56{
57 SculptSession &ss = *object.sculpt;
58 SubdivCCG &subdiv_ccg = *ss.subdiv_ccg;
59
60 const Span<int> grids = node.grids();
61 const MutableSpan positions = gather_grids_positions(subdiv_ccg, grids, tls.positions);
62
63 calc_factors_common_grids(depsgraph, brush, object, positions, node, tls.factors, tls.distances);
64
65 scale_factors(tls.factors, strength);
66
67 tls.translations.resize(positions.size());
68 const MutableSpan<float3> translations = tls.translations;
69 calc_limit_positions(subdiv_ccg, grids, translations);
70 for (const int i : positions.index_range()) {
71 translations[i] -= positions[i];
72 }
73 scale_translations(translations, tls.factors);
74
75 clip_and_lock_translations(sd, ss, positions, translations);
76 apply_translations(translations, grids, subdiv_ccg);
77}
78
79} // namespace multires_displacement_eraser_cc
80
82 const Sculpt &sd,
83 Object &object,
84 const IndexMask &node_mask)
85{
86 SculptSession &ss = *object.sculpt;
87 SubdivCCG &subdiv_ccg = *object.sculpt->subdiv_ccg;
88 MutableSpan<float3> positions = subdiv_ccg.positions;
89 const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
90 const float strength = std::min(ss.cache->bstrength, 1.0f);
91
95 node_mask.foreach_index(GrainSize(1), [&](const int i) {
96 LocalData &tls = all_tls.local();
97 calc_node(depsgraph, sd, object, brush, strength, nodes[i], tls);
98 bke::pbvh::update_node_bounds_grids(subdiv_ccg.grid_area, positions, nodes[i]);
99 });
100 pbvh.tag_positions_changed(node_mask);
102}
103
104} // namespace blender::ed::sculpt_paint
const Brush * BKE_paint_brush_for_read(const Paint *paint)
Definition paint.cc:654
void BKE_subdiv_ccg_eval_limit_positions(const SubdivCCG &subdiv_ccg, const CCGKey &key, int grid_index, blender::MutableSpan< blender::float3 > r_limit_positions)
CCGKey BKE_subdiv_ccg_key_top_level(const SubdivCCG &subdiv_ccg)
#define BLI_NOINLINE
Object is a sort of wrapper for general info.
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:574
constexpr IndexRange index_range() const
Definition BLI_span.hh:402
void tag_positions_changed(const IndexMask &node_mask)
Definition pbvh.cc:549
Span< NodeT > nodes() const
void foreach_index(Fn &&fn) const
const Depsgraph * depsgraph
pbvh::Tree * pbvh_get(Object &object)
Definition paint.cc:2846
void update_node_bounds_grids(int grid_area, Span< float3 > positions, GridsNode &node)
Definition pbvh.cc:1084
void flush_bounds_to_parents(Tree &pbvh)
Definition pbvh.cc:1132
static void calc_node(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const Brush &brush, const float strength, bke::pbvh::GridsNode &node, LocalData &tls)
static BLI_NOINLINE void calc_limit_positions(const SubdivCCG &subdiv_ccg, const Span< int > grids, const MutableSpan< float3 > limit_positions)
MutableSpan< float3 > gather_grids_positions(const SubdivCCG &subdiv_ccg, const Span< int > grids, Vector< float3 > &positions)
void do_displacement_eraser_brush(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const IndexMask &node_mask)
void calc_factors_common_grids(const Depsgraph &depsgraph, const Brush &brush, const Object &object, Span< float3 > positions, const bke::pbvh::GridsNode &node, Vector< float > &r_factors, Vector< float > &r_distances)
Definition sculpt.cc:6270
void scale_translations(MutableSpan< float3 > translations, Span< float > factors)
Definition sculpt.cc:7210
void scale_factors(MutableSpan< float > factors, float strength)
Definition sculpt.cc:7227
void clip_and_lock_translations(const Sculpt &sd, const SculptSession &ss, Span< float3 > positions, Span< int > verts, MutableSpan< float3 > translations)
Definition sculpt.cc:7022
void apply_translations(Span< float3 > translations, Span< int > verts, MutableSpan< float3 > positions)
Definition sculpt.cc:6958
int grid_area
Definition BKE_ccg.hh:35
blender::ed::sculpt_paint::StrokeCache * cache
Definition BKE_paint.hh:427
SubdivCCG * subdiv_ccg
Definition BKE_paint.hh:405
blender::Array< blender::float3 > positions