[Bf-blender-cvs] [a4216075696] master: Cycles: Add utility function to calculate triangle's normal

Sergey Sharybin noreply at git.blender.org
Wed Oct 11 10:47:01 CEST 2017


Commit: a4216075696ba3e067a5655d0465ae8ab5dd6238
Author: Sergey Sharybin
Date:   Tue Oct 10 13:12:06 2017 +0500
Branches: master
https://developer.blender.org/rBa4216075696ba3e067a5655d0465ae8ab5dd6238

Cycles: Add utility function to calculate triangle's normal

===================================================================

M	intern/cycles/render/mesh.cpp
M	intern/cycles/render/mesh.h

===================================================================

diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index c02a5222463..c5eb3a0d3a8 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -107,6 +107,19 @@ void Mesh::Triangle::verts_for_step(const float3 *verts,
 	}
 }
 
+float3 Mesh::Triangle::compute_normal(const float3 *verts) const
+{
+	const float3& v0 = verts[v[0]];
+	const float3& v1 = verts[v[1]];
+	const float3& v2 = verts[v[2]];
+	const float3 norm = cross(v1 - v0, v2 - v0);
+	const float normlen = len(norm);
+	if(normlen == 0.0f) {
+		return make_float3(1.0f, 0.0f, 0.0f);
+	}
+	return norm / normlen;
+}
+
 /* Curve */
 
 void Mesh::Curve::bounds_grow(const int k, const float3 *curve_keys, const float *curve_radius, BoundBox& bounds) const
@@ -701,21 +714,6 @@ void Mesh::compute_bounds()
 	bounds = bnds;
 }
 
-static float3 compute_face_normal(const Mesh::Triangle& t, float3 *verts)
-{
-	float3 v0 = verts[t.v[0]];
-	float3 v1 = verts[t.v[1]];
-	float3 v2 = verts[t.v[2]];
-
-	float3 norm = cross(v1 - v0, v2 - v0);
-	float normlen = len(norm);
-
-	if(normlen == 0.0f)
-		return make_float3(1.0f, 0.0f, 0.0f);
-
-	return norm / normlen;
-}
-
 void Mesh::add_face_normals()
 {
 	/* don't compute if already there */
@@ -733,7 +731,7 @@ void Mesh::add_face_normals()
 		float3 *verts_ptr = verts.data();
 
 		for(size_t i = 0; i < triangles_size; i++) {
-			fN[i] = compute_face_normal(get_triangle(i), verts_ptr);
+			fN[i] = get_triangle(i).compute_normal(verts_ptr);
 		}
 	}
 
@@ -795,7 +793,7 @@ void Mesh::add_vertex_normals()
 
 			for(size_t i = 0; i < triangles_size; i++) {
 				for(size_t j = 0; j < 3; j++) {
-					float3 fN = compute_face_normal(get_triangle(i), mP);
+					float3 fN = get_triangle(i).compute_normal(mP);
 					mN[get_triangle(i).v[j]] += fN;
 				}
 			}
diff --git a/intern/cycles/render/mesh.h b/intern/cycles/render/mesh.h
index 9a51ca73950..3483ab4fd69 100644
--- a/intern/cycles/render/mesh.h
+++ b/intern/cycles/render/mesh.h
@@ -70,6 +70,8 @@ public:
 		                    size_t num_steps,
 		                    size_t step,
 		                    float3 r_verts[3]) const;
+
+		float3 compute_normal(const float3 *verts) const;
 	};
 
 	Triangle get_triangle(size_t i) const



More information about the Bf-blender-cvs mailing list