xoreos  0.0.5
modelnode.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef GRAPHICS_AURORA_MODELNODE_H
26 #define GRAPHICS_AURORA_MODELNODE_H
27 
28 #include <list>
29 #include <vector>
30 
31 #include "src/common/ustring.h"
32 #include "src/common/boundingbox.h"
33 
34 #include "src/graphics/types.h"
37 
40 
43 
44 namespace Graphics {
45 
46 namespace Aurora {
47 
48 class Model;
49 
51  float time;
52  float x;
53  float y;
54  float z;
55 };
56 
58  float time;
59  float x;
60  float y;
61  float z;
62  float q;
63 };
64 
65 class ModelNode {
66 public:
67  ModelNode(Model &model);
68  virtual ~ModelNode();
69 
71  const Common::UString &getName() const;
72 
73  float getWidth () const;
74  float getHeight() const;
75  float getDepth () const;
76 
78  void setInvisible(bool invisible);
79 
81  void setEnvironmentMap(const Common::UString &environmentMap = "");
82 
83  // Positioning
84 
86  void getPosition(float &x, float &y, float &z) const;
88  void getRotation(float &x, float &y, float &z) const;
90  void getOrientation(float &x, float &y, float &z, float &a) const;
91 
93  void getAbsolutePosition(float &x, float &y, float &z) const;
94 
96  glm::mat4 getAbsolutePosition() const;
97 
98  uint16 getNodeNumber() const;
99 
101  void setPosition(float x, float y, float z);
103  void setRotation(float x, float y, float z);
105  void setOrientation(float x, float y, float z, float a);
106 
108  void move (float x, float y, float z);
110  void rotate(float x, float y, float z);
111 
113  void setTextures(const std::vector<Common::UString> &textures);
114 
115  void computeInverseBindPose();
117 
119  float getAlpha();
120 
122  void setAlpha(float alpha, bool isRecursive = true);
123 
124  float getScaleX() { return _scale[0]; }
125  float getScaleY() { return _scale[1]; }
126  float getScaleZ() { return _scale[2]; }
127 
132  };
133 
134  struct DanglyData {
135  std::vector<float> constraints;
136  };
137 
138  struct Dangly {
139  float period;
140  float tightness;
142 
144 
145  Dangly();
146  };
147 
148  struct Skin {
149  std::vector<float> boneMapping;
151  std::vector<float> boneWeights;
152  std::vector<float> boneMappingId;
153  std::vector<ModelNode *> boneNodeMap;
154 
155  Skin();
156  };
157 
158  struct MeshData {
160 
161  std::vector<float> initialVertexCoords;
162 
163  std::vector<TextureHandle> textures;
164 
167 
168  MeshData();
169  };
170 
171  struct Mesh {
172  float wirecolor[3];
173  float ambient [3];
174  float diffuse [3];
175  float specular [3];
176  float selfIllum[3];
177  float shininess;
178 
179  float alpha;
180 
181  int tilefade;
182 
183  bool render;
184  bool shadow;
185 
186  bool beaming;
189 
191 
195 
197 
201  // TODO Anim, AABB Meshes
202 
203  Mesh();
204  };
205 
206 protected:
208 
210  std::list<ModelNode *> _children;
211 
213 
215 
217 
218  std::vector<Shader::ShaderRenderable> _renderableArray;
219 
220  float _center [3];
221  float _position [3];
222  float _rotation [3];
223  float _orientation[4];
224  float _scale [3];
225 
226  float _alpha;
227 
228  std::vector<PositionKeyFrame> _positionFrames;
229  std::vector<QuaternionKeyFrame> _orientationFrames;
230 
232  glm::mat4 _absolutePosition;
233  glm::mat4 _renderTransform;
234 
235  bool _render;
237  bool _dirtyMesh;
238 
241 
244 
246 
247  glm::mat4 _invBindPose;
248  glm::mat4 _absoluteTransform;
249 
250  // .--- Node position and geometry buffers
251  float _positionBuffer[3];
255  std::vector<float> _vertexCoordsBuffer;
257  // '---
258 
261 
262  // Loading helpers
263  void loadTextures(const std::vector<Common::UString> &textures);
264  void createBound();
265  void createCenter();
266 
267  void createAbsoluteBound();
268  void createAbsoluteBound(Common::BoundingBox parentPosition);
269 
270  void render(RenderPass pass);
271  void drawSkeleton(const glm::mat4 &parent, bool showInvisible);
272 
274  void calcRenderTransform(const glm::mat4 &parentTransform);
275  void renderImmediate(const glm::mat4 &parentTransform);
276  void queueRender(const glm::mat4 &parentTransform);
277 
278  void lockFrame();
279  void unlockFrame();
280 
281  void lockFrameIfVisible();
282  void unlockFrameIfVisible();
283 
284  void setBufferedPosition(float x, float y, float z);
285  void setBufferedOrientation(float x, float y, float z, float angle);
286  void flushBuffers();
287 
290 
291  void setMaterial(Shader::ShaderMaterial *material);
292  virtual void buildMaterial();
293 
294 private:
295  const Common::BoundingBox &getAbsoluteBound() const;
296 
297  void orderChildren();
298 
299  static void renderGeometry(Mesh &mesh);
300  static void renderGeometryNormal(Mesh &mesh);
301  static void renderGeometryEnvMappedUnder(Mesh &mesh);
302  static void renderGeometryEnvMappedOver(Mesh &mesh);
303 
304  static bool renderableMesh(Mesh *mesh);
305 
306 public:
307  // General helpers
308 
309  ModelNode *getParent();
310  const ModelNode *getParent() const;
311 
312  void setParent(ModelNode *parent);
313 
314  std::list<ModelNode *> &getChildren();
315 
316  Mesh *getMesh() const;
317 
319  bool isInFrontOf(const ModelNode &node) const;
320 
321  void inheritPosition(ModelNode &node) const;
322  void inheritOrientation(ModelNode &node) const;
323 
324  friend class Model;
325  friend class Animation;
326  friend class AnimationChannel;
327 };
328 
329 } // End of namespace Aurora
330 
331 } // End of namespace Graphics
332 
333 #endif // GRAPHICS_AURORA_MODELNODE_H
void setBufferedPosition(float x, float y, float z)
Definition: modelnode.cpp:842
std::vector< float > boneMapping
Definition: modelnode.h:149
void setEnvironmentMap(const Common::UString &environmentMap="")
Change the environment map on this model node.
Definition: modelnode.cpp:275
EnvironmentMapMode
The way the environment map is applied to a model node.
Definition: modelnode.h:129
static void renderGeometryEnvMappedOver(Mesh &mesh)
Definition: modelnode.cpp:587
Shader renderable, a class for easier managing of a collection of items (surface, material...
void setInvisible(bool invisible)
Should the node never be rendered at all?
Definition: modelnode.cpp:293
A class holding an UTF-8 string.
Definition: ustring.h:48
void setPosition(float x, float y, float z)
Set the position of the node.
Definition: modelnode.cpp:217
std::vector< float > boneWeights
Definition: modelnode.h:151
Shader::ShaderRenderable * _shaderRenderable
Definition: modelnode.h:260
void loadTextures(const std::vector< Common::UString > &textures)
Definition: modelnode.cpp:340
void getRotation(float &x, float &y, float &z) const
Get the rotation of the node.
Definition: modelnode.cpp:187
std::list< ModelNode * > & getChildren()
Get the node&#39;s children.
Definition: modelnode.cpp:152
bool render
Render this mesh?
Definition: modelnode.h:183
void setBufferedOrientation(float x, float y, float z, float angle)
Definition: modelnode.cpp:849
glm::mat4 _invBindPose
Inverse bind pose matrix used for animations.
Definition: modelnode.h:247
float _rotation[3]
Node rotation.
Definition: modelnode.h:222
bool _dirtyMesh
Mesh data needs updating.
Definition: modelnode.h:237
float getHeight() const
Get the height of the node&#39;s bounding box.
Definition: modelnode.cpp:164
void queueRender(const glm::mat4 &parentTransform)
Definition: modelnode.cpp:750
void setParent(ModelNode *parent)
Set the node&#39;s parent.
Definition: modelnode.cpp:143
void rotate(float x, float y, float z)
Rotate the node, relative to its current rotation.
Definition: modelnode.cpp:258
Diffuse textures first, then blend the environment map in.
Definition: modelnode.h:131
bool _render
Render the node?
Definition: modelnode.h:235
Basic graphics types.
TextureHandle * getEnvironmentMap(EnvironmentMapMode &mode)
Definition: modelnode.cpp:988
void getPosition(float &x, float &y, float &z) const
Get the position of the node.
Definition: modelnode.cpp:181
float _alpha
Alpha of the node, used if no _mesh is present in this node.
Definition: modelnode.h:226
TextureHandle * getTextures(uint32 &count)
Definition: modelnode.cpp:967
A bounding box around 3D points.
Definition: boundingbox.h:33
A index buffer.
A handle to an Aurora texture.
std::vector< ModelNode * > boneNodeMap
Definition: modelnode.h:153
float getAlpha()
Get the alpha (transparency) of the node.
Definition: modelnode.cpp:318
Environment map first, then blend the diffuse textures in.
Definition: modelnode.h:130
Model * _model
The model this node belongs to.
Definition: modelnode.h:207
float _scale[3]
Scale of the node.
Definition: modelnode.h:224
void setAlpha(float alpha, bool isRecursive=true)
Set the alpha (transparency) of the node.
Definition: modelnode.cpp:326
bool _dirtyRender
Rendering information needs updating.
Definition: modelnode.h:236
RenderPass
Definition: types.h:97
std::vector< float > initialVertexCoords
Initial node vertex coordinates.
Definition: modelnode.h:161
uint16_t uint16
Definition: types.h:202
float selfIllum[3]
Self illumination color.
Definition: modelnode.h:176
Basic Aurora graphics types.
void setRotation(float x, float y, float z)
Set the rotation of the node.
Definition: modelnode.cpp:230
TextureHandle envMap
The environment map texture.
Definition: modelnode.h:165
float getWidth() const
Get the width of the node&#39;s bounding box.
Definition: modelnode.cpp:160
virtual void buildMaterial()
Definition: modelnode.cpp:1008
static bool renderableMesh(Mesh *mesh)
Definition: modelnode.cpp:636
glm::mat4 _absoluteTransform
Absolute transformation matrix used for animations.
Definition: modelnode.h:248
float getDepth() const
Get the depth of the node&#39;s bounding box.
Definition: modelnode.cpp:168
float ambient[3]
Ambient color.
Definition: modelnode.h:173
void setMaterial(Shader::ShaderMaterial *material)
Definition: modelnode.cpp:311
The global mesh manager.
float specular[3]
Specular color.
Definition: modelnode.h:175
A bounding box.
std::vector< QuaternionKeyFrame > _orientationFrames
Keyframes for orientation animation.
Definition: modelnode.h:229
bool isInFrontOf(const ModelNode &node) const
Is this node in front of that other node?
Definition: modelnode.cpp:172
float _position[3]
Position of the node.
Definition: modelnode.h:221
static void renderGeometry(Mesh &mesh)
Definition: modelnode.cpp:536
void render(RenderPass pass)
Definition: modelnode.cpp:640
std::vector< TextureHandle > textures
Textures.
Definition: modelnode.h:163
void renderImmediate(const glm::mat4 &parentTransform)
Definition: modelnode.cpp:709
Unicode string handling.
std::vector< float > boneMappingId
Definition: modelnode.h:152
Common::BoundingBox _boundBox
Definition: modelnode.h:242
Graphics::Mesh::Mesh * rawMesh
Node raw mesh data.
Definition: modelnode.h:159
void inheritPosition(ModelNode &node) const
Definition: modelnode.cpp:262
Common::UString _name
The node&#39;s name.
Definition: modelnode.h:216
std::vector< Shader::ShaderRenderable > _renderableArray
Damn you bioware.
Definition: modelnode.h:218
bool shadow
Does the node have a shadow?
Definition: modelnode.h:184
EnvironmentMapMode envMapMode
The way the environment map is applied.
Definition: modelnode.h:166
uint32_t uint32
Definition: types.h:204
glm::mat4 getAbsolutePosition() const
Get the position of the node after translate/rotate.
Definition: modelnode.cpp:206
float wirecolor[3]
Color of the wireframe.
Definition: modelnode.h:172
float diffuse[3]
Diffuse color.
Definition: modelnode.h:174
float _orientation[4]
Orientation of the node.
Definition: modelnode.h:223
const Common::UString & getName() const
Get the node&#39;s name.
Definition: modelnode.cpp:156
void move(float x, float y, float z)
Move the node, relative to its current position.
Definition: modelnode.cpp:251
std::vector< float > _vertexCoordsBuffer
Definition: modelnode.h:255
static void renderGeometryEnvMappedUnder(Mesh &mesh)
Definition: modelnode.cpp:560
uint16 getNodeNumber() const
Definition: modelnode.cpp:213
std::list< ModelNode * > _children
The node&#39;s children.
Definition: modelnode.h:210
#define pass
Definition: fft.cpp:257
Common::BoundingBox _absoluteBoundBox
Definition: modelnode.h:243
std::vector< PositionKeyFrame > _positionFrames
Keyframes for position animation.
Definition: modelnode.h:228
glm::mat4 _absolutePosition
Position of the node after translate/rotate.
Definition: modelnode.h:232
const Common::BoundingBox & getAbsoluteBound() const
Definition: modelnode.cpp:446
void calcRenderTransform(const glm::mat4 &parentTransform)
Calculate the transform used for rendering.
Definition: modelnode.cpp:692
ModelNode * getParent()
Get the node&#39;s parent.
Definition: modelnode.cpp:135
ModelNode * _parent
The node&#39;s parent.
Definition: modelnode.h:209
Model * _attachedModel
The model that is attached to this node.
Definition: modelnode.h:212
float _center[3]
The node&#39;s center.
Definition: modelnode.h:220
A handle to a texture.
Definition: texturehandle.h:51
A vertex buffer.
void getOrientation(float &x, float &y, float &z, float &a) const
Get the orientation of the node.
Definition: modelnode.cpp:193
Shader::ShaderMaterial * _material
Definition: modelnode.h:259
void drawSkeleton(const glm::mat4 &parent, bool showInvisible)
Definition: modelnode.cpp:791
static void renderGeometryNormal(Mesh &mesh)
Definition: modelnode.cpp:540
void setOrientation(float x, float y, float z, float a)
Set the orientation of the node.
Definition: modelnode.cpp:240
void setTextures(const std::vector< Common::UString > &textures)
Set textures to the node.
Definition: modelnode.cpp:297
void inheritOrientation(ModelNode &node) const
Definition: modelnode.cpp:268