diff options
author | Hans Goudey <h.goudey@me.com> | 2022-07-08 06:33:57 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-07-08 06:33:57 +0300 |
commit | c4b32f1b291a3c3447879175225a3664aeb0b7ef (patch) | |
tree | b575e57a45e30e59ae469f815857f8b9e6f1acd3 /source/blender/blenkernel/BKE_mesh_legacy_convert.h | |
parent | b98a937db64c365de889adcc084248716607521d (diff) |
Cleanup: Move mesh legacy conversion to a separate file
It's helpful to make the separation of legacy data formats explicit,
because it declutters actively changed code and makes it clear which
areas do not follow Blender's current design. In this case I separated
the `MFace`/"tessface" conversion code into a separate blenkernel
.cc file and header. This also makes refactoring to remove these
functions simpler because they're easier to find.
In the future, conversions to the `MLoopUV` type and `MVert`
can be implemented here for the same reasons (see T95965).
Differential Revision: https://developer.blender.org/D15396
Diffstat (limited to 'source/blender/blenkernel/BKE_mesh_legacy_convert.h')
-rw-r--r-- | source/blender/blenkernel/BKE_mesh_legacy_convert.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_mesh_legacy_convert.h b/source/blender/blenkernel/BKE_mesh_legacy_convert.h new file mode 100644 index 00000000000..909fd0e0dea --- /dev/null +++ b/source/blender/blenkernel/BKE_mesh_legacy_convert.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2001-2002 NaN Holding BV. All rights reserved. */ + +#pragma once + +/** \file + * \ingroup bke + */ + +#include "BLI_utildefines.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct CustomData; +struct Mesh; +struct MFace; + +/** + * 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. + */ + +void BKE_mesh_tessface_calc(struct Mesh *mesh); + +void BKE_mesh_tessface_ensure(struct Mesh *mesh); + +void BKE_mesh_add_mface_layers(struct CustomData *fdata, struct CustomData *ldata, int total); + +/** + * 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. + */ +int BKE_mesh_mface_index_validate(struct MFace *mface, + struct CustomData *mfdata, + int mfindex, + int nr); + +void BKE_mesh_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. + */ +void BKE_mesh_do_versions_convert_mfaces_to_mpolys(struct Mesh *mesh); + +/* Inlines */ + +/* NOTE(@sybren): Instead of -1 that function uses ORIGINDEX_NONE as defined in BKE_customdata.h, + * but I don't want to force every user of BKE_mesh.h to also include that file. */ +BLI_INLINE int BKE_mesh_origindex_mface_mpoly(const int *index_mf_to_mpoly, + const int *index_mp_to_orig, + const int i) +{ + const int j = index_mf_to_mpoly[i]; + return (j != -1) ? (index_mp_to_orig ? index_mp_to_orig[j] : j) : -1; +} + +#ifdef __cplusplus +} +#endif |