Blender V5.3
draw_sharp.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_mesh.hh"
17#include "BKE_object_types.hh"
18#include "BKE_paint.hh"
19#include "BKE_paint_bvh.hh"
20#include "BKE_subdiv_ccg.hh"
21
22#include "BLI_array.hh"
24#include "BLI_task.hh"
25
29
30#include "bmesh.hh"
31
33
34inline namespace draw_sharp_cc {
35
41
42static void calc_faces(const Depsgraph &depsgraph,
43 const Sculpt &sd,
44 const Brush &brush,
45 const float3 &offset,
46 const MeshAttributeData &attribute_data,
48 Object &object,
49 const PositionDeformData &position_data)
50{
51 SculptSession &ss = *object.runtime->sculpt_session;
52
53 const OrigPositionData orig_data = orig_position_data_get_mesh(object, node);
54 const Span<int> verts = node.verts();
55
59 brush,
60 object,
61 attribute_data,
62 orig_data.positions,
63 orig_data.normals,
64 node,
65 factors,
66 distances);
67
69 translations_from_offset_and_factors(offset, factors, translations);
70
71 clip_and_lock_translations(sd, ss, position_data.eval, verts, translations);
72 position_data.deform(translations, verts);
73}
74
75static void calc_grids(const Depsgraph &depsgraph,
76 const Sculpt &sd,
77 Object &object,
78 const Brush &brush,
79 const float3 &offset,
81 LocalData &tls)
82{
83 SculptSession &ss = *object.runtime->sculpt_session;
84 SubdivCCG &subdiv_ccg = *ss.subdiv_ccg;
85 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
86
87 const OrigPositionData orig_data = orig_position_data_get_grids(object, node);
88 const Span<int> grids = node.grids();
89 const int grid_verts_num = grids.size() * key.grid_area;
90
92 brush,
93 object,
94 orig_data.positions,
95 orig_data.normals,
96 node,
97 tls.factors,
98 tls.distances);
99
100 tls.translations.resize(grid_verts_num);
101 const MutableSpan<float3> translations = tls.translations;
102 translations_from_offset_and_factors(offset, tls.factors, translations);
103
104 clip_and_lock_translations(sd, ss, orig_data.positions, translations);
105 apply_translations(translations, grids, subdiv_ccg);
106}
107
108static void calc_bmesh(const Depsgraph &depsgraph,
109 const Sculpt &sd,
110 Object &object,
111 const Brush &brush,
112 const float3 &offset,
114 LocalData &tls)
115{
116 SculptSession &ss = *object.runtime->sculpt_session;
117
119
120 Array<float3> orig_positions(verts.size());
121 Array<float3> orig_normals(verts.size());
122 orig_position_data_gather_bmesh(*ss.bm_log, verts, orig_positions, orig_normals);
123
125 depsgraph, brush, object, orig_positions, orig_normals, node, tls.factors, tls.distances);
126
127 tls.translations.resize(verts.size());
128 const MutableSpan<float3> translations = tls.translations;
129 translations_from_offset_and_factors(offset, tls.factors, translations);
130
131 clip_and_lock_translations(sd, ss, orig_positions, translations);
132 apply_translations(translations, verts);
133}
134
135} // namespace draw_sharp_cc
136
137static void offset_positions(const Depsgraph &depsgraph,
138 const Sculpt &sd,
139 Object &object,
140 const float3 &offset,
141 const IndexMask &node_mask)
142{
145
147 switch (pbvh.type()) {
149 const Mesh &mesh = *id_cast<Mesh *>(object.data);
150 const MeshAttributeData attribute_data(mesh);
151 const PositionDeformData position_data(depsgraph, object);
153 node_mask.foreach_index(
154 [&](const int i) {
156 depsgraph, sd, brush, offset, attribute_data, nodes[i], object, position_data);
157 bke::pbvh::update_node_bounds_mesh(position_data.eval, nodes[i]);
158 },
160 break;
161 }
163 SubdivCCG &subdiv_ccg = *object.runtime->sculpt_session->subdiv_ccg;
164 MutableSpan<float3> positions = subdiv_ccg.positions;
166 node_mask.foreach_index(
167 [&](const int i) {
168 LocalData &tls = all_tls.local();
169 calc_grids(depsgraph, sd, object, brush, offset, nodes[i], tls);
170 bke::pbvh::update_node_bounds_grids(subdiv_ccg.grid_area, positions, nodes[i]);
171 },
173 break;
174 }
177 node_mask.foreach_index(
178 [&](const int i) {
179 LocalData &tls = all_tls.local();
180 calc_bmesh(depsgraph, sd, object, brush, offset, nodes[i], tls);
182 },
184 break;
185 }
186 }
187 pbvh.tag_positions_changed(node_mask);
188 pbvh.flush_bounds_to_parents();
189}
190
191void do_draw_sharp_brush(const Depsgraph &depsgraph,
192 const Sculpt &sd,
193 Object &object,
194 const IndexMask &node_mask)
195{
197 const SculptSession &ss = *object.runtime->sculpt_session;
199
200 const float3 effective_normal = tilt_effective_normal_get(ss, brush);
201
202 const float3 offset = effective_normal * ss.cache->radius * ss.cache->scale *
203 ss.cache->bstrength;
204
205 offset_positions(depsgraph, sd, object, offset, node_mask);
206}
207
208} // 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)
int64_t size() const
Definition BLI_set.hh:606
constexpr int64_t size() const
Definition BLI_span.hh:256
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
pbvh::Tree * pbvh_get(Object &object)
void update_node_bounds_bmesh(BMeshNode &node)
Definition pbvh.cc:1216
void update_node_bounds_mesh(Span< float3 > positions, MeshNode &node)
Definition pbvh.cc:1196
void update_node_bounds_grids(int grid_area, Span< float3 > positions, GridsNode &node)
Definition pbvh.cc:1205
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 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_draw_sharp_brush(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const IndexMask &node_mask)
static void offset_positions(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const float3 &offset, const IndexMask &node_mask)
Definition draw.cc:125
void calc_factors_common_from_orig_data_grids(const Depsgraph &depsgraph, const Brush &brush, const Object &object, Span< float3 > positions, Span< float3 > normals, const bke::pbvh::GridsNode &node, Vector< float > &r_factors, Vector< float > &r_distances)
Definition sculpt.cc:7008
float3 tilt_effective_normal_get(const SculptSession &ss, const Brush &brush)
Definition sculpt.cc:2904
void calc_factors_common_from_orig_data_mesh(const Depsgraph &depsgraph, const Brush &brush, const Object &object, const MeshAttributeData &attribute_data, Span< float3 > positions, Span< float3 > normals, const bke::pbvh::MeshNode &node, MutableSpan< float > r_factors, MutableSpan< float > r_distances)
Definition sculpt.cc:6976
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)
Definition sculpt.cc:7664
void apply_translations(Span< float3 > translations, Span< int > verts, MutableSpan< float3 > positions)
Definition sculpt.cc:7592
OrigPositionData orig_position_data_get_mesh(const Object &object, const bke::pbvh::MeshNode &node)
OrigPositionData orig_position_data_get_grids(const Object &object, const bke::pbvh::GridsNode &node)
void translations_from_offset_and_factors(const float3 &offset, Span< float > factors, MutableSpan< float3 > r_translations)
Definition sculpt.cc:7877
void calc_factors_common_from_orig_data_bmesh(const Depsgraph &depsgraph, const Brush &brush, const Object &object, Span< float3 > positions, Span< float3 > normals, bke::pbvh::BMeshNode &node, Vector< float > &r_factors, Vector< float > &r_distances)
Definition sculpt.cc:7043
constexpr ParallelGrainSize grain_size(int grain_size)
CCGKey BKE_subdiv_ccg_key_top_level(const SubdivCCG &subdiv_ccg)
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
Definition BKE_paint.hh:409
Array< float3 > positions