Blender  V3.3
Macros
mesh_legacy_convert.cc File Reference
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "BLI_edgehash.h"
#include "BLI_math.h"
#include "BLI_memarena.h"
#include "BLI_polyfill_2d.h"
#include "BLI_utildefines.h"
#include "BKE_customdata.h"
#include "BKE_mesh.h"
#include "BKE_mesh_legacy_convert.h"
#include "BKE_multires.h"

Go to the source code of this file.

Macros

#define ME_FGON   (1 << 3)
 
#define ML(v1, v2)
 
#define USE_TESSFACE_SPEEDUP
 
#define USE_TESSFACE_QUADS
 
#define TESSFACE_IS_QUAD   1
 
#define ML_TO_MF(i1, i2, i3)
 
#define ML_TO_MF_QUAD()
 
#define LAYER_CMP(l_a, t_a, l_b, t_b)
 

Functions

NGon Tessellation (NGon to MFace Conversion)
static void bm_corners_to_loops_ex (ID *id, CustomData *fdata, CustomData *ldata, MFace *mface, int totloop, int findex, int loopstart, int numTex, int numCol)
 
static void CustomData_to_bmeshpoly (CustomData *fdata, CustomData *ldata, int totloop)
 
static void convert_mfaces_to_mpolys (ID *id, CustomData *fdata, CustomData *ldata, CustomData *pdata, int totedge_i, int totface_i, int totloop_i, int totpoly_i, MEdge *medge, MFace *mface, int *r_totloop, int *r_totpoly, MLoop **r_mloop, MPoly **r_mpoly)
 
void BKE_mesh_convert_mfaces_to_mpolys (Mesh *mesh)
 
static void CustomData_bmesh_do_versions_update_active_layers (CustomData *fdata, CustomData *ldata)
 
void BKE_mesh_do_versions_convert_mfaces_to_mpolys (Mesh *mesh)
 
MFace Tessellation

MFace is a legacy data-structure that should be avoided, use MLoopTri instead.

static void mesh_loops_to_tessdata (CustomData *fdata, CustomData *ldata, MFace *mface, const int *polyindices, uint(*loopindices)[4], const int num_faces)
 
int BKE_mesh_mface_index_validate (MFace *mface, CustomData *fdata, int mfindex, int nr)
 
static int mesh_tessface_calc (CustomData *fdata, CustomData *ldata, CustomData *pdata, MVert *mvert, int totface, int totloop, int totpoly)
 
void BKE_mesh_tessface_calc (Mesh *mesh)
 
void BKE_mesh_tessface_ensure (struct Mesh *mesh)
 
static bool check_matching_legacy_layer_counts (CustomData *fdata, CustomData *ldata, bool fallback)
 
void BKE_mesh_add_mface_layers (CustomData *fdata, CustomData *ldata, int total)
 

Detailed Description

Functions to convert mesh data to and from legacy formats like MFace.

Definition in file mesh_legacy_convert.cc.

Macro Definition Documentation

◆ LAYER_CMP

#define LAYER_CMP (   l_a,
  t_a,
  l_b,
  t_b 
)
Value:
((a_num += CustomData_number_of_layers(l_a, t_a)) == \
(b_num += CustomData_number_of_layers(l_b, t_b)))
int CustomData_number_of_layers(const struct CustomData *data, int type)
ATTR_WARN_UNUSED_RESULT const BMLoop * l_b

◆ ME_FGON

#define ME_FGON   (1 << 3)

◆ ML

#define ML (   v1,
  v2 
)
Value:
{ \
ml->v = mf->v1; \
ml->e = POINTER_AS_UINT(BLI_edgehash_lookup(eh, mf->v1, mf->v2)); \
ml++; \
j++; \
} \
(void)0
void * BLI_edgehash_lookup(const EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:295
#define POINTER_AS_UINT(i)
SyclQueue void void size_t num_bytes void

◆ ML_TO_MF

#define ML_TO_MF (   i1,
  i2,
  i3 
)
Value:
mface_to_poly_map[mface_index] = poly_index; \
mf = &mface[mface_index]; \
lidx = lindices[mface_index]; \
/* Set loop indices, transformed to vert indices later. */ \
l1 = mp_loopstart + i1; \
l2 = mp_loopstart + i2; \
l3 = mp_loopstart + i3; \
mf->v1 = mloop[l1].v; \
mf->v2 = mloop[l2].v; \
mf->v3 = mloop[l3].v; \
mf->v4 = 0; \
lidx[0] = l1; \
lidx[1] = l2; \
lidx[2] = l3; \
lidx[3] = 0; \
mf->mat_nr = mp->mat_nr; \
mf->flag = mp->flag; \
mf->edcode = 0; \
(void)0
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint i1

