Blender V4.3
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 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 totloop_i, int faces_num_i, 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 823 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]; \
/* Set loop indices, transformed to vert indices later. */ \
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]; \
/* 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 = 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()

void BKE_mesh_do_versions_cd_flag_init ( Mesh * mesh)

Definition at line 282 of file mesh_legacy_convert.cc.

References CustomData_get_layer(), UNLIKELY, and verts.

Referenced by blo_do_versions_260().

◆ 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 793 of file mesh_legacy_convert.cc.

References BKE_mesh_legacy_convert_loops_to_corners(), BKE_mesh_legacy_convert_polys_to_offsets(), CD_MFACE, convert_mfaces_to_mpolys(), CustomData_bmesh_do_versions_update_active_layers(), CustomData_get_layer(), and mesh_ensure_tessellation_customdata().

Referenced by do_versions_after_linking_280().

◆ BKE_mesh_legacy_attribute_flags_to_strings()

void BKE_mesh_legacy_attribute_flags_to_strings ( Mesh * mesh)

◆ 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 1476 of file mesh_legacy_convert.cc.

References CD_PROP_FLOAT, and replace_custom_data_layer_with_named().

Referenced by blo_do_versions_400().

◆ BKE_mesh_legacy_bevel_weight_to_layers()

void BKE_mesh_legacy_bevel_weight_to_layers ( Mesh * mesh)

Copy bevel weights from vertices and edges to separate layers.

Definition at line 1421 of file mesh_legacy_convert.cc.

References CD_CONSTRUCT, CustomData_add_layer(), CustomData_has_layer(), and verts.

Referenced by version_mesh_legacy_to_struct_of_array_format().

◆ 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)

Convert the old hide flags (#ME_HIDE) to the hidden element attribute for reading. Only add the attributes when there are any elements in each domain hidden.

Definition at line 1597 of file mesh_legacy_convert.cc.

References blender::bke::SpanAttributeWriter< T >::finish(), and verts.

Referenced by version_mesh_legacy_to_struct_of_array_format().

◆ BKE_mesh_legacy_convert_flags_to_selection_layers()

void BKE_mesh_legacy_convert_flags_to_selection_layers ( Mesh * mesh)

Convert the old selection flags (SELECT/#ME_FACE_SEL) to the selected element attribute for reading. Only add the attributes when there are any elements in each domain selected.

Definition at line 1825 of file mesh_legacy_convert.cc.

References blender::bke::SpanAttributeWriter< T >::finish(), and verts.

Referenced by version_mesh_legacy_to_struct_of_array_format().

◆ BKE_mesh_legacy_convert_loops_to_corners()

◆ BKE_mesh_legacy_convert_mpoly_to_material_indices()

void BKE_mesh_legacy_convert_mpoly_to_material_indices ( Mesh * mesh)

Move material indices from the #MPoly to a generic attributes. Only add the attribute when the indices are not all zero.

Definition at line 1663 of file mesh_legacy_convert.cc.

References blender::Span< T >::begin(), CustomData_get_layer(), CustomData_has_layer(), blender::Span< T >::end(), blender::bke::SpanAttributeWriter< T >::finish(), and blender::Span< T >::index_range().

Referenced by version_mesh_legacy_to_struct_of_array_format().

◆ BKE_mesh_legacy_convert_polys_to_offsets()

◆ BKE_mesh_legacy_convert_uvs_to_generic()

◆ BKE_mesh_legacy_convert_verts_to_positions()

void BKE_mesh_legacy_convert_verts_to_positions ( Mesh * mesh)

◆ 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)

Copy edge creases from edges to a separate layer.

Definition at line 1494 of file mesh_legacy_convert.cc.

References CD_CONSTRUCT, CustomData_add_layer(), and CustomData_has_layer().

Referenced by version_mesh_legacy_to_struct_of_array_format().

◆ BKE_mesh_legacy_face_map_to_generic()

void BKE_mesh_legacy_face_map_to_generic ( Main * bmain)

◆ BKE_mesh_legacy_face_set_to_generic()

void BKE_mesh_legacy_face_set_to_generic ( Mesh * mesh)

◆ BKE_mesh_legacy_sharp_edges_from_flags()

void BKE_mesh_legacy_sharp_edges_from_flags ( Mesh * mesh)

◆ BKE_mesh_legacy_sharp_faces_from_flags()

◆ BKE_mesh_legacy_uv_seam_from_flags()

void BKE_mesh_legacy_uv_seam_from_flags ( Mesh * mesh)

◆ 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 932 of file mesh_legacy_convert.cc.

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

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

◆ BKE_mesh_strip_loose_faces()

void BKE_mesh_strip_loose_faces ( Mesh * mesh)

◆ BKE_mesh_tessface_calc()

void BKE_mesh_tessface_calc ( Mesh * mesh)

◆ BKE_mesh_tessface_ensure()

◆ bm_corners_to_loops_ex()

◆ check_matching_legacy_layer_counts()

static 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 627 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, LAYER_CMP, and true.

Referenced by add_mface_layers().

◆ convert_mfaces_to_mpolys()

◆ CustomData_bmesh_do_versions_update_active_layers()

static 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 759 of file mesh_legacy_convert.cc.

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

◆ mesh_calc_edges_mdata()

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 )
static

◆ mesh_ensure_tessellation_customdata()

◆ mesh_loops_to_tessdata()

static 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 843 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(), float, MESH_MLOOPCOL_TO_MCOL, normal_float_to_short_v3(), MTFace::uv, OrigSpaceLoop::uv, and MFace::v4.

Referenced by mesh_tessface_calc().

◆ mesh_tessface_calc()

◆ move_face_map_data_to_attributes()

◆ poly_loops_orders_match()

static bool poly_loops_orders_match ( const Span< MPoly > polys)
static

◆ replace_custom_data_layer_with_named()

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 )
static

◆ to_edgesort()

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

Definition at line 63 of file mesh_legacy_convert.cc.

References EdgeSort::is_draw, EdgeSort::is_loose, EdgeSort::v1, EdgeSort::v2, and v2.

Referenced by mesh_calc_edges_mdata().

◆ update_active_fdata_layers()

◆ vergedgesort()

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

Definition at line 77 of file mesh_legacy_convert.cc.

References EdgeSort::v1, EdgeSort::v2, and v2.

Referenced by mesh_calc_edges_mdata().