Blender V5.0
mesh_brush_common.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "BLI_array.hh"
8#include "BLI_bit_span.hh"
11#include "BLI_offset_indices.hh"
12#include "BLI_set.hh"
13#include "BLI_span.hh"
14#include "BLI_vector.hh"
15#include "BLI_virtual_array.hh"
16
17#include "BKE_subdiv_ccg.hh"
18
19#include "DNA_brush_enums.h"
20
21#include "sculpt_intern.hh"
22
37
38struct BMesh;
39struct BMVert;
40struct BMFace;
41struct Brush;
42struct Mesh;
43struct Object;
44struct Sculpt;
45struct SculptSession;
46struct SubdivCCG;
47struct SubdivCCGCoord;
48namespace blender {
49namespace bke {
51}
52namespace bke::pbvh {
53class Node;
54class Tree;
55} // namespace bke::pbvh
56} // namespace blender
57
59struct StrokeCache;
60
61namespace auto_mask {
62struct Cache;
63};
64
65void scale_translations(MutableSpan<float3> translations, Span<float> factors);
66void scale_translations(MutableSpan<float3> translations, float factor);
67void scale_factors(MutableSpan<float> factors, float strength);
68void scale_factors(MutableSpan<float> factors, Span<float> strengths);
70 Span<float> factors,
71 MutableSpan<float3> r_translations);
72
79 Span<float3> old_positions,
80 MutableSpan<float3> translations);
82 Span<float3> old_positions,
83 MutableSpan<float3> translations);
84
86template<typename T> void gather_data_mesh(Span<T> src, Span<int> indices, MutableSpan<T> dst);
87template<typename T>
89{
90 dst.resize(indices.size());
92 return dst;
93}
94template<typename T>
95void gather_data_grids(const SubdivCCG &subdiv_ccg,
96 Span<T> src,
97 Span<int> grids,
98 MutableSpan<T> node_data);
99template<typename T>
101 const Span<T> src,
102 const Span<int> grids,
103 Vector<T> &dst)
104{
105 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
106 dst.resize(grids.size() * key.grid_area);
107 gather_data_grids(subdiv_ccg, src, grids, dst.as_mutable_span());
108 return dst;
109}
110
111template<typename T>
113template<typename T>
115{
116 dst.resize(verts.size());
118 return dst;
119}
120
122template<typename T> void scatter_data_mesh(Span<T> src, Span<int> indices, MutableSpan<T> dst);
123template<typename T>
124void scatter_data_grids(const SubdivCCG &subdiv_ccg,
125 Span<T> node_data,
126 Span<int> grids,
127 MutableSpan<T> dst);
128template<typename T>
130
133 const Span<int> grids,
134 Vector<float3> &positions)
135{
136 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
137 positions.resize(key.grid_area * grids.size());
138 gather_data_grids(subdiv_ccg, subdiv_ccg.positions.as_span(), grids, positions);
139 return positions;
140}
143 Vector<float3> &positions)
144{
145 positions.resize(verts.size());
147 return positions;
148}
149
151void gather_grids_normals(const SubdivCCG &subdiv_ccg,
152 Span<int> grids,
155
160 /* Point Domain */
163
164 /* Face Domain */
167
168 explicit MeshAttributeData(const Mesh &mesh);
169};
170
171void calc_factors_common_mesh(const Depsgraph &depsgraph,
172 const Brush &brush,
173 const Object &object,
174 const MeshAttributeData &attribute_data,
175 Span<float3> positions,
176 Span<float3> vert_normals,
177 const bke::pbvh::MeshNode &node,
178 Vector<float> &r_factors,
179 Vector<float> &r_distances);
180void calc_factors_common_mesh_indexed(const Depsgraph &depsgraph,
181 const Brush &brush,
182 const Object &object,
183 const MeshAttributeData &attribute_data,
184 Span<float3> vert_positions,
185 Span<float3> vert_normals,
186 const bke::pbvh::MeshNode &node,
187 Vector<float> &r_factors,
188 Vector<float> &r_distances);
189void calc_factors_common_mesh_indexed(const Depsgraph &depsgraph,
190 const Brush &brush,
191 const Object &object,
192 const MeshAttributeData &attribute_data,
193 Span<float3> vert_positions,
194 Span<float3> vert_normals,
195 const bke::pbvh::MeshNode &node,
196 MutableSpan<float> factors,
197 MutableSpan<float> distances);
198void calc_factors_common_grids(const Depsgraph &depsgraph,
199 const Brush &brush,
200 const Object &object,
201 Span<float3> positions,
202 const bke::pbvh::GridsNode &node,
203 Vector<float> &r_factors,
204 Vector<float> &r_distances);
205void calc_factors_common_bmesh(const Depsgraph &depsgraph,
206 const Brush &brush,
207 const Object &object,
208 Span<float3> positions,
210 Vector<float> &r_factors,
211 Vector<float> &r_distances);
213 const Brush &brush,
214 const Object &object,
215 const MeshAttributeData &attribute_data,
216 Span<float3> positions,
218 const bke::pbvh::MeshNode &node,
219 Vector<float> &r_factors,
220 Vector<float> &r_distances);
222 const Brush &brush,
223 const Object &object,
224 Span<float3> positions,
226 const bke::pbvh::GridsNode &node,
227 Vector<float> &r_factors,
228 Vector<float> &r_distances);
230 const Brush &brush,
231 const Object &object,
232 Span<float3> positions,
235 Vector<float> &r_factors,
236 Vector<float> &r_distances);
237
242void fill_factor_from_hide(const SubdivCCG &subdiv_ccg,
243 Span<int> grids,
244 MutableSpan<float> r_factors);
246
253 MutableSpan<float> r_factors);
254void fill_factor_from_hide_and_mask(const SubdivCCG &subdiv_ccg,
255 Span<int> grids,
256 MutableSpan<float> r_factors);
258 const Set<BMVert *, 0> &verts,
259 MutableSpan<float> r_factors);
260
264void calc_front_face(const float3 &view_normal, Span<float3> normals, MutableSpan<float> factors);
265void calc_front_face(const float3 &view_normal,
266 Span<float3> vert_normals,
268 MutableSpan<float> factors);
269void calc_front_face(const float3 &view_normal,
270 const SubdivCCG &subdiv_ccg,
271 Span<int> grids,
272 MutableSpan<float> factors);
273void calc_front_face(const float3 &view_normal,
274 const Set<BMVert *, 0> &verts,
275 MutableSpan<float> factors);
276void calc_front_face(const float3 &view_normal,
277 const Set<BMFace *, 0> &faces,
278 MutableSpan<float> factors);
279
286 Span<float3> vert_positions,
288 MutableSpan<float> factors);
290 Span<float3> positions,
291 MutableSpan<float> factors);
292
298 Span<float3> vert_positions,
299 Span<int> vert,
300 eBrushFalloffShape falloff_shape,
301 MutableSpan<float> r_distances);
303 Span<float3> positions,
304 eBrushFalloffShape falloff_shape,
305 MutableSpan<float> r_distances);
307 Span<float3> positions,
309 eBrushFalloffShape falloff_shape,
310 MutableSpan<float> r_distances);
312 Span<float3> positions,
313 eBrushFalloffShape falloff_shape,
314 MutableSpan<float> r_distances);
315
317void filter_distances_with_radius(float radius, Span<float> distances, MutableSpan<float> factors);
318
323template<typename T>
324void calc_brush_cube_distances(const Brush &brush,
325 const Span<T> positions,
326 const MutableSpan<float> r_distances);
327
332void apply_hardness_to_distances(float radius, float hardness, MutableSpan<float> distances);
334 const MutableSpan<float> distances)
335{
336 apply_hardness_to_distances(cache.radius, cache.hardness, distances);
337}
338
342void calc_brush_strength_factors(const StrokeCache &cache,
343 const Brush &brush,
344 Span<float> distances,
345 MutableSpan<float> factors);
346
351 const Brush &brush,
352 Span<float3> vert_positions,
353 Span<int> vert,
354 MutableSpan<float> factors);
356 const Brush &brush,
357 Span<float3> positions,
358 MutableSpan<float> factors);
359
367void apply_translations(Span<float3> translations, Span<int> grids, SubdivCCG &subdiv_ccg);
368void apply_translations(Span<float3> translations, const Set<BMVert *, 0> &verts);
369
371void project_translations(MutableSpan<float3> translations, const float3 &plane);
372
381 Span<float3> positions,
382 Span<float3> orig_positions);
383
393 MutableSpan<float3> translations);
394
399 const SculptSession &ss,
400 Span<float3> positions,
402 MutableSpan<float3> translations);
404 const SculptSession &ss,
405 Span<float3> positions,
406 MutableSpan<float3> translations);
407
413 const IndexMask &node_mask,
414 Array<int> &node_data);
417 const IndexMask &node_mask,
418 Array<int> &node_data);
420 const IndexMask &node_mask,
421 Array<int> &node_data);
422
430 Span<int> corner_verts,
431 GroupedSpan<int> vert_to_face,
432 Span<bool> hide_poly,
434 Vector<int> &r_offset_data,
435 Vector<int> &r_data);
437 Span<int> grids,
438 Vector<int> &r_offset_data,
439 Vector<int> &r_data);
441 Vector<int> &r_offset_data,
442 Vector<BMVert *> &r_data);
443
451 Span<int> corner_verts,
452 GroupedSpan<int> vert_to_face,
453 BitSpan boundary_verts,
454 Span<bool> hide_poly,
456 Vector<int> &r_offset_data,
457 Vector<int> &r_data);
459 Span<int> corner_verts,
460 GroupedSpan<int> vert_to_face,
461 BitSpan boundary_verts,
462 Span<bool> hide_poly,
464 Span<float> factors,
465 Vector<int> &r_offset_data,
466 Vector<int> &r_data);
468 Span<int> corner_verts,
469 BitSpan boundary_verts,
470 const SubdivCCG &subdiv_ccg,
471 Span<int> grids,
475
477void calc_translations_to_plane(Span<float3> vert_positions,
479 const float4 &plane,
480 MutableSpan<float3> translations);
482 const float4 &plane,
483 MutableSpan<float3> translations);
484
487 const float3 &pivot,
489 MutableSpan<float> factors);
490
492void filter_plane_trim_limit_factors(const Brush &brush,
493 const StrokeCache &cache,
494 Span<float3> translations,
495 MutableSpan<float> factors);
496
498void filter_below_plane_factors(Span<float3> vert_positions,
500 const float4 &plane,
501 MutableSpan<float> factors);
503 const float4 &plane,
504 MutableSpan<float> factors);
505
506/* Ignore points above the plane. */
507void filter_above_plane_factors(Span<float3> vert_positions,
509 const float4 &plane,
510 MutableSpan<float> factors);
512 const float4 &plane,
513 MutableSpan<float> factors);
514
515} // namespace blender::ed::sculpt_paint
CCGKey BKE_subdiv_ccg_key_top_level(const SubdivCCG &subdiv_ccg)
eBrushFalloffShape
ePaintSymmetryFlags
BMesh * bm
BPy_StructRNA * depsgraph
constexpr int64_t size() const
Definition BLI_span.hh:252
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
static ushort indices[]
static float verts[][3]
static float normals[][3]
static char faces[256]
void fill_factor_from_hide_and_mask(Span< bool > hide_vert, Span< float > mask, Span< int > verts, MutableSpan< float > r_factors)
Definition sculpt.cc:6823
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)
Definition sculpt.cc:6461
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:6706
void gather_bmesh_positions(const Set< BMVert *, 0 > &verts, MutableSpan< float3 > positions)
Definition sculpt.cc:6367
void calc_brush_strength_factors(const StrokeCache &cache, const Brush &brush, Span< float > distances, MutableSpan< float > factors)
Definition sculpt.cc:7183
void gather_data_grids(const SubdivCCG &subdiv_ccg, Span< T > src, Span< int > grids, MutableSpan< T > node_data)
Definition sculpt.cc:6405
void filter_below_plane_factors(Span< float3 > vert_positions, Span< int > verts, const float4 &plane, MutableSpan< float > factors)
Definition sculpt.cc:7879
void apply_hardness_to_distances(float radius, float hardness, MutableSpan< float > distances)
Definition sculpt.cc:7156
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
GroupedSpan< int > calc_vert_neighbors(OffsetIndices< int > faces, Span< int > corner_verts, GroupedSpan< int > vert_to_face, Span< bool > hide_poly, Span< int > verts, Vector< int > &r_offset_data, Vector< int > &r_data)
Definition sculpt.cc:7597
void gather_bmesh_normals(const Set< BMVert *, 0 > &verts, MutableSpan< float3 > normals)
Definition sculpt.cc:6385
void calc_factors_common_mesh_indexed(const Depsgraph &depsgraph, const Brush &brush, const Object &object, const MeshAttributeData &attribute_data, Span< float3 > vert_positions, Span< float3 > vert_normals, const bke::pbvh::MeshNode &node, Vector< float > &r_factors, Vector< float > &r_distances)
Definition sculpt.cc:6512
void filter_distances_with_radius(float radius, Span< float > distances, MutableSpan< float > factors)
Definition sculpt.cc:7105
void filter_region_clip_factors(const SculptSession &ss, Span< float3 > vert_positions, Span< int > verts, MutableSpan< float > factors)
Definition sculpt.cc:6972
void gather_data_bmesh(Span< T > src, const Set< BMVert *, 0 > &verts, MutableSpan< T > node_data)
Definition sculpt.cc:6421
void reset_translations_to_original(MutableSpan< float3 > translations, Span< float3 > positions, Span< float3 > orig_positions)
Definition sculpt.cc:7249
void scale_translations(MutableSpan< float3 > translations, Span< float > factors)
Definition sculpt.cc:7495
void filter_verts_outside_symmetry_area(Span< float3 > positions, const float3 &pivot, ePaintSymmetryFlags symm, MutableSpan< float > factors)
Definition sculpt.cc:7849
void calc_translations_to_plane(Span< float3 > vert_positions, Span< int > verts, const float4 &plane, MutableSpan< float3 > translations)
Definition sculpt.cc:7824
void scale_factors(MutableSpan< float > factors, float strength)
Definition sculpt.cc:7512
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, Vector< float > &r_factors, Vector< float > &r_distances)
Definition sculpt.cc:6670
void translations_from_new_positions(Span< float3 > new_positions, Span< int > verts, Span< float3 > old_positions, MutableSpan< float3 > translations)
Definition sculpt.cc:7542
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 scatter_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
Definition sculpt.cc:6435
void calc_brush_distances(const SculptSession &ss, Span< float3 > vert_positions, Span< int > vert, eBrushFalloffShape falloff_shape, MutableSpan< float > r_distances)
Definition sculpt.cc:7055
void project_translations(MutableSpan< float3 > translations, const float3 &plane)
Definition sculpt.cc:7311
void filter_plane_trim_limit_factors(const Brush &brush, const StrokeCache &cache, Span< float3 > translations, MutableSpan< float > factors)
Definition sculpt.cc:7863
OffsetIndices< int > create_node_vert_offsets(Span< bke::pbvh::MeshNode > nodes, const IndexMask &node_mask, Array< int > &node_data)
Definition sculpt.cc:7563
void apply_translations(Span< float3 > translations, Span< int > verts, MutableSpan< float3 > positions)
Definition sculpt.cc:7268
void calc_factors_common_mesh(const Depsgraph &depsgraph, const Brush &brush, const Object &object, const MeshAttributeData &attribute_data, Span< float3 > positions, Span< float3 > vert_normals, const bke::pbvh::MeshNode &node, Vector< float > &r_factors, Vector< float > &r_distances)
Definition sculpt.cc:6568
void gather_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
Definition sculpt.cc:6395
void calc_brush_texture_factors(const SculptSession &ss, const Brush &brush, Span< float3 > vert_positions, Span< int > vert, MutableSpan< float > factors)
Definition sculpt.cc:7195
void filter_above_plane_factors(Span< float3 > vert_positions, Span< int > verts, const float4 &plane, MutableSpan< float > factors)
Definition sculpt.cc:7902
void apply_crazyspace_to_translations(Span< float3x3 > deform_imats, Span< int > verts, MutableSpan< float3 > translations)
Definition sculpt.cc:7324
void calc_front_face(const float3 &view_normal, Span< float3 > normals, MutableSpan< float > factors)
Definition sculpt.cc:6914
void calc_brush_distances_squared(const SculptSession &ss, Span< float3 > positions, Span< int > verts, eBrushFalloffShape falloff_shape, MutableSpan< float > r_distances)
Definition sculpt.cc:7027
void gather_grids_normals(const SubdivCCG &subdiv_ccg, Span< int > grids, MutableSpan< float3 > normals)
Definition sculpt.cc:6378
void translations_from_offset_and_factors(const float3 &offset, Span< float > factors, MutableSpan< float3 > r_translations)
Definition sculpt.cc:7531
void calc_brush_cube_distances(const Brush &brush, const Span< T > positions, const MutableSpan< float > r_distances)
Definition sculpt.cc:7117
void fill_factor_from_hide(Span< bool > hide_vert, Span< int > verts, MutableSpan< float > r_factors)
Definition sculpt.cc:6775
void scatter_data_grids(const SubdivCCG &subdiv_ccg, Span< T > node_data, Span< int > grids, MutableSpan< T > dst)
Definition sculpt.cc:6445
OffsetIndices< int > create_node_vert_offsets_bmesh(Span< bke::pbvh::BMeshNode > nodes, const IndexMask &node_mask, Array< int > &node_data)
Definition sculpt.cc:7585
void calc_factors_common_bmesh(const Depsgraph &depsgraph, const Brush &brush, const Object &object, Span< float3 > positions, bke::pbvh::BMeshNode &node, Vector< float > &r_factors, Vector< float > &r_distances)
Definition sculpt.cc:6637
GroupedSpan< int > calc_vert_neighbors_interior(OffsetIndices< int > faces, Span< int > corner_verts, GroupedSpan< int > vert_to_face, BitSpan boundary_verts, Span< bool > hide_poly, Span< int > verts, Vector< int > &r_offset_data, Vector< int > &r_data)
Definition sculpt.cc:7739
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:6741
VecBase< float, 4 > float4
VecBase< float, 3 > float3
int grid_area
Definition BKE_ccg.hh:35
blender::Array< blender::float3 > positions