TDME2  1.9.200
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Node.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 #include <unordered_map>
6 #include <vector>
7 
8 #include <tdme/tdme.h>
10 #include <tdme/math/Matrix4x4.h>
11 #include <tdme/math/Vector2.h>
12 #include <tdme/math/Vector3.h>
13 
14 using std::string;
15 using std::unique_ptr;
16 using std::unordered_map;
17 using std::vector;
18 
26 
27 /**
28  * Model node
29  * @author andreas.drewke
30  */
32 {
33 private:
36  string id;
37  string name;
38  bool joint;
40  vector<Vector3> vertices;
41  vector<Vector3> normals;
42  vector<Vector2> textureCoordinates;
43  vector<Vector3> tangents;
44  vector<Vector3> bitangents;
45  unique_ptr<Animation> animation;
46  unique_ptr<Skinning> skinning;
47  vector<FacesEntity> facesEntities;
48  vector<Vector3> origins;
49  unordered_map<string, Node*> subNodes;
50 
53 public:
54  // forbid class copy
56 
57  /**
58  * Public constructor
59  * @param model model
60  * @param parentNode parent node
61  * @param id id
62  * @param name name
63  */
64  Node(Model* model, Node* parentNode, const string& id, const string& name);
65 
66  /**
67  * Destructor
68  */
69  ~Node();
70 
71  /**
72  * @return model
73  */
74  inline Model* getModel() {
75  return model;
76  }
77 
78  /**
79  * @return parent node
80  */
81  inline Node* getParentNode() {
82  return parentNode;
83  }
84 
85  /**
86  * Returns id
87  * @return id
88  */
89  inline const string& getId() {
90  return id;
91  }
92 
93  /**
94  * @return node's name
95  */
96  inline const string& getName() {
97  return name;
98  }
99 
100  /**
101  * @return if this node is empty
102  */
103  inline bool isEmpty() const {
104  return vertices.empty() == true;
105  }
106 
107  /**
108  * @return if this node is a joint/bone
109  */
110  inline bool isJoint() const {
111  return joint;
112  }
113 
114  /**
115  * Sets up if this node is a joint or not
116  * @param isJoint isbone
117  */
118  inline void setJoint(bool isJoint) {
119  joint = isJoint;
120  }
121 
122  /**
123  * @return transform matrix related to parent node
124  */
125  inline const Matrix4x4& getTransformMatrix() const {
126  return transformMatrix;
127  }
128 
129  /**
130  * @return transform matrix related to parent node
131  */
133  this->transformMatrix = transformMatrix;
134  }
135 
136  /**
137  * @return if vertices or normals have been changed
138  */
139  inline bool hasUpdate() {
140  return verticesUpdated == true || normalsUpdated == true;
141  }
142 
143  /**
144  * @return if vertices have been updated
145  */
146  inline bool hasVerticesUpdate() {
147  auto updated = verticesUpdated;
148  verticesUpdated = false;
149  return updated;
150  }
151 
152  /**
153  * @return vertices
154  */
155  inline const vector<Vector3>& getVertices() const {
156  return vertices;
157  }
158 
159  /**
160  * Set vertices
161  * @param vertices vertices
162  */
163  void setVertices(const vector<Vector3>& vertices);
164 
165  /**
166  * @return if normals have been updated
167  */
168  inline bool hasNormalsUpdate() {
169  auto updated = normalsUpdated;
170  normalsUpdated = false;
171  return updated;
172  }
173 
174  /**
175  * @return normals
176  */
177  inline const vector<Vector3>& getNormals() const {
178  return normals;
179  }
180 
181  /**
182  * Set normals
183  * @param normals normals
184  */
185  void setNormals(const vector<Vector3>& normals);
186 
187  /**
188  * @return texture coordinates or null (optional)
189  */
190  inline const vector<Vector2>& getTextureCoordinates() const {
191  return textureCoordinates;
192  }
193 
194  /**
195  * Set texture coordinates
196  * @param textureCoordinates texture coordinates
197  */
198  void setTextureCoordinates(const vector<Vector2>& textureCoordinates);
199 
200  /**
201  * @return tangents
202  */
203  inline const vector<Vector3>& getTangents() const {
204  return tangents;
205  }
206 
207  /**
208  * Set tangents
209  * @param tangents tangents
210  */
211  void setTangents(const vector<Vector3>& tangents);
212 
213  /**
214  * @return bitangents
215  */
216  inline const vector<Vector3>& getBitangents() const {
217  return bitangents;
218  }
219 
220  /**
221  * Set bitangents
222  * @param bitangents bitangents
223  */
224  void setBitangents(const vector<Vector3>& bitangents);
225 
226  /**
227  * @return animation
228  */
230  return animation.get();
231  }
232 
233  /**
234  * Sets animation object
235  * @param animation animation
236  */
238 
239  /**
240  * @return skinning or null
241  */
242  inline Skinning* getSkinning() {
243  return skinning.get();
244  }
245 
246  /**
247  * Sets skinning object
248  * @param skinning skinning
249  */
251 
252  /**
253  * @return number of faces in node
254  */
255  int32_t getFaceCount() const;
256 
257  /**
258  * @return faces entities
259  */
260  inline const vector<FacesEntity>& getFacesEntities() const {
261  return facesEntities;
262  }
263 
264  /**
265  * Find faces entity by id
266  * @param id id
267  * @return faces entity
268  */
269  FacesEntity* getFacesEntity(const string& id);
270 
271  /**
272  * Set up faces entities
273  * @param facesEntities faces entity
274  */
275  void setFacesEntities(const vector<FacesEntity>& facesEntities);
276 
277  /**
278  * @return origins
279  */
280  inline const vector<Vector3>& getOrigins() const {
281  return origins;
282  }
283 
284  /**
285  * Set origins
286  * @param origins render node object origins
287  */
288  void setOrigins(const vector<Vector3>& origins);
289 
290  /**
291  * @return sub sub nodes of this node
292  */
293  inline unordered_map<string, Node*>& getSubNodes() {
294  return subNodes;
295  }
296 
297 };
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
Model node.
Definition: Node.h:32
const vector< Vector3 > & getBitangents() const
Definition: Node.h:216
int32_t getFaceCount() const
Definition: Node.cpp:105
bool hasVerticesUpdate()
Definition: Node.h:146
unordered_map< string, Node * > & getSubNodes()
Definition: Node.h:293
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
const vector< Vector3 > & getTangents() const
Definition: Node.h:203
unordered_map< string, Node * > subNodes
Definition: Node.h:49
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
bool isJoint() const
Definition: Node.h:110
~Node()
Destructor.
Definition: Node.cpp:45
Model * getModel()
Definition: Node.h:74
const vector< Vector3 > & getOrigins() const
Definition: Node.h:280
vector< FacesEntity > facesEntities
Definition: Node.h:47
void setTransformMatrix(const Matrix4x4 &transformMatrix)
Definition: Node.h:132
void setTextureCoordinates(const vector< Vector2 > &textureCoordinates)
Set texture coordinates.
Definition: Node.cpp:68
const string & getName()
Definition: Node.h:96
Animation * getAnimation()
Definition: Node.h:229
void setJoint(bool isJoint)
Sets up if this node is a joint or not.
Definition: Node.h:118
Matrix4x4 transformMatrix
Definition: Node.h:39
const vector< Vector3 > & getVertices() const
Definition: Node.h:155
unique_ptr< Animation > animation
Definition: Node.h:45
const vector< Vector3 > & getNormals() const
Definition: Node.h:177
vector< Vector3 > tangents
Definition: Node.h:43
const vector< Vector2 > & getTextureCoordinates() const
Definition: Node.h:190
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
bool isEmpty() const
Definition: Node.h:103
Skinning * getSkinning()
Definition: Node.h:242
void setNormals(const vector< Vector3 > &normals)
Set normals.
Definition: Node.cpp:58
const string & getId()
Returns id.
Definition: Node.h:89
void setBitangents(const vector< Vector3 > &bitangents)
Set bitangents.
Definition: Node.cpp:86
Node * getParentNode()
Definition: Node.h:81
Node(Model *model, Node *parentNode, const string &id, const string &name)
Public constructor.
Definition: Node.cpp:31
const vector< FacesEntity > & getFacesEntities() const
Definition: Node.h:260
void setTangents(const vector< Vector3 > &tangents)
Set tangents.
Definition: Node.cpp:77
const Matrix4x4 & getTransformMatrix() const
Definition: Node.h:125
Skinning definition for nodes.
Definition: Skinning.h:25
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
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
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6