TDME2 1.9.121
Object3DBase.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <string>
5#include <vector>
6
7#include <tdme/tdme.h>
15#include <tdme/engine/Engine.h>
18
19using std::map;
20using std::string;
21using std::vector;
22
32
33/**
34 * Object3D base class
35 * @author Andreas Drewke
36 */
38{
39 friend class Object3DNode;
40 friend class Object3DNodeMesh;
44
45private:
47
48protected:
50 vector<Object3DNode*> object3dNodes;
54 vector<Object3DAnimation*> instanceAnimations;
55 vector<bool> instanceEnabled;
56 vector<Transformations> instanceTransformations;
59
60 /**
61 * Private constructor
62 * @param model model
63 * @param useManagers use mesh and object 3d node renderer model manager
64 * @param animationProcessingTarget animation processing target
65 * @param instances instances to compute and render by duplication
66 */
68
69 /**
70 * Destructor
71 */
72 virtual ~Object3DBase();
73
74public:
75
76 /**
77 * @return model
78 */
79 inline Model* getModel() {
80 return model;
81 }
82
83 /**
84 * Pre render step, computes transformations
85 * @param contextIdx context index
86 * @param lastFrameAtTime time of last animation computation
87 * @param currentFrameAtTime time of current animation computation
88 */
89 virtual inline void computeTransformations(int contextIdx, int64_t lastFrameAtTime, int64_t currentFrameAtTime){
91 for (auto i = 0; i < instances; i++) {
92 if (instanceEnabled[i] == false) continue;
93 instanceAnimations[i]->computeTransformations(contextIdx, instanceTransformations[i].getTransformationsMatrix(), lastFrameAtTime, currentFrameAtTime);
95 }
97 }
98
99 /**
100 * @return node count
101 */
102 int getNodeCount() const;
103
104 /**
105 * Retrieves list of triangles of all or given nodes
106 * @param triangles triangles
107 * @param nodeIdx node index or -1 for all nodes
108 */
109 void getTriangles(vector<Triangle>& triangles, int nodeIdx = -1);
110
111 /**
112 * @return transformed faces iterator
113 */
115
116 /**
117 * Returns object3d node mesh object
118 * @param nodeId node id
119 * @return object3d node mesh object
120 */
121 Object3DNodeMesh* getMesh(const string& nodeId);
122
123 /**
124 * Initiates this object3d
125 */
126 virtual void initialize();
127
128 /**
129 * Disposes this object3d
130 */
131 virtual void dispose();
132
133 /**
134 * @return maximum of instances
135 */
136 inline int getInstances() {
137 return instances;
138 }
139
140 /**
141 * @return current instance
142 */
143 inline int getCurrentInstance() {
144 return currentInstance;
145 }
146
147 /**
148 * Set current instance
149 * @param current instance
150 */
152 if (currentInstance >= 0 && currentInstance < instances) this->currentInstance = currentInstance;
153 }
154
155 /**
156 * @return current instance enabled
157 */
158 inline bool getInstanceEnabled() {
160 }
161
162 /**
163 * Set current instance enabled
164 * @param enabled instance enabled
165 */
166 inline void setInstanceEnabled(bool enabled) {
168 }
169
170 /**
171 * Sets up a base animation to play
172 * @param id id
173 * @param speed speed whereas 1.0 is default speed
174 */
175 inline void setAnimation(const string& id, float speed = 1.0f) {
176 instanceAnimations[currentInstance]->setAnimation(id, speed);
177 }
178
179 /**
180 * Set up animation speed
181 * @param speed speed whereas 1.0 is default speed
182 */
183 inline void setAnimationSpeed(float speed) {
184 instanceAnimations[currentInstance]->setAnimationSpeed(speed);
185 }
186
187 /**
188 * Overlays a animation above the base animation
189 * @param id id
190 */
191 inline void addOverlayAnimation(const string& id) {
192 instanceAnimations[currentInstance]->addOverlayAnimation(id);
193 }
194
195 /**
196 * Removes a overlay animation
197 * @param id id
198 */
199 inline void removeOverlayAnimation(const string& id) {
200 instanceAnimations[currentInstance]->removeOverlayAnimation(id);
201 }
202
203 /**
204 * Removes all finished overlay animations
205 */
207 instanceAnimations[currentInstance]->removeOverlayAnimationsFinished();
208 }
209
210 /**
211 * Removes all overlay animations
212 */
214 instanceAnimations[currentInstance]->removeOverlayAnimations();
215 }
216
217 /**
218 * @return active animation setup id
219 */
220 inline const string getAnimation() {
221 return instanceAnimations[currentInstance]->getAnimation();
222 }
223
224 /**
225 * Returns current base animation time
226 * @return 0.0 <= time <= 1.0
227 */
228 inline float getAnimationTime() {
229 return instanceAnimations[currentInstance]->getAnimationTime();
230 }
231
232 /**
233 * Returns if there is currently running a overlay animation with given id
234 * @param id id
235 * @return animation is running
236 */
237 inline bool hasOverlayAnimation(const string& id) {
238 return instanceAnimations[currentInstance]->hasOverlayAnimation(id);
239 }
240
241 /**
242 * Returns current overlay animation time
243 * @param id id
244 * @return 0.0 <= time <= 1.0
245 */
246 inline float getOverlayAnimationTime(const string& id) {
247 return instanceAnimations[currentInstance]->getOverlayAnimationTime(id);
248 }
249
250 /**
251 * Returns transformation matrix for given node
252 * @param id node id
253 * @return transformation matrix or identity matrix if not found
254 */
255 inline const Matrix4x4 getNodeTransformationsMatrix(const string& id) {
256 return instanceAnimations[currentInstance]->getNodeTransformationsMatrix(id);
257 }
258
259 /**
260 * Set transformation matrix for given node
261 * @param id node id
262 * @param matrix transformation matrix
263 */
264 inline void setNodeTransformationsMatrix(const string& id, const Matrix4x4& matrix) {
265 instanceAnimations[currentInstance]->setNodeTransformationsMatrix(id, matrix);
266 }
267
268 /**
269 * Unset transformation matrix for given node
270 * @param id node id
271 */
272 inline void unsetNodeTransformationsMatrix(const string& id) {
273 instanceAnimations[currentInstance]->unsetNodeTransformationsMatrix(id);
274 }
275
276 /**
277 * @return this transformations matrix
278 */
279 inline const Matrix4x4& getTransformationsMatrix() const {
280 return instanceTransformations[currentInstance].getTransformationsMatrix();
281 }
282
283};
Engine main class.
Definition: Engine.h:122
Transformations which contain scale, rotations and translation.
Representation of a 3d model.
Definition: Model.h:32
Model node.
Definition: Node.h:31
Triangle entity, this is not directly connectable with physics engine.
Definition: Triangle.h:19
void getTriangles(vector< Triangle > &triangles, int nodeIdx=-1)
Retrieves list of triangles of all or given nodes.
Object3DBase(Model *model, bool useManagers, Engine::AnimationProcessingTarget animationProcessingTarget, int instances)
Private constructor.
void setAnimation(const string &id, float speed=1.0f)
Sets up a base animation to play.
Definition: Object3DBase.h:175
const Matrix4x4 & getTransformationsMatrix() const
Definition: Object3DBase.h:279
virtual void initialize()
Initiates this object3d.
void unsetNodeTransformationsMatrix(const string &id)
Unset transformation matrix for given node.
Definition: Object3DBase.h:272
void addOverlayAnimation(const string &id)
Overlays a animation above the base animation.
Definition: Object3DBase.h:191
Engine::AnimationProcessingTarget animationProcessingTarget
Definition: Object3DBase.h:58
vector< Transformations > instanceTransformations
Definition: Object3DBase.h:56
float getOverlayAnimationTime(const string &id)
Returns current overlay animation time.
Definition: Object3DBase.h:246
vector< Object3DAnimation * > instanceAnimations
Definition: Object3DBase.h:54
void removeOverlayAnimation(const string &id)
Removes a overlay animation.
Definition: Object3DBase.h:199
bool hasOverlayAnimation(const string &id)
Returns if there is currently running a overlay animation with given id.
Definition: Object3DBase.h:237
Object3DBase_TransformedFacesIterator * transformedFacesIterator
Definition: Object3DBase.h:46
void setNodeTransformationsMatrix(const string &id, const Matrix4x4 &matrix)
Set transformation matrix for given node.
Definition: Object3DBase.h:264
Object3DNodeMesh * getMesh(const string &nodeId)
Returns object3d node mesh object.
const Matrix4x4 getNodeTransformationsMatrix(const string &id)
Returns transformation matrix for given node.
Definition: Object3DBase.h:255
void setCurrentInstance(int currentInstance)
Set current instance.
Definition: Object3DBase.h:151
void setAnimationSpeed(float speed)
Set up animation speed.
Definition: Object3DBase.h:183
Object3DBase_TransformedFacesIterator * getTransformedFacesIterator()
void removeOverlayAnimations()
Removes all overlay animations.
Definition: Object3DBase.h:213
void removeOverlayAnimationsFinished()
Removes all finished overlay animations.
Definition: Object3DBase.h:206
virtual void dispose()
Disposes this object3d.
float getAnimationTime()
Returns current base animation time.
Definition: Object3DBase.h:228
void setInstanceEnabled(bool enabled)
Set current instance enabled.
Definition: Object3DBase.h:166
virtual void computeTransformations(int contextIdx, int64_t lastFrameAtTime, int64_t currentFrameAtTime)
Pre render step, computes transformations.
Definition: Object3DBase.h:89
Object 3D node mesh specifically for rendering.
Object 3d node specifically for rendering.
Definition: Object3DNode.h:39
static void computeTransformations(int contextIdx, vector< Object3DNode * > &object3DNodes)
Applies transformations to meshes for given object 3d nodes.
Interface to compute shader skinning shader program.
4x4 3D Matrix class
Definition: Matrix4x4.h:24