Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TAosTriMesh.ipp
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/assertion.h>
6
7#include <utility>
8#include <limits>
9
10namespace ph
11{
12
13template<
14 typename Index,
15 typename Vertex,
16 typename VerticesToTriFace>
18
20 std::vector<Vertex> vertices,
21 std::vector<Index> indices,
22 VerticesToTriFace verticesToTriFace) :
23
25 vertices.date(),
26 vertices.size(),
27 indices.data(),
28 indices.size(),
29 std::move(verticesToTriFace))
30{}
31
32template<
33 typename Index,
34 typename Vertex,
35 typename VerticesToTriFace>
37
39 const Vertex* const vertices,
40 const std::size_t numVertices,
41 const Index* const indices,
42 const std::size_t numIndices,
43 VerticesToTriFace verticesToTriFace) :
44
45 IndexedTriMesh(numIndices / 3),
46
47 m_verticesToTriFace(std::move(verticesToTriFace))
48{
49 PH_ASSERT(vertices);
50 PH_ASSERT_GT(numVertices, 0);
51 PH_ASSERT_LE(numVertices - 1, std::numeric_limits<Index>::max());
52 PH_ASSERT(indices);
53 PH_ASSERT_GT(numIndices, 0);
54
55 m_numVertices = numVertices;
56 m_numIndices = numIndices;
57
58 m_vertices = std::make_unique<Vertex[]>(new Vertex[numVertices]);
59 for(std::size_t i = 0; i < numVertices; ++i)
60 {
61 m_vertices[i] = vertices[i];
62 }
63
64 m_indices = std::make_unique<Index[]>(new Index[numIndices]);
65 for(std::size_t i = 0; i < numIndices; ++i)
66 {
67 PH_ASSERT_IN_RANGE_INCLUSIVE(indices[i], Index(0), std::numeric_limits<Index>::max());
68
69 m_indices[i] = indices[i];
70 }
71}
72
73template<
74 typename Index,
75 typename Vertex,
76 typename VerticesToTriFace>
78
79getFace(const std::size_t faceIndex) const
80-> TriFace
81{
82 PH_ASSERT_LT(faceIndex, numFaces());
83
84 const std::size_t indicesIndex = faceIndex * 3;
85 PH_ASSERT_LT(indicesIndex + 2, m_numIndices);
86
87 return m_verticesToTriFace(
88 faceIndex,
89 m_vertices[m_indices[indicesIndex]],
90 m_vertices[m_indices[indicesIndex + 1]],
91 m_vertices[m_indices[indicesIndex + 2]]);
92}
93
94}// end namespace ph
Definition IndexedTriMesh.h:15
Definition TAosTriMesh.h:15
TriFace getFace(std::size_t faceIndex) const override
Definition TAosTriMesh.ipp:79
TAosTriMesh(std::vector< Vertex > vertices, std::vector< Index > indices, VerticesToTriFace verticesToTriFace)
Definition TAosTriMesh.ipp:19
Definition TriFace.h:15
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96