Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Object.hpp
1#pragma once
2
3#include "scene/Animated.hpp"
4#include "scene/Animation.hpp"
5#include "resources/ResourcesManager.hpp"
6#include "system/Codable.hpp"
7#include "Common.hpp"
8
10class Material;
11
16class Object {
17
18public:
19
21 Object() = default;
22
27 Object(const Mesh * mesh, bool castShadows);
28
32 void addAnimation(const std::shared_ptr<Animation> & anim);
33
37 void set(const glm::mat4 & model);
38
43 virtual void update(double fullTime, double frameTime);
44
49 const BoundingBox & boundingBox() const;
50
54 const Mesh * mesh() const { return _mesh; }
55
59 const glm::mat4 & model() const { return _model; }
60
64 bool castsShadow() const { return _castShadow; }
65
69 bool useTexCoords() const { return !_skipUVs; }
70
74 bool animated() const { return !_animations.empty(); }
75
79 void setMaterial(const Material* material);
80
82 const Material& material() const { return *_material; }
83
85 const std::string& materialName() const { return _materialName; }
86
104 virtual bool decode(const KeyValues & params, Storage options);
105
109 virtual KeyValues encode() const;
110
112 virtual ~Object() = default;
113
115 Object(const Object &) = delete;
116
120 Object & operator=(const Object &) = delete;
121
123 Object(Object &&) = default;
124
128 Object & operator=(Object &&) = default;
129
130protected:
131 const Mesh * _mesh = nullptr;
132 std::string _materialName;
133 const Material * _material = nullptr;
134 std::vector<std::shared_ptr<Animation>> _animations;
135 Animated<glm::mat4> _model { glm::mat4(1.0f) };
137 bool _castShadow = true;
138 bool _skipUVs = false;
139
140 mutable bool _dirtyBbox = true;
141};
Wraps an animated property so that the initial value is preserved.
Definition: Animated.hpp:11
Represent the smallest axis-aligne box containing a given object or region of space.
Definition: Bounds.hpp:28
Represent a surface material, including textures describing the surface parameters.
Definition: Material.hpp:72
Represents a geometric mesh composed of vertices, other attributes and triangles.
Definition: Mesh.hpp:15
Represent a 3D textured object.
Definition: Object.hpp:16
bool castsShadow() const
Definition: Object.hpp:64
virtual ~Object()=default
const Mesh * _mesh
Geometry of the object.
Definition: Object.hpp:131
BoundingBox _bbox
The world space object bounding box.
Definition: Object.hpp:136
Object & operator=(Object &&)=default
std::vector< std::shared_ptr< Animation > > _animations
Animations list (applied in order).
Definition: Object.hpp:134
Animated< glm::mat4 > _model
The transformation matrix of the 3D model, updated by the animations.
Definition: Object.hpp:135
bool animated() const
Definition: Object.hpp:74
const glm::mat4 & model() const
Definition: Object.hpp:59
void set(const glm::mat4 &model)
Definition: Object.cpp:83
const std::string & materialName() const
Definition: Object.hpp:85
virtual void update(double fullTime, double frameTime)
Definition: Object.cpp:88
const BoundingBox & boundingBox() const
Definition: Object.cpp:99
void addAnimation(const std::shared_ptr< Animation > &anim)
Definition: Object.cpp:79
virtual KeyValues encode() const
Definition: Object.cpp:46
Object(Object &&)=default
bool _dirtyBbox
Has the bounding box been updated following an animation update.
Definition: Object.hpp:140
const Mesh * mesh() const
Definition: Object.hpp:54
Object & operator=(const Object &)=delete
const Material & material() const
Definition: Object.hpp:82
Object(const Object &)=delete
void setMaterial(const Material *material)
Definition: Object.cpp:74
bool _castShadow
Can the object casts shadows.
Definition: Object.hpp:137
std::string _materialName
Material name.
Definition: Object.hpp:132
bool _skipUVs
The object doesn't use UV coordinates.
Definition: Object.hpp:138
bool useTexCoords() const
Definition: Object.hpp:69
virtual bool decode(const KeyValues &params, Storage options)
Definition: Object.cpp:10
const Material * _material
Material.
Definition: Object.hpp:133
Object()=default
Storage
Storage and loading options.
Definition: ResourcesManager.hpp:14
Represent a key-values tuple.
Definition: Config.hpp:9