Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
GTriangle.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/TVector3.h"
5#include "SDL/sdl_interface.h"
6
7#include <Common/assertion.h>
8
9namespace ph
10{
11
12class GTriangle : public Geometry
13{
14public:
15 void storeCooked(
16 CookedGeometry& out_geometry,
17 const CookingContext& ctx) const override;
18
19 void genPrimitive(
20 const PrimitiveBuildingMaterial& data,
21 std::vector<std::unique_ptr<Primitive>>& out_primitives) const override;
22
23 std::shared_ptr<Geometry> genTransformed(
24 const math::StaticAffineTransform& transform) const override;
25
26 bool isDegenerate() const;
27
28 const math::Vector3R& getVa() const;
29 const math::Vector3R& getVb() const;
30 const math::Vector3R& getVc() const;
31 const math::Vector3R& getNa() const;
32 const math::Vector3R& getNb() const;
33 const math::Vector3R& getNc() const;
34 const math::Vector3R& getUVWa() const;
35 const math::Vector3R& getUVWb() const;
36 const math::Vector3R& getUVWc() const;
37
38 GTriangle& setNa(const math::Vector3R& nA);
39 GTriangle& setNb(const math::Vector3R& nB);
40 GTriangle& setNc(const math::Vector3R& nC);
41 GTriangle& setUVWa(const math::Vector3R& uvwA);
42 GTriangle& setUVWb(const math::Vector3R& uvwB);
43 GTriangle& setUVWc(const math::Vector3R& uvwC);
44
46 const math::Vector3R& vA,
47 const math::Vector3R& vB,
48 const math::Vector3R& vC);
49
50private:
51 math::Vector3R m_vA;
52 math::Vector3R m_vB;
53 math::Vector3R m_vC;
54
55 math::Vector3R m_uvwA;
56 math::Vector3R m_uvwB;
57 math::Vector3R m_uvwC;
58
59 math::Vector3R m_nA;
60 math::Vector3R m_nB;
61 math::Vector3R m_nC;
62
63public:
65 {
66 ClassType clazz("triangle");
67 clazz.docName("Triangle Geometry");
68 clazz.description(
69 "A single triangle-shaped surface. Please note that using this type of triangle for "
70 "triangle mesh may induce significant overhead (in terms of memory usage). This is "
71 "meant for very simple shapes or debug usages.");
72 clazz.baseOn<Geometry>();
73
74 TSdlVector3<OwnerType> vA("v-A", &OwnerType::m_vA);
75 vA.description("The first vertex coordinates of the triangle.");
76 vA.required();
77 clazz.addField(vA);
78
79 TSdlVector3<OwnerType> vB("v-B", &OwnerType::m_vB);
80 vB.description("The second vertex coordinates of the triangle, in CCW.");
81 vB.required();
82 clazz.addField(vB);
83
84 TSdlVector3<OwnerType> vC("v-C", &OwnerType::m_vC);
85 vC.description("The third vertex coordinates of the triangle, in CCW.");
86 vC.required();
87 clazz.addField(vC);
88
89 TSdlVector3<OwnerType> uvwA("uvw-A", &OwnerType::m_uvwA);
90 uvwA.description("Texture coordinates of the first vertex.");
91 uvwA.defaultTo({0, 0, 0});
92 uvwA.optional();
93 clazz.addField(uvwA);
94
95 TSdlVector3<OwnerType> uvwB("uvw-B", &OwnerType::m_uvwB);
96 uvwB.description("Texture coordinates of the first vertex.");
97 uvwB.defaultTo({1, 0, 0});
98 uvwB.optional();
99 clazz.addField(uvwB);
100
101 TSdlVector3<OwnerType> uvwC("uvw-C", &OwnerType::m_uvwC);
102 uvwC.description("Texture coordinates of the first vertex.");
103 uvwC.defaultTo({0, 1, 0});
104 uvwC.optional();
105 clazz.addField(uvwC);
106
107 TSdlVector3<OwnerType> nA("n-A", &OwnerType::m_nA);
108 nA.description("Normal vector of the first vertex.");
109 nA.defaultTo({0, 0, 0});
110 nA.optional();
111 clazz.addField(nA);
112
113 TSdlVector3<OwnerType> nB("n-B", &OwnerType::m_nB);
114 nB.description("Normal vector of the second vertex.");
115 nB.defaultTo({0, 0, 0});
116 nB.optional();
117 clazz.addField(nB);
118
119 TSdlVector3<OwnerType> nC("n-C", &OwnerType::m_nC);
120 nC.description("Normal vector of the third vertex.");
121 nC.defaultTo({0, 0, 0});
122 nC.optional();
123 clazz.addField(nC);
124
125 return clazz;
126 }
127};
128
129// In-header Implementations:
130
131inline const math::Vector3R& GTriangle::getVa() const
132{
133 return m_vA;
134}
135
136inline const math::Vector3R& GTriangle::getVb() const
137{
138 return m_vB;
139}
140
141inline const math::Vector3R& GTriangle::getVc() const
142{
143 return m_vC;
144}
145
146inline const math::Vector3R& GTriangle::getNa() const
147{
148 return m_nA;
149}
150
151inline const math::Vector3R& GTriangle::getNb() const
152{
153 return m_nB;
154}
155
156inline const math::Vector3R& GTriangle::getNc() const
157{
158 return m_nC;
159}
160
162{
163 return m_uvwA;
164}
165
167{
168 return m_uvwB;
169}
170
172{
173 return m_uvwC;
174}
175
177{
178 m_nA = nA;
179
180 return *this;
181}
182
184{
185 m_nB = nB;
186
187 return *this;
188}
189
191{
192 m_nC = nC;
193
194 return *this;
195}
196
198{
199 m_uvwA = uvwA;
200
201 return *this;
202}
203
205{
206 m_uvwB = uvwB;
207
208 return *this;
209}
210
212{
213 m_uvwC = uvwC;
214
215 return *this;
216}
217
219 const math::Vector3R& vA,
220 const math::Vector3R& vB,
221 const math::Vector3R& vC)
222{
223 m_vA = vA;
224 m_vB = vB;
225 m_vC = vC;
226
227 return *this;
228}
229
230}// end namespace ph
Definition CookedGeometry.h:13
Information about the world being cooked.
Definition CookingContext.h:24
Definition GTriangle.h:13
void storeCooked(CookedGeometry &out_geometry, const CookingContext &ctx) const override
Store data suitable for rendering into out_geometry.
Definition GTriangle.cpp:21
const math::Vector3R & getUVWb() const
Definition GTriangle.h:166
const math::Vector3R & getNb() const
Definition GTriangle.h:151
const math::Vector3R & getVa() const
Definition GTriangle.h:131
GTriangle & setUVWc(const math::Vector3R &uvwC)
Definition GTriangle.h:211
std::shared_ptr< Geometry > genTransformed(const math::StaticAffineTransform &transform) const override
Definition GTriangle.cpp:76
GTriangle & setUVWb(const math::Vector3R &uvwB)
Definition GTriangle.h:204
GTriangle & setVertices(const math::Vector3R &vA, const math::Vector3R &vB, const math::Vector3R &vC)
Definition GTriangle.h:218
const math::Vector3R & getNa() const
Definition GTriangle.h:146
const math::Vector3R & getVc() const
Definition GTriangle.h:141
const math::Vector3R & getUVWc() const
Definition GTriangle.h:171
const math::Vector3R & getNc() const
Definition GTriangle.h:156
bool isDegenerate() const
Definition GTriangle.cpp:113
GTriangle & setUVWa(const math::Vector3R &uvwA)
Definition GTriangle.h:197
const math::Vector3R & getVb() const
Definition GTriangle.h:136
void genPrimitive(const PrimitiveBuildingMaterial &data, std::vector< std::unique_ptr< Primitive > > &out_primitives) const override
Definition GTriangle.cpp:45
PH_DEFINE_SDL_CLASS(TSdlOwnerClass< GTriangle >)
Definition GTriangle.h:64
GTriangle & setNa(const math::Vector3R &nA)
Definition GTriangle.h:176
GTriangle & setNb(const math::Vector3R &nB)
Definition GTriangle.h:183
GTriangle & setNc(const math::Vector3R &nC)
Definition GTriangle.h:190
const math::Vector3R & getUVWa() const
Definition GTriangle.h:161
Definition Geometry.h:21
Definition PrimitiveBuildingMaterial.h:11
SDL binding type for a canonical SDL resource class.
Definition TSdlOwnerClass.h:23
TSdlValue & description(std::string descriptionStr)
Definition TSdlValue.ipp:95
TSdlValue & optional()
Definition TSdlValue.ipp:103
TSdlValue & defaultTo(T defaultValue)
Definition TSdlValue.ipp:71
TSdlValue & required()
Definition TSdlValue.ipp:117
Definition TSdlVector3.h:19
Definition StaticAffineTransform.h:14
The root for all renderer implementations.
Definition EEngineProject.h:6