Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2017-10-10 11:12:06 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2017-10-11 11:18:59 +0300
commita4216075696ba3e067a5655d0465ae8ab5dd6238 (patch)
tree9e80f94dc3882318fdd5d353cfaf596cc135261e
parent552d15c97698ac4270c462385a9b111f6e8329c3 (diff)
Cycles: Add utility function to calculate triangle's normal
-rw-r--r--intern/cycles/render/mesh.cpp32
-rw-r--r--intern/cycles/render/mesh.h2
2 files changed, 17 insertions, 17 deletions
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