73 threading::parallel_for(indices_to_set.index_range(), 8192, [&](const IndexRange range) {
74 for (const int i : range) {
75 bools[indices_to_set[i]] = true;
86 if (!
mesh.runtime->loose_edges_cache.is_cached() || !
mesh.loose_edges().is_empty()) {
89 if (!
mesh.runtime->loose_verts_cache.is_cached() || !
mesh.loose_verts().is_empty()) {
101Span<int> Mesh::corner_to_face_map()
const
103 this->runtime->corner_to_face_map_cache.ensure([&](Array<int> &r_data) {
104 const OffsetIndices faces = this->faces();
105 r_data = bke::mesh::build_corner_to_face_map(faces);
107 return this->runtime->corner_to_face_map_cache.
data();
110OffsetIndices<int> Mesh::vert_to_face_map_offsets()
const
112 this->runtime->vert_to_face_offset_cache.ensure([&](Array<int> &r_data) {
113 r_data = Array<int>(this->verts_num + 1, 0);
114 offset_indices::build_reverse_offsets(this->corner_verts(), r_data);
116 return OffsetIndices<int>(this->runtime->vert_to_face_offset_cache.data());
119GroupedSpan<int> Mesh::vert_to_face_map()
const
121 const OffsetIndices offsets = this->vert_to_face_map_offsets();
122 this->runtime->vert_to_face_map_cache.ensure([&](Array<int> &r_data) {
123 r_data.reinitialize(this->corners_num);
124 if (this->runtime->vert_to_corner_map_cache.is_cached() &&
125 this->runtime->corner_to_face_map_cache.is_cached())
129 array_utils::gather(this->runtime->corner_to_face_map_cache.data().as_span(),
130 this->runtime->vert_to_corner_map_cache.data().as_span(),
131 r_data.as_mutable_span());
134 bke::mesh::build_vert_to_face_indices(this->faces(), this->corner_verts(), offsets, r_data);
137 return {offsets, this->runtime->vert_to_face_map_cache.data()};
140GroupedSpan<int> Mesh::vert_to_corner_map()
const
142 const OffsetIndices offsets = this->vert_to_face_map_offsets();
143 this->runtime->vert_to_corner_map_cache.ensure([&](Array<int> &r_data) {
144 r_data = bke::mesh::build_vert_to_corner_indices(this->corner_verts(), offsets);
146 return {offsets, this->runtime->vert_to_corner_map_cache.data()};
149GroupedSpan<int> Mesh::edge_to_corner_map()
const
151 this->runtime->edge_to_corner_offset_cache.ensure([&](Array<int> &r_data) {
152 r_data = Array<int>(this->edges_num + 1, 0);
153 offset_indices::build_reverse_offsets(this->corner_edges(), r_data);
155 const OffsetIndices<int> offsets(this->runtime->edge_to_corner_offset_cache.data());
156 this->runtime->edge_to_corner_map_cache.ensure([&](Array<int> &r_data) {
157 r_data.reinitialize(offsets.total_size());
158 offset_indices::reverse_indices_in_groups(this->corner_edges(), offsets, r_data);
160 return {offsets, this->runtime->edge_to_corner_map_cache.data()};
163const IndexMask &Mesh::loose_verts()
const
165 using namespace blender::bke;
166 this->
runtime->loose_verts_cache.ensure([&](LooseGeomCache &r_data) {
167 Array<bool, 256> bools(this->
verts_num,
false);
170 new (&r_data.
allocator) LinearAllocator<>();
171 r_data.
mask = IndexMask::from_bools_inverse(bools, r_data.
allocator);
173 return this->
runtime->loose_verts_cache.data().mask;
176const IndexMask &Mesh::verts_no_face()
const
178 using namespace blender::bke;
179 this->
runtime->verts_no_face_cache.ensure([&](LooseGeomCache &r_data) {
180 Array<bool, 256> bools(this->
verts_num,
false);
183 new (&r_data.
allocator) LinearAllocator<>();
184 r_data.
mask = IndexMask::from_bools_inverse(bools, r_data.
allocator);
186 return this->
runtime->verts_no_face_cache.data().mask;
189bool Mesh::no_overlapping_topology()
const
194const IndexMask &Mesh::loose_edges()
const
196 using namespace blender::bke;
197 this->
runtime->loose_edges_cache.ensure([&](LooseGeomCache &r_data) {
198 Array<bool, 256> bools(this->
edges_num,
false);
201 new (&r_data.
allocator) LinearAllocator<>();
202 r_data.
mask = IndexMask::from_bools_inverse(bools, r_data.
allocator);
204 return this->
runtime->loose_edges_cache.data().mask;
207void Mesh::tag_loose_verts_none()
const
209 using namespace blender::bke;
210 this->
runtime->loose_verts_cache.ensure([&](LooseGeomCache &r_data) {
212 new (&r_data.
allocator) LinearAllocator<>();
218void Mesh::tag_loose_edges_none()
const
220 using namespace blender::bke;
221 this->
runtime->loose_edges_cache.ensure([&](LooseGeomCache &r_data) {
223 new (&r_data.
allocator) LinearAllocator<>();
229void Mesh::tag_overlapping_none()
231 using namespace blender::bke;
247 this->
data.tag_dirty();
258 this->
data.tag_dirty();
266 this->runtime->corner_tris_cache.
data.ensure([&](
Array<int3> &r_data) {
269 const Span<int> corner_verts = this->corner_verts();
278 positions, faces, corner_verts, this->face_normals(), r_data);
282 return this->
runtime->corner_tris_cache.data.data();
287 this->
runtime->corner_tri_faces_cache.ensure([&](Array<int> &r_data) {
288 const OffsetIndices faces = this->faces();
290 bke::mesh::corner_tris_calc_face_indices(faces, r_data);
292 return this->
runtime->corner_tri_faces_cache.
data();
303 if (!
mesh->runtime->edit_data) {
304 mesh->runtime->edit_data = std::make_unique<bke::EditMeshData>();
313 mesh->runtime->edit_data.reset();
321 mesh->runtime->subdiv_ccg.reset();
322 mesh->runtime->bounds_cache.tag_dirty();
323 mesh->runtime->vert_to_face_offset_cache.tag_dirty();
324 mesh->runtime->vert_to_face_map_cache.tag_dirty();
325 mesh->runtime->vert_to_corner_map_cache.tag_dirty();
326 mesh->runtime->corner_to_face_map_cache.tag_dirty();
327 mesh->runtime->edge_to_corner_offset_cache.tag_dirty();
328 mesh->runtime->edge_to_corner_map_cache.tag_dirty();
329 mesh->runtime->vert_normals_cache.tag_dirty();
330 mesh->runtime->vert_normals_true_cache.tag_dirty();
331 mesh->runtime->face_normals_cache.tag_dirty();
332 mesh->runtime->face_normals_true_cache.tag_dirty();
333 mesh->runtime->corner_normals_cache.tag_dirty();
334 mesh->runtime->loose_edges_cache.tag_dirty();
335 mesh->runtime->loose_verts_cache.tag_dirty();
336 mesh->runtime->verts_no_face_cache.tag_dirty();
337 mesh->runtime->corner_tris_cache.data.tag_dirty();
338 mesh->runtime->corner_tri_faces_cache.tag_dirty();
339 mesh->runtime->shrinkwrap_boundary_cache.tag_dirty();
340 mesh->runtime->max_material_index.tag_dirty();
341 mesh->runtime->subsurf_face_dot_tags.clear_and_shrink();
342 mesh->runtime->subsurf_optimal_display_edges.clear_and_shrink();
343 mesh->runtime->spatial_groups.reset();
347void Mesh::tag_edges_split()
351 this->runtime->vert_normals_cache.tag_dirty();
352 this->runtime->corner_normals_cache.tag_dirty();
353 this->runtime->subdiv_ccg.reset();
354 this->runtime->vert_to_face_offset_cache.tag_dirty();
355 this->runtime->vert_to_face_map_cache.tag_dirty();
356 this->runtime->vert_to_corner_map_cache.tag_dirty();
357 this->runtime->edge_to_corner_offset_cache.tag_dirty();
358 this->runtime->edge_to_corner_map_cache.tag_dirty();
359 if (this->runtime->loose_edges_cache.is_cached() &&
360 !this->runtime->loose_edges_cache.data().mask.is_empty())
362 this->runtime->loose_edges_cache.tag_dirty();
364 if (this->
runtime->loose_verts_cache.is_cached() &&
365 !this->runtime->loose_verts_cache.data().mask.is_empty())
367 this->
runtime->loose_verts_cache.tag_dirty();
369 if (this->
runtime->verts_no_face_cache.is_cached() &&
370 !this->runtime->verts_no_face_cache.data().mask.is_empty())
372 this->
runtime->verts_no_face_cache.tag_dirty();
374 this->
runtime->subsurf_face_dot_tags.clear_and_shrink();
375 this->
runtime->subsurf_optimal_display_edges.clear_and_shrink();
376 this->
runtime->shrinkwrap_boundary_cache.tag_dirty();
379void Mesh::tag_sharpness_changed()
381 this->
runtime->vert_normals_cache.tag_dirty();
382 this->
runtime->face_normals_cache.tag_dirty();
383 this->
runtime->corner_normals_cache.tag_dirty();
386void Mesh::tag_custom_normals_changed()
388 this->
runtime->vert_normals_cache.tag_dirty();
389 this->
runtime->face_normals_cache.tag_dirty();
390 this->
runtime->corner_normals_cache.tag_dirty();
393void Mesh::tag_face_winding_changed()
395 this->
runtime->vert_normals_cache.tag_dirty();
396 this->
runtime->face_normals_cache.tag_dirty();
397 this->
runtime->vert_normals_true_cache.tag_dirty();
398 this->
runtime->face_normals_true_cache.tag_dirty();
399 this->
runtime->corner_normals_cache.tag_dirty();
400 this->
runtime->vert_to_corner_map_cache.tag_dirty();
403 this->
runtime->edge_to_corner_map_cache.tag_dirty();
404 this->
runtime->shrinkwrap_boundary_cache.tag_dirty();
407void Mesh::tag_positions_changed()
409 this->
runtime->vert_normals_cache.tag_dirty();
410 this->
runtime->face_normals_cache.tag_dirty();
411 this->
runtime->vert_normals_true_cache.tag_dirty();
412 this->
runtime->face_normals_true_cache.tag_dirty();
413 this->
runtime->corner_normals_cache.tag_dirty();
414 this->
runtime->shrinkwrap_boundary_cache.tag_dirty();
415 this->tag_positions_changed_no_normals();
418void Mesh::tag_positions_changed_no_normals()
421 this->
runtime->corner_tris_cache.tag_dirty();
422 this->
runtime->bounds_cache.tag_dirty();
423 this->
runtime->shrinkwrap_boundary_cache.tag_dirty();
426void Mesh::tag_positions_changed_uniformly()
430 this->
runtime->bounds_cache.tag_dirty();
433void Mesh::tag_topology_changed()
438void Mesh::tag_visibility_changed()
440 this->
runtime->bvh_cache_corner_tris_no_hidden.tag_dirty();
441 this->
runtime->bvh_cache_loose_verts_no_hidden.tag_dirty();
442 this->
runtime->bvh_cache_loose_edges_no_hidden.tag_dirty();
445void Mesh::tag_material_index_changed()
447 this->
runtime->max_material_index.tag_dirty();
463 if (
mesh->runtime->batch_cache) {
469 Mesh *mesh_eval =
mesh->runtime->mesh_eval;
CustomData interface, see also DNA_customdata_types.h.
constexpr const T * data() const
void reinitialize(const int64_t new_size)
constexpr const T * data() const
constexpr int64_t size() const
ccl_device_inline int4 cast(const float4 a)
void corner_tris_calc(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, MutableSpan< int3 > corner_tris)
void corner_tris_calc_with_normals(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, Span< float3 > face_normals, MutableSpan< int3 > corner_tris)
static void try_tag_verts_no_face_none(const Mesh &mesh)
static void set_bools(MutableSpan< bool > bools, const Span< int > indices_to_set)
static void free_bvh_caches(MeshRuntime &mesh_runtime)
static void free_batch_cache(MeshRuntime &mesh_runtime)
static void free_mesh_eval(MeshRuntime &mesh_runtime)
constexpr int poly_to_tri_count(const int poly_count, const int corner_count)
void memory_bandwidth_bound_task(const int64_t approximate_bytes_touched, const Function &function)
void BKE_mesh_batch_cache_dirty_tag(Mesh *mesh, eMeshBatchDirtyMode mode)
void BKE_mesh_runtime_clear_cache(Mesh *mesh)
int BKE_mesh_runtime_corner_tris_len(const Mesh *mesh)
MINLINE int poly_to_tri_count(int poly_count, int corner_count)
@ ME_NO_OVERLAPPING_TOPOLOGY
@ ME_FLAG_UV_SELECT_SYNC_VALID
void BKE_id_free(Main *bmain, void *idv)
void(*) BKE_mesh_batch_cache_free_cb(draw::MeshBatchCache *batch_cache)
void BKE_mesh_batch_cache_free(draw::MeshBatchCache *batch_cache)
void BKE_mesh_runtime_ensure_edit_data(Mesh *mesh)
bool BKE_mesh_face_normals_are_dirty(const Mesh *mesh)
void BKE_mesh_runtime_clear_geometry(Mesh *mesh)
void(*) BKE_mesh_batch_cache_dirty_tag_cb(Mesh *mesh, eMeshBatchDirtyMode mode)
bke::MeshRuntime * runtime
LinearAllocator allocator
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_loose_verts
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_loose_edges_no_hidden
SharedCache< bke::bvh::Tree > bvh_embree_tris_cache
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_corner_tris
SharedCache< bke::bvh::Tree > bvh_embree_edges_cache
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_edges
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_loose_verts_no_hidden
SharedCache< bke::bvh::Tree > bvh_embree_verts_cache
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_loose_edges
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_faces
draw::MeshBatchCache * batch_cache
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_corner_tris_no_hidden
SharedCache< Array< int3 > > data