Blender  V3.3
extract_mesh.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 Blender Foundation. All rights reserved. */
3 
10 #pragma once
11 
12 #include "DNA_mesh_types.h"
13 #include "DNA_meshdata_types.h"
14 #include "DNA_object_types.h"
15 #include "DNA_scene_types.h"
16 
17 #include "BKE_customdata.h"
18 #include "BKE_editmesh.h"
19 
20 #include "draw_cache_extract.hh"
21 
22 struct DRWSubdivCache;
23 
24 #define MIN_RANGE_LEN 1024
25 
26 /* ---------------------------------------------------------------------- */
34 };
35 
38 
43  int tri_len;
44  int mat_len;
45 
46  bool use_hide;
49 
51  float obmat[4][4];
52 
58 
59  /* For deformed edit-mesh data. */
60  /* Use for #ME_WRAPPER_TYPE_BMESH. */
61  const float (*bm_vert_coords)[3];
62  const float (*bm_vert_normals)[3];
63  const float (*bm_poly_normals)[3];
64  const float (*bm_poly_centers)[3];
65 
73  Mesh *me;
74  const MVert *mvert;
75  const MEdge *medge;
76  const MLoop *mloop;
77  const MPoly *mpoly;
82  /* Data created on-demand (usually not for #BMesh based data). */
84  const float (*vert_normals)[3];
85  const float (*poly_normals)[3];
87  int *lverts, *ledges;
88 
89  const char *active_color_name;
90  const char *default_color_name;
91 
92  struct {
97 };
98 
99 BLI_INLINE const Mesh *editmesh_final_or_this(const Object *object, const Mesh *me)
100 {
101  if (me->edit_mesh != nullptr) {
102  Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object);
103  if (editmesh_eval_final != nullptr) {
104  return editmesh_eval_final;
105  }
106  }
107 
108  return me;
109 }
110 
112 {
113  switch ((eMeshWrapperType)me->runtime.wrapper_type) {
116  return &me->ldata;
117  break;
119  return &me->edit_mesh->bm->ldata;
120  break;
121  }
122 
123  BLI_assert(0);
124  return &me->ldata;
125 }
126 
128 {
129  switch ((eMeshWrapperType)me->runtime.wrapper_type) {
132  return &me->pdata;
133  break;
135  return &me->edit_mesh->bm->pdata;
136  break;
137  }
138 
139  BLI_assert(0);
140  return &me->pdata;
141 }
142 
144 {
145  switch ((eMeshWrapperType)me->runtime.wrapper_type) {
148  return &me->edata;
149  break;
151  return &me->edit_mesh->bm->edata;
152  break;
153  }
154 
155  BLI_assert(0);
156  return &me->edata;
157 }
158 
160 {
161  switch ((eMeshWrapperType)me->runtime.wrapper_type) {
164  return &me->vdata;
165  break;
167  return &me->edit_mesh->bm->vdata;
168  break;
169  }
170 
171  BLI_assert(0);
172  return &me->vdata;
173 }
174 
176 {
177  return ((mr->p_origindex != NULL) && (mr->p_origindex[idx] != ORIGINDEX_NONE) && mr->bm) ?
178  BM_face_at_index(mr->bm, mr->p_origindex[idx]) :
179  NULL;
180 }
181 
183 {
184  return ((mr->e_origindex != NULL) && (mr->e_origindex[idx] != ORIGINDEX_NONE) && mr->bm) ?
185  BM_edge_at_index(mr->bm, mr->e_origindex[idx]) :
186  NULL;
187 }
188 
190 {
191  return ((mr->v_origindex != NULL) && (mr->v_origindex[idx] != ORIGINDEX_NONE) && mr->bm) ?
192  BM_vert_at_index(mr->bm, mr->v_origindex[idx]) :
193  NULL;
194 }
195 
196 BLI_INLINE const float *bm_vert_co_get(const MeshRenderData *mr, const BMVert *eve)
197 {
198  const float(*vert_coords)[3] = mr->bm_vert_coords;
199  if (vert_coords != NULL) {
200  return vert_coords[BM_elem_index_get(eve)];
201  }
202 
203  UNUSED_VARS(mr);
204  return eve->co;
205 }
206 
207 BLI_INLINE const float *bm_vert_no_get(const MeshRenderData *mr, const BMVert *eve)
208 {
209  const float(*vert_normals)[3] = mr->bm_vert_normals;
210  if (vert_normals != NULL) {
211  return vert_normals[BM_elem_index_get(eve)];
212  }
213 
214  UNUSED_VARS(mr);
215  return eve->no;
216 }
217 
218 BLI_INLINE const float *bm_face_no_get(const MeshRenderData *mr, const BMFace *efa)
219 {
220  const float(*poly_normals)[3] = mr->bm_poly_normals;
221  if (poly_normals != NULL) {
222  return poly_normals[BM_elem_index_get(efa)];
223  }
224 
225  UNUSED_VARS(mr);
226  return efa->no;
227 }
228 
231 /* ---------------------------------------------------------------------- */
235 /* TODO(jbakker): move parameters inside a struct. */
236 
237 using ExtractTriBMeshFn = void(const MeshRenderData *mr, BMLoop **elt, int elt_index, void *data);
239  const MLoopTri *mlt,
240  int elt_index,
241  void *data);
243  const BMFace *f,
244  int f_index,
245  void *data);
247  const MPoly *mp,
248  int mp_index,
249  void *data);
251  const BMEdge *eed,
252  int ledge_index,
253  void *data);
255  const MEdge *med,
256  int ledge_index,
257  void *data);
259  const BMVert *eve,
260  int lvert_index,
261  void *data);
263  const MVert *mv,
264  int lvert_index,
265  void *data);
266 using ExtractLooseGeomSubdivFn = void(const DRWSubdivCache *subdiv_cache,
267  const MeshRenderData *mr,
268  void *buffer,
269  void *data);
271  MeshBatchCache *cache,
272  void *buffer,
273  void *r_data);
275  MeshBatchCache *cache,
276  void *buffer,
277  void *data);
278 using ExtractTaskReduceFn = void(void *userdata, void *task_userdata);
279 
280 using ExtractInitSubdivFn = void(const DRWSubdivCache *subdiv_cache,
281  const MeshRenderData *mr,
282  MeshBatchCache *cache,
283  void *buf,
284  void *data);
285 using ExtractIterSubdivBMeshFn = void(const DRWSubdivCache *subdiv_cache,
286  const MeshRenderData *mr,
287  void *data,
288  uint subdiv_quad_index,
289  const BMFace *coarse_quad);
290 using ExtractIterSubdivMeshFn = void(const DRWSubdivCache *subdiv_cache,
291  const MeshRenderData *mr,
292  void *data,
293  uint subdiv_quad_index,
294  const MPoly *coarse_quad);
295 using ExtractFinishSubdivFn = void(const DRWSubdivCache *subdiv_cache,
296  const MeshRenderData *mr,
297  MeshBatchCache *cache,
298  void *buf,
299  void *data);
300 
301 struct MeshExtract {
324  size_t data_size;
332 };
333 
336 /* draw_cache_extract_mesh_render_data.c */
337 
343  Mesh *me,
344  bool is_editmode,
345  bool is_paint_mode,
346  bool is_mode_active,
347  const float obmat[4][4],
348  bool do_final,
349  bool do_uvedit,
350  const ToolSettings *ts);
354  MeshBufferCache *cache,
355  eMRIterType iter_type,
356  eMRDataType data_flag);
358  MeshBufferCache *cache,
359  eMRDataType data_flag);
364  eMRIterType iter_type,
365  eMRDataType data_flag);
366 
367 /* draw_cache_extract_mesh_extractors.c */
368 
369 struct EditLoopData {
372  /* This is used for both vertex and edge creases. The edge crease value is stored in the bottom 4
373  * bits, while the vertex crease is stored in the upper 4 bits. */
376 };
377 
378 void *mesh_extract_buffer_get(const MeshExtract *extractor, MeshBufferList *mbuflist);
379 eMRIterType mesh_extract_iter_type(const MeshExtract *ext);
380 const MeshExtract *mesh_extract_override_get(const MeshExtract *extractor,
381  bool do_hq_normals,
382  bool do_single_mat);
384  const BMFace *efa,
385  int cd_ofs,
386  EditLoopData *eattr);
388  BMLoop *l,
389  int cd_ofs,
390  EditLoopData *eattr);
392  BMLoop *l,
393  int cd_ofs,
394  EditLoopData *eattr);
395 
396 extern const MeshExtract extract_tris;
398 extern const MeshExtract extract_lines;
401 extern const MeshExtract extract_points;
402 extern const MeshExtract extract_fdots;
405 extern const MeshExtract extract_edituv_tris;
406 extern const MeshExtract extract_edituv_lines;
408 extern const MeshExtract extract_edituv_fdots;
409 extern const MeshExtract extract_pos_nor;
410 extern const MeshExtract extract_pos_nor_hq;
411 extern const MeshExtract extract_lnor_hq;
412 extern const MeshExtract extract_lnor;
413 extern const MeshExtract extract_uv;
414 extern const MeshExtract extract_tan;
415 extern const MeshExtract extract_tan_hq;
416 extern const MeshExtract extract_sculpt_data;
417 extern const MeshExtract extract_vcol;
418 extern const MeshExtract extract_orco;
419 extern const MeshExtract extract_edge_fac;
420 extern const MeshExtract extract_weights;
421 extern const MeshExtract extract_edit_data;
422 extern const MeshExtract extract_edituv_data;
426 extern const MeshExtract extract_fdots_pos;
427 extern const MeshExtract extract_fdots_nor;
428 extern const MeshExtract extract_fdots_nor_hq;
429 extern const MeshExtract extract_fdots_uv;
431 extern const MeshExtract extract_skin_roots;
432 extern const MeshExtract extract_poly_idx;
433 extern const MeshExtract extract_edge_idx;
434 extern const MeshExtract extract_vert_idx;
435 extern const MeshExtract extract_fdot_idx;
typedef float(TangentPoint)[2]
CustomData interface, see also DNA_customdata_types.h.
#define ORIGINDEX_NONE
struct Mesh * BKE_object_get_editmesh_eval_final(const struct Object *object)
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_INLINE
unsigned char uchar
Definition: BLI_sys_types.h:70
unsigned int uint
Definition: BLI_sys_types.h:67
#define UNUSED_VARS(...)
eMeshWrapperType
@ ME_WRAPPER_TYPE_MDATA
@ ME_WRAPPER_TYPE_SUBD
@ ME_WRAPPER_TYPE_BMESH
Object is a sort of wrapper for general info.
#define GPU_MAX_ATTR
Definition: GPU_shader.h:388
#define BM_elem_index_get(ele)
Definition: bmesh_inline.h:110
BLI_INLINE BMFace * BM_face_at_index(BMesh *bm, const int index)
Definition: bmesh_mesh.h:115
BLI_INLINE BMEdge * BM_edge_at_index(BMesh *bm, const int index)
Definition: bmesh_mesh.h:109
BLI_INLINE BMVert * BM_vert_at_index(BMesh *bm, const int index)
Definition: bmesh_mesh.h:103
ATTR_WARN_UNUSED_RESULT const BMLoop * l
SyclQueue void void size_t num_bytes void
const MeshExtract extract_fdots_pos
void(const MeshRenderData *mr, MeshBatchCache *cache, void *buffer, void *data) ExtractFinishFn
const MeshExtract extract_tris_single_mat
void mesh_render_data_face_flag(const MeshRenderData *mr, const BMFace *efa, int cd_ofs, EditLoopData *eattr)
Definition: extract_mesh.cc:92
const MeshExtract extract_uv
const MeshExtract extract_fdots_nor
BLI_INLINE const float * bm_face_no_get(const MeshRenderData *mr, const BMFace *efa)
const MeshExtract extract_lines_with_lines_loose
void(const MeshRenderData *mr, MeshBatchCache *cache, void *buffer, void *r_data) ExtractInitFn
const MeshExtract extract_edge_fac
BLI_INLINE const CustomData * mesh_cd_pdata_get_from_mesh(const Mesh *me)
const MeshExtract extract_edituv_stretch_area
BLI_INLINE const float * bm_vert_co_get(const MeshRenderData *mr, const BMVert *eve)
const MeshExtract extract_weights
BLI_INLINE BMFace * bm_original_face_get(const MeshRenderData *mr, int idx)
void(const DRWSubdivCache *subdiv_cache, const MeshRenderData *mr, MeshBatchCache *cache, void *buf, void *data) ExtractInitSubdivFn
void(const MeshRenderData *mr, BMLoop **elt, int elt_index, void *data) ExtractTriBMeshFn
const MeshExtract extract_vert_idx
eMRIterType mesh_extract_iter_type(const MeshExtract *ext)
Definition: extract_mesh.cc:30
BLI_INLINE BMEdge * bm_original_edge_get(const MeshRenderData *mr, int idx)
void mesh_render_data_update_normals(MeshRenderData *mr, eMRDataType data_flag)
void(const DRWSubdivCache *subdiv_cache, const MeshRenderData *mr, void *buffer, void *data) ExtractLooseGeomSubdivFn
const MeshExtract extract_fdots
void(void *userdata, void *task_userdata) ExtractTaskReduceFn
const MeshExtract extract_lines_loose_only
const MeshExtract extract_lnor
BLI_INLINE const CustomData * mesh_cd_vdata_get_from_mesh(const Mesh *me)
const MeshExtract extract_fdots_nor_hq
void * mesh_extract_buffer_get(const MeshExtract *extractor, MeshBufferList *mbuflist)
Definition: extract_mesh.cc:20
const MeshExtract extract_fdots_edituv_data
BLI_INLINE BMVert * bm_original_vert_get(const MeshRenderData *mr, int idx)
const MeshExtract extract_orco
const MeshExtract extract_edituv_fdots
const MeshExtract extract_fdot_idx
const MeshExtract extract_lines
void(const MeshRenderData *mr, const BMVert *eve, int lvert_index, void *data) ExtractLVertBMeshFn
const MeshExtract extract_edituv_points
const MeshExtract extract_edituv_tris
const MeshExtract extract_sculpt_data
const MeshExtract extract_edge_idx
void mesh_render_data_free(MeshRenderData *mr)
const MeshExtract extract_vcol
BLI_INLINE const CustomData * mesh_cd_edata_get_from_mesh(const Mesh *me)
const MeshExtract extract_poly_idx
const MeshExtract extract_tris
const MeshExtract extract_edituv_data
eMRExtractType
Definition: extract_mesh.hh:30
@ MR_EXTRACT_BMESH
Definition: extract_mesh.hh:31
@ MR_EXTRACT_MESH
Definition: extract_mesh.hh:33
@ MR_EXTRACT_MAPPED
Definition: extract_mesh.hh:32
void mesh_render_data_update_looptris(MeshRenderData *mr, eMRIterType iter_type, eMRDataType data_flag)
const MeshExtract extract_pos_nor_hq
void mesh_render_data_update_loose_geom(MeshRenderData *mr, MeshBufferCache *cache, eMRIterType iter_type, eMRDataType data_flag)
const MeshExtract extract_points
const MeshExtract extract_lnor_hq
void(const MeshRenderData *mr, const MPoly *mp, int mp_index, void *data) ExtractPolyMeshFn
void(const MeshRenderData *mr, const MLoopTri *mlt, int elt_index, void *data) ExtractTriMeshFn
BLI_INLINE const float * bm_vert_no_get(const MeshRenderData *mr, const BMVert *eve)
void(const MeshRenderData *mr, const MEdge *med, int ledge_index, void *data) ExtractLEdgeMeshFn
void(const DRWSubdivCache *subdiv_cache, const MeshRenderData *mr, void *data, uint subdiv_quad_index, const MPoly *coarse_quad) ExtractIterSubdivMeshFn
void(const DRWSubdivCache *subdiv_cache, const MeshRenderData *mr, void *data, uint subdiv_quad_index, const BMFace *coarse_quad) ExtractIterSubdivBMeshFn
const MeshExtract extract_fdots_uv
const MeshExtract extract_edituv_stretch_angle
void(const MeshRenderData *mr, const BMFace *f, int f_index, void *data) ExtractPolyBMeshFn
void(const MeshRenderData *mr, const BMEdge *eed, int ledge_index, void *data) ExtractLEdgeBMeshFn
void(const DRWSubdivCache *subdiv_cache, const MeshRenderData *mr, MeshBatchCache *cache, void *buf, void *data) ExtractFinishSubdivFn
void(const MeshRenderData *mr, const MVert *mv, int lvert_index, void *data) ExtractLVertMeshFn
const MeshExtract extract_mesh_analysis
const MeshExtract extract_pos_nor
const MeshExtract extract_edit_data
const MeshExtract extract_skin_roots
const MeshExtract * mesh_extract_override_get(const MeshExtract *extractor, bool do_hq_normals, bool do_single_mat)
Definition: extract_mesh.cc:71
const MeshExtract extract_lines_paint_mask
const MeshExtract extract_tan_hq
const MeshExtract extract_tan
const MeshExtract extract_attr[GPU_MAX_ATTR]
void mesh_render_data_loop_flag(const MeshRenderData *mr, BMLoop *l, int cd_ofs, EditLoopData *eattr)
const MeshExtract extract_edituv_lines
const MeshExtract extract_lines_adjacency
BLI_INLINE const Mesh * editmesh_final_or_this(const Object *object, const Mesh *me)
Definition: extract_mesh.hh:99
void mesh_render_data_loop_edge_flag(const MeshRenderData *mr, BMLoop *l, int cd_ofs, EditLoopData *eattr)
MeshRenderData * mesh_render_data_create(Object *object, Mesh *me, bool is_editmode, bool is_paint_mode, bool is_mode_active, const float obmat[4][4], bool do_final, bool do_uvedit, const ToolSettings *ts)
BLI_INLINE const CustomData * mesh_cd_ldata_get_from_mesh(const Mesh *me)
void mesh_render_data_update_polys_sorted(MeshRenderData *mr, MeshBufferCache *cache, eMRDataType data_flag)
ccl_global float * buffer
struct BMesh * bm
Definition: BKE_editmesh.h:40
float no[3]
Definition: bmesh_class.h:271
float co[3]
Definition: bmesh_class.h:87
float no[3]
Definition: bmesh_class.h:88
CustomData vdata
Definition: bmesh_class.h:337
CustomData edata
Definition: bmesh_class.h:337
CustomData pdata
Definition: bmesh_class.h:337
CustomData ldata
Definition: bmesh_class.h:337
ExtractIterSubdivBMeshFn * iter_subdiv_bm
size_t mesh_buffer_offset
eMRDataType data_type
ExtractFinishFn * finish
ExtractLVertBMeshFn * iter_lvert_bm
ExtractLVertMeshFn * iter_lvert_mesh
ExtractLEdgeBMeshFn * iter_ledge_bm
ExtractIterSubdivMeshFn * iter_subdiv_mesh
ExtractInitSubdivFn * init_subdiv
size_t data_size
ExtractTriBMeshFn * iter_looptri_bm
ExtractPolyBMeshFn * iter_poly_bm
ExtractLEdgeMeshFn * iter_ledge_mesh
ExtractFinishSubdivFn * finish_subdiv
ExtractPolyMeshFn * iter_poly_mesh
ExtractLooseGeomSubdivFn * iter_loose_geom_subdiv
ExtractTaskReduceFn * task_reduce
ExtractTriMeshFn * iter_looptri_mesh
bool use_threading
ExtractInitFn * init
eMRExtractType extract_type
Definition: extract_mesh.hh:37
BMVert * eve_act
Definition: extract_mesh.hh:78
const float(* bm_vert_normals)[3]
Definition: extract_mesh.hh:62
const float(* poly_normals)[3]
Definition: extract_mesh.hh:85
const MLoop * mloop
Definition: extract_mesh.hh:76
const float(* bm_poly_centers)[3]
Definition: extract_mesh.hh:64
BMEdge * eed_act
Definition: extract_mesh.hh:79
const int * v_origindex
Definition: extract_mesh.hh:66
const float(* vert_normals)[3]
Definition: extract_mesh.hh:84
const float(* bm_poly_normals)[3]
Definition: extract_mesh.hh:63
EditMeshData * edit_data
Definition: extract_mesh.hh:57
bool use_subsurf_fdots
Definition: extract_mesh.hh:47
const char * default_color_name
Definition: extract_mesh.hh:90
BMFace * efa_act_uv
Definition: extract_mesh.hh:81
const MVert * mvert
Definition: extract_mesh.hh:74
float(* loop_normals)[3]
Definition: extract_mesh.hh:86
const float(* bm_vert_coords)[3]
Definition: extract_mesh.hh:61
const ToolSettings * toolsettings
Definition: extract_mesh.hh:53
const char * active_color_name
Definition: extract_mesh.hh:89
const MPoly * mpoly
Definition: extract_mesh.hh:77
MLoopTri * mlooptri
Definition: extract_mesh.hh:83
struct MeshRenderData::@319 poly_sorted
BMEditMesh * edit_bmesh
Definition: extract_mesh.hh:55
const int * p_origindex
Definition: extract_mesh.hh:66
BMFace * efa_act
Definition: extract_mesh.hh:80
const MEdge * medge
Definition: extract_mesh.hh:75
int * tri_first_index
Definition: extract_mesh.hh:93
const int * e_origindex
Definition: extract_mesh.hh:66
float obmat[4][4]
Definition: extract_mesh.hh:51
struct BMEditMesh * edit_mesh
CustomData vdata
Mesh_Runtime runtime
CustomData pdata
CustomData edata
CustomData ldata