Blender V5.3
extract_mesh.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
15#include "BLI_task.hh"
16#include "BLI_virtual_array.hh"
17
18#include "DNA_scene_types.h"
19
20#include "BKE_mesh.hh"
21#include "BKE_object.hh"
22
23#include "bmesh.hh"
24
25#include "GPU_vertex_buffer.hh"
26
27#include "draw_cache_extract.hh"
28
29struct DRWSubdivCache;
30
31namespace blender {
32
33struct BMVert;
34struct BMEdge;
35struct BMEditMesh;
36struct BMFace;
37struct BMLoop;
38
39namespace draw {
40
41/* ---------------------------------------------------------------------- */
44
45enum class MeshExtractType {
48};
49
52
57
61
64
69
75
76 /* For deformed edit-mesh data. */
77 /* Use for #ME_WRAPPER_TYPE_BMESH. */
85
86 const int *orig_index_vert;
87 const int *orig_index_edge;
88 const int *orig_index_face;
95 const Mesh *mesh;
101
107
111
119
122
123 const char *active_color_name;
125};
126
127inline const Mesh &editmesh_final_or_this(const Object &object, const Mesh &mesh)
128{
129 if (mesh.runtime->edit_mesh != nullptr) {
130 if (const Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(&object)) {
131 return *editmesh_eval_final;
132 }
133 }
134
135 return mesh;
136}
137
139{
140 return ((mr.orig_index_face != nullptr) && (mr.orig_index_face[idx] != ORIGINDEX_NONE) &&
141 mr.bm) ?
142 BM_face_at_index(mr.bm, mr.orig_index_face[idx]) :
143 nullptr;
144}
145
147{
148 return ((mr.orig_index_edge != nullptr) && (mr.orig_index_edge[idx] != ORIGINDEX_NONE) &&
149 mr.bm) ?
150 BM_edge_at_index(mr.bm, mr.orig_index_edge[idx]) :
151 nullptr;
152}
153
155{
156 return ((mr.orig_index_vert != nullptr) && (mr.orig_index_vert[idx] != ORIGINDEX_NONE) &&
157 mr.bm) ?
158 BM_vert_at_index(mr.bm, mr.orig_index_vert[idx]) :
159 nullptr;
160}
161
162BLI_INLINE const float *bm_vert_co_get(const MeshRenderData &mr, const BMVert *eve)
163{
164 if (!mr.bm_vert_coords.is_empty()) {
165 return mr.bm_vert_coords[BM_elem_index_get(eve)];
166 }
167 return eve->co;
168}
169
170BLI_INLINE const float *bm_vert_no_get(const MeshRenderData &mr, const BMVert *eve)
171{
172 if (mr.bm_free_normal_offset_vert != -1) {
174 }
175 if (!mr.bm_vert_normals.is_empty()) {
176 return mr.bm_vert_normals[BM_elem_index_get(eve)];
177 }
178 return eve->no;
179}
180
181BLI_INLINE const float *bm_face_no_get(const MeshRenderData &mr, const BMFace *efa)
182{
183 if (mr.bm_free_normal_offset_face != -1) {
185 }
186 if (!mr.bm_face_normals.is_empty()) {
187 return mr.bm_face_normals[BM_elem_index_get(efa)];
188 }
189 return efa->no;
190}
191
193
194/* `draw_cache_extract_mesh_render_data.cc` */
195
201 Mesh &mesh,
202 bool is_editmode,
203 bool is_paint_mode,
204 bool do_final,
205 bool do_uvedit,
206 bool use_hide,
207 const ToolSettings *ts);
212 MeshBufferCache &cache);
213
214/* draw_cache_extract_mesh_extractors.c */
215
219 /* This is used for both vertex and edge creases. The edge crease value is stored in the bottom 4
220 * bits, while the vertex crease is stored in the upper 4 bits. */
223};
224
226 const BMFace *efa,
227 const BMUVOffsets &offsets,
228 EditLoopData &eattr);
230 const BMLoop *l,
231 const BMUVOffsets &offsets,
232 EditLoopData &eattr);
234 const BMLoop *l,
235 const BMUVOffsets &offsets,
236 EditLoopData &eattr);
237
238/* In the GPU vertex buffers, the value for each vertex is duplicated to each of its vertex
239 * corners. So the edges on the GPU connect face corners rather than vertices. */
240inline uint2 edge_from_corners(const IndexRange face, const int corner)
241{
242 const int corner_next = bke::mesh::face_corner_next(face, corner);
243 return uint2(corner, corner_next);
244}
245
246template<typename T>
248 const Span<int2> edges,
249 const IndexMask &loose_edges,
250 MutableSpan<T> gpu_data)
251{
252 loose_edges.foreach_index_optimized<int>(
253 [&](const int i, const int pos) {
254 const int2 edge = edges[i];
255 gpu_data[pos * 2 + 0] = vert_data[edge[0]];
256 gpu_data[pos * 2 + 1] = vert_data[edge[1]];
257 },
259}
260
261/* ---------------------------------------------------------------------- */
274
276 MeshBufferCache &cache,
277 gpu::VertBuf &src,
278 gpu::VertBuf &dst);
280 MeshBufferCache &cache,
281 gpu::VertBuf &src,
282 gpu::VertBuf &dst);
284 MeshBufferCache &cache,
285 gpu::VertBuf &src,
286 gpu::VertBuf &dst);
287
289template<typename T>
290void loose_data_upload(const MeshRenderData &mr, const Span<T> loose_data, gpu::VertBuf &dst)
291{
292 if (loose_data.is_empty()) {
293 return;
294 }
295 BLI_assert(GPU_vertbuf_get_format(&dst)->stride == sizeof(T));
296 GPU_vertbuf_use(&dst);
298 &dst, mr.corners_num * sizeof(T), loose_data.size_in_bytes(), loose_data.data());
299}
300
302
305 const MeshRenderData &mr,
306 gpu::VertBufPtr *orco_vbo);
307
309void extract_face_dots_subdiv(const DRWSubdivCache &subdiv_cache,
310 gpu::VertBufPtr &fdots_pos,
311 gpu::VertBufPtr *fdots_nor,
312 gpu::IndexBufPtr &fdots);
313
314gpu::VertBufPtr extract_normals(const MeshRenderData &mr, MeshBufferCache &cache, bool use_hq);
316 const DRWSubdivCache &subdiv_cache,
317 gpu::VertBuf &pos);
322 const MeshRenderData &mr,
323 gpu::VertBuf &pos);
324
325gpu::IndexBufPtr extract_tris(const MeshRenderData &mr, const SortedFaceData &face_sorted);
326void create_material_subranges(const SortedFaceData &face_sorted,
327 gpu::IndexBuf &tris_ibo,
330
331void extract_lines(const MeshRenderData &mr,
332 gpu::IndexBufPtr *lines,
333 gpu::IndexBufPtr *lines_loose,
334 bool &no_loose_wire);
335void extract_lines_subdiv(const DRWSubdivCache &subdiv_cache,
336 const MeshRenderData &mr,
337 gpu::IndexBufPtr *lines,
338 gpu::IndexBufPtr *lines_loose,
339 bool &no_loose_wire);
340
343 const DRWSubdivCache &subdiv_cache);
344
347 const DRWSubdivCache &subdiv_cache);
348
350 const MeshBatchCache &cache,
351 bool use_hq);
353 const DRWSubdivCache &subdiv_cache,
354 const MeshBatchCache &cache);
355
360
362 const MeshRenderData &mr);
364 const MeshRenderData &mr);
366 const MeshRenderData &mr);
367
369 const MeshBatchCache &batch_cache,
370 MeshBufferCache &cache);
372 const DRWSubdivCache &subdiv_cache,
373 const MeshBatchCache &batch_cache,
374 MeshBufferCache &cache);
375
377
380
383 const DRWSubdivCache &subdiv_cache);
384
385gpu::IndexBufPtr extract_lines_adjacency(const MeshRenderData &mr, bool &r_is_manifold);
387 bool &r_is_manifold);
388
391 const MeshBatchCache &cache);
393 float &tot_area,
394 float &tot_uv_area);
396 const DRWSubdivCache &subdiv_cache,
397 float &tot_area,
398 float &tot_uv_area);
401 const DRWSubdivCache &subdiv_cache,
402 const MeshBatchCache &cache);
405 const DRWSubdivCache &subdiv_cache);
406gpu::IndexBufPtr extract_edituv_tris(const MeshRenderData &mr, bool edit_uvs);
408 const DRWSubdivCache &subdiv_cache);
409
415
418 const DRWSubdivCache &subdiv_cache,
419 UvExtractionMode mode);
422 const DRWSubdivCache &subdiv_cache);
424
425gpu::VertBufPtr extract_mesh_analysis(const MeshRenderData &mr, const float4x4 &object_to_world);
426
428
431 const DRWSubdivCache &subdiv_cache);
432
434
436 MeshBufferCache &cache,
437 StringRef name);
439 MeshBufferCache &cache,
440 const DRWSubdivCache &subdiv_cache,
441 StringRef name);
443
446 const DRWSubdivCache &subdiv_cache);
447
448} // namespace draw
449} // namespace blender
#define ORIGINDEX_NONE
General operations, lookup, etc. for blender objects.
#define BLI_INLINE
#define BM_ELEM_CD_GET_FLOAT_P(ele, offset)
#define BM_elem_index_get(ele)
constexpr int64_t size_in_bytes() const
Definition BLI_span.hh:272
constexpr const T * data() const
Definition BLI_span.hh:219
constexpr bool is_empty() const
Definition BLI_span.hh:264
void foreach_index_optimized(Fn &&fn, Mode mode=exec_mode::serial) const
#define T
int face_corner_next(const IndexRange face, const int corner)
Definition BKE_mesh.hh:315
void extract_mesh_loose_edge_data(const Span< T > vert_data, const Span< int2 > edges, const IndexMask &loose_edges, MutableSpan< T > gpu_data)
BLI_INLINE BMFace * bm_original_face_get(const MeshRenderData &mr, int idx)
void mesh_render_data_update_face_normals(MeshRenderData &mr)
BLI_INLINE BMVert * bm_original_vert_get(const MeshRenderData &mr, int idx)
gpu::IndexBufPtr extract_lines_adjacency_subdiv(const DRWSubdivCache &subdiv_cache, bool &r_is_manifold)
gpu::VertBufPtr extract_edit_data_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache)
gpu::VertBufPtr extract_skin_roots(const MeshRenderData &mr)
gpu::IndexBufPtr extract_edituv_lines_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache, UvExtractionMode mode)
gpu::IndexBufPtr extract_lines_adjacency(const MeshRenderData &mr, bool &r_is_manifold)
gpu::IndexBufPtr extract_points_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache)
gpu::IndexBufPtr extract_edituv_face_dots(const MeshRenderData &mr)
BLI_INLINE BMEdge * bm_original_edge_get(const MeshRenderData &mr, int idx)
gpu::VertBufPtr extract_edit_data(const MeshRenderData &mr)
void scatter_face_to_corner_gpu(const MeshRenderData &mr, MeshBufferCache &cache, gpu::VertBuf &src, gpu::VertBuf &dst)
gpu::VertBufPtr extract_tangents_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache, const MeshBatchCache &cache)
gpu::VertBufPtr extract_edituv_stretch_angle_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache, const MeshBatchCache &cache)
gpu::VertBufPtr extract_edge_index(const MeshRenderData &mr)
gpu::VertBufPtr extract_attribute_subdiv(const MeshRenderData &mr, MeshBufferCache &cache, const DRWSubdivCache &subdiv_cache, StringRef name)
gpu::VertBufPtr extract_vert_index_subdiv(const DRWSubdivCache &subdiv_cache, const MeshRenderData &mr)
gpu::VertBufPtr extract_weights_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache, const MeshBatchCache &batch_cache, MeshBufferCache &cache)
gpu::VertBufPtr extract_tangents(const MeshRenderData &mr, const MeshBatchCache &cache, bool use_hq)
gpu::VertBufPtr extract_normals(const MeshRenderData &mr, MeshBufferCache &cache, bool use_hq)
gpu::VertBufPtr extract_face_dot_index(const MeshRenderData &mr)
gpu::IndexBufPtr extract_edituv_tris(const MeshRenderData &mr, bool edit_uvs)
void mesh_render_data_loop_flag(const MeshRenderData &mr, const BMLoop *l, const BMUVOffsets &offsets, EditLoopData &eattr)
gpu::VertBufPtr extract_sculpt_data_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache)
gpu::IndexBufPtr extract_edituv_points(const MeshRenderData &mr)
gpu::IndexBufPtr extract_edituv_tris_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache)
void extract_lines(const MeshRenderData &mr, gpu::IndexBufPtr *lines, gpu::IndexBufPtr *lines_loose, bool &no_loose_wire)
uint2 edge_from_corners(const IndexRange face, const int corner)
void mesh_render_data_face_flag(const MeshRenderData &mr, const BMFace *efa, const BMUVOffsets &offsets, EditLoopData &eattr)
gpu::VertBufPtr extract_orco(const MeshRenderData &mr, MeshBufferCache &cache)
gpu::VertBufPtr extract_positions_subdiv(const DRWSubdivCache &subdiv_cache, const MeshRenderData &mr, gpu::VertBufPtr *orco_vbo)
gpu::IndexBufPtr extract_edituv_points_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache)
gpu::VertBufPtr extract_positions(const MeshRenderData &mr, MeshBufferCache &cache)
gpu::VertBufPtr extract_face_index_subdiv(const DRWSubdivCache &subdiv_cache, const MeshRenderData &mr)
void gather_edge_to_corner_gpu(const MeshRenderData &mr, MeshBufferCache &cache, gpu::VertBuf &src, gpu::VertBuf &dst)
gpu::IndexBufPtr extract_lines_paint_mask(const MeshRenderData &mr)
gpu::VertBufPtr extract_uv_maps(const MeshRenderData &mr, const MeshBatchCache &cache)
void mesh_render_data_loop_edge_flag(const MeshRenderData &mr, const BMLoop *l, const BMUVOffsets &offsets, EditLoopData &eattr)
gpu::VertBufPtr extract_edge_index_subdiv(const DRWSubdivCache &subdiv_cache, const MeshRenderData &mr)
gpu::VertBufPtr extract_paint_overlay_flags_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache)
gpu::VertBufPtr extract_edituv_data(const MeshRenderData &mr)
gpu::VertBufPtr extract_weights(const MeshRenderData &mr, const MeshBatchCache &batch_cache, MeshBufferCache &cache)
const Mesh & editmesh_final_or_this(const Object &object, const Mesh &mesh)
gpu::VertBufPtr extract_paint_overlay_flags(const MeshRenderData &mr)
gpu::IndexBufPtr extract_tris_subdiv(const DRWSubdivCache &subdiv_cache, MeshBatchCache &cache)
gpu::IndexBufPtr extract_face_dots(const MeshRenderData &mr)
BLI_INLINE const float * bm_face_no_get(const MeshRenderData &mr, const BMFace *efa)
gpu::VertBufPtr extract_face_dot_normals(const MeshRenderData &mr, bool use_hq)
void gather_vert_to_corner_gpu(const MeshRenderData &mr, MeshBufferCache &cache, gpu::VertBuf &src, gpu::VertBuf &dst)
void mesh_render_data_update_corner_normals(MeshRenderData &mr)
void extract_face_dots_subdiv(const DRWSubdivCache &subdiv_cache, gpu::VertBufPtr &fdots_pos, gpu::VertBufPtr *fdots_nor, gpu::IndexBufPtr &fdots)
gpu::VertBufPtr extract_edituv_stretch_area(const MeshRenderData &mr, float &tot_area, float &tot_uv_area)
gpu::VertBufPtr extract_edge_factor_subdiv(const DRWSubdivCache &subdiv_cache, const MeshRenderData &mr, gpu::VertBuf &pos)
const SortedFaceData & mesh_render_data_faces_sorted_ensure(const MeshRenderData &mr, MeshBufferCache &cache)
gpu::VertBufPtr extract_normals_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache, gpu::VertBuf &pos)
gpu::VertBufPtr extract_attr_viewer(const MeshRenderData &mr, MeshBufferCache &cache)
gpu::IndexBufPtr extract_tris(const MeshRenderData &mr, const SortedFaceData &face_sorted)
gpu::IndexBufPtr extract_edituv_lines(const MeshRenderData &mr, UvExtractionMode mode)
gpu::VertBufPtr extract_face_dots_position(const MeshRenderData &mr)
BLI_INLINE const float * bm_vert_no_get(const MeshRenderData &mr, const BMVert *eve)
gpu::VertBufPtr extract_edituv_stretch_area_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache, float &tot_area, float &tot_uv_area)
gpu::VertBufPtr extract_edge_factor(const MeshRenderData &mr)
MeshRenderData mesh_render_data_create(Object &object, Mesh &mesh, const bool is_editmode, const bool is_paint_mode, const bool do_final, const bool do_uvedit, const bool use_hide, const ToolSettings *ts)
void mesh_render_data_update_loose_geom(MeshRenderData &mr, MeshBufferCache &cache)
gpu::VertBufPtr extract_vert_index(const MeshRenderData &mr)
gpu::IndexBufPtr extract_lines_paint_mask_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache)
gpu::VertBufPtr extract_edituv_stretch_angle(const MeshRenderData &mr)
gpu::VertBufPtr extract_vert_normals(const MeshRenderData &mr, MeshBufferCache &cache)
void loose_data_upload(const MeshRenderData &mr, const Span< T > loose_data, gpu::VertBuf &dst)
gpu::VertBufPtr extract_uv_maps_subdiv(const DRWSubdivCache &subdiv_cache, const MeshBatchCache &cache)
gpu::IndexBufPtr extract_points(const MeshRenderData &mr)
gpu::VertBufPtr extract_face_index(const MeshRenderData &mr)
BLI_INLINE const float * bm_vert_co_get(const MeshRenderData &mr, const BMVert *eve)
gpu::VertBufPtr extract_attribute(const MeshRenderData &mr, MeshBufferCache &cache, StringRef name)
gpu::VertBufPtr extract_face_dots_uv(const MeshRenderData &mr)
gpu::VertBufPtr extract_face_dots_edituv_data(const MeshRenderData &mr)
gpu::VertBufPtr extract_mesh_analysis(const MeshRenderData &mr, const float4x4 &object_to_world)
gpu::VertBufPtr extract_sculpt_data(const MeshRenderData &mr)
gpu::VertBufPtr extract_edituv_data_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache)
void extract_lines_subdiv(const DRWSubdivCache &subdiv_cache, const MeshRenderData &mr, gpu::IndexBufPtr *lines, gpu::IndexBufPtr *lines_loose, bool &no_loose_wire)
void create_material_subranges(const SortedFaceData &face_sorted, gpu::IndexBuf &tris_ibo, MutableSpan< gpu::IndexBufPtr > ibos)
constexpr ParallelGrainSize grain_size(int grain_size)
std::unique_ptr< IndexBuf, IndexBufDeleter > IndexBufPtr
std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > VertBufPtr
BMesh Iterators.
VecBase< uint32_t, 2 > uint2
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
BLI_INLINE BMEdge * BM_edge_at_index(BMesh *bm, const int index)
const Mesh * BKE_object_get_editmesh_eval_final(const Object *object)
Definition object.cc:4477
void GPU_vertbuf_use(gpu::VertBuf *)
const GPUVertFormat * GPU_vertbuf_get_format(const gpu::VertBuf *verts)
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
unsigned char uchar
Definition BKE_text.h:58
void GPU_vertbuf_update_sub(gpu::VertBuf *verts, uint start, uint len, const void *data)
BLI_INLINE BMVert * BM_vert_at_index(BMesh *bm, const int index)
BLI_INLINE BMFace * BM_face_at_index(BMesh *bm, const int index)
signed char int8_t
Definition BKE_text.h:76
bke::EditMeshData * edit_data
const ToolSettings * toolsettings
VArraySpan< bool > select_vert
VArraySpan< bool > sharp_faces
VArraySpan< bool > select_poly
VArraySpan< bool > select_edge
VArraySpan< int > material_indices
OffsetIndices< int > faces
bke::MeshNormalDomain normals_domain