TDME2 1.9.121
Object3DRenderGroup.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <string>
5#include <vector>
6
7#include <tdme/tdme.h>
15#include <tdme/engine/Camera.h>
16#include <tdme/engine/Entity.h>
22#include <tdme/math/fwd-tdme.h>
23
24using std::array;
25using std::string;
26using std::to_string;
27using std::vector;
28
43
44/**
45 * Object 3D render group for static objects that might be animated by shaders
46 * @author Andreas Drewke
47 * @version $Id$
48 */
50 public Transformations,
51 public Entity
52{
53private:
54 Engine* engine { nullptr };
55 Entity* parentEntity { nullptr };
56 bool frustumCulling { true };
57
58 string id;
59 bool enabled;
70 map<Model*, vector<Transformations>> transformationsByModel;
71 vector<Model*> combinedModels;
73 string shaderId { "default" };
74 string distanceShaderId { "" };
75 float distanceShaderDistance { 50.0f };
76 array<int, 3> lodReduceBy;
77 bool enableEarlyZRejection { false };
78
81
83
84 /**
85 * Compute bounding box
86 */
87 inline void updateBoundingBox() {
88 if (combinedEntity == nullptr) return;
91 }
92
93 /**
94 * Combine node into given combined model
95 * @param sourceNode source node to combine into current model
96 * @param origins origins
97 * @param objectParentTransformationsMatrices object parent transformations matrix
98 * @param combinedModel combined model
99 * @param reduceFactorBy reduce factor by
100 */
101 static void combineNode(Node* sourceNode, const vector<Vector3>& origins, const vector<Matrix4x4>& objectParentTransformationsMatrices, Model* combinedModel);
102
103 /**
104 * Combine model with transformations into current model
105 * @param model model
106 * @param transformations transformations
107 * @param combinedModel combined model
108 * @param reduceFactorBy reduce factor by
109 * @return model
110 */
111 static void combineObjects(Model* model, const vector<Transformations>& objectsTransformations, Model* combinedModel);
112
113 // overridden methods
114 inline void setParentEntity(Entity* entity) override {
115 this->parentEntity = entity;
116 }
117 inline Entity* getParentEntity() override {
118 return parentEntity;
119 }
120 inline void applyParentTransformations(const Transformations& parentTransformations) override {
121 Transformations::applyParentTransformations(parentTransformations);
123 }
124
125public:
126 /**
127 * Public constructor
128 * @param id id
129 * @param model model
130 * @param lodLevels lod levels
131 * @param modelLOD2MinDistance model LOD 2 min distance
132 * @param modelLOD3MinDistance model LOD 3 min distance
133 * @param modelLOD2ReduceBy model LOD 2 reduce by factor
134 * @param modelLOD3ReduceBy model LOD 3 reduce by factor
135 * @param optimizeModels optimize models
136 */
138 const string& id,
139 int lodLevels = 1,
140 float modelLOD2MinDistance = 25.0f,
141 float modelLOD3MinDistance = 50.0f,
142 int modelLOD2ReduceBy = 4,
143 int modelLOD3ReduceBy = 16,
144 bool optimizeModels = true
145 );
146
147 /**
148 * Destructor
149 */
151
152 // overridden methods
153 inline EntityType getEntityType() override {
155 }
156
157 /**
158 * Update render group model and bounding box
159 */
160 void updateRenderGroup();
161
162 /**
163 * @return entity
164 */
165 inline Entity* getEntity() {
166 return combinedEntity;
167 }
168
169 /**
170 * Adds a instance to this render group
171 * @param model model
172 * @param transformations transformations
173 */
174 void addObject(Model* model, const Transformations& transformations);
175
176 // overridden methods
177 void setEngine(Engine* engine) override;
178 void setRenderer(Renderer* renderer) override;
179 void initialize() override;
180 void dispose() override;
181
182 inline bool isEnabled() override {
183 return enabled;
184 }
185
186 void setEnabled(bool enabled) override;
187 bool isFrustumCulling() override;
188 void setFrustumCulling(bool frustumCulling) override;
189 void fromTransformations(const Transformations& transformations) override;
190 void update() override;
191
192 inline BoundingBox* getBoundingBox() override {
193 return &boundingBox;
194 }
195
198 }
199
200 inline const Color4& getEffectColorMul() const override {
201 return effectColorMul;
202 }
203
204 inline void setEffectColorMul(const Color4& effectColorMul) override {
205 this->effectColorMul = effectColorMul;
206 }
207
208 inline const Color4& getEffectColorAdd() const override {
209 return effectColorAdd;
210 }
211
212 inline void setEffectColorAdd(const Color4& effectColorAdd) override {
213 this->effectColorAdd = effectColorAdd;
214 }
215
216 inline const string& getId() override {
217 return id;
218 }
219
220 inline bool isPickable() override {
221 return pickable;
222 }
223
224 inline bool isContributesShadows() override {
225 return contributesShadows;
226 }
227
228 inline void setContributesShadows(bool contributesShadows) override {
229 this->contributesShadows = contributesShadows;
231 }
232
233 inline bool isReceivesShadows() override {
234 return receivesShadows;
235 }
236
237 inline void setReceivesShadows(bool receivesShadows) override {
238 this->receivesShadows = receivesShadows;
240 }
241
242 inline void setPickable(bool pickable) override {
244 }
245
246 inline const Vector3& getTranslation() const override {
248 }
249
250 inline void setTranslation(const Vector3& translation) override {
252 }
253
254 inline const Vector3& getScale() const override {
256 }
257
258 inline void setScale(const Vector3& scale) override {
260 }
261
262 inline const Vector3& getPivot() const override {
264 }
265
266 inline void setPivot(const Vector3& pivot) override {
268 }
269
270 inline const int getRotationCount() const override {
272 }
273
274 inline Rotation& getRotation(const int idx) override {
276 }
277
278 inline void addRotation(const Vector3& axis, const float angle) override {
279 Transformations::addRotation(axis, angle);
280 }
281
282 inline void removeRotation(const int idx) override {
284 }
285
286 inline const Vector3& getRotationAxis(const int idx) const override {
288 }
289
290 inline void setRotationAxis(const int idx, const Vector3& axis) override {
292 }
293
294 inline const float getRotationAngle(const int idx) const override {
296 }
297
298 inline void setRotationAngle(const int idx, const float angle) override {
300 }
301
302 inline const Quaternion& getRotationsQuaternion() const override {
304 }
305
306 inline const Matrix4x4& getTransformationsMatrix() const override {
308 }
309
310 inline const Transformations& getTransformations() const override {
311 return *this;
312 }
313
314 inline RenderPass getRenderPass() const override {
315 return renderPass;
316 }
317
318 inline void setRenderPass(RenderPass renderPass) override {
319 this->renderPass = renderPass;
320 if (combinedEntity == nullptr) return;
322 }
323
324 /**
325 * @return shader id
326 */
327 inline const string& getShader() {
328 return shaderId;
329 }
330
331 /**
332 * Set shader id
333 * @param id shader
334 */
335 inline void setShader(const string& id) {
336 this->shaderId = id;
337 shaderParameters.setShader(id);
338 // TODO: put me into entity interface
339 if (combinedEntity == nullptr) return;
341 static_cast<Object3D*>(combinedEntity)->setShader(id);
343 } else
345 static_cast<LODObject3D*>(combinedEntity)->setShader(id);
347 }
348 }
349
350 /**
351 * @return distance shader id
352 */
353 inline const string& getDistanceShader() {
354 return distanceShaderId;
355 }
356
357 /**
358 * Set distance shader id
359 * @param id shader
360 */
361 inline void setDistanceShader(const string& id) {
362 this->distanceShaderId = id;
363 distanceShaderParameters.setShader(id);
364 // TODO: put me into entity interface
365 if (combinedEntity == nullptr) return;
367 static_cast<Object3D*>(combinedEntity)->setDistanceShader(id);
369 } else
371 static_cast<LODObject3D*>(combinedEntity)->setDistanceShader(id);
373 }
374 }
375
376 /**
377 * @return distance shader distance
378 */
381 }
382
383 /**
384 * Set distance shader distance
385 * @param distanceShaderDistance shader
386 */
388 this->distanceShaderDistance = distanceShaderDistance;
389 // TODO: put me into entity interface
390 if (combinedEntity == nullptr) return;
393 } else
396 }
397 }
398
399 /**
400 * @return If early z rejection is enabled
401 */
404 }
405
406 /**
407 * Enable/disable early z rejection
408 * @param enableEarlyZRejection enable early z rejection
409 */
411 this->enableEarlyZRejection = enableEarlyZRejection;
412 }
413
414 /**
415 * Returns shader parameter for given parameter name, if the value does not exist, the default will be returned
416 * @param shaderId shader id
417 * @param parameterName parameter name
418 * @return shader parameter
419 */
420 inline const ShaderParameter getShaderParameter(const string& parameterName) {
421 return shaderParameters.getShaderParameter(parameterName);
422 }
423
424 /**
425 * Set shader parameter for given parameter name
426 * @param shaderId shader id
427 * @param parameterName parameter name
428 * @param paraemterValue parameter value
429 */
430 inline void setShaderParameter(const string& parameterName, const ShaderParameter& parameterValue) {
431 shaderParameters.setShaderParameter(parameterName, parameterValue);
432 if (combinedEntity == nullptr) return;
434 static_cast<Object3D*>(combinedEntity)->setShaderParameter(parameterName, parameterValue);
435 } else
437 static_cast<LODObject3D*>(combinedEntity)->setShaderParameter(parameterName, parameterValue);
438 }
439 }
440
441 /**
442 * Returns distance shader parameter for given parameter name, if the value does not exist, the default will be returned
443 * @param shaderId shader id
444 * @param parameterName parameter name
445 * @return shader parameter
446 */
447 inline const ShaderParameter getDistanceShaderParameter(const string& parameterName) {
448 return distanceShaderParameters.getShaderParameter(parameterName);
449 }
450
451 /**
452 * Set distance shader parameter for given parameter name
453 * @param shaderId shader id
454 * @param parameterName parameter name
455 * @param paraemterValue parameter value
456 */
457 inline void setDistanceShaderParameter(const string& parameterName, const ShaderParameter& parameterValue) {
458 distanceShaderParameters.setShaderParameter(parameterName, parameterValue);
459 if (combinedEntity == nullptr) return;
461 static_cast<Object3D*>(combinedEntity)->setDistanceShaderParameter(parameterName, parameterValue);
462 } else
464 static_cast<LODObject3D*>(combinedEntity)->setDistanceShaderParameter(parameterName, parameterValue);
465 }
466 }
467
468};
Engine main class.
Definition: Engine.h:122
TDME2 engine entity shader parameters.
void setShaderParameter(const string &parameterName, const ShaderParameter &parameterValue)
Set shader parameter for given parameter name.
void setShader(const string &shaderId)
Set shader.
const ShaderParameter getShaderParameter(const string &parameterName) const
Returns shader parameter for given parameter name, if the value does not exist, the default will be r...
TDME engine entity.
Definition: Entity.h:31
virtual void setRenderPass(RenderPass renderPass)=0
Set render pass.
virtual EntityType getEntityType()=0
virtual BoundingBox * getBoundingBox()=0
virtual void setContributesShadows(bool contributesShadows)=0
Enable/disable contributes shadows.
@ ENTITYTYPE_OBJECT3DRENDERGROUP
Definition: Entity.h:68
virtual void setPickable(bool pickable)=0
Set this object pickable.
virtual void setReceivesShadows(bool receivesShadows)=0
Enable/disable receives shadows.
LOD object 3D to be used with engine class.
Definition: LODObject3D.h:47
const string & getShader()
Definition: LODObject3D.h:476
const string & getDistanceShader()
Definition: LODObject3D.h:495
Object 3D render group for static objects that might be animated by shaders.
const Matrix4x4 & getTransformationsMatrix() const override
map< Model *, vector< Transformations > > transformationsByModel
const Color4 & getEffectColorAdd() const override
The effect color will be added to fragment color.
RenderPass getRenderPass() const override
void dispose() override
Dispose this object 3d.
void setShader(const string &id)
Set shader id.
Object3DRenderGroup(const string &id, int lodLevels=1, float modelLOD2MinDistance=25.0f, float modelLOD3MinDistance=50.0f, int modelLOD2ReduceBy=4, int modelLOD3ReduceBy=16, bool optimizeModels=true)
Public constructor.
void setTranslation(const Vector3 &translation) override
Set translation.
void setParentEntity(Entity *entity) override
Set parent entity, needs to be called before adding to engine.
void removeRotation(const int idx) override
Remove rotation.
void setPivot(const Vector3 &pivot) override
Set pivot.
const int getRotationCount() const override
const Quaternion & getRotationsQuaternion() const override
void initialize() override
Initiates this object 3d.
EntityShaderParameters shaderParameters
BoundingBox * getBoundingBox() override
void setRenderPass(RenderPass renderPass) override
Set render pass.
void setReceivesShadows(bool receivesShadows) override
Enable/disable receives shadows.
void addRotation(const Vector3 &axis, const float angle) override
Add rotation.
void update() override
Update transformations.
static void combineObjects(Model *model, const vector< Transformations > &objectsTransformations, Model *combinedModel)
Combine model with transformations into current model.
void addObject(Model *model, const Transformations &transformations)
Adds a instance to this render group.
void setPickable(bool pickable) override
Set this object pickable.
void updateRenderGroup()
Update render group model and bounding box.
void setEffectColorMul(const Color4 &effectColorMul) override
Set effect color that will be multiplied with fragment color.
const ShaderParameter getShaderParameter(const string &parameterName)
Returns shader parameter for given parameter name, if the value does not exist, the default will be r...
const Vector3 & getTranslation() const override
void setShaderParameter(const string &parameterName, const ShaderParameter &parameterValue)
Set shader parameter for given parameter name.
static void combineNode(Node *sourceNode, const vector< Vector3 > &origins, const vector< Matrix4x4 > &objectParentTransformationsMatrices, Model *combinedModel)
Combine node into given combined model.
const ShaderParameter getDistanceShaderParameter(const string &parameterName)
Returns distance shader parameter for given parameter name, if the value does not exist,...
void fromTransformations(const Transformations &transformations) override
Set up this transformations from given transformations.
void updateBoundingBox()
Compute bounding box.
const Color4 & getEffectColorMul() const override
The effect color will be multiplied with fragment color.
const Vector3 & getScale() const override
const Vector3 & getPivot() const override
void setEnableEarlyZRejection(bool enableEarlyZRejection)
Enable/disable early z rejection.
BoundingBox * getBoundingBoxTransformed() override
void setDistanceShader(const string &id)
Set distance shader id.
void setScale(const Vector3 &scale) override
Set scale.
EntityShaderParameters distanceShaderParameters
void applyParentTransformations(const Transformations &parentTransformations) override
Apply parent transformations.
const float getRotationAngle(const int idx) const override
const Transformations & getTransformations() const override
void setFrustumCulling(bool frustumCulling) override
Set frustum culling.
void setEngine(Engine *engine) override
Set up engine.
void setEnabled(bool enabled) override
Enable/disable rendering.
const Vector3 & getRotationAxis(const int idx) const override
void setDistanceShaderDistance(float distanceShaderDistance)
Set distance shader distance.
void setContributesShadows(bool contributesShadows) override
Enable/disable contributes shadows.
void setRotationAxis(const int idx, const Vector3 &axis) override
Set rotation axis.
Rotation & getRotation(const int idx) override
Get rotation at given index.
void setEffectColorAdd(const Color4 &effectColorAdd) override
Set effect color that will be added to fragment color.
void setDistanceShaderParameter(const string &parameterName, const ShaderParameter &parameterValue)
Set distance shader parameter for given parameter name.
void setRenderer(Renderer *renderer) override
Set up renderer.
void setRotationAngle(const int idx, const float angle) override
Object 3D to be used with engine class.
Definition: Object3D.h:60
const string & getShader()
Definition: Object3D.h:346
const string & getDistanceShader()
Definition: Object3D.h:366
Rotation representation.
Definition: Rotation.h:18
Shader parameter model class.
Transformations which contain scale, rotations and translation.
const Matrix4x4 & getTransformationsMatrix() const
Rotation & getRotation(const int idx)
Get rotation at given index.
void setRotationAngle(const int idx, const float angle)
void setRotationAxis(const int idx, const Vector3 &axis)
Set rotation axis.
void setTranslation(const Vector3 &translation)
Set translation.
void removeRotation(const int idx)
Remove rotation.
const Quaternion & getRotationsQuaternion() const
virtual void applyParentTransformations(const Transformations &parentTransformations)
Apply parent transformations.
const Vector3 & getScale() const
void setScale(const Vector3 &scale)
Set scale.
const Vector3 & getRotationAxis(const int idx) const
const int getRotationCount() const
const Vector3 & getPivot() const
const Vector3 & getTranslation() const
void setPivot(const Vector3 &pivot)
Set pivot.
void addRotation(const Vector3 &axis, const float angle)
Add rotation.
const float getRotationAngle(const int idx) const
Color 4 definition.
Definition: Color4.h:20
Representation of a 3d model.
Definition: Model.h:32
Model node.
Definition: Node.h:31
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:25
void fromBoundingVolumeWithTransformations(BoundingBox *original, const Transformations &transformations)
Create bounding volume from given original(of same type) with applied transformations.
Definition: BoundingBox.cpp:79
void fromBoundingVolume(BoundingBox *original)
Set up this bounding volume from given bounding volume.
Definition: BoundingBox.cpp:70
4x4 3D Matrix class
Definition: Matrix4x4.h:24
Quaternion class.
Definition: Quaternion.h:22
3D vector 3 class
Definition: Vector3.h:22