Blender V4.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
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#include "GPU_vertex_format.hh"
26
27#include "draw_cache_extract.hh"
28
29struct DRWSubdivCache;
30struct BMVert;
31struct BMEdge;
32struct BMEditMesh;
33struct BMFace;
34struct BMLoop;
35
36namespace blender::draw {
37
38#define MIN_RANGE_LEN 1024
39
40/* ---------------------------------------------------------------------- */
48
51
56
60
63
69
72
78
79 /* For deformed edit-mesh data. */
80 /* 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
127const Mesh &editmesh_final_or_this(const Object &object, const Mesh &mesh);
132
134{
135 return ((mr.orig_index_face != nullptr) && (mr.orig_index_face[idx] != ORIGINDEX_NONE) &&
136 mr.bm) ?
137 BM_face_at_index(mr.bm, mr.orig_index_face[idx]) :
138 nullptr;
139}
140
142{
143 return ((mr.orig_index_edge != nullptr) && (mr.orig_index_edge[idx] != ORIGINDEX_NONE) &&
144 mr.bm) ?
145 BM_edge_at_index(mr.bm, mr.orig_index_edge[idx]) :
146 nullptr;
147}
148
150{
151 return ((mr.orig_index_vert != nullptr) && (mr.orig_index_vert[idx] != ORIGINDEX_NONE) &&
152 mr.bm) ?
153 BM_vert_at_index(mr.bm, mr.orig_index_vert[idx]) :
154 nullptr;
155}
156
157BLI_INLINE const float *bm_vert_co_get(const MeshRenderData &mr, const BMVert *eve)
158{
159 if (!mr.bm_vert_coords.is_empty()) {
160 return mr.bm_vert_coords[BM_elem_index_get(eve)];
161 }
162 return eve->co;
163}
164
165BLI_INLINE const float *bm_vert_no_get(const MeshRenderData &mr, const BMVert *eve)
166{
167 if (!mr.bm_vert_normals.is_empty()) {
168 return mr.bm_vert_normals[BM_elem_index_get(eve)];
169 }
170 return eve->no;
171}
172
173BLI_INLINE const float *bm_face_no_get(const MeshRenderData &mr, const BMFace *efa)
174{
175 if (!mr.bm_face_normals.is_empty()) {
176 return mr.bm_face_normals[BM_elem_index_get(efa)];
177 }
178 return efa->no;
179}
180
183/* `draw_cache_extract_mesh_render_data.cc` */
184
189std::unique_ptr<MeshRenderData> mesh_render_data_create(Object &object,
190 Mesh &mesh,
191 bool is_editmode,
192 bool is_paint_mode,
193 bool edit_mode_active,
194 const float4x4 &object_to_world,
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 BMUVOffsets offsets,
219 EditLoopData &eattr);
221 const BMLoop *l,
222 BMUVOffsets offsets,
223 EditLoopData &eattr);
225 const BMLoop *l,
226 BMUVOffsets offsets,
227 EditLoopData &eattr);
228
229template<typename GPUType> inline GPUType convert_normal(const float3 &src);
230
231template<> inline GPUPackedNormal convert_normal(const float3 &src)
232{
233 return GPU_normal_convert_i10_v3(src);
234}
235
236template<> inline short4 convert_normal(const float3 &src)
237{
238 short4 dst;
239 normal_float_to_short_v3(dst, src);
240 return dst;
241}
242
243template<typename GPUType> void convert_normals(Span<float3> src, MutableSpan<GPUType> dst);
244
245template<typename T>
247 const Span<int2> edges,
248 const Span<int> loose_edges,
249 MutableSpan<T> gpu_data)
250{
251 threading::parallel_for(loose_edges.index_range(), 4096, [&](const IndexRange range) {
252 for (const int i : range) {
253 const int2 edge = edges[loose_edges[i]];
254 gpu_data[i * 2 + 0] = vert_data[edge[0]];
255 gpu_data[i * 2 + 1] = vert_data[edge[1]];
256 }
257 });
258}
259
260void extract_positions(const MeshRenderData &mr, gpu::VertBuf &vbo);
261void extract_positions_subdiv(const DRWSubdivCache &subdiv_cache,
262 const MeshRenderData &mr,
263 gpu::VertBuf &vbo,
264 gpu::VertBuf *orco_vbo);
265
266void extract_face_dots_position(const MeshRenderData &mr, gpu::VertBuf &vbo);
267void extract_face_dots_subdiv(const DRWSubdivCache &subdiv_cache,
268 gpu::VertBuf &fdots_pos,
269 gpu::VertBuf *fdots_nor,
270 gpu::IndexBuf &fdots);
271
272void extract_normals(const MeshRenderData &mr, bool use_hq, gpu::VertBuf &vbo);
273void extract_normals_subdiv(const MeshRenderData &mr,
274 const DRWSubdivCache &subdiv_cache,
275 gpu::VertBuf &pos_nor,
276 gpu::VertBuf &lnor);
277void extract_vert_normals(const MeshRenderData &mr, gpu::VertBuf &vbo);
278void extract_face_dot_normals(const MeshRenderData &mr, const bool use_hq, gpu::VertBuf &vbo);
279void extract_edge_factor(const MeshRenderData &mr, gpu::VertBuf &vbo);
280void extract_edge_factor_subdiv(const DRWSubdivCache &subdiv_cache,
281 const MeshRenderData &mr,
282 gpu::VertBuf &pos_nor,
283 gpu::VertBuf &vbo);
284
285void extract_tris(const MeshRenderData &mr,
286 const SortedFaceData &face_sorted,
287 MeshBatchCache &cache,
288 gpu::IndexBuf &ibo);
289void extract_tris_subdiv(const DRWSubdivCache &subdiv_cache,
290 MeshBatchCache &cache,
291 gpu::IndexBuf &ibo);
292
293void extract_lines(const MeshRenderData &mr,
294 gpu::IndexBuf *lines,
295 gpu::IndexBuf *lines_loose,
296 bool &no_loose_wire);
297void extract_lines_subdiv(const DRWSubdivCache &subdiv_cache,
298 const MeshRenderData &mr,
299 gpu::IndexBuf *lines,
300 gpu::IndexBuf *lines_loose,
301 bool &no_loose_wire);
302
303void extract_points(const MeshRenderData &mr, gpu::IndexBuf &points);
304void extract_points_subdiv(const MeshRenderData &mr,
305 const DRWSubdivCache &subdiv_cache,
306 gpu::IndexBuf &points);
307
308void extract_edit_data(const MeshRenderData &mr, gpu::VertBuf &vbo);
309void extract_edit_data_subdiv(const MeshRenderData &mr,
310 const DRWSubdivCache &subdiv_cache,
311 gpu::VertBuf &vbo);
312
313void extract_tangents(const MeshRenderData &mr,
314 const MeshBatchCache &cache,
315 const bool use_hq,
316 gpu::VertBuf &vbo);
317void extract_tangents_subdiv(const MeshRenderData &mr,
318 const DRWSubdivCache &subdiv_cache,
319 const MeshBatchCache &cache,
320 gpu::VertBuf &vbo);
321
322void extract_vert_index(const MeshRenderData &mr, gpu::VertBuf &vbo);
323void extract_edge_index(const MeshRenderData &mr, gpu::VertBuf &vbo);
324void extract_face_index(const MeshRenderData &mr, gpu::VertBuf &vbo);
325void extract_face_dot_index(const MeshRenderData &mr, gpu::VertBuf &vbo);
326
327void extract_vert_index_subdiv(const DRWSubdivCache &subdiv_cache,
328 const MeshRenderData &mr,
329 gpu::VertBuf &vbo);
330void extract_edge_index_subdiv(const DRWSubdivCache &subdiv_cache,
331 const MeshRenderData &mr,
332 gpu::VertBuf &vbo);
333void extract_face_index_subdiv(const DRWSubdivCache &subdiv_cache,
334 const MeshRenderData &mr,
335 gpu::VertBuf &vbo);
336
337void extract_weights(const MeshRenderData &mr, const MeshBatchCache &cache, gpu::VertBuf &vbo);
338void extract_weights_subdiv(const MeshRenderData &mr,
339 const DRWSubdivCache &subdiv_cache,
340 const MeshBatchCache &cache,
341 gpu::VertBuf &vbo);
342
343void extract_face_dots(const MeshRenderData &mr, gpu::IndexBuf &face_dots);
344
345void extract_face_dots_uv(const MeshRenderData &mr, gpu::VertBuf &vbo);
346void extract_face_dots_edituv_data(const MeshRenderData &mr, gpu::VertBuf &vbo);
347
348void extract_lines_paint_mask(const MeshRenderData &mr, gpu::IndexBuf &lines);
349void extract_lines_paint_mask_subdiv(const MeshRenderData &mr,
350 const DRWSubdivCache &subdiv_cache,
351 gpu::IndexBuf &lines);
352
353void extract_lines_adjacency(const MeshRenderData &mr, gpu::IndexBuf &ibo, bool &r_is_manifold);
354void extract_lines_adjacency_subdiv(const DRWSubdivCache &subdiv_cache,
355 gpu::IndexBuf &ibo,
356 bool &r_is_manifold);
357
358void extract_uv_maps(const MeshRenderData &mr, const MeshBatchCache &cache, gpu::VertBuf &vbo);
359void extract_uv_maps_subdiv(const DRWSubdivCache &subdiv_cache,
360 const MeshBatchCache &cache,
361 gpu::VertBuf &vbo);
362void extract_edituv_stretch_area(const MeshRenderData &mr,
363 gpu::VertBuf &vbo,
364 float &tot_area,
365 float &tot_uv_area);
366void extract_edituv_stretch_area_subdiv(const MeshRenderData &mr,
367 const DRWSubdivCache &subdiv_cache,
368 gpu::VertBuf &vbo,
369 float &tot_area,
370 float &tot_uv_area);
371void extract_edituv_stretch_angle(const MeshRenderData &mr, gpu::VertBuf &vbo);
372void extract_edituv_stretch_angle_subdiv(const MeshRenderData &mr,
373 const DRWSubdivCache &subdiv_cache,
374 const MeshBatchCache &cache,
375 gpu::VertBuf &vbo);
376void extract_edituv_data(const MeshRenderData &mr, gpu::VertBuf &vbo);
377void extract_edituv_data_subdiv(const MeshRenderData &mr,
378 const DRWSubdivCache &subdiv_cache,
379 gpu::VertBuf &vbo);
380void extract_edituv_tris(const MeshRenderData &mr, gpu::IndexBuf &ibo);
381void extract_edituv_tris_subdiv(const MeshRenderData &mr,
382 const DRWSubdivCache &subdiv_cache,
383 gpu::IndexBuf &ibo);
384void extract_edituv_lines(const MeshRenderData &mr, gpu::IndexBuf &ibo);
385void extract_edituv_lines_subdiv(const MeshRenderData &mr,
386 const DRWSubdivCache &subdiv_cache,
387 gpu::IndexBuf &ibo);
388void extract_edituv_points(const MeshRenderData &mr, gpu::IndexBuf &ibo);
389void extract_edituv_points_subdiv(const MeshRenderData &mr,
390 const DRWSubdivCache &subdiv_cache,
391 gpu::IndexBuf &ibo);
392void extract_edituv_face_dots(const MeshRenderData &mr, gpu::IndexBuf &ibo);
393
394void extract_skin_roots(const MeshRenderData &mr, gpu::VertBuf &vbo);
395
396void extract_sculpt_data(const MeshRenderData &mr, gpu::VertBuf &vbo);
397void extract_sculpt_data_subdiv(const MeshRenderData &mr,
398 const DRWSubdivCache &subdiv_cache,
399 gpu::VertBuf &vbo);
400
401void extract_orco(const MeshRenderData &mr, gpu::VertBuf &vbo);
402
403void extract_mesh_analysis(const MeshRenderData &mr, gpu::VertBuf &vbo);
404
405void extract_attributes(const MeshRenderData &mr,
406 const Span<DRW_AttributeRequest> requests,
407 const Span<gpu::VertBuf *> vbos);
408void extract_attributes_subdiv(const MeshRenderData &mr,
409 const DRWSubdivCache &subdiv_cache,
410 const Span<DRW_AttributeRequest> requests,
411 const Span<gpu::VertBuf *> vbos);
412void extract_attr_viewer(const MeshRenderData &mr, gpu::VertBuf &vbo);
413
414} // namespace blender::draw
#define ORIGINDEX_NONE
#define BLI_INLINE
MINLINE void normal_float_to_short_v3(short out[3], const float in[3])
unsigned char uchar
BLI_INLINE GPUPackedNormal GPU_normal_convert_i10_v3(const float data[3])
#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:402
constexpr bool is_empty() const
Definition BLI_span.hh:261
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)
GPUType convert_normal(const float3 &src)
BLI_INLINE BMEdge * bm_original_edge_get(const MeshRenderData &mr, int idx)
void convert_normals(Span< float3 > src, MutableSpan< GPUType > dst)
const CustomData & mesh_cd_edata_get_from_mesh(const Mesh &mesh)
const Mesh & editmesh_final_or_this(const Object &object, const Mesh &mesh)
std::unique_ptr< MeshRenderData > mesh_render_data_create(Object &object, Mesh &mesh, const bool is_editmode, const bool is_paint_mode, const bool edit_mode_active, const float4x4 &object_to_world, const bool do_final, const bool do_uvedit, const bool use_hide, const ToolSettings *ts)
BLI_INLINE const float * bm_face_no_get(const MeshRenderData &mr, const BMFace *efa)
void mesh_render_data_update_corner_normals(MeshRenderData &mr)
void mesh_render_data_face_flag(const MeshRenderData &mr, const BMFace *efa, const BMUVOffsets offsets, EditLoopData &eattr)
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)
void mesh_render_data_update_loose_geom(MeshRenderData &mr, MeshBufferCache &cache)
void mesh_render_data_loop_flag(const MeshRenderData &mr, const BMLoop *l, const BMUVOffsets offsets, EditLoopData &eattr)
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)
void mesh_render_data_loop_edge_flag(const MeshRenderData &mr, const BMLoop *l, const BMUVOffsets offsets, EditLoopData &eattr)
const CustomData & mesh_cd_pdata_get_from_mesh(const Mesh &mesh)
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:95
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