[Bf-blender-cvs] [c1eeb38f7c8] master: Cleanup: Move poly normal calculation to mesh_normals.cc
Hans Goudey
noreply at git.blender.org
Wed Nov 23 16:58:13 CET 2022
Commit: c1eeb38f7c823bf8cf090b98ead117a3d22a06ab
Author: Hans Goudey
Date: Wed Nov 23 09:49:04 2022 -0600
Branches: master
https://developer.blender.org/rBc1eeb38f7c823bf8cf090b98ead117a3d22a06ab
Cleanup: Move poly normal calculation to mesh_normals.cc
===================================================================
M source/blender/blenkernel/BKE_mesh.h
M source/blender/blenkernel/intern/mesh_evaluate.cc
M source/blender/blenkernel/intern/mesh_normals.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 2a06409429e..1b327e11a53 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -432,6 +432,15 @@ bool BKE_mesh_vertex_normals_are_dirty(const struct Mesh *mesh);
*/
bool BKE_mesh_poly_normals_are_dirty(const struct Mesh *mesh);
+void BKE_mesh_calc_poly_normal(const struct MPoly *mpoly,
+ const struct MLoop *loopstart,
+ const struct MVert *mvarray,
+ float r_no[3]);
+void BKE_mesh_calc_poly_normal_coords(const struct MPoly *mpoly,
+ const struct MLoop *loopstart,
+ const float (*vertex_coords)[3],
+ float r_no[3]);
+
/**
* Calculate face normals directly into a result array.
*
@@ -694,14 +703,6 @@ void BKE_mesh_set_custom_normals_from_verts(struct Mesh *mesh, float (*r_custom_
/* *** mesh_evaluate.cc *** */
-void BKE_mesh_calc_poly_normal(const struct MPoly *mpoly,
- const struct MLoop *loopstart,
- const struct MVert *mvarray,
- float r_no[3]);
-void BKE_mesh_calc_poly_normal_coords(const struct MPoly *mpoly,
- const struct MLoop *loopstart,
- const float (*vertex_coords)[3],
- float r_no[3]);
void BKE_mesh_calc_poly_center(const struct MPoly *mpoly,
const struct MLoop *loopstart,
const struct MVert *mvarray,
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.cc b/source/blender/blenkernel/intern/mesh_evaluate.cc
index 9a199c9c768..de080c9dff2 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.cc
+++ b/source/blender/blenkernel/intern/mesh_evaluate.cc
@@ -38,113 +38,6 @@ using blender::VArray;
/** \name Polygon Calculations
* \{ */
-/*
- * COMPUTE POLY NORMAL
- *
- * Computes the normal of a planar
- * polygon See Graphics Gems for
- * computing newell normal.
- */
-static void mesh_calc_ngon_normal(const MPoly *mpoly,
- const MLoop *loopstart,
- const MVert *mvert,
- float normal[3])
-{
- const int nverts = mpoly->totloop;
- const float *v_prev = mvert[loopstart[nverts - 1].v].co;
- const float *v_curr;
-
- zero_v3(normal);
-
- /* Newell's Method */
- for (int i = 0; i < nverts; i++) {
- v_curr = mvert[loopstart[i].v].co;
- add_newell_cross_v3_v3v3(normal, v_prev, v_curr);
- v_prev = v_curr;
- }
-
- if (UNLIKELY(normalize_v3(normal) == 0.0f)) {
- normal[2] = 1.0f; /* other axis set to 0.0 */
- }
-}
-
-void BKE_mesh_calc_poly_normal(const MPoly *mpoly,
- const MLoop *loopstart,
- const MVert *mvarray,
- float r_no[3])
-{
- if (mpoly->totloop > 4) {
- mesh_calc_ngon_normal(mpoly, loopstart, mvarray, r_no);
- }
- else if (mpoly->totloop == 3) {
- normal_tri_v3(
- r_no, mvarray[loopstart[0].v].co, mvarray[loopstart[1].v].co, mvarray[loopstart[2].v].co);
- }
- else if (mpoly->totloop == 4) {
- normal_quad_v3(r_no,
- mvarray[loopstart[0].v].co,
- mvarray[loopstart[1].v].co,
- mvarray[loopstart[2].v].co,
- mvarray[loopstart[3].v].co);
- }
- else { /* horrible, two sided face! */
- r_no[0] = 0.0;
- r_no[1] = 0.0;
- r_no[2] = 1.0;
- }
-}
-/* duplicate of function above _but_ takes coords rather than mverts */
-static void mesh_calc_ngon_normal_coords(const MPoly *mpoly,
- const MLoop *loopstart,
- const float (*vertex_coords)[3],
- float r_normal[3])
-{
- const int nverts = mpoly->totloop;
- const float *v_prev = vertex_coords[loopstart[nverts - 1].v];
- const float *v_curr;
-
- zero_v3(r_normal);
-
- /* Newell's Method */
- for (int i = 0; i < nverts; i++) {
- v_curr = vertex_coords[loopstart[i].v];
- add_newell_cross_v3_v3v3(r_normal, v_prev, v_curr);
- v_prev = v_curr;
- }
-
- if (UNLIKELY(normalize_v3(r_normal) == 0.0f)) {
- r_normal[2] = 1.0f; /* other axis set to 0.0 */
- }
-}
-
-void BKE_mesh_calc_poly_normal_coords(const MPoly *mpoly,
- const MLoop *loopstart,
- const float (*vertex_coords)[3],
- float r_no[3])
-{
- if (mpoly->totloop > 4) {
- mesh_calc_ngon_normal_coords(mpoly, loopstart, vertex_coords, r_no);
- }
- else if (mpoly->totloop == 3) {
- normal_tri_v3(r_no,
- vertex_coords[loopstart[0].v],
- vertex_coords[loopstart[1].v],
- vertex_coords[loopstart[2].v]);
- }
- else if (mpoly->totloop == 4) {
- normal_quad_v3(r_no,
- vertex_coords[loopstart[0].v],
- vertex_coords[loopstart[1].v],
- vertex_coords[loopstart[2].v],
- vertex_coords[loopstart[3].v]);
- }
- else { /* horrible, two sided face! */
- r_no[0] = 0.0;
- r_no[1] = 0.0;
- r_no[2] = 1.0;
- }
-}
-
static void mesh_calc_ngon_center(const MPoly *mpoly,
const MLoop *loopstart,
const MVert *mvert,
diff --git a/source/blender/blenkernel/intern/mesh_normals.cc b/source/blender/blenkernel/intern/mesh_normals.cc
index cee8f770208..d4ba2499140 100644
--- a/source/blender/blenkernel/intern/mesh_normals.cc
+++ b/source/blender/blenkernel/intern/mesh_normals.cc
@@ -153,6 +153,113 @@ bool BKE_mesh_poly_normals_are_dirty(const Mesh *mesh)
/** \name Mesh Normal Calculation (Polygons)
* \{ */
+/*
+ * COMPUTE POLY NORMAL
+ *
+ * Computes the normal of a planar
+ * polygon See Graphics Gems for
+ * computing newell normal.
+ */
+static void mesh_calc_ngon_normal(const MPoly *mpoly,
+ const MLoop *loopstart,
+ const MVert *mvert,
+ float normal[3])
+{
+ const int nverts = mpoly->totloop;
+ const float *v_prev = mvert[loopstart[nverts - 1].v].co;
+ const float *v_curr;
+
+ zero_v3(normal);
+
+ /* Newell's Method */
+ for (int i = 0; i < nverts; i++) {
+ v_curr = mvert[loopstart[i].v].co;
+ add_newell_cross_v3_v3v3(normal, v_prev, v_curr);
+ v_prev = v_curr;
+ }
+
+ if (UNLIKELY(normalize_v3(normal) == 0.0f)) {
+ normal[2] = 1.0f; /* other axis set to 0.0 */
+ }
+}
+
+void BKE_mesh_calc_poly_normal(const MPoly *mpoly,
+ const MLoop *loopstart,
+ const MVert *mvarray,
+ float r_no[3])
+{
+ if (mpoly->totloop > 4) {
+ mesh_calc_ngon_normal(mpoly, loopstart, mvarray, r_no);
+ }
+ else if (mpoly->totloop == 3) {
+ normal_tri_v3(
+ r_no, mvarray[loopstart[0].v].co, mvarray[loopstart[1].v].co, mvarray[loopstart[2].v].co);
+ }
+ else if (mpoly->totloop == 4) {
+ normal_quad_v3(r_no,
+ mvarray[loopstart[0].v].co,
+ mvarray[loopstart[1].v].co,
+ mvarray[loopstart[2].v].co,
+ mvarray[loopstart[3].v].co);
+ }
+ else { /* horrible, two sided face! */
+ r_no[0] = 0.0;
+ r_no[1] = 0.0;
+ r_no[2] = 1.0;
+ }
+}
+/* duplicate of function above _but_ takes coords rather than mverts */
+static void mesh_calc_ngon_normal_coords(const MPoly *mpoly,
+ const MLoop *loopstart,
+ const float (*vertex_coords)[3],
+ float r_normal[3])
+{
+ const int nverts = mpoly->totloop;
+ const float *v_prev = vertex_coords[loopstart[nverts - 1].v];
+ const float *v_curr;
+
+ zero_v3(r_normal);
+
+ /* Newell's Method */
+ for (int i = 0; i < nverts; i++) {
+ v_curr = vertex_coords[loopstart[i].v];
+ add_newell_cross_v3_v3v3(r_normal, v_prev, v_curr);
+ v_prev = v_curr;
+ }
+
+ if (UNLIKELY(normalize_v3(r_normal) == 0.0f)) {
+ r_normal[2] = 1.0f; /* other axis set to 0.0 */
+ }
+}
+
+void BKE_mesh_calc_poly_normal_coords(const MPoly *mpoly,
+ const MLoop *loopstart,
+ const float (*vertex_coords)[3],
+ float r_no[3])
+{
+ if (mpoly->totloop > 4) {
+ mesh_calc_ngon_normal_coords(mpoly, loopstart, vertex_coords, r_no);
+ }
+ else if (mpoly->totloop == 3) {
+ normal_tri_v3(r_no,
+ vertex_coords[loopstart[0].v],
+ vertex_coords[loopstart[1].v],
+ vertex_coords[loopstart[2].v]);
+ }
+ else if (mpoly->totloop == 4) {
+ normal_quad_v3(r_no,
+ vertex_coords[loopstart[0].v],
+ vertex_coords[loopstart[1].v],
+ vertex_coords[loopstart[2].v],
+ vertex_coords[loopstart[3].v]);
+ }
+ else { /* horrible, two sided face! */
+ r_no[0] = 0.0;
+ r_no[1] = 0.0;
+ r_no[2] = 1.0;
+ }
+}
+
struct MeshCalcNormalsData_Poly {
const MVert *mvert;
const MLoop *mloop;
More information about the Bf-blender-cvs
mailing list