21 #ifndef LIB_LIGHTMETRICA_TEST_STUB_TRIANGLE_MESH_H
22 #define LIB_LIGHTMETRICA_TEST_STUB_TRIANGLE_MESH_H
25 #include <lightmetrica/trianglemesh.h>
26 #include <lightmetrica/align.h>
30 LM_TEST_NAMESPACE_BEGIN
36 LM_COMPONENT_IMPL_DEF(
"stub");
40 virtual int NumVertices()
const {
return static_cast<int>(positions.size()); }
41 virtual int NumFaces()
const {
return static_cast<int>(faces.size()); }
42 virtual const Math::Float*
Positions()
const {
return positions.empty() ?
nullptr : &positions[0]; }
43 virtual const Math::Float*
Normals()
const {
return normals.empty() ?
nullptr : &normals[0]; }
44 virtual const Math::Float*
TexCoords()
const {
return texcoords.empty() ?
nullptr : &texcoords[0]; }
45 virtual const unsigned int*
Faces()
const {
return faces.empty() ?
nullptr : &faces[0]; }
50 std::vector<Math::Float> positions;
51 std::vector<Math::Float> normals;
52 std::vector<Math::Float> texcoords;
53 std::vector<unsigned int> faces;
100 const unsigned int fs[] =
108 for (
int i = 0; i < 8; i++)
110 positions.push_back(Math::Float(ps[3*i ]));
111 positions.push_back(Math::Float(ps[3*i+1]));
112 positions.push_back(Math::Float(ps[3*i+2]));
113 normals.push_back(Math::Float(ns[3*i ]));
114 normals.push_back(Math::Float(ns[3*i+1]));
115 normals.push_back(Math::Float(ns[3*i+2]));
116 texcoords.push_back(Math::Float(ts[2*i ]));
117 texcoords.push_back(Math::Float(ts[2*i+1]));
120 for (
int i = 0; i < 4; i++)
122 faces.push_back(fs[3*i]);
123 faces.push_back(fs[3*i+1]);
124 faces.push_back(fs[3*i+2]);
153 const unsigned int fs[] =
159 auto n = Math::Normalize(Math::Vec3(1, 0, 1));
161 for (
int i = 0; i < 4; i++)
163 positions.push_back(Math::Float(ps[3*i ]));
164 positions.push_back(Math::Float(ps[3*i+1]));
165 positions.push_back(Math::Float(ps[3*i+2]));
166 normals.push_back(n[0]);
167 normals.push_back(n[1]);
168 normals.push_back(n[2]);
169 texcoords.push_back(Math::Float(ts[2*i ]));
170 texcoords.push_back(Math::Float(ts[2*i+1]));
173 for (
int i = 0; i < 2; i++)
175 faces.push_back(fs[3*i]);
176 faces.push_back(fs[3*i+1]);
177 faces.push_back(fs[3*i+2]);
191 std::mt19937 gen(42);
192 std::uniform_real_distribution<double> dist;
194 const int FaceCount = 1000;
195 for (
int i = 0; i < FaceCount; i++)
197 auto p1 = Math::Vec3(Math::Float(dist(gen)), Math::Float(dist(gen)), Math::Float(dist(gen)));
198 auto p2 = Math::Vec3(Math::Float(dist(gen)), Math::Float(dist(gen)), Math::Float(dist(gen)));
199 auto p3 = Math::Vec3(Math::Float(dist(gen)), Math::Float(dist(gen)), Math::Float(dist(gen)));
201 positions.push_back(p1[0]);
202 positions.push_back(p1[1]);
203 positions.push_back(p1[2]);
204 positions.push_back(p2[0]);
205 positions.push_back(p2[1]);
206 positions.push_back(p2[2]);
207 positions.push_back(p3[0]);
208 positions.push_back(p3[1]);
209 positions.push_back(p3[2]);
211 auto n = Math::Cross(p2 - p1, p3 - p1);
212 for (
int j = 0; j < 3; j++)
214 normals.push_back(n[0]);
215 normals.push_back(n[1]);
216 normals.push_back(n[2]);
219 faces.push_back(3*i);
220 faces.push_back(3*i+1);
221 faces.push_back(3*i+2);
227 LM_TEST_NAMESPACE_END
230 #endif // LIB_LIGHTMETRICA_TEST_STUB_TRIANGLE_MESH_H
virtual const Math::Float * Normals() const
Definition: stub.trianglemesh.h:43
virtual const Math::Float * Positions() const
Definition: stub.trianglemesh.h:42
virtual int NumVertices() const
Definition: stub.trianglemesh.h:40
Definition: stub.trianglemesh.h:32
virtual const Math::Float * TexCoords() const
Definition: stub.trianglemesh.h:44
virtual bool Load(const ConfigNode &node, const Assets &assets)
Definition: stub.trianglemesh.h:46
Definition: stub.trianglemesh.h:58
virtual int NumFaces() const
Definition: stub.trianglemesh.h:41
Definition: confignode.h:37
Definition: stub.trianglemesh.h:184
Definition: trianglemesh.h:34
virtual const unsigned int * Faces() const
Definition: stub.trianglemesh.h:45
Definition: stub.trianglemesh.h:131