Blender V4.5
mesh_legacy_convert.cc File Reference
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "BLI_array_utils.hh"
#include "BLI_listbase.h"
#include "BLI_map.hh"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector_types.hh"
#include "BLI_memarena.h"
#include "BLI_multi_value_map.hh"
#include "BLI_polyfill_2d.h"
#include "BLI_string.h"
#include "BLI_task.hh"
#include "BLI_utildefines.h"
#include "BKE_attribute.hh"
#include "BKE_customdata.hh"
#include "BKE_global.hh"
#include "BKE_idprop.hh"
#include "BKE_lib_id.hh"
#include "BKE_main.hh"
#include "BKE_main_namemap.hh"
#include "BKE_mesh.hh"
#include "BKE_mesh_legacy_convert.hh"
#include "BKE_modifier.hh"
#include "BKE_multires.hh"
#include "BKE_node.hh"
#include "BKE_node_runtime.hh"
#include "BKE_node_tree_update.hh"
#include "BLT_translation.hh"

Go to the source code of this file.

Classes

struct  EdgeSort

Namespaces

namespace  blender
namespace  blender::bke

Macros

#define DNA_DEPRECATED_ALLOW
#define ML(v1, v2)
#define LAYER_CMP(l_a, t_a, l_b, t_b)
#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()

Functions

static bNodeTreeblender::bke::add_auto_smooth_node_tree (Main &bmain, Library *owner_library)
static VectorSet< const bNodeSocket * > blender::bke::build_socket_indices (const Span< const bNode * > nodes)
static bool blender::bke::is_auto_smooth_node_tree (const bNodeTree &group)
static ModifierDatablender::bke::create_auto_smooth_modifier (Object &object, const FunctionRef< bNodeTree *(Library *owner_library)> get_node_group, const float angle)
void blender::bke::mesh_sculpt_mask_to_legacy (MutableSpan< CustomDataLayer > vert_layers)
void blender::bke::mesh_sculpt_mask_to_generic (Mesh &mesh)
void blender::bke::mesh_custom_normals_to_legacy (MutableSpan< CustomDataLayer > corner_layers)
void blender::bke::mesh_custom_normals_to_generic (Mesh &mesh)
void BKE_mesh_calc_edges_tessface (Mesh *mesh)
Legacy Edge Calculation
static void to_edgesort (EdgeSort *ed, uint v1, uint v2, char is_loose, short is_draw)
static int vergedgesort (const void *v1, const void *v2)
static void mesh_calc_edges_mdata (const MVert *, const MFace *allface, MLoop *allloop, const MPoly *allpoly, int, int totface, int, int faces_num, MEdge **r_medge, int *r_totedge)
void BKE_mesh_calc_edges_legacy (Mesh *mesh)
void BKE_mesh_strip_loose_faces (Mesh *mesh)
CD Flag Initialization
void BKE_mesh_do_versions_cd_flag_init (Mesh *mesh)
Sharp Edge Conversion
void BKE_mesh_legacy_sharp_faces_from_flags (Mesh *mesh)
void BKE_mesh_legacy_sharp_edges_from_flags (Mesh *mesh)
Face Set Conversion
void BKE_mesh_legacy_face_set_to_generic (Mesh *mesh)
Face Map Conversion
static void move_face_map_data_to_attributes (Mesh *mesh)
void BKE_mesh_legacy_face_map_to_generic (Main *bmain)
Bevel Weight Conversion
void BKE_mesh_legacy_bevel_weight_to_layers (Mesh *mesh)
static void replace_custom_data_layer_with_named (CustomData &custom_data, const eCustomDataType old_type, const eCustomDataType new_type, const int elems_num, const char *new_name)
void BKE_mesh_legacy_bevel_weight_to_generic (Mesh *mesh)
Crease Conversion
void BKE_mesh_legacy_edge_crease_to_layers (Mesh *mesh)
void BKE_mesh_legacy_crease_to_generic (Mesh *mesh)
UV Seam Conversion
void BKE_mesh_legacy_uv_seam_from_flags (Mesh *mesh)
Hide Attribute and Legacy Flag Conversion
void BKE_mesh_legacy_convert_flags_to_hide_layers (Mesh *mesh)
Material Index Conversion
void BKE_mesh_legacy_convert_mpoly_to_material_indices (Mesh *mesh)
Generic UV Map Conversion
void BKE_mesh_legacy_convert_uvs_to_generic (Mesh *mesh)
Selection Attribute and Legacy Flag Conversion
void BKE_mesh_legacy_convert_flags_to_selection_layers (Mesh *mesh)
Vertex and Position Conversion
void BKE_mesh_legacy_convert_verts_to_positions (Mesh *mesh)
MEdge and int2 conversion
void BKE_mesh_legacy_convert_edges_to_generic (Mesh *mesh)
Attribute Active Flag to String Conversion
void BKE_mesh_legacy_attribute_flags_to_strings (Mesh *mesh)
Face Corner Conversion
void BKE_mesh_legacy_convert_loops_to_corners (Mesh *mesh)
Poly Offset Conversion
static bool poly_loops_orders_match (const Span< MPoly > polys)
void BKE_mesh_legacy_convert_polys_to_offsets (Mesh *mesh)
Auto Smooth Conversion
void BKE_main_mesh_legacy_convert_auto_smooth (Main &bmain)

