scimesh
0.3.4
Headless CPU-only 3D software renderer for scientific mesh visualization
Loading...
Searching...
No Matches
normals.cpp
Go to the documentation of this file.
1
#include <
scimesh/normals.h
>
2
3
namespace
scimesh
{
4
5
void
compute_vertex_normals
(
const
Mesh
&mesh, std::vector<Vec3> &normals) {
6
normals.assign(mesh.
vertices
.size(),
Vec3
(0.0f));
7
8
for
(
const
auto
&
tri
: mesh.
triangles
) {
9
Vec3
face_normal
=
compute_face_normal
(
10
mesh.
vertices
[
tri
.v0],
11
mesh.
vertices
[
tri
.v1],
12
mesh.
vertices
[
tri
.v2]);
13
14
normals[
tri
.v0] +=
face_normal
;
15
normals[
tri
.v1] +=
face_normal
;
16
normals[
tri
.v2] +=
face_normal
;
17
}
18
19
for
(
auto
&
n
: normals) {
20
float
len
= glm::length(
n
);
21
if
(
len
> 1e-12f)
22
n
/=
len
;
23
else
24
n
=
Vec3
(0.0f, 0.0f, 1.0f);
25
}
26
}
27
28
}
// namespace scimesh
scimesh
Definition
camera.cpp:8
scimesh::compute_vertex_normals
void compute_vertex_normals(const Mesh &mesh, std::vector< Vec3 > &normals)
Compute per-vertex normals by averaging adjacent face normals.
Definition
normals.cpp:5
scimesh::Vec3
glm::vec3 Vec3
3-component floating-point vector (xyz).
Definition
types.h:46
scimesh::compute_face_normal
Vec3 compute_face_normal(const Vec3 &v0, const Vec3 &v1, const Vec3 &v2)
Compute the unit-length normal vector of a triangle face.
Definition
math_utils.h:37
normals.h
Compute per-vertex surface normals for lighting.
scimesh::Mesh
A 3D triangle mesh using an indexed face set representation.
Definition
mesh.h:76
scimesh::Mesh::vertices
std::vector< Vec3 > vertices
3D vertex positions.
Definition
mesh.h:86
scimesh::Mesh::triangles
std::vector< Triangle > triangles
Triangle index triplets.
Definition
mesh.h:94
x
int x
Left edge of the bitmap, in image pixels.
Definition
text.cpp:223
src
core
normals.cpp
Generated by
1.9.8