TDME2  1.9.200
Node.cpp
Go to the documentation of this file.
2 
3 #include <map>
4 #include <string>
5 #include <vector>
6 
7 #include <tdme/tdme.h>
13 #include <tdme/math/Matrix4x4.h>
14 #include <tdme/math/Vector2.h>
15 #include <tdme/math/Vector3.h>
16 
17 using std::map;
18 using std::string;
19 using std::vector;
20 
30 
31 Node::Node(Model* model, Node* parentNode, const string& id, const string& name)
32 {
33  this->model = model;
34  this->parentNode = parentNode;
35  this->id = id;
36  this->name = name;
37  this->transformMatrix.identity();
38  this->animation = nullptr;
39  this->skinning = nullptr;
40  this->joint = false;
41  this->verticesUpdated = false;
42  this->normalsUpdated = false;
43 }
44 
46 }
47 
48 void Node::setVertices(const vector<Vector3>& vertices)
49 {
50  this->vertices.resize(vertices.size());
51  auto i = 0;
52  for (const auto& vertex: vertices) {
53  this->vertices[i++] = vertex;
54  }
55  this->verticesUpdated = true;
56 }
57 
58 void Node::setNormals(const vector<Vector3>& normals)
59 {
60  this->normals.resize(normals.size());
61  auto i = 0;
62  for (const auto& normal: normals) {
63  this->normals[i++] = normal;
64  }
65  this->normalsUpdated = true;
66 }
67 
68 void Node::setTextureCoordinates(const vector<Vector2>& textureCoordinates)
69 {
70  this->textureCoordinates.resize(textureCoordinates.size());
71  auto i = 0;
72  for (const auto& textureCoordinate: textureCoordinates) {
73  this->textureCoordinates[i++] = textureCoordinate;
74  }
75 }
76 
77 void Node::setTangents(const vector<Vector3>& tangents)
78 {
79  this->tangents.resize(tangents.size());
80  auto i = 0;
81  for (const auto& tangent: tangents) {
82  this->tangents[i++] = tangent;
83  }
84 }
85 
86 void Node::setBitangents(const vector<Vector3>& bitangents)
87 {
88  this->bitangents.resize(bitangents.size());
89  auto i = 0;
90  for (const auto& bitangent: bitangents) {
91  this->bitangents[i++] = bitangent;
92  }
93 }
94 
95 void Node::setAnimation(Animation* animation) {
96  this->animation = unique_ptr<Animation>(animation);
97 }
98 
99 void Node::setSkinning(Skinning* skinning)
100 {
101  this->skinning = unique_ptr<Skinning>(skinning);
102  if (skinning != nullptr) model->setHasSkinning(true);
103 }
104 
105 int32_t Node::getFaceCount() const
106 {
107  auto faceCount = 0;
108  for (const auto& facesEntity : facesEntities) {
109  faceCount += facesEntity.getFaces().size();
110  }
111  return faceCount;
112 }
113 
114 FacesEntity* Node::getFacesEntity(const string& id) {
115  for (auto& facesEntity: facesEntities) {
116  if (facesEntity.getId() == id) return &facesEntity;
117  }
118  return nullptr;
119 }
120 
121 void Node::setFacesEntities(const vector<FacesEntity>& facesEntities)
122 {
123  this->facesEntities.resize(facesEntities.size());
124  auto i = 0;
125  for (const auto& facesEntity: facesEntities) {
126  this->facesEntities[i++] = facesEntity;
127  }
128 }
129 
130 void Node::setOrigins(const vector<Vector3>& origins) {
131  this->origins.resize(origins.size());
132  auto i = 0;
133  for (const auto& origin: origins) {
134  this->origins[i++] = origin;
135  }
136 }
Represents a model face, consisting of vertex, normal, tangent and bitangent vectors,...
Definition: Face.h:18
Node faces entity A node can have multiple entities containing faces and a applied material.
Definition: FacesEntity.h:23
Representation of a 3D model.
Definition: Model.h:35
void setHasSkinning(bool hasSkinning)
Set up if model has skinning.
Definition: Model.h:76
Model node.
Definition: Node.h:32
int32_t getFaceCount() const
Definition: Node.cpp:105
FacesEntity * getFacesEntity(const string &id)
Find faces entity by id.
Definition: Node.cpp:114
void setAnimation(Animation *animation)
Sets animation object.
Definition: Node.cpp:95
unique_ptr< Skinning > skinning
Definition: Node.h:46
vector< Vector3 > bitangents
Definition: Node.h:44
void setOrigins(const vector< Vector3 > &origins)
Set origins.
Definition: Node.cpp:130
void setVertices(const vector< Vector3 > &vertices)
Set vertices.
Definition: Node.cpp:48
void setFacesEntities(const vector< FacesEntity > &facesEntities)
Set up faces entities.
Definition: Node.cpp:121
void setSkinning(Skinning *skinning)
Sets skinning object.
Definition: Node.cpp:99
~Node()
Destructor.
Definition: Node.cpp:45
vector< FacesEntity > facesEntities
Definition: Node.h:47
void setTextureCoordinates(const vector< Vector2 > &textureCoordinates)
Set texture coordinates.
Definition: Node.cpp:68
Matrix4x4 transformMatrix
Definition: Node.h:39
unique_ptr< Animation > animation
Definition: Node.h:45
vector< Vector3 > tangents
Definition: Node.h:43
vector< Vector2 > textureCoordinates
Definition: Node.h:42
vector< Vector3 > normals
Definition: Node.h:41
vector< Vector3 > origins
Definition: Node.h:48
vector< Vector3 > vertices
Definition: Node.h:40
void setNormals(const vector< Vector3 > &normals)
Set normals.
Definition: Node.cpp:58
void setBitangents(const vector< Vector3 > &bitangents)
Set bitangents.
Definition: Node.cpp:86
void setTangents(const vector< Vector3 > &tangents)
Set tangents.
Definition: Node.cpp:77
Skinning definition for nodes.
Definition: Skinning.h:25
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Matrix4x4 & identity()
Creates identity matrix.
Definition: Matrix4x4.h:158
Vector2 class representing vector2 mathematical structure and operations with x, y components.
Definition: Vector2.h:20
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20