NGon Tessellation (NGon to MFace Conversion)

#define MESH_MLOOPCOL_FROM_MCOL(_mloopcol, _mcol)
static void bm_corners_to_loops_ex (ID *id, CustomData *fdata_legacy, const int totface, CustomData *ldata, MFace *mface, int totloop, int findex, int loopstart, int numTex, int numCol)
static void CustomData_to_bmeshpoly (CustomData *fdata_legacy, CustomData *ldata, int totloop)
static void convert_mfaces_to_mpolys (ID *id, CustomData *fdata_legacy, CustomData *ldata, CustomData *pdata, int totedge_i, int totface_i, int, int, blender::int2 *edges, MFace *mface, int *r_totloop, int *r_faces_num)
static void update_active_fdata_layers (Mesh &mesh, CustomData *fdata_legacy, CustomData *ldata)
static bool check_matching_legacy_layer_counts (CustomData *fdata_legacy, CustomData *ldata, bool fallback)
static void add_mface_layers (Mesh &mesh, CustomData *fdata_legacy, CustomData *ldata, int total)
static void mesh_ensure_tessellation_customdata (Mesh *mesh)
void BKE_mesh_convert_mfaces_to_mpolys (Mesh *mesh)
static void CustomData_bmesh_do_versions_update_active_layers (CustomData *fdata_legacy, CustomData *corner_data)
void BKE_mesh_do_versions_convert_mfaces_to_mpolys (Mesh *mesh)

MFace Tessellation

MFace is a legacy data-structure that should be avoided, use #Mesh::corner_tris() instead.

#define MESH_MLOOPCOL_TO_MCOL(_mloopcol, _mcol)
static void mesh_loops_to_tessdata (CustomData *fdata_legacy, CustomData *corner_data, MFace *mface, const int *polyindices, uint(*loopindices)[4], const int num_faces)
int BKE_mesh_mface_index_validate (MFace *mface, CustomData *fdata_legacy, int mfindex, int nr)
static int mesh_tessface_calc (Mesh &mesh, CustomData *fdata_legacy, CustomData *ldata, CustomData *pdata, float(*positions)[3], int totface, int totloop, int faces_num)
void BKE_mesh_tessface_calc (Mesh *mesh)
void BKE_mesh_tessface_ensure (Mesh *mesh)

Detailed Description

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

Definition in file mesh_legacy_convert.cc.

Macro Definition Documentation

◆ DNA_DEPRECATED_ALLOW

#define DNA_DEPRECATED_ALLOW

Definition at line 11 of file mesh_legacy_convert.cc.

◆ 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 CustomData *data, eCustomDataType type)
ATTR_WARN_UNUSED_RESULT const BMLoop * l_b

Referenced by check_matching_legacy_layer_counts().

◆ MESH_MLOOPCOL_FROM_MCOL

#define MESH_MLOOPCOL_FROM_MCOL ( _mloopcol,
_mcol )
Value:
{ \
MLoopCol *mloopcol__tmp = _mloopcol; \
const MCol *mcol__tmp = _mcol; \
mloopcol__tmp->r = mcol__tmp->b; \
mloopcol__tmp->g = mcol__tmp->g; \
mloopcol__tmp->b = mcol__tmp->r; \
mloopcol__tmp->a = mcol__tmp->a; \
} \
(void)0
unsigned char r
unsigned char a
unsigned char g
unsigned char b
unsigned char a
unsigned char b
unsigned char r
unsigned char g

Definition at line 325 of file mesh_legacy_convert.cc.

Referenced by bm_corners_to_loops_ex().

◆ MESH_MLOOPCOL_TO_MCOL

#define MESH_MLOOPCOL_TO_MCOL ( _mloopcol,
_mcol )
Value:
{ \
const MLoopCol *mloopcol__tmp = _mloopcol; \
MCol *mcol__tmp = _mcol; \
mcol__tmp->b = mloopcol__tmp->r; \
mcol__tmp->g = mloopcol__tmp->g; \
mcol__tmp->r = mloopcol__tmp->b; \
mcol__tmp->a = mloopcol__tmp->a; \
} \
(void)0

Definition at line 828 of file mesh_legacy_convert.cc.

