Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
GCuboid.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/TVector3.h"
5#include "Math/TVector4.h"
6#include "SDL/sdl_interface.h"
7
8#include <Common/primitive_type.h>
9
10#include <array>
11#include <vector>
12#include <memory>
13
14namespace ph
15{
16
17class GCuboid : public Geometry
18{
19public:
20 void storeCooked(
21 CookedGeometry& out_geometry,
22 const CookingContext& ctx) const override;
23
24 void genPrimitive(
25 const PrimitiveBuildingMaterial& data,
26 std::vector<std::unique_ptr<Primitive>>& out_primitives) const override;
27
28 std::shared_ptr<Geometry> genTriangulated() const override;
29
30 GCuboid& setSize(real sideLength);
31 GCuboid& setSize(real xLen, real yLen, real zLen);
32 GCuboid& setSize(const math::Vector3R& minVertex, const math::Vector3R& maxVertex);
33 GCuboid& setSize(real xLen, real yLen, real zLen, const math::Vector3R& offset);
34
35private:
36 math::Vector3R m_size;
37 math::Vector3R m_offset;
38 math::Vector4R m_pxFaceUV;
39 math::Vector4R m_nxFaceUV;
40 math::Vector4R m_pyFaceUV;
41 math::Vector4R m_nyFaceUV;
42 math::Vector4R m_pzFaceUV;
43 math::Vector4R m_nzFaceUV;
44
45 static bool checkData(
46 const PrimitiveBuildingMaterial& data,
47 const real xLen, const real yLen, const real zLen);
48
49 static bool checkData(real xLen, real yLen, real zLen);
50
51 static math::Vector4R makeNormalizedFaceUV();
52
53public:
55 {
56 ClassType clazz("cuboid");
57 clazz.docName("Cuboid Geometry");
58 clazz.description(
59 "A shape that is similar to cube but may contain rectangular faces. "
60 "It is centered around origin.");
61 clazz.baseOn<Geometry>();
62
63 TSdlVector3<OwnerType> size("size", &OwnerType::m_size);
64 size.description("x, y, z dimensions of the cuboid.");
65 size.defaultTo({1, 1, 1});
66 clazz.addField(size);
67
68 TSdlVector3<OwnerType> offset("offset", &OwnerType::m_offset);
69 offset.description("x, y, z offsets of the cuboid, origin is at the centroid.");
70 offset.defaultTo({0, 0, 0});
71 offset.optional();
72 clazz.addField(offset);
73
74 TSdlVector4<OwnerType> pxFaceUV("px-face-uv", &OwnerType::m_pxFaceUV);
75 pxFaceUV.description(
76 "UV coordinates of the +x face (+y as upward), in (min-u, min-v, max-u, max-v).");
77 pxFaceUV.defaultTo(makeNormalizedFaceUV());
78 pxFaceUV.optional();
79 clazz.addField(pxFaceUV);
80
81 TSdlVector4<OwnerType> nxFaceUV("nx-face-uv", &OwnerType::m_nxFaceUV);
82 nxFaceUV.description(
83 "UV coordinates of the -x face (+y as upward), in (min-u, min-v, max-u, max-v).");
84 nxFaceUV.defaultTo(makeNormalizedFaceUV());
85 nxFaceUV.optional();
86 clazz.addField(nxFaceUV);
87
88 TSdlVector4<OwnerType> pyFaceUV("py-face-uv", &OwnerType::m_pyFaceUV);
89 pyFaceUV.description(
90 "UV coordinates of the +y face (-z as upward), in (min-u, min-v, max-u, max-v).");
91 pyFaceUV.defaultTo(makeNormalizedFaceUV());
92 pyFaceUV.optional();
93 clazz.addField(pyFaceUV);
94
95 TSdlVector4<OwnerType> nyFaceUV("ny-face-uv", &OwnerType::m_nyFaceUV);
96 nyFaceUV.description(
97 "UV coordinates of the -y face (+z as upward), in (min-u, min-v, max-u, max-v).");
98 nyFaceUV.defaultTo(makeNormalizedFaceUV());
99 nyFaceUV.optional();
100 clazz.addField(nyFaceUV);
101
102 TSdlVector4<OwnerType> pzFaceUV("pz-face-uv", &OwnerType::m_pzFaceUV);
103 pzFaceUV.description(
104 "UV coordinates of the +z face (+y as upward), in (min-u, min-v, max-u, max-v).");
105 pzFaceUV.defaultTo(makeNormalizedFaceUV());
106 pzFaceUV.optional();
107 clazz.addField(pzFaceUV);
108
109 TSdlVector4<OwnerType> nzFaceUV("nz-face-uv", &OwnerType::m_nzFaceUV);
110 nzFaceUV.description(
111 "UV coordinates of the -z face (+y as upward), in (min-u, min-v, max-u, max-v).");
112 nzFaceUV.defaultTo(makeNormalizedFaceUV());
113 nzFaceUV.optional();
114 clazz.addField(nzFaceUV);
115
116 return clazz;
117 }
118};
119
120}// end namespace ph
Definition CookedGeometry.h:13
Information about the world being cooked.
Definition CookingContext.h:24
Definition GCuboid.h:18
void genPrimitive(const PrimitiveBuildingMaterial &data, std::vector< std::unique_ptr< Primitive > > &out_primitives) const override
Definition GCuboid.cpp:32
PH_DEFINE_SDL_CLASS(TSdlOwnerClass< GCuboid >)
Definition GCuboid.h:54
void storeCooked(CookedGeometry &out_geometry, const CookingContext &ctx) const override
Store data suitable for rendering into out_geometry.
Definition GCuboid.cpp:20
std::shared_ptr< Geometry > genTriangulated() const override
Definition GCuboid.cpp:44
GCuboid & setSize(real sideLength)
Definition GCuboid.cpp: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
Definition TSdlVector3.h:19
Definition TSdlVector4.h:19
The root for all renderer implementations.
Definition EEngineProject.h:6