Blender V4.5
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
22#include "bmesh.hh"
23
24#include "GPU_vertex_buffer.hh"
25
26#include "draw_cache_extract.hh"
27
28struct DRWSubdivCache;
29struct BMVert;
30struct BMEdge;
31struct BMEditMesh;
32struct BMFace;
33struct BMLoop;
34
35namespace blender::draw {
36
37/* ---------------------------------------------------------------------- */
40
41enum class MeshExtractType {
44};
45
48
53
57
60
65
71
72 /* For deformed edit-mesh data. */
73 /* Use for #ME_WRAPPER_TYPE_BMESH. */
81
82 const int *orig_index_vert;
83 const int *orig_index_edge;
84 const int *orig_index_face;
91 const Mesh *mesh;
97
103
107
115
118
119 const char *active_color_name;
121};
122
123const Mesh &editmesh_final_or_this(const Object &object, const Mesh &mesh);
128
130{
131 return ((mr.orig_index_face != nullptr) && (mr.orig_index_face[idx] != ORIGINDEX_NONE) &&
132 mr.bm) ?
133 BM_face_at_index(mr.bm, mr.orig_index_face[idx]) :
134 nullptr;
135}
136
138{
139 return ((mr.orig_index_edge != nullptr) && (mr.orig_index_edge[idx] != ORIGINDEX_NONE) &&
140 mr.bm) ?
141 BM_edge_at_index(mr.bm, mr.orig_index_edge[idx]) :
142 nullptr;
143}
144
146{
147 return ((mr.orig_index_vert != nullptr) && (mr.orig_index_vert[idx] != ORIGINDEX_NONE) &&
148 mr.bm) ?
149 BM_vert_at_index(mr.bm, mr.orig_index_vert[idx]) :
150 nullptr;
151}
152
153BLI_INLINE const float *bm_vert_co_get(const MeshRenderData &mr, const BMVert *eve)
154{
155 if (!mr.bm_vert_coords.is_empty()) {
156 return mr.bm_vert_coords[BM_elem_index_get(eve)];
157 }
158 return eve->co;
159}
160
161BLI_INLINE const float *bm_vert_no_get(const MeshRenderData &mr, const BMVert *eve)
162{
163 if (mr.bm_free_normal_offset_vert != -1) {
165 }
166 if (!mr.bm_vert_normals.is_empty()) {
167 return mr.bm_vert_normals[BM_elem_index_get(eve)];
168 }
169 return eve->no;
170}
171
172BLI_INLINE const float *bm_face_no_get(const MeshRenderData &mr, const BMFace *efa)
173{
174 if (mr.bm_free_normal_offset_face != -1) {
176 }
177 if (!mr.bm_face_normals.is_empty()) {
178 return mr.bm_face_normals[BM_elem_index_get(efa)];
179 }
180 return efa->no;
181}
182
184
185/* `draw_cache_extract_mesh_render_data.cc` */
186
191MeshRenderData mesh_render_data_create(Object &object,
192 Mesh &mesh,
193 bool is_editmode,
194 bool is_paint_mode,
195 bool do_final,
196 bool do_uvedit,
197 bool use_hide,
198 const ToolSettings *ts);
199void mesh_render_data_update_corner_normals(MeshRenderData &mr);
200void mesh_render_data_update_face_normals(MeshRenderData &mr);
201void mesh_render_data_update_loose_geom(MeshRenderData &mr, MeshBufferCache &cache);
202const SortedFaceData &mesh_render_data_faces_sorted_ensure(const MeshRenderData &mr,
203 MeshBufferCache &cache);
204
205/* draw_cache_extract_mesh_extractors.c */
206
210 /* This is used for both vertex and edge creases. The edge crease value is stored in the bottom 4
211 * bits, while the vertex crease is stored in the upper 4 bits. */
214};
215
217 const BMFace *efa,
218 const BMUVOffsets &offsets,
219 EditLoopData &eattr);
221 const BMLoop *l,
222 const BMUVOffsets &offsets,
223 EditLoopData &eattr);
225 const BMLoop *l,
226 const BMUVOffsets &offsets,
227 EditLoopData &eattr);
228
229/* In the GPU vertex buffers, the value for each vertex is duplicated to each of its vertex
230 * corners. So the edges on the GPU connect face corners rather than vertices. */
231inline uint2 edge_from_corners(const IndexRange face, const int corner)
232{
233 const int corner_next = bke::mesh::face_corner_next(face, corner);
234 return uint2(corner, corner_next);
235}
236
237template<typename T>
239 const Span<int2> edges,
240 const Span<int> loose_edges,
241 MutableSpan<T> gpu_data)
242{
243 threading::parallel_for(loose_edges.index_range(), 4096, [&](const IndexRange range) {
244 for (const int i : range) {
245 const int2 edge = edges[loose_edges[i]];
246 gpu_data[i * 2 + 0] = vert_data[edge[0]];
247 gpu_data[i * 2 + 1] = vert_data[edge[1]];
248 }
249 });
250}
251
252gpu::VertBufPtr extract_positions(const MeshRenderData &mr);
253gpu::VertBufPtr extract_positions_subdiv(const DRWSubdivCache &subdiv_cache,
254 const MeshRenderData &mr,
255 gpu::VertBufPtr *orco_vbo);
256
257gpu::VertBufPtr extract_face_dots_position(const MeshRenderData &mr);
258void extract_face_dots_subdiv(const DRWSubdivCache &subdiv_cache,
259 gpu::VertBufPtr &fdots_pos,
260 gpu::VertBufPtr *fdots_nor,
261 gpu::IndexBufPtr &fdots);
262
263gpu::VertBufPtr extract_normals(const MeshRenderData &mr, bool use_hq);
264gpu::VertBufPtr extract_normals_subdiv(const MeshRenderData &mr,
265 const DRWSubdivCache &subdiv_cache,
266 gpu::VertBuf &pos_nor);
267gpu::VertBufPtr extract_vert_normals(const MeshRenderData &mr);
268gpu::VertBufPtr extract_face_dot_normals(const MeshRenderData &mr, bool use_hq);
269gpu::VertBufPtr extract_edge_factor(const MeshRenderData &mr);
270gpu::VertBufPtr extract_edge_factor_subdiv(const DRWSubdivCache &subdiv_cache,
271 const MeshRenderData &mr,
272 gpu::VertBuf &pos_nor);
273
274gpu::IndexBufPtr extract_tris(const MeshRenderData &mr, const SortedFaceData &face_sorted);
275void create_material_subranges(const SortedFaceData &face_sorted,
276 gpu::IndexBuf &tris_ibo,
278gpu::IndexBufPtr extract_tris_subdiv(const DRWSubdivCache &subdiv_cache, MeshBatchCache &cache);
279
280void extract_lines(const MeshRenderData &mr,
281 gpu::IndexBufPtr *lines,
282 gpu::IndexBufPtr *lines_loose,
283 bool &no_loose_wire);
284void extract_lines_subdiv(const DRWSubdivCache &subdiv_cache,
285 const MeshRenderData &mr,
286 gpu::IndexBufPtr *lines,
287 gpu::IndexBufPtr *lines_loose,
288 bool &no_loose_wire);
289
290gpu::IndexBufPtr extract_points(const MeshRenderData &mr);
291gpu::IndexBufPtr extract_points_subdiv(const MeshRenderData &mr,
292 const DRWSubdivCache &subdiv_cache);
293
294gpu::VertBufPtr extract_edit_data(const MeshRenderData &mr);
295gpu::VertBufPtr extract_edit_data_subdiv(const MeshRenderData &mr,
296 const DRWSubdivCache &subdiv_cache);
297
298gpu::VertBufPtr extract_tangents(const MeshRenderData &mr,
299 const MeshBatchCache &cache,
300 bool use_hq);
301gpu::VertBufPtr extract_tangents_subdiv(const MeshRenderData &mr,
302 const DRWSubdivCache &subdiv_cache,
303 const MeshBatchCache &cache);
304
305gpu::VertBufPtr extract_vert_index(const MeshRenderData &mr);
306gpu::VertBufPtr extract_edge_index(const MeshRenderData &mr);
307gpu::VertBufPtr extract_face_index(const MeshRenderData &mr);
308gpu::VertBufPtr extract_face_dot_index(const MeshRenderData &mr);
309
310gpu::VertBufPtr extract_vert_index_subdiv(const DRWSubdivCache &subdiv_cache,
311 const MeshRenderData &mr);
312gpu::VertBufPtr extract_edge_index_subdiv(const DRWSubdivCache &subdiv_cache,
313 const MeshRenderData &mr);
314gpu::VertBufPtr extract_face_index_subdiv(const DRWSubdivCache &subdiv_cache,
315 const MeshRenderData &mr);
316
317gpu::VertBufPtr extract_weights(const MeshRenderData &mr, const MeshBatchCache &cache);
318gpu::VertBufPtr extract_weights_subdiv(const MeshRenderData &mr,
319 const DRWSubdivCache &subdiv_cache,
320 const MeshBatchCache &cache);
321
322gpu::IndexBufPtr extract_face_dots(const MeshRenderData &mr);
323
324gpu::VertBufPtr extract_face_dots_uv(const MeshRenderData &mr);
325gpu::VertBufPtr extract_face_dots_edituv_data(const MeshRenderData &mr);
326
327gpu::IndexBufPtr extract_lines_paint_mask(const MeshRenderData &mr);
328gpu::IndexBufPtr extract_lines_paint_mask_subdiv(const MeshRenderData &mr,
329 const DRWSubdivCache &subdiv_cache);
330
331gpu::IndexBufPtr extract_lines_adjacency(const MeshRenderData &mr, bool &r_is_manifold);
332gpu::IndexBufPtr extract_lines_adjacency_subdiv(const DRWSubdivCache &subdiv_cache,
333 bool &r_is_manifold);
334
335gpu::VertBufPtr extract_uv_maps(const MeshRenderData &mr, const MeshBatchCache &cache);
336gpu::VertBufPtr extract_uv_maps_subdiv(const DRWSubdivCache &subdiv_cache,
337 const MeshBatchCache &cache);
338gpu::VertBufPtr extract_edituv_stretch_area(const MeshRenderData &mr,
339 float &tot_area,
340 float &tot_uv_area);
341gpu::VertBufPtr extract_edituv_stretch_area_subdiv(const MeshRenderData &mr,
342 const DRWSubdivCache &subdiv_cache,
343 float &tot_area,
344 float &tot_uv_area);
345gpu::VertBufPtr extract_edituv_stretch_angle(const MeshRenderData &mr);
346gpu::VertBufPtr extract_edituv_stretch_angle_subdiv(const MeshRenderData &mr,
347 const DRWSubdivCache &subdiv_cache,
348 const MeshBatchCache &cache);
349gpu::VertBufPtr extract_edituv_data(const MeshRenderData &mr);
350gpu::VertBufPtr extract_edituv_data_subdiv(const MeshRenderData &mr,
351 const DRWSubdivCache &subdiv_cache);
352gpu::IndexBufPtr extract_edituv_tris(const MeshRenderData &mr, bool edit_uvs);
353gpu::IndexBufPtr extract_edituv_tris_subdiv(const MeshRenderData &mr,
354 const DRWSubdivCache &subdiv_cache);
355
356enum class UvExtractionMode : int8_t {
359 All,
360};
361
362gpu::IndexBufPtr extract_edituv_lines(const MeshRenderData &mr, UvExtractionMode mode);
363gpu::IndexBufPtr extract_edituv_lines_subdiv(const MeshRenderData &mr,
364 const DRWSubdivCache &subdiv_cache,
365 UvExtractionMode mode);
366gpu::IndexBufPtr extract_edituv_points(const MeshRenderData &mr);
367gpu::IndexBufPtr extract_edituv_points_subdiv(const MeshRenderData &mr,
368 const DRWSubdivCache &subdiv_cache);
369gpu::IndexBufPtr extract_edituv_face_dots(const MeshRenderData &mr);
370
371gpu::VertBufPtr extract_mesh_analysis(const MeshRenderData &mr, const float4x4 &object_to_world);
372
373gpu::VertBufPtr extract_skin_roots(const MeshRenderData &mr);
374
375gpu::VertBufPtr extract_sculpt_data(const MeshRenderData &mr);
376gpu::VertBufPtr extract_sculpt_data_subdiv(const MeshRenderData &mr,
377 const DRWSubdivCache &subdiv_cache);
378
379gpu::VertBufPtr extract_orco(const MeshRenderData &mr);
380
381gpu::VertBufPtr extract_attribute(const MeshRenderData &mr, StringRef name);
382gpu::VertBufPtr extract_attribute_subdiv(const MeshRenderData &mr,
383 const DRWSubdivCache &subdiv_cache,
384 StringRef name);
385gpu::VertBufPtr extract_attr_viewer(const MeshRenderData &mr);
386
387} // namespace blender::draw
#define ORIGINDEX_NONE
#define BLI_INLINE
unsigned char uchar
#define BM_ELEM_CD_GET_FLOAT_P(ele, offset)
#define BM_elem_index_get(ele)
BLI_INLINE BMEdge * BM_edge_at_index(BMesh *bm, const int index)
BLI_INLINE BMVert * BM_vert_at_index(BMesh *bm, const int index)
BLI_INLINE BMFace * BM_face_at_index(BMesh *bm, const int index)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
constexpr IndexRange index_range() const
Definition BLI_span.hh:401
int face_corner_next(const IndexRange face, const int corner)
Definition BKE_mesh.hh:299
const CustomData & mesh_cd_ldata_get_from_mesh(const Mesh &mesh)
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)
BLI_INLINE BMEdge * bm_original_edge_get(const MeshRenderData &mr, int idx)
void mesh_render_data_loop_flag(const MeshRenderData &mr, const BMLoop *l, const BMUVOffsets &offsets, EditLoopData &eattr)
const CustomData & mesh_cd_edata_get_from_mesh(const Mesh &mesh)
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)
void mesh_render_data_loop_edge_flag(const MeshRenderData &mr, const BMLoop *l, const BMUVOffsets &offsets, EditLoopData &eattr)
const Mesh & editmesh_final_or_this(const Object &object, const Mesh &mesh)
BLI_INLINE const float * bm_face_no_get(const MeshRenderData &mr, const BMFace *efa)
void mesh_render_data_update_corner_normals(MeshRenderData &mr)
const SortedFaceData & mesh_render_data_faces_sorted_ensure(const MeshRenderData &mr, MeshBufferCache &cache)
const CustomData & mesh_cd_vdata_get_from_mesh(const Mesh &mesh)
BLI_INLINE const float * bm_vert_no_get(const MeshRenderData &mr, const BMVert *eve)
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)
void extract_mesh_loose_edge_data(const Span< T > vert_data, const Span< int2 > edges, const Span< int > loose_edges, MutableSpan< T > gpu_data)
BLI_INLINE const float * bm_vert_co_get(const MeshRenderData &mr, const BMVert *eve)
const CustomData & mesh_cd_pdata_get_from_mesh(const Mesh &mesh)
std::unique_ptr< IndexBuf, IndexBufDeleter > IndexBufPtr
std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > VertBufPtr
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:93
VecBase< uint32_t, 2 > uint2
MatBase< float, 4, 4 > float4x4
float no[3]
float co[3]
float no[3]
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