◆ ML_TO_MF_QUAD

#define ML_TO_MF_QUAD ( )
Value:
mface_to_poly_map[mface_index] = poly_index; \
mf = &mface[mface_index]; \
lidx = lindices[mface_index]; \
/* Set loop indices, transformed to vert indices later. */ \
l1 = mp_loopstart + 0; /* EXCEPTION */ \
l2 = mp_loopstart + 1; /* EXCEPTION */ \
l3 = mp_loopstart + 2; /* EXCEPTION */ \
l4 = mp_loopstart + 3; /* EXCEPTION */ \
mf->v1 = mloop[l1].v; \
mf->v2 = mloop[l2].v; \
mf->v3 = mloop[l3].v; \
mf->v4 = mloop[l4].v; \
lidx[0] = l1; \
lidx[1] = l2; \
lidx[2] = l3; \
lidx[3] = l4; \
mf->mat_nr = mp->mat_nr; \
mf->flag = mp->flag; \
mf->edcode = TESSFACE_IS_QUAD; \
(void)0
#define TESSFACE_IS_QUAD

◆ TESSFACE_IS_QUAD

#define TESSFACE_IS_QUAD   1

◆ USE_TESSFACE_QUADS

#define USE_TESSFACE_QUADS

◆ USE_TESSFACE_SPEEDUP

#define USE_TESSFACE_SPEEDUP

Function Documentation

◆ BKE_mesh_add_mface_layers()

void BKE_mesh_add_mface_layers ( CustomData fdata,
CustomData ldata,
int  total 
)

◆ BKE_mesh_convert_mfaces_to_mpolys()

void BKE_mesh_convert_mfaces_to_mpolys ( Mesh mesh)

◆ BKE_mesh_do_versions_convert_mfaces_to_mpolys()

void BKE_mesh_do_versions_convert_mfaces_to_mpolys ( struct Mesh mesh)

The same as BKE_mesh_convert_mfaces_to_mpolys but oriented to be used in do_versions from readfile.c the difference is how active/render/clone/stencil indices are handled here.

normally they're being set from pdata which totally makes sense for meshes which are already converted to BMesh structures, but when loading older files indices shall be updated in other way around, so newly added pdata and ldata would have this indices set based on fdata layer.

this is normally only needed when reading older files, in all other cases BKE_mesh_convert_mfaces_to_mpolys shall be always used.

Definition at line 337 of file mesh_legacy_convert.cc.

References BKE_mesh_update_customdata_pointers(), convert_mfaces_to_mpolys(), CustomData_bmesh_do_versions_update_active_layers(), Mesh::fdata, Mesh::id, Mesh::ldata, Mesh::medge, mesh, Mesh::mface, Mesh::mloop, Mesh::mpoly, Mesh::pdata, Mesh::totedge, Mesh::totface, Mesh::totloop, and Mesh::totpoly.

Referenced by do_versions_after_linking_280().

◆ BKE_mesh_mface_index_validate()

int BKE_mesh_mface_index_validate ( struct MFace mface,
struct CustomData mfdata,
int  mfindex,
int  nr 
)

Rotates the vertices of a face in case v[2] or v[3] (vertex index) is = 0. this is necessary to make the if MFace.v4 check for quads work.

Definition at line 470 of file mesh_legacy_convert.cc.

References CustomData_swap_corners(), SWAP, MFace::v1, MFace::v2, MFace::v3, and MFace::v4.

Referenced by cutEdges(), explodeMesh(), and mesh_tessface_calc().

◆ BKE_mesh_tessface_calc()

void BKE_mesh_tessface_calc ( struct Mesh mesh)

Recreate MFace Tessellation.

Note
This doesn't use multi-threading like BKE_mesh_recalc_looptri since it's not used in many places and MFace should be phased out.

Definition at line 781 of file mesh_legacy_convert.cc.

References BKE_mesh_update_customdata_pointers(), Mesh::fdata, Mesh::ldata, mesh, mesh_tessface_calc(), Mesh::mvert, Mesh::pdata, Mesh::totface, Mesh::totloop, and Mesh::totpoly.

