Blender V5.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
8
10
11#include "DNA_brush_types.h"
12#include "DNA_mesh_types.h"
13#include "DNA_object_types.h"
14#include "DNA_scene_types.h"
15
16#include "BKE_object_types.hh"
17#include "BKE_paint.hh"
18#include "BKE_paint_bvh.hh"
19#include "BKE_subdiv_ccg.hh"
20
22#include "BLI_task.hh"
23
27
29
31
38
39static BLI_NOINLINE void calc_limit_positions(const SubdivCCG &subdiv_ccg,
40 const Span<int> grids,
41 const MutableSpan<float3> limit_positions)
42{
44 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
45 for (const int i : grids.index_range()) {
46 const int start = i * key.grid_area;
48 subdiv_ccg, key, grids[i], limit_positions.slice(start, key.grid_area));
49 }
50}
51
52static void calc_node(const Depsgraph &depsgraph,
53 const Sculpt &sd,
54 Object &object,
55 const Brush &brush,
56 const float strength,
58 LocalData &tls)
59{
60 SculptSession &ss = *object.runtime->sculpt_session;
61 SubdivCCG &subdiv_ccg = *ss.subdiv_ccg;
62
63 const Span<int> grids = node.grids();
64 const MutableSpan positions = gather_grids_positions(subdiv_ccg, grids, tls.positions);
65
66 calc_factors_common_grids(depsgraph, brush, object, positions, node, tls.factors, tls.distances);
67
68 scale_factors(tls.factors, strength);
69
70 tls.translations.resize(positions.size());
71 const MutableSpan<float3> translations = tls.translations;
72 calc_limit_positions(subdiv_ccg, grids, translations);
73 for (const int i : positions.index_range()) {
74 translations[i] -= positions[i];
75 }
76 scale_translations(translations, tls.factors);
77
78 clip_and_lock_translations(sd, ss, positions, translations);
79 apply_translations(translations, grids, subdiv_ccg);
80}
81
82} // namespace multires_displacement_eraser_cc
83
84void do_displacement_eraser_brush(const Depsgraph &depsgraph,
85 const Sculpt &sd,
86 Object &object,
87 const IndexMask &node_mask)
88{
90 SculptSession &ss = *object.runtime->sculpt_session;
91 SubdivCCG &subdiv_ccg = *object.runtime->sculpt_session->subdiv_ccg;
92 MutableSpan<float3> positions = subdiv_ccg.positions;
94 const float strength = std::min(ss.cache->bstrength, 1.0f);
95
99 node_mask.foreach_index(
100 [&](const int i) {
101 LocalData &tls = all_tls.local();
102 calc_node(depsgraph, sd, object, brush, strength, nodes[i], tls);
103 bke::pbvh::update_node_bounds_grids(subdiv_ccg.grid_area, positions, nodes[i]);
104 },
106 pbvh.tag_positions_changed(node_mask);
107 pbvh.flush_bounds_to_parents();
108}
109
110} // namespace blender::ed::sculpt_paint::brushes
A BVH for high poly meshes.
Object is a sort of wrapper for general info.
#define PRF_scope(category)
#define BLI_NOINLINE
constexpr int64_t size() const
Definition BLI_span.hh:499
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:579
constexpr IndexRange index_range() const
Definition BLI_span.hh:676
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
pbvh::Tree * pbvh_get(Object &object)
void update_node_bounds_grids(int grid_area, Span< float3 > positions, GridsNode &node)
Definition pbvh.cc:1205
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)
void do_displacement_eraser_brush(const Depsgraph &depsgraph, const Sculpt &sd, Object &ob, const IndexMask &node_mask)
MutableSpan< float3 > gather_grids_positions(const SubdivCCG &subdiv_ccg, const Span< int > grids, Vector< float3 > &positions)
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:6804
void scale_translations(MutableSpan< float3 > translations, Span< float > factors)
Definition sculpt.cc:7837
void scale_factors(MutableSpan< float > factors, float strength)
Definition sculpt.cc:7856
void clip_and_lock_translations(const Sculpt &sd, const SculptSession &ss, Span< float3 > positions, Span< int > verts, MutableSpan< float3 > translations)
Definition sculpt.cc:7664
void apply_translations(Span< float3 > translations, Span< int > verts, MutableSpan< float3 > positions)
Definition sculpt.cc:7592
constexpr ParallelGrainSize grain_size(int grain_size)
CCGKey BKE_subdiv_ccg_key_top_level(const SubdivCCG &subdiv_ccg)
const Brush * BKE_paint_brush_for_read(const Paint *paint)
void BKE_subdiv_ccg_eval_limit_positions(const SubdivCCG &subdiv_ccg, const CCGKey &key, int grid_index, MutableSpan< float3 > r_limit_positions)
ed::sculpt_paint::StrokeCache * cache
Definition BKE_paint.hh:409
Array< float3 > positions