Referenced by mesh_loops_to_tessdata().

◆ ML

#define ML ( v1,
v2 )
Value:
{ \
ml->v = mf->v1; \
ml->e = eh.lookup({mf->v1, mf->v2}); \
ml++; \
j++; \
} \
(void)0

Referenced by convert_mfaces_to_mpolys().

◆ 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]; \
\
l1 = mp_loopstart + i1; \
l2 = mp_loopstart + i2; \
l3 = mp_loopstart + i3; \
mf->v1 = corner_verts[l1]; \
mf->v2 = corner_verts[l2]; \
mf->v3 = corner_verts[l3]; \
mf->v4 = 0; \
lidx[0] = l1; \
lidx[1] = l2; \
lidx[2] = l3; \
lidx[3] = 0; \
mf->mat_nr = material_indices ? material_indices[poly_index] : 0; \
mf->flag = (sharp_faces && sharp_faces[poly_index]) ? 0 : ME_SMOOTH; \
mf->edcode = 0; \
(void)0

Referenced by mesh_tessface_calc().

◆ 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]; \
\
l1 = mp_loopstart + 0; \
l2 = mp_loopstart + 1; \
l3 = mp_loopstart + 2; \
l4 = mp_loopstart + 3; \
mf->v1 = corner_verts[l1]; \
mf->v2 = corner_verts[l2]; \
mf->v3 = corner_verts[l3]; \
mf->v4 = corner_verts[l4]; \
lidx[0] = l1; \
lidx[1] = l2; \
lidx[2] = l3; \
lidx[3] = l4; \
mf->mat_nr = material_indices ? material_indices[poly_index] : 0; \
mf->flag = (sharp_faces && sharp_faces[poly_index]) ? 0 : ME_SMOOTH; \
mf->edcode = TESSFACE_IS_QUAD; \
(void)0
#define TESSFACE_IS_QUAD

Referenced by mesh_tessface_calc().

◆ TESSFACE_IS_QUAD

#define TESSFACE_IS_QUAD   1

Referenced by mesh_tessface_calc().

◆ USE_TESSFACE_QUADS

#define USE_TESSFACE_QUADS

◆ USE_TESSFACE_SPEEDUP

#define USE_TESSFACE_SPEEDUP

Function Documentation

◆ add_mface_layers()

◆ BKE_main_mesh_legacy_convert_auto_smooth()

◆ BKE_mesh_calc_edges_legacy()

◆ BKE_mesh_calc_edges_tessface()

◆ BKE_mesh_convert_mfaces_to_mpolys()

◆ BKE_mesh_do_versions_cd_flag_init()

◆ BKE_mesh_do_versions_convert_mfaces_to_mpolys()

void BKE_mesh_do_versions_convert_mfaces_to_mpolys ( Mesh * mesh)

The same as BKE_mesh_convert_mfaces_to_mpolys but oriented to be used in #do_versions from readfile.cc 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 pdata 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 798 of file mesh_legacy_convert.cc.

References BKE_mesh_do_versions_convert_mfaces_to_mpolys(), BKE_mesh_legacy_convert_loops_to_corners(), BKE_mesh_legacy_convert_polys_to_offsets(), CD_MFACE, convert_mfaces_to_mpolys(), Mesh::corner_data, Mesh::corners_num, CustomData_bmesh_do_versions_update_active_layers(), CustomData_get_layer(), Mesh::edges_num, Mesh::face_data, Mesh::faces_num, Mesh::fdata_legacy, Mesh::id, mesh_ensure_tessellation_customdata(), and Mesh::totface_legacy.

Referenced by BKE_mesh_do_versions_convert_mfaces_to_mpolys(), and do_versions_after_linking_280().

◆ BKE_mesh_legacy_attribute_flags_to_strings()

◆ BKE_mesh_legacy_bevel_weight_to_generic()

void BKE_mesh_legacy_bevel_weight_to_generic ( Mesh * mesh)

Move bevel weight to generic float attribute type.

Definition at line 1480 of file mesh_legacy_convert.cc.

References BKE_mesh_legacy_bevel_weight_to_generic(), CD_PROP_FLOAT, and replace_custom_data_layer_with_named().

Referenced by BKE_mesh_legacy_bevel_weight_to_generic(), and blo_do_versions_400().

◆ BKE_mesh_legacy_bevel_weight_to_layers()

void BKE_mesh_legacy_bevel_weight_to_layers ( Mesh * mesh)

◆ BKE_mesh_legacy_convert_edges_to_generic()

◆ BKE_mesh_legacy_convert_flags_to_hide_layers()

void BKE_mesh_legacy_convert_flags_to_hide_layers ( Mesh * mesh)

◆ BKE_mesh_legacy_convert_flags_to_selection_layers()

