Blender V5.3
thumb.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_math_vector.hh"
25#include "BLI_task.hh"
26
30
31#include "bmesh.hh"
32
34
35inline namespace thumb_cc {
36
42
43static void calc_faces(const Depsgraph &depsgraph,
44 const Sculpt &sd,
45 const Brush &brush,
46 const float3 &offset,
47 const MeshAttributeData &attribute_data,
49 Object &object,
50 const PositionDeformData &position_data)
51{
52 SculptSession &ss = *object.runtime->sculpt_session;
53
54 const OrigPositionData orig_data = orig_position_data_get_mesh(object, node);
55 const Span<int> verts = node.verts();
56
60 brush,
61 object,
62 attribute_data,
63 orig_data.positions,
64 orig_data.normals,
65 node,
66 factors,
67 distances);
68
70 translations_from_offset_and_factors(offset, factors, translations);
71
72 clip_and_lock_translations(sd, ss, position_data.eval, verts, translations);
73 position_data.deform(translations, verts);
74}
75
76static void calc_grids(const Depsgraph &depsgraph,
77 const Sculpt &sd,
78 Object &object,
79 const Brush &brush,
80 const float3 &offset,
82 LocalData &tls)
83{
84 SculptSession &ss = *object.runtime->sculpt_session;
85 SubdivCCG &subdiv_ccg = *ss.subdiv_ccg;
86 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
87
88 const OrigPositionData orig_data = orig_position_data_get_grids(object, node);
89 const Span<int> grids = node.grids();
90 const int grid_verts_num = grids.size() * key.grid_area;
91
93 brush,
94 object,
95 orig_data.positions,
96 orig_data.normals,
97 node,
98 tls.factors,
99 tls.distances);
100
101 tls.translations.resize(grid_verts_num);
102 const MutableSpan<float3> translations = tls.translations;
103 translations_from_offset_and_factors(offset, tls.factors, translations);
104
105 clip_and_lock_translations(sd, ss, orig_data.positions, translations);
106 apply_translations(translations, grids, subdiv_ccg);
107}
108
109static void calc_bmesh(const Depsgraph &depsgraph,
110 const Sculpt &sd,
111 Object &object,
112 const Brush &brush,
113 const float3 &offset,
115 LocalData &tls)
116{
117 SculptSession &ss = *object.runtime->sculpt_session;
118
120
121 Array<float3> orig_positions(verts.size());
122 Array<float3> orig_normals(verts.size());
123 orig_position_data_gather_bmesh(*ss.bm_log, verts, orig_positions, orig_normals);
124
126 depsgraph, brush, object, orig_positions, orig_normals, node, tls.factors, tls.distances);
127
128 tls.translations.resize(verts.size());
129 const MutableSpan<float3> translations = tls.translations;
130 translations_from_offset_and_factors(offset, tls.factors, translations);
131
132 clip_and_lock_translations(sd, ss, orig_positions, translations);
133 apply_translations(translations, verts);
134}
135
136} // namespace thumb_cc
137
138void do_thumb_brush(const Depsgraph &depsgraph,
139 const Sculpt &sd,
140 Object &object,
141 const IndexMask &node_mask)
142{
144 const SculptSession &ss = *object.runtime->sculpt_session;
147
148 const float3 &grab_delta = ss.cache->grab_delta_symm;
149 const float3 &normal = ss.cache->sculpt_normal_symm;
150 const float3 offset = math::cross(math::cross(normal, grab_delta), normal) * ss.cache->bstrength;
151
153 switch (pbvh.type()) {
155 const Mesh &mesh = *id_cast<Mesh *>(object.data);
156 const MeshAttributeData attribute_data(mesh);
157 const PositionDeformData position_data(depsgraph, object);
159 node_mask.foreach_index(
160 [&](const int i) {
162 depsgraph, sd, brush, offset, attribute_data, nodes[i], object, position_data);
163 bke::pbvh::update_node_bounds_mesh(position_data.eval, nodes[i]);
164 },
166 break;
167 }
169 SubdivCCG &subdiv_ccg = *object.runtime->sculpt_session->subdiv_ccg;
170 MutableSpan<float3> positions = subdiv_ccg.positions;
172 node_mask.foreach_index(
173 [&](const int i) {
174 LocalData &tls = all_tls.local();
175 calc_grids(depsgraph, sd, object, brush, offset, nodes[i], tls);
176 bke::pbvh::update_node_bounds_grids(subdiv_ccg.grid_area, positions, nodes[i]);
177 },
179 break;
180 }
183 node_mask.foreach_index(
184 [&](const int i) {
185 LocalData &tls = all_tls.local();
186 calc_bmesh(depsgraph, sd, object, brush, offset, nodes[i], tls);
188 },
190 break;
191 }
192 }
193 pbvh.tag_positions_changed(node_mask);
194 pbvh.flush_bounds_to_parents();
195}
196
197} // 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_thumb_brush(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const IndexMask &node_mask)
Definition thumb.cc:138
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 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)
AxisSigned cross(const AxisSigned a, const AxisSigned b)
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