1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
7 #ifndef __C_SKINNED_MESH_H_INCLUDED__
\r
8 #define __C_SKINNED_MESH_H_INCLUDED__
\r
10 #include "ISkinnedMesh.h"
\r
11 #include "SMeshBuffer.h"
\r
12 #include "S3DVertex.h"
\r
13 #include "irrString.h"
\r
14 #include "matrix4.h"
\r
15 #include "quaternion.h"
\r
22 class IAnimatedMeshSceneNode;
\r
23 class IBoneSceneNode;
\r
25 class CSkinnedMesh: public ISkinnedMesh
\r
33 virtual ~CSkinnedMesh();
\r
35 //! returns the amount of frames. If the amount is 1, it is a static (=non animated) mesh.
\r
36 u32 getFrameCount() const override;
\r
38 //! Gets the default animation speed of the animated mesh.
\r
39 /** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */
\r
40 f32 getAnimationSpeed() const override;
\r
42 //! Gets the frame count of the animated mesh.
\r
43 /** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated.
\r
44 The actual speed is set in the scene node the mesh is instantiated in.*/
\r
45 void setAnimationSpeed(f32 fps) override;
\r
47 //! returns the animated mesh based on a detail level (which is ignored)
\r
48 IMesh* getMesh(s32 frame, s32 detailLevel=255, s32 startFrameLoop=-1, s32 endFrameLoop=-1) override;
\r
50 //! Animates this mesh's joints based on frame input
\r
51 //! blend: {0-old position, 1-New position}
\r
52 void animateMesh(f32 frame, f32 blend) override;
\r
54 //! Preforms a software skin on this mesh based of joint positions
\r
55 void skinMesh() override;
\r
57 //! returns amount of mesh buffers.
\r
58 u32 getMeshBufferCount() const override;
\r
60 //! returns pointer to a mesh buffer
\r
61 IMeshBuffer* getMeshBuffer(u32 nr) const override;
\r
63 //! Returns pointer to a mesh buffer which fits a material
\r
64 /** \param material: material to search for
\r
65 \return Returns the pointer to the mesh buffer or
\r
66 NULL if there is no such mesh buffer. */
\r
67 IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const override;
\r
69 //! returns an axis aligned bounding box
\r
70 const core::aabbox3d<f32>& getBoundingBox() const override;
\r
72 //! set user axis aligned bounding box
\r
73 void setBoundingBox( const core::aabbox3df& box) override;
\r
75 //! sets a flag of all contained materials to a new value
\r
76 void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) override;
\r
78 //! set the hardware mapping hint, for driver
\r
79 void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) override;
\r
81 //! flags the meshbuffer as changed, reloads hardware buffers
\r
82 void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) override;
\r
84 //! Returns the type of the animated mesh.
\r
85 E_ANIMATED_MESH_TYPE getMeshType() const override;
\r
87 //! Gets joint count.
\r
88 u32 getJointCount() const override;
\r
90 //! Gets the name of a joint.
\r
91 const c8* getJointName(u32 number) const override;
\r
93 //! Gets a joint number from its name
\r
94 s32 getJointNumber(const c8* name) const override;
\r
96 //! uses animation from another mesh
\r
97 bool useAnimationFrom(const ISkinnedMesh *mesh) override;
\r
99 //! Update Normals when Animating
\r
100 //! False= Don't (default)
\r
101 //! True = Update normals, slower
\r
102 void updateNormalsWhenAnimating(bool on) override;
\r
104 //! Sets Interpolation Mode
\r
105 void setInterpolationMode(E_INTERPOLATION_MODE mode) override;
\r
107 //! Convertes the mesh to contain tangent information
\r
108 void convertMeshToTangents() override;
\r
110 //! Does the mesh have no animation
\r
111 bool isStatic() override;
\r
113 //! (This feature is not implemented in irrlicht yet)
\r
114 bool setHardwareSkinning(bool on) override;
\r
116 //! Refreshes vertex data cached in joints such as positions and normals
\r
117 void refreshJointCache() override;
\r
119 //! Moves the mesh into static position.
\r
120 void resetAnimation() override;
\r
122 //Interface for the mesh loaders (finalize should lock these functions, and they should have some prefix like loader_
\r
123 //these functions will use the needed arrays, set values, etc to help the loaders
\r
125 //! exposed for loaders to add mesh buffers
\r
126 core::array<SSkinMeshBuffer*> &getMeshBuffers() override;
\r
128 //! alternative method for adding joints
\r
129 core::array<SJoint*> &getAllJoints() override;
\r
131 //! alternative method for adding joints
\r
132 const core::array<SJoint*> &getAllJoints() const override;
\r
134 //! loaders should call this after populating the mesh
\r
135 void finalize() override;
\r
137 //! Adds a new meshbuffer to the mesh, access it as last one
\r
138 SSkinMeshBuffer *addMeshBuffer() override;
\r
140 //! Adds a new joint to the mesh, access it as last one
\r
141 SJoint *addJoint(SJoint *parent=0) override;
\r
143 //! Adds a new position key to the mesh, access it as last one
\r
144 SPositionKey *addPositionKey(SJoint *joint) override;
\r
145 //! Adds a new rotation key to the mesh, access it as last one
\r
146 SRotationKey *addRotationKey(SJoint *joint) override;
\r
147 //! Adds a new scale key to the mesh, access it as last one
\r
148 SScaleKey *addScaleKey(SJoint *joint) override;
\r
150 //! Adds a new weight to the mesh, access it as last one
\r
151 SWeight *addWeight(SJoint *joint) override;
\r
153 virtual void updateBoundingBox(void);
\r
155 //! Recovers the joints from the mesh
\r
156 void recoverJointsFromMesh(core::array<IBoneSceneNode*> &jointChildSceneNodes);
\r
158 //! Tranfers the joint data to the mesh
\r
159 void transferJointsToMesh(const core::array<IBoneSceneNode*> &jointChildSceneNodes);
\r
161 //! Tranfers the joint hints to the mesh
\r
162 void transferOnlyJointsHintsToMesh(const core::array<IBoneSceneNode*> &jointChildSceneNodes);
\r
164 //! Creates an array of joints from this mesh as children of node
\r
165 void addJoints(core::array<IBoneSceneNode*> &jointChildSceneNodes,
\r
166 IAnimatedMeshSceneNode* node,
\r
167 ISceneManager* smgr);
\r
170 void checkForAnimation();
\r
172 void normalizeWeights();
\r
174 void buildAllLocalAnimatedMatrices();
\r
176 void buildAllGlobalAnimatedMatrices(SJoint *Joint=0, SJoint *ParentJoint=0);
\r
178 void getFrameData(f32 frame, SJoint *Node,
\r
179 core::vector3df &position, s32 &positionHint,
\r
180 core::vector3df &scale, s32 &scaleHint,
\r
181 core::quaternion &rotation, s32 &rotationHint);
\r
183 void calculateGlobalMatrices(SJoint *Joint,SJoint *ParentJoint);
\r
185 void skinJoint(SJoint *Joint, SJoint *ParentJoint);
\r
187 void calculateTangents(core::vector3df& normal,
\r
188 core::vector3df& tangent, core::vector3df& binormal,
\r
189 const core::vector3df& vt1, const core::vector3df& vt2, const core::vector3df& vt3,
\r
190 const core::vector2df& tc1, const core::vector2df& tc2, const core::vector2df& tc3);
\r
192 core::array<SSkinMeshBuffer*> *SkinningBuffers; //Meshbuffer to skin, default is to skin localBuffers
\r
194 core::array<SSkinMeshBuffer*> LocalBuffers;
\r
196 core::array<SJoint*> AllJoints;
\r
197 core::array<SJoint*> RootJoints;
\r
199 // bool can't be used here because std::vector<bool>
\r
200 // doesn't allow taking a reference to individual elements.
\r
201 core::array< core::array<char> > Vertices_Moved;
\r
203 core::aabbox3d<f32> BoundingBox;
\r
206 f32 FramesPerSecond;
\r
208 f32 LastAnimatedFrame;
\r
209 bool SkinnedLastFrame;
\r
211 E_INTERPOLATION_MODE InterpolationMode:8;
\r
214 bool PreparedForSkinning;
\r
215 bool AnimateNormals;
\r
216 bool HardwareSkinning;
\r
219 } // end namespace scene
\r
220 } // end namespace irr
\r