TDME2 1.9.121
Object3DInternal.cpp
Go to the documentation of this file.
2
3#include <string>
4
5#include <tdme/tdme.h>
15#include <tdme/engine/Engine.h>
17#include <tdme/math/Vector3.h>
18
19using std::string;
20
34
35Object3DInternal::Object3DInternal(const string& id, Model* model, int instances) :
36 Object3DBase(model, true, Engine::animationProcessingTarget, instances)
37{
38 this->id = id;
39 enabled = true;
40 pickable = false;
41 contributesShadows = false;
42 receivesShadows = false;
43 effectColorMul.set(1.0f, 1.0f, 1.0f, 1.0f);
44 effectColorAdd.set(0.0f, 0.0f, 0.0f, 0.0f);
46}
47
49}
50
51void Object3DInternal::bindDiffuseTexture(FrameBuffer* frameBuffer, const string& nodeId, const string& facesEntityId)
52{
53 bindDiffuseTexture(frameBuffer->getColorBufferTextureId(), nodeId, facesEntityId);
54}
55
56void Object3DInternal::unbindDiffuseTexture(const string& nodeId, const string& facesEntityId)
57{
59}
60
61void Object3DInternal::bindDiffuseTexture(int32_t textureId, const string& nodeId, const string& facesEntityId)
62{
63 for (auto i = 0; i < object3dNodes.size(); i++) {
64 auto object3DNode = object3dNodes[i];
65 // skip if a node is desired but not matching
66 if (nodeId != "" && nodeId != object3DNode->node->getId())
67 continue;
68
69 auto& facesEntities = object3DNode->node->getFacesEntities();
70 for (auto facesEntityIdx = 0; facesEntityIdx < facesEntities.size(); facesEntityIdx++) {
71 auto& facesEntity = facesEntities[facesEntityIdx];
72 // skip if a faces entity is desired but not matching
73 if (facesEntityId != "" && facesEntityId != facesEntity.getId())
74 continue;
75 // set dynamic texture id
76 object3DNode->specularMaterialDynamicDiffuseTextureIdsByEntities[facesEntityIdx] = textureId;
77 }
78 }
79}
80
81void Object3DInternal::setTextureMatrix(const Matrix2D3x3& textureMatrix, const string& nodeId, const string& facesEntityId) {
82 for (auto i = 0; i < object3dNodes.size(); i++) {
83 auto object3DNode = object3dNodes[i];
84 // skip if a node is desired but not matching
85 if (nodeId != "" && nodeId != object3DNode->node->getId())
86 continue;
87
88 auto& facesEntities = object3DNode->node->getFacesEntities();
89 for (auto facesEntityIdx = 0; facesEntityIdx < facesEntities.size(); facesEntityIdx++) {
90 auto& facesEntity = facesEntities[facesEntityIdx];
91 // skip if a faces entity is desired but not matching
92 if (facesEntityId != "" && facesEntityId != facesEntity.getId())
93 continue;
94 // set dynamic texture id
95 object3DNode->textureMatricesByEntities[facesEntityIdx].set(textureMatrix);
96 }
97 }
98}
99
100void Object3DInternal::setNodeTransformationsMatrix(const string& id, const Matrix4x4& matrix) {
102 map<string, Matrix4x4*> _overriddenTransformationsMatrices;
103 for (auto overriddenTransformationsMatrixIt: instanceAnimations[currentInstance]->overriddenTransformationsMatrices) {
104 _overriddenTransformationsMatrices[overriddenTransformationsMatrixIt.first] = new Matrix4x4(*overriddenTransformationsMatrixIt.second);
105 }
106 auto newBoundingBox = ModelUtilitiesInternal::createBoundingBox(this->getModel(), _overriddenTransformationsMatrices);
107 boundingBox.fromBoundingVolume(newBoundingBox);
108 delete newBoundingBox;
109}
110
113 map<string, Matrix4x4*> _overriddenTransformationsMatrices;
114 for (auto overriddenTransformationsMatrixIt: instanceAnimations[currentInstance]->overriddenTransformationsMatrices) {
115 _overriddenTransformationsMatrices[overriddenTransformationsMatrixIt.first] = new Matrix4x4(*overriddenTransformationsMatrixIt.second);
116 }
117 auto newBoundingBox = ModelUtilitiesInternal::createBoundingBox(this->getModel(), _overriddenTransformationsMatrices);
118 boundingBox.fromBoundingVolume(newBoundingBox);
119 delete newBoundingBox;
120}
121
123{
124 instanceTransformations[currentInstance].fromTransformations(transformations);
126}
127
129{
132}
133
135 BoundingBox instanceBoundingBox;
138 for (auto i = 1; i < instances; i++) {
140 boundingBoxTransformed.extend(&instanceBoundingBox);
141 }
142}
Engine main class.
Definition: Engine.h:122
Frame buffer class.
Definition: FrameBuffer.h:21
int32_t getColorBufferTextureId()
Definition: FrameBuffer.h:97
Transformations which contain scale, rotations and translation.
void set(const array< float, 4 > &color)
Set up color.
Definition: Color4Base.h:68
Color 4 definition.
Definition: Color4.h:20
Represents a model face, consisting of vertex, normal, tangent and bitangent vectors,...
Definition: Face.h:19
Node faces entity A node can have multiple entities containing faces and a applied material.
Definition: FacesEntity.h:28
Representation of a 3d model.
Definition: Model.h:32
BoundingBox * getBoundingBox()
Definition: Model.cpp:142
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
void extend(BoundingBox *boundingBox)
Extend bounding box with given bounding box.
Definition: BoundingBox.h:148
static BoundingBox * createBoundingBox(Model *model, const map< string, Matrix4x4 * > overriddenNodeTransformationsMatrices=map< string, Matrix4x4 * >())
Creates a bounding box from given model.
void unsetNodeTransformationsMatrix(const string &id)
Unset transformation matrix for given node.
Definition: Object3DBase.h:272
vector< Transformations > instanceTransformations
Definition: Object3DBase.h:56
vector< Object3DAnimation * > instanceAnimations
Definition: Object3DBase.h:54
void setNodeTransformationsMatrix(const string &id, const Matrix4x4 &matrix)
Set transformation matrix for given node.
Definition: Object3DBase.h:264
void setTextureMatrix(const Matrix2D3x3 &textureMatrix, const string &nodeId=string(), const string &facesEntityId=string())
Set texture matrix.
void unbindDiffuseTexture(const string &nodeId=string(), const string &facesEntityId=string())
Unbind dynamic texture to a node and faces entity of this object.
void bindDiffuseTexture(int32_t textureId, const string &nodeId=string(), const string &facesEntityId=string())
Bind a texture to a node and faces entity.
void setNodeTransformationsMatrix(const string &id, const Matrix4x4 &matrix)
void fromTransformations(const Transformations &transformations)
Object 3d node specifically for rendering.
Definition: Object3DNode.h:39
3x3 2D Matrix class
Definition: Matrix2D3x3.h:22
4x4 3D Matrix class
Definition: Matrix4x4.h:24
3D vector 3 class
Definition: Vector3.h:22