Blender V5.3
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
8
9#pragma once
10
11#include "BLI_array.hh"
12#include "BLI_array_utils.hh"
13#include "BLI_bit_span.hh"
16#include "BLI_offset_indices.hh"
17#include "BLI_set.hh"
18#include "BLI_span.hh"
19#include "BLI_vector.hh"
20#include "BLI_virtual_array.hh"
21
22#include "BKE_subdiv_ccg.hh"
23
24#include "DNA_brush_enums.h"
25
26#include "PRF_profile.hh"
27
28#include "sculpt_intern.hh"
29
30namespace blender {
31
46
47struct BMesh;
48struct BMVert;
49struct BMFace;
50struct Brush;
51struct Mesh;
52struct Object;
53struct Sculpt;
54struct SculptSession;
55struct SubdivCCG;
56struct SubdivCCGCoord;
57namespace bke {
59}
60namespace bke::pbvh {
61class Node;
62class Tree;
63} // namespace bke::pbvh
64
65namespace ed::sculpt_paint {
66struct StrokeCache;
67
68namespace auto_mask {
69struct Cache;
70};
71
72void filter_translations(MutableSpan<float3> translations, Span<float> factors);
73void scale_translations(MutableSpan<float3> translations, Span<float> factors);
74void scale_translations(MutableSpan<float3> translations, float factor);
75void scale_factors(MutableSpan<float> factors, float strength);
76void scale_factors(MutableSpan<float> factors, Span<float> strengths);
78 Span<float> factors,
79 MutableSpan<float3> r_translations);
80
86 Span<int> verts,
87 Span<float3> old_positions,
88 MutableSpan<float3> translations);
90 Span<float3> old_positions,
91 MutableSpan<float3> translations);
92
94template<typename T> void gather_data_mesh(Span<T> src, Span<int> indices, MutableSpan<T> dst)
95{
97 /* #exec_mode::serial because this is called from tasks with TLS that don't use isolation. */
98 array_utils::gather(src, indices, dst, exec_mode::serial);
99}
100template<typename T>
102{
103 dst.resize(indices.size());
104 gather_data_mesh(src, indices, dst.as_mutable_span());
105 return dst;
106}
107template<typename T>
108void gather_data_grids(const SubdivCCG &subdiv_ccg,
109 Span<T> src,
110 Span<int> grids,
111 MutableSpan<T> node_data);
112template<typename T>
114 const Span<T> src,
115 const Span<int> grids,
116 Vector<T> &dst)
117{
118 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
119 dst.resize(grids.size() * key.grid_area);
120 gather_data_grids(subdiv_ccg, src, grids, dst.as_mutable_span());
121 return dst;
122}
123
124template<typename T>
125void gather_data_bmesh(Span<T> src, const Set<BMVert *, 0> &verts, MutableSpan<T> node_data);
126template<typename T>
128{
129 dst.resize(verts.size());
130 gather_data_bmesh(src, verts, dst.as_mutable_span());
131 return dst;
132}
133
135template<typename T> void scatter_data_mesh(Span<T> src, Span<int> indices, MutableSpan<T> dst)
136{
138 /* #exec_mode::serial because this is called from tasks with TLS that don't use isolation. */
139 array_utils::scatter(src, indices, dst, exec_mode::serial);
140}
141template<typename T>
142void scatter_data_grids(const SubdivCCG &subdiv_ccg,
143 Span<T> node_data,
144 Span<int> grids,
145 MutableSpan<T> dst);
146template<typename T>
147void scatter_data_bmesh(Span<T> node_data, const Set<BMVert *, 0> &verts, MutableSpan<T> dst);
148
151 const Span<int> grids,
152 Vector<float3> &positions)
153{
155 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
156 positions.resize(key.grid_area * grids.size());
157 gather_data_grids(subdiv_ccg, subdiv_ccg.positions.as_span(), grids, positions);
158 return positions;
159}
162 Vector<float3> &positions)
163{
164 positions.resize(verts.size());
165 gather_bmesh_positions(verts, positions.as_mutable_span());
166 return positions;
167}
168
170void gather_grids_normals(const SubdivCCG &subdiv_ccg,
171 Span<int> grids,
172 MutableSpan<float3> normals);
174
179 /* Point Domain */
182
183 /* Face Domain */
186
187 explicit MeshAttributeData(const Mesh &mesh);
188};
189
190void calc_factors_common_mesh(const Depsgraph &depsgraph,
191 const Brush &brush,
192 const Object &object,
193 const MeshAttributeData &attribute_data,
194 Span<float3> positions,
195 Span<float3> vert_normals,
197 MutableSpan<float> factors,
198 MutableSpan<float> distances);
199void calc_factors_common_mesh_indexed(const Depsgraph &depsgraph,
200 const Brush &brush,
201 const Object &object,
202 const MeshAttributeData &attribute_data,
203 Span<float3> vert_positions,
204 Span<float3> vert_normals,
206 MutableSpan<float> factors,
207 MutableSpan<float> distances);
208void calc_factors_common_grids(const Depsgraph &depsgraph,
209 const Brush &brush,
210 const Object &object,
211 Span<float3> positions,
213 Vector<float> &r_factors,
214 Vector<float> &r_distances);
215void calc_factors_common_bmesh(const Depsgraph &depsgraph,
216 const Brush &brush,
217 const Object &object,
218 Span<float3> positions,
220 Vector<float> &r_factors,
221 Vector<float> &r_distances);
222void calc_cube_tip_factors_common_grids(const Depsgraph &depsgraph,
223 const Brush &brush,
224 const Object &object,
225 const float4x4 &mat,
226 Span<float3> positions,
228 Vector<float> &r_factors,
229 Vector<float> &r_distances);
230void calc_cube_tip_factors_common_bmesh(const Depsgraph &depsgraph,
231 const Brush &brush,
232 const Object &object,
233 const float4x4 &mat,
234 Span<float3> positions,
236 Vector<float> &r_factors,
237 Vector<float> &r_distances);
238void calc_factors_common_from_orig_data_mesh(const Depsgraph &depsgraph,
239 const Brush &brush,
240 const Object &object,
241 const MeshAttributeData &attribute_data,
242 Span<float3> positions,
243 Span<float3> normals,
245 MutableSpan<float> r_factors,
246 MutableSpan<float> r_distances);
247void calc_factors_common_from_orig_data_grids(const Depsgraph &depsgraph,
248 const Brush &brush,
249 const Object &object,
250 Span<float3> positions,
251 Span<float3> normals,
253 Vector<float> &r_factors,
254 Vector<float> &r_distances);
255void calc_factors_common_from_orig_data_bmesh(const Depsgraph &depsgraph,
256 const Brush &brush,
257 const Object &object,
258 Span<float3> positions,
259 Span<float3> normals,
261 Vector<float> &r_factors,
262 Vector<float> &r_distances);
263
267void fill_factor_from_hide(Span<bool> hide_vert, Span<int> verts, MutableSpan<float> r_factors);
268void fill_factor_from_hide(const SubdivCCG &subdiv_ccg,
269 Span<int> grids,
270 MutableSpan<float> r_factors);
271void fill_factor_from_hide(const Set<BMVert *, 0> &verts, MutableSpan<float> r_factors);
272
278 Span<int> verts,
279 MutableSpan<float> r_factors);
280void fill_factor_from_hide_and_mask(const SubdivCCG &subdiv_ccg,
281 Span<int> grids,
282 MutableSpan<float> r_factors);
284 const Set<BMVert *, 0> &verts,
285 MutableSpan<float> r_factors);
286
290void calc_front_face(const float3 &view_normal, Span<float3> normals, MutableSpan<float> factors);
291void calc_front_face(const float3 &view_normal,
292 Span<float3> vert_normals,
293 Span<int> verts,
294 MutableSpan<float> factors);
295void calc_front_face(const float3 &view_normal,
296 const SubdivCCG &subdiv_ccg,
297 Span<int> grids,
298 MutableSpan<float> factors);
299void calc_front_face(const float3 &view_normal,
300 const Set<BMVert *, 0> &verts,
301 MutableSpan<float> factors);
302void calc_front_face(const float3 &view_normal,
303 const Set<BMFace *, 0> &faces,
304 MutableSpan<float> factors);
305
312 Span<float3> vert_positions,
313 Span<int> verts,
314 MutableSpan<float> factors);
316 Span<float3> positions,
317 MutableSpan<float> factors);
318
324 Span<float3> vert_positions,
325 Span<int> vert,
326 eBrushFalloffShape falloff_shape,
327 MutableSpan<float> r_distances);
329 Span<float3> positions,
330 eBrushFalloffShape falloff_shape,
331 MutableSpan<float> r_distances);
333 Span<float3> positions,
334 Span<int> verts,
335 eBrushFalloffShape falloff_shape,
336 MutableSpan<float> r_distances);
338 Span<float3> positions,
339 eBrushFalloffShape falloff_shape,
340 MutableSpan<float> r_distances);
341
343void filter_distances_with_radius(float radius, Span<float> distances, MutableSpan<float> factors);
344
349template<typename T>
351 const Span<T> positions,
352 const MutableSpan<float> r_distances);
353
358void apply_hardness_to_distances(float radius, float hardness, MutableSpan<float> distances);
360 const MutableSpan<float> distances)
361{
362 apply_hardness_to_distances(cache.radius, cache.hardness, distances);
363}
364
369 const Brush &brush,
370 Span<float> distances,
371 MutableSpan<float> factors);
372
377 const SculptSession &ss,
378 const Brush &brush,
379 Span<float3> vert_positions,
380 Span<int> vert,
381 MutableSpan<float> factors);
383 const SculptSession &ss,
384 const Brush &brush,
385 Span<float3> positions,
386 MutableSpan<float> factors);
387
394void apply_translations(Span<float3> translations, Span<int> verts, MutableSpan<float3> positions);
395void apply_translations(Span<float3> translations, Span<int> grids, SubdivCCG &subdiv_ccg);
396void apply_translations(Span<float3> translations, const Set<BMVert *, 0> &verts);
397
399void project_translations(MutableSpan<float3> translations, const float3 &plane);
400
409 Span<float3> positions,
410 Span<float3> orig_positions);
411
420 Span<int> verts,
421 MutableSpan<float3> translations);
422
427 const SculptSession &ss,
428 Span<float3> positions,
429 Span<int> verts,
430 MutableSpan<float3> translations);
432 const SculptSession &ss,
433 Span<float3> positions,
434 MutableSpan<float3> translations);
435
441 const IndexMask &node_mask,
442 Array<int> &node_data);
445 const IndexMask &node_mask,
446 Array<int> &node_data);
448 const IndexMask &node_mask,
449 Array<int> &node_data);
450
458 Span<int> corner_verts,
459 GroupedSpan<int> vert_to_face,
460 Span<bool> hide_poly,
461 Span<int> verts,
462 Vector<int> &r_offset_data,
463 Vector<int> &r_data);
465 Span<int> grids,
466 Vector<int> &r_offset_data,
467 Vector<int> &r_data);
469 Vector<int> &r_offset_data,
470 Vector<BMVert *> &r_data);
471
479 Span<int> corner_verts,
480 GroupedSpan<int> vert_to_face,
481 BitSpan boundary_verts,
482 const Set<OrderedEdge> &boundary_edges,
483 Span<bool> hide_poly,
484 Span<int> verts,
485 Vector<int> &r_offset_data,
486 Vector<int> &r_data);
488 Span<int> corner_verts,
489 GroupedSpan<int> vert_to_face,
490 BitSpan boundary_verts,
491 const Set<OrderedEdge> &boundary_edges,
492 Span<bool> hide_poly,
493 Span<int> verts,
494 Span<float> factors,
495 Vector<int> &r_offset_data,
496 Vector<int> &r_data);
498 Span<int> corner_verts,
499 BitSpan boundary_verts,
500 const Set<OrderedEdge> &boundary_edges,
501 const SubdivCCG &subdiv_ccg,
502 Span<int> grids,
506
508void calc_translations_to_plane(Span<float3> vert_positions,
509 Span<int> verts,
510 const float4 &plane,
511 MutableSpan<float3> translations);
513 const float4 &plane,
514 MutableSpan<float3> translations);
515
518 const float3 &pivot,
520 MutableSpan<float> factors);
521
524 const StrokeCache &cache,
525 Span<float3> translations,
526 MutableSpan<float> factors);
527
529void filter_below_plane_factors(Span<float3> vert_positions,
530 Span<int> verts,
531 const float4 &plane,
532 MutableSpan<float> factors);
534 const float4 &plane,
535 MutableSpan<float> factors);
536
537/* Ignore points above the plane. */
538void filter_above_plane_factors(Span<float3> vert_positions,
539 Span<int> verts,
540 const float4 &plane,
541 MutableSpan<float> factors);
543 const float4 &plane,
544 MutableSpan<float> factors);
545
550void calc_local_positions(Span<float3> vert_positions,
551 Span<int> verts,
552 const float4x4 &mat,
553 const float3 &plane_center,
554 const float3 &view_normal,
555 eBrushFalloffShape falloff_shape,
556 MutableSpan<float3> local_positions);
557
559 const float4x4 &mat,
560 const float3 &plane_center,
561 const float3 &view_normal,
562 eBrushFalloffShape falloff_shape,
563 MutableSpan<float3> local_positions);
564
571void calc_local_positions(Span<float3> vert_positions,
572 Span<int> verts,
573 const float4x4 &mat,
574 const float3 &plane_center,
575 const float3 &view_normal,
576 eBrushFalloffShape falloff_shape,
577 MutableSpan<float2> xy_positions,
578 MutableSpan<float> z_positions);
580 const float4x4 &mat,
581 const float3 &plane_center,
582 const float3 &view_normal,
583 eBrushFalloffShape falloff_shape,
584 MutableSpan<float2> xy_positions,
585 MutableSpan<float> z_positions);
586
587} // namespace ed::sculpt_paint
588
589} // namespace blender
#define PRF_scope(category)
Span< T > as_span() const
Definition BLI_array.hh:254
int64_t size() const
Definition BLI_set.hh:606
constexpr int64_t size() const
Definition BLI_span.hh:256
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void scatter(const Span< T > src, const Span< IndexT > indices, MutableSpan< T > dst, const Mode mode={})
void fill_factor_from_hide_and_mask(Span< bool > hide_vert, Span< float > mask, Span< int > verts, MutableSpan< float > r_factors)
Definition sculpt.cc:7128
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:6577
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
void gather_bmesh_positions(const Set< BMVert *, 0 > &verts, MutableSpan< float3 > positions)
Definition sculpt.cc:6497
void calc_brush_strength_factors(const StrokeCache &cache, const Brush &brush, Span< float > distances, MutableSpan< float > factors)
Definition sculpt.cc:7501
void gather_data_grids(const SubdivCCG &subdiv_ccg, Span< T > src, Span< int > grids, MutableSpan< T > node_data)
Definition sculpt.cc:6528
void filter_below_plane_factors(Span< float3 > vert_positions, Span< int > verts, const float4 &plane, MutableSpan< float > factors)
Definition sculpt.cc:8248
void apply_hardness_to_distances(float radius, float hardness, MutableSpan< float > distances)
Definition sculpt.cc:7473
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
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:7949
void gather_bmesh_normals(const Set< BMVert *, 0 > &verts, MutableSpan< float3 > normals)
Definition sculpt.cc:6517
void filter_translations(MutableSpan< float3 > translations, Span< float > factors)
Definition sculpt.cc:7827
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 filter_distances_with_radius(float radius, Span< float > distances, MutableSpan< float > factors)
Definition sculpt.cc:7422
void filter_region_clip_factors(const SculptSession &ss, Span< float3 > vert_positions, Span< int > verts, MutableSpan< float > factors)
Definition sculpt.cc:7285
void gather_data_bmesh(Span< T > src, const Set< BMVert *, 0 > &verts, MutableSpan< T > node_data)
Definition sculpt.cc:6545
void reset_translations_to_original(MutableSpan< float3 > translations, Span< float3 > positions, Span< float3 > orig_positions)
Definition sculpt.cc:7572
void scale_translations(MutableSpan< float3 > translations, Span< float > factors)
Definition sculpt.cc:7837
GroupedSpan< int > calc_vert_neighbors_interior(OffsetIndices< int > faces, Span< int > corner_verts, GroupedSpan< int > vert_to_face, BitSpan boundary_verts, const Set< OrderedEdge > &boundary_edges, Span< bool > hide_poly, Span< int > verts, Vector< int > &r_offset_data, Vector< int > &r_data)
Definition sculpt.cc:8099
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, MutableSpan< float > factors, MutableSpan< float > distances)
Definition sculpt.cc:6739
void calc_cube_tip_factors_common_bmesh(const Depsgraph &depsgraph, const Brush &brush, const Object &object, const float4x4 &mat, Span< float3 > positions, bke::pbvh::BMeshNode &node, Vector< float > &r_factors, Vector< float > &r_distances)
Definition sculpt.cc:6924
void filter_verts_outside_symmetry_area(Span< float3 > positions, const float3 &pivot, ePaintSymmetryFlags symm, MutableSpan< float > factors)
Definition sculpt.cc:8216
void calc_translations_to_plane(Span< float3 > vert_positions, Span< int > verts, const float4 &plane, MutableSpan< float3 > translations)
Definition sculpt.cc:8189
void scale_factors(MutableSpan< float > factors, float strength)
Definition sculpt.cc:7856
void translations_from_new_positions(Span< float3 > new_positions, Span< int > verts, Span< float3 > old_positions, MutableSpan< float3 > translations)
Definition sculpt.cc:7889
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 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, MutableSpan< float > factors, MutableSpan< float > distances)
Definition sculpt.cc:6772
void scatter_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
void calc_brush_distances(const SculptSession &ss, Span< float3 > vert_positions, Span< int > vert, eBrushFalloffShape falloff_shape, MutableSpan< float > r_distances)
Definition sculpt.cc:7370
void project_translations(MutableSpan< float3 > translations, const float3 &plane)
Definition sculpt.cc:7638
void filter_plane_trim_limit_factors(const Brush &brush, const StrokeCache &cache, Span< float3 > translations, MutableSpan< float > factors)
Definition sculpt.cc:8231
OffsetIndices< int > create_node_vert_offsets(Span< bke::pbvh::MeshNode > nodes, const IndexMask &node_mask, Array< int > &node_data)
Definition sculpt.cc:7912
void apply_translations(Span< float3 > translations, Span< int > verts, MutableSpan< float3 > positions)
Definition sculpt.cc:7592
void gather_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
void calc_cube_tip_factors_common_grids(const Depsgraph &depsgraph, const Brush &brush, const Object &object, const float4x4 &mat, Span< float3 > positions, const bke::pbvh::GridsNode &node, Vector< float > &r_factors, Vector< float > &r_distances)
Definition sculpt.cc:6838
void filter_above_plane_factors(Span< float3 > vert_positions, Span< int > verts, const float4 &plane, MutableSpan< float > factors)
Definition sculpt.cc:8273
void apply_crazyspace_to_translations(Span< float3x3 > deform_imats, Span< int > verts, MutableSpan< float3 > translations)
Definition sculpt.cc:7652
void calc_front_face(const float3 &view_normal, Span< float3 > normals, MutableSpan< float > factors)
Definition sculpt.cc:7223
void calc_brush_distances_squared(const SculptSession &ss, Span< float3 > positions, Span< int > verts, eBrushFalloffShape falloff_shape, MutableSpan< float > r_distances)
Definition sculpt.cc:7342
void gather_grids_normals(const SubdivCCG &subdiv_ccg, Span< int > grids, MutableSpan< float3 > normals)
Definition sculpt.cc:6509
void translations_from_offset_and_factors(const float3 &offset, Span< float > factors, MutableSpan< float3 > r_translations)
Definition sculpt.cc:7877
void calc_brush_cube_distances(const Brush &brush, const Span< T > positions, const MutableSpan< float > r_distances)
Definition sculpt.cc:7435
void calc_local_positions(Span< float3 > vert_positions, Span< int > verts, const float4x4 &mat, const float3 &plane_center, const float3 &view_normal, eBrushFalloffShape falloff_shape, MutableSpan< float3 > local_positions)
Definition sculpt.cc:6619
void calc_brush_texture_factors(PaintMode paint_mode, const SculptSession &ss, const Brush &brush, Span< float3 > vert_positions, Span< int > vert, MutableSpan< float > factors)
Definition sculpt.cc:7513
void fill_factor_from_hide(Span< bool > hide_vert, Span< int > verts, MutableSpan< float > r_factors)
Definition sculpt.cc:7077
void scatter_data_grids(const SubdivCCG &subdiv_ccg, Span< T > node_data, Span< int > grids, MutableSpan< T > dst)
Definition sculpt.cc:6560
OffsetIndices< int > create_node_vert_offsets_bmesh(Span< bke::pbvh::BMeshNode > nodes, const IndexMask &node_mask, Array< int > &node_data)
Definition sculpt.cc:7936
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:6891
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 Serial serial
BMesh Iterators.
MatBase< float, 4, 4 > float4x4
CCGKey BKE_subdiv_ccg_key_top_level(const SubdivCCG &subdiv_ccg)
VecBase< float, 4 > float4
VecBase< float, 3 > float3
Array< float3 > positions