Blender V5.0
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_paint_bvh.hh"
14#include "BKE_subdiv_ccg.hh"
15
17#include "BLI_task.hh"
18
22
24
26
33
34static BLI_NOINLINE void calc_limit_positions(const SubdivCCG &subdiv_ccg,
35 const Span<int> grids,
36 const MutableSpan<float3> limit_positions)
37{
38 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
39 for (const int i : grids.index_range()) {
40 const int start = i * key.grid_area;
42 subdiv_ccg, key, grids[i], limit_positions.slice(start, key.grid_area));
43 }
44}
45
46static void calc_node(const Depsgraph &depsgraph,
47 const Sculpt &sd,
48 Object &object,
49 const Brush &brush,
50 const float strength,
52 LocalData &tls)
53{
54 SculptSession &ss = *object.sculpt;
55 SubdivCCG &subdiv_ccg = *ss.subdiv_ccg;
56
57 const Span<int> grids = node.grids();
58 const MutableSpan positions = gather_grids_positions(subdiv_ccg, grids, tls.positions);
59
60 calc_factors_common_grids(depsgraph, brush, object, positions, node, tls.factors, tls.distances);
61
62 scale_factors(tls.factors, strength);
63
64 tls.translations.resize(positions.size());
65 const MutableSpan<float3> translations = tls.translations;
66 calc_limit_positions(subdiv_ccg, grids, translations);
67 for (const int i : positions.index_range()) {
68 translations[i] -= positions[i];
69 }
70 scale_translations(translations, tls.factors);
71
72 clip_and_lock_translations(sd, ss, positions, translations);
73 apply_translations(translations, grids, subdiv_ccg);
74}
75
76} // namespace multires_displacement_eraser_cc
77
79 const Sculpt &sd,
80 Object &object,
81 const IndexMask &node_mask)
82{
83 SculptSession &ss = *object.sculpt;
84 SubdivCCG &subdiv_ccg = *object.sculpt->subdiv_ccg;
85 MutableSpan<float3> positions = subdiv_ccg.positions;
86 const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
87 const float strength = std::min(ss.cache->bstrength, 1.0f);
88
92 node_mask.foreach_index(GrainSize(1), [&](const int i) {
93 LocalData &tls = all_tls.local();
94 calc_node(depsgraph, sd, object, brush, strength, nodes[i], tls);
96 });
97 pbvh.tag_positions_changed(node_mask);
99}
100
101} // namespace blender::ed::sculpt_paint::brushes
const Brush * BKE_paint_brush_for_read(const Paint *paint)
Definition paint.cc:650
A BVH for high poly meshes.
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.
BPy_StructRNA * depsgraph
constexpr int64_t size() const
Definition BLI_span.hh:493
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:573
constexpr IndexRange index_range() const
Definition BLI_span.hh:670
constexpr IndexRange index_range() const
Definition BLI_span.hh:401
void tag_positions_changed(const IndexMask &node_mask)
Definition pbvh.cc:635
Span< NodeT > nodes() const
void flush_bounds_to_parents()
Definition pbvh.cc:1306
void foreach_index(Fn &&fn) const
pbvh::Tree * pbvh_get(Object &object)
Definition paint.cc:3052
void update_node_bounds_grids(int grid_area, Span< float3 > positions, GridsNode &node)
Definition pbvh.cc:1283
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:6603
void scale_translations(MutableSpan< float3 > translations, Span< float > factors)
Definition sculpt.cc:7495
void scale_factors(MutableSpan< float > factors, float strength)
Definition sculpt.cc:7512
void clip_and_lock_translations(const Sculpt &sd, const SculptSession &ss, Span< float3 > positions, Span< int > verts, MutableSpan< float3 > translations)
Definition sculpt.cc:7335
void apply_translations(Span< float3 > translations, Span< int > verts, MutableSpan< float3 > positions)
Definition sculpt.cc:7268
int grid_area
Definition BKE_ccg.hh:35
blender::ed::sculpt_paint::StrokeCache * cache
Definition BKE_paint.hh:417
SubdivCCG * subdiv_ccg
Definition BKE_paint.hh:395
blender::Array< blender::float3 > positions
i
Definition text_draw.cc:230