void BKE_mesh_legacy_convert_flags_to_selection_layers ( Mesh * mesh)

◆ BKE_mesh_legacy_convert_loops_to_corners()

◆ BKE_mesh_legacy_convert_mpoly_to_material_indices()

◆ BKE_mesh_legacy_convert_polys_to_offsets()

◆ BKE_mesh_legacy_convert_uvs_to_generic()

◆ BKE_mesh_legacy_convert_verts_to_positions()

◆ BKE_mesh_legacy_crease_to_generic()

void BKE_mesh_legacy_crease_to_generic ( Mesh * mesh)

◆ BKE_mesh_legacy_edge_crease_to_layers()

void BKE_mesh_legacy_edge_crease_to_layers ( Mesh * mesh)

◆ BKE_mesh_legacy_face_map_to_generic()

◆ BKE_mesh_legacy_face_set_to_generic()

◆ BKE_mesh_legacy_sharp_edges_from_flags()

◆ BKE_mesh_legacy_sharp_faces_from_flags()

◆ BKE_mesh_legacy_uv_seam_from_flags()

◆ BKE_mesh_mface_index_validate()

int BKE_mesh_mface_index_validate ( MFace * mface,
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 937 of file mesh_legacy_convert.cc.

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

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

◆ BKE_mesh_strip_loose_faces()

◆ BKE_mesh_tessface_calc()

◆ BKE_mesh_tessface_ensure()

◆ bm_corners_to_loops_ex()

◆ check_matching_legacy_layer_counts()

bool check_matching_legacy_layer_counts ( CustomData * fdata_legacy,
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 632 of file mesh_legacy_convert.cc.

References CD_MCOL, CD_MTFACE, CD_NORMAL, CD_ORIGSPACE, CD_ORIGSPACE_MLOOP, CD_PROP_BYTE_COLOR, CD_PROP_FLOAT2, CD_TANGENT, CD_TESSLOOPNORMAL, check_matching_legacy_layer_counts(), LAYER_CMP, and true.

Referenced by add_mface_layers(), and check_matching_legacy_layer_counts().

◆ convert_mfaces_to_mpolys()

◆ CustomData_bmesh_do_versions_update_active_layers()

void CustomData_bmesh_do_versions_update_active_layers ( CustomData * fdata_legacy,
CustomData * corner_data )
static

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

Definition at line 764 of file mesh_legacy_convert.cc.

References CD_MCOL, CD_MTFACE, CD_PROP_BYTE_COLOR, CD_PROP_FLOAT2, CustomData_bmesh_do_versions_update_active_layers(), 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(), and CustomData_bmesh_do_versions_update_active_layers().

◆ CustomData_to_bmeshpoly()

◆ mesh_calc_edges_mdata()

void mesh_calc_edges_mdata ( const MVert * ,
const MFace * allface,
MLoop * allloop,
const MPoly * allpoly,
int ,
int totface,
int ,
int faces_num,
MEdge ** r_medge,
int * r_totedge )
static

◆ mesh_ensure_tessellation_customdata()

◆ mesh_loops_to_tessdata()

void mesh_loops_to_tessdata ( CustomData * fdata_legacy,
CustomData * corner_data,
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 848 of file mesh_legacy_convert.cc.

References CD_MCOL, CD_MTFACE, CD_NORMAL, CD_ORIGSPACE, CD_ORIGSPACE_MLOOP, CD_PROP_BYTE_COLOR, CD_PROP_FLOAT2, CD_TANGENT, CD_TESSLOOPNORMAL, copy_v2_v2(), copy_v4_v4(), CustomData_get_layer(), CustomData_get_layer_n(), CustomData_get_layer_n_for_write(), CustomData_has_layer(), CustomData_number_of_layers(), i, mesh_loops_to_tessdata(), MESH_MLOOPCOL_TO_MCOL, normal_float_to_short_v3(), MTFace::uv, OrigSpaceFace::uv, OrigSpaceLoop::uv, and MFace::v4.

Referenced by mesh_loops_to_tessdata(), and mesh_tessface_calc().

◆ mesh_tessface_calc()

◆ move_face_map_data_to_attributes()

◆ poly_loops_orders_match()

bool poly_loops_orders_match ( const Span< MPoly > polys)
static

◆ replace_custom_data_layer_with_named()

◆ to_edgesort()

void to_edgesort ( EdgeSort * ed,
uint v1,
uint v2,
char is_loose,
short is_draw )
static

◆ update_active_fdata_layers()

◆ vergedgesort()

int vergedgesort ( const void * v1,
const void * v2 )
static

Definition at line 77 of file mesh_legacy_convert.cc.

References EdgeSort::v1, EdgeSort::v2, v2, and vergedgesort().

Referenced by mesh_calc_edges_mdata(), and vergedgesort().