Referenced by BKE_mesh_tessface_ensure(), and blender::ed::curves::convert_to_particle_system::try_convert_single_object().

◆ BKE_mesh_tessface_ensure()

void BKE_mesh_tessface_ensure ( struct Mesh mesh)

◆ bm_corners_to_loops_ex()

static void bm_corners_to_loops_ex ( ID id,
CustomData fdata,
CustomData ldata,
MFace mface,
int  totloop,
int  findex,
int  loopstart,
int  numTex,
int  numCol 
)
static

◆ check_matching_legacy_layer_counts()

static bool check_matching_legacy_layer_counts ( CustomData fdata,
CustomData ldata,
bool  fallback 
)
static

Debug check, used to assert when we expect layers to be in/out of sync.

Parameters
fallbackUse when there are no layers to handle, since callers may expect success or failure.

Definition at line 808 of file mesh_legacy_convert.cc.

References CD_MCOL, CD_MLOOPUV, CD_MTFACE, CD_NORMAL, CD_ORIGSPACE, CD_ORIGSPACE_MLOOP, CD_PREVIEW_MCOL, CD_PREVIEW_MLOOPCOL, CD_PROP_BYTE_COLOR, CD_TANGENT, CD_TESSLOOPNORMAL, and LAYER_CMP.

Referenced by BKE_mesh_add_mface_layers().

◆ convert_mfaces_to_mpolys()

static void convert_mfaces_to_mpolys ( ID id,
CustomData fdata,
CustomData ldata,
CustomData pdata,
int  totedge_i,
int  totface_i,
int  totloop_i,
int  totpoly_i,
MEdge medge,
MFace mface,
int *  r_totloop,
int *  r_totpoly,
MLoop **  r_mloop,
MPoly **  r_mpoly 
)
static

◆ CustomData_bmesh_do_versions_update_active_layers()

static void CustomData_bmesh_do_versions_update_active_layers ( CustomData fdata,
CustomData ldata 
)
static

Update active indices for active/render/clone/stencil custom data layers based on indices from fdata layers used when creating pdata and ldata for pre-bmesh meshes and needed to preserve active/render/clone/stencil flags set in pre-bmesh files.

Definition at line 304 of file mesh_legacy_convert.cc.

References CD_MCOL, CD_MLOOPUV, CD_MTFACE, CD_PROP_BYTE_COLOR, CustomData_get_active_layer(), CustomData_get_clone_layer(), CustomData_get_render_layer(), CustomData_get_stencil_layer(), CustomData_has_layer(), CustomData_set_layer_active(), CustomData_set_layer_clone(), CustomData_set_layer_render(), and CustomData_set_layer_stencil().

Referenced by BKE_mesh_do_versions_convert_mfaces_to_mpolys().

◆ CustomData_to_bmeshpoly()

static void CustomData_to_bmeshpoly ( CustomData fdata,
CustomData ldata,
int  totloop 
)
static

◆ mesh_loops_to_tessdata()

static void mesh_loops_to_tessdata ( CustomData fdata,
CustomData ldata,
MFace mface,
const int *  polyindices,
uint(*)  loopindices[4],
const int  num_faces 
)
static

Convert all CD layers from loop/poly to tessface data.

Parameters
loopindicesis an array of an int[4] per tessface, mapping tessface's verts to loops indices.
Note
when mface is not null, mface[face_index].v4 is used to test quads, else, loopindices[face_index][3] is used.

Definition at line 376 of file mesh_legacy_convert.cc.

References CD_MCOL, CD_MLOOPUV, CD_MTFACE, CD_NORMAL, CD_ORIGSPACE, CD_ORIGSPACE_MLOOP, CD_PREVIEW_MCOL, CD_PREVIEW_MLOOPCOL, CD_PROP_BYTE_COLOR, CD_TANGENT, CD_TESSLOOPNORMAL, copy_v2_v2(), copy_v4_v4(), CustomData_get_layer(), CustomData_get_layer_n(), CustomData_has_layer(), CustomData_number_of_layers(), float(), MESH_MLOOPCOL_TO_MCOL, normal_float_to_short_v3(), MLoopUV::uv, OrigSpaceLoop::uv, OrigSpaceFace::uv, MTFace::uv, and MFace::v4.

Referenced by mesh_tessface_calc().

◆ mesh_tessface_calc()

static int mesh_tessface_calc ( CustomData fdata,
CustomData ldata,
CustomData pdata,
MVert mvert,
int  totface,
int  totloop,
int  totpoly 
)
static