[Bf-blender-cvs] [253c5d25f79] master: Cleanup: move mesh tessellation into it's own file
Campbell Barton
noreply at git.blender.org
Fri Jun 18 08:36:25 CEST 2021
Commit: 253c5d25f79f08e8801778bc7d36403c9419901d
Author: Campbell Barton
Date: Fri Jun 18 14:38:25 2021 +1000
Branches: master
https://developer.blender.org/rB253c5d25f79f08e8801778bc7d36403c9419901d
Cleanup: move mesh tessellation into it's own file
This matches BMesh which also has tessellation in it's own file.
Using a separate file helps with organization when
extracting code into smaller functions.
===================================================================
M source/blender/blenkernel/BKE_mesh.h
M source/blender/blenkernel/CMakeLists.txt
M source/blender/blenkernel/intern/mesh.c
M source/blender/blenkernel/intern/mesh_evaluate.c
A source/blender/blenkernel/intern/mesh_tessellate.c
M source/blender/bmesh/intern/bmesh_mesh_tessellate.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index c24e87b3788..2a1fbc8273b 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -247,7 +247,6 @@ bool BKE_mesh_minmax(const struct Mesh *me, float r_min[3], float r_max[3]);
void BKE_mesh_transform(struct Mesh *me, const float mat[4][4], bool do_keys);
void BKE_mesh_translate(struct Mesh *me, const float offset[3], const bool do_keys);
-void BKE_mesh_tessface_calc(struct Mesh *mesh);
void BKE_mesh_tessface_ensure(struct Mesh *mesh);
void BKE_mesh_tessface_clear(struct Mesh *mesh);
@@ -270,6 +269,32 @@ void BKE_mesh_vert_coords_apply_with_mat4(struct Mesh *mesh,
void BKE_mesh_vert_coords_apply(struct Mesh *mesh, const float (*vert_coords)[3]);
void BKE_mesh_vert_normals_apply(struct Mesh *mesh, const short (*vert_normals)[3]);
+/* *** mesh_tessellate.c *** */
+
+void BKE_mesh_loops_to_tessdata(struct CustomData *fdata,
+ struct CustomData *ldata,
+ struct MFace *mface,
+ const int *polyindices,
+ unsigned int (*loopindices)[4],
+ const int num_faces);
+
+int BKE_mesh_tessface_calc_ex(struct CustomData *fdata,
+ struct CustomData *ldata,
+ struct CustomData *pdata,
+ struct MVert *mvert,
+ int totface,
+ int totloop,
+ int totpoly,
+ const bool do_face_nor_copy);
+void BKE_mesh_tessface_calc(struct Mesh *mesh);
+
+void BKE_mesh_recalc_looptri(const struct MLoop *mloop,
+ const struct MPoly *mpoly,
+ const struct MVert *mvert,
+ int totloop,
+ int totpoly,
+ struct MLoopTri *mlooptri);
+
/* *** mesh_evaluate.c *** */
void BKE_mesh_calc_normals_mapping_simple(struct Mesh *me);
@@ -521,12 +546,6 @@ void BKE_mesh_loops_to_mface_corners(struct CustomData *fdata,
const bool hasPCol,
const bool hasOrigSpace,
const bool hasLNor);
-void BKE_mesh_loops_to_tessdata(struct CustomData *fdata,
- struct CustomData *ldata,
- struct MFace *mface,
- const int *polyindices,
- unsigned int (*loopindices)[4],
- const int num_faces);
void BKE_mesh_tangent_loops_to_tessdata(struct CustomData *fdata,
struct CustomData *ldata,
struct MFace *mface,
@@ -534,20 +553,6 @@ void BKE_mesh_tangent_loops_to_tessdata(struct CustomData *fdata,
unsigned int (*loopindices)[4],
const int num_faces,
const char *layer_name);
-int BKE_mesh_tessface_calc_ex(struct CustomData *fdata,
- struct CustomData *ldata,
- struct CustomData *pdata,
- struct MVert *mvert,
- int totface,
- int totloop,
- int totpoly,
- const bool do_face_nor_copy);
-void BKE_mesh_recalc_looptri(const struct MLoop *mloop,
- const struct MPoly *mpoly,
- const struct MVert *mvert,
- int totloop,
- int totpoly,
- struct MLoopTri *mlooptri);
void BKE_mesh_convert_mfaces_to_mpolys(struct Mesh *mesh);
void BKE_mesh_do_versions_convert_mfaces_to_mpolys(struct Mesh *mesh);
void BKE_mesh_convert_mfaces_to_mpolys_ex(struct ID *id,
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 021d7e15814..0f36887b234 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -194,6 +194,7 @@ set(SRC
intern/mesh_runtime.c
intern/mesh_sample.cc
intern/mesh_tangent.c
+ intern/mesh_tessellate.c
intern/mesh_validate.c
intern/mesh_validate.cc
intern/mesh_wrapper.c
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 0068821bab0..b70fea459f6 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -1554,22 +1554,6 @@ void BKE_mesh_translate(Mesh *me, const float offset[3], const bool do_keys)
}
}
-void BKE_mesh_tessface_calc(Mesh *mesh)
-{
- mesh->totface = BKE_mesh_tessface_calc_ex(
- &mesh->fdata,
- &mesh->ldata,
- &mesh->pdata,
- mesh->mvert,
- mesh->totface,
- mesh->totloop,
- mesh->totpoly,
- /* calc normals right after, don't copy from polys here */
- false);
-
- BKE_mesh_update_customdata_pointers(mesh, true);
-}
-
void BKE_mesh_tessface_ensure(Mesh *mesh)
{
if (mesh->totpoly && mesh->totface == 0) {
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index 2ce6e1f15f0..56f820848cb 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -40,7 +40,6 @@
#include "BLI_linklist_stack.h"
#include "BLI_math.h"
#include "BLI_memarena.h"
-#include "BLI_polyfill_2d.h"
#include "BLI_stack.h"
#include "BLI_task.h"
#include "BLI_utildefines.h"
@@ -2858,108 +2857,6 @@ void BKE_mesh_loops_to_mface_corners(
}
}
-/**
- * Convert all CD layers from loop/poly to tessface data.
- *
- * \param loopindices: is 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.
- */
-void BKE_mesh_loops_to_tessdata(CustomData *fdata,
- CustomData *ldata,
- MFace *mface,
- const int *polyindices,
- uint (*loopindices)[4],
- const int num_faces)
-{
- /* Note: performances are sub-optimal when we get a NULL mface,
- * we could be ~25% quicker with dedicated code...
- * Issue is, unless having two different functions with nearly the same code,
- * there's not much ways to solve this. Better imho to live with it for now. :/ --mont29
- */
- const int numUV = CustomData_number_of_layers(ldata, CD_MLOOPUV);
- const int numCol = CustomData_number_of_layers(ldata, CD_MLOOPCOL);
- const bool hasPCol = CustomData_has_layer(ldata, CD_PREVIEW_MLOOPCOL);
- const bool hasOrigSpace = CustomData_has_layer(ldata, CD_ORIGSPACE_MLOOP);
- const bool hasLoopNormal = CustomData_has_layer(ldata, CD_NORMAL);
- const bool hasLoopTangent = CustomData_has_layer(ldata, CD_TANGENT);
- int findex, i, j;
- const int *pidx;
- uint(*lidx)[4];
-
- for (i = 0; i < numUV; i++) {
- MTFace *texface = CustomData_get_layer_n(fdata, CD_MTFACE, i);
- MLoopUV *mloopuv = CustomData_get_layer_n(ldata, CD_MLOOPUV, i);
-
- for (findex = 0, pidx = polyindices, lidx = loopindices; findex < num_faces;
- pidx++, lidx++, findex++, texface++) {
- for (j = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; j--;) {
- copy_v2_v2(texface->uv[j], mloopuv[(*lidx)[j]].uv);
- }
- }
- }
-
- for (i = 0; i < numCol; i++) {
- MCol(*mcol)[4] = CustomData_get_layer_n(fdata, CD_MCOL, i);
- MLoopCol *mloopcol = CustomData_get_layer_n(ldata, CD_MLOOPCOL, i);
-
- for (findex = 0, lidx = loopindices; findex < num_faces; lidx++, findex++, mcol++) {
- for (j = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; j--;) {
- MESH_MLOOPCOL_TO_MCOL(&mloopcol[(*lidx)[j]], &(*mcol)[j]);
- }
- }
- }
-
- if (hasPCol) {
- MCol(*mcol)[4] = CustomData_get_layer(fdata, CD_PREVIEW_MCOL);
- MLoopCol *mloopcol = CustomData_get_layer(ldata, CD_PREVIEW_MLOOPCOL);
-
- for (findex = 0, lidx = loopindices; findex < num_faces; lidx++, findex++, mcol++) {
- for (j = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; j--;) {
- MESH_MLOOPCOL_TO_MCOL(&mloopcol[(*lidx)[j]], &(*mcol)[j]);
- }
- }
- }
-
- if (hasOrigSpace) {
- OrigSpaceFace *of = CustomData_get_layer(fdata, CD_ORIGSPACE);
- OrigSpaceLoop *lof = CustomData_get_layer(ldata, CD_ORIGSPACE_MLOOP);
-
- for (findex = 0, lidx = loopindices; findex < num_faces; lidx++, findex++, of++) {
- for (j = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; j--;) {
- copy_v2_v2(of->uv[j], lof[(*lidx)[j]].uv);
- }
- }
- }
-
- if (hasLoopNormal) {
- short(*fnors)[4][3] = CustomData_get_layer(fdata, CD_TESSLOOPNORMAL);
- float(*lnors)[3] = CustomData_get_layer(ldata, CD_NORMAL);
-
- for (findex = 0, lidx = loopindices; findex < num_faces; lidx++, findex++, fnors++) {
- for (j = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; j--;) {
- normal_float_to_short_v3((*fnors)[j], lnors[(*lidx)[j]]);
- }
- }
- }
-
- if (hasLoopTangent) {
- /* need to do for all uv maps at some point */
- float(*ftangents)[4] = CustomData_get_layer(fdata, CD_TANGENT);
- float(*ltangents)[4] = CustomData_get_layer(ldata, CD_TANGENT);
-
- for (findex = 0, pidx = polyindices, lidx = loopindices; findex < num_faces;
- pidx++, lidx++, findex++) {
- int nverts = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3;
- for (j = nverts; j--;) {
- copy_v4_v4(ftangents[findex * 4 + j], ltangents[(*lidx)[j]]);
- }
- }
- }
-}
-
void BKE_mesh_tangent_loops_to_tessdata(CustomData *fdata,
CustomData *ldata,
MFace *mface,
@
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list