blob: 4b205de8bf992d1410220bb643ed9c9efe524b89 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Copyright NVIDIA Corporation 2008 -- Ignacio Castano <icastano@nvidia.com>
#include "nvmesh.h" // pch
#include "SingleFaceMap.h"
#include "nvmesh/halfedge/Mesh.h"
#include "nvmesh/halfedge/Vertex.h"
#include "nvmesh/halfedge/Face.h"
#include "nvmath/Vector.inl"
using namespace nv;
void nv::computeSingleFaceMap(HalfEdge::Mesh * mesh)
{
nvDebugCheck(mesh != NULL);
nvDebugCheck(mesh->faceCount() == 1);
HalfEdge::Face * face = mesh->faceAt(0);
nvCheck(face != NULL);
Vector3 p0 = face->edge->from()->pos;
Vector3 p1 = face->edge->to()->pos;
Vector3 X = normalizeSafe(p1 - p0, Vector3(0.0f), 0.0f);
Vector3 Z = face->normal();
Vector3 Y = normalizeSafe(cross(Z, X), Vector3(0.0f), 0.0f);
uint i = 0;
for (HalfEdge::Face::EdgeIterator it(face->edges()); !it.isDone(); it.advance(), i++)
{
HalfEdge::Vertex * vertex = it.vertex();
nvCheck(vertex != NULL);
if (i == 0)
{
vertex->tex = Vector2(0);
}
else
{
Vector3 pn = vertex->pos;
float xn = dot((pn - p0), X);
float yn = dot((pn - p0), Y);
vertex->tex = Vector2(xn, yn);
}
}
}
|