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
5 #ifndef __I_SKINNED_MESH_H_INCLUDED__
\r
6 #define __I_SKINNED_MESH_H_INCLUDED__
\r
8 #include "irrArray.h"
\r
9 #include "IBoneSceneNode.h"
\r
10 #include "IAnimatedMesh.h"
\r
11 #include "SSkinMeshBuffer.h"
\r
18 enum E_INTERPOLATION_MODE
\r
20 // constant does use the current key-values without interpolation
\r
23 // linear interpolation
\r
26 //! count of all available interpolation modes
\r
31 //! Interface for using some special functions of Skinned meshes
\r
32 class ISkinnedMesh : public IAnimatedMesh
\r
36 //! Gets joint count.
\r
37 /** \return Amount of joints in the skeletal animated mesh. */
\r
38 virtual u32 getJointCount() const = 0;
\r
40 //! Gets the name of a joint.
\r
41 /** \param number: Zero based index of joint. The last joint
\r
42 has the number getJointCount()-1;
\r
43 \return Name of joint and null if an error happened. */
\r
44 virtual const c8* getJointName(u32 number) const = 0;
\r
46 //! Gets a joint number from its name
\r
47 /** \param name: Name of the joint.
\r
48 \return Number of the joint or -1 if not found. */
\r
49 virtual s32 getJointNumber(const c8* name) const = 0;
\r
51 //! Use animation from another mesh
\r
52 /** The animation is linked (not copied) based on joint names
\r
53 so make sure they are unique.
\r
54 \return True if all joints in this mesh were
\r
55 matched up (empty names will not be matched, and it's case
\r
56 sensitive). Unmatched joints will not be animated. */
\r
57 virtual bool useAnimationFrom(const ISkinnedMesh *mesh) = 0;
\r
59 //! Update Normals when Animating
\r
60 /** \param on If false don't animate, which is faster.
\r
61 Else update normals, which allows for proper lighting of
\r
63 virtual void updateNormalsWhenAnimating(bool on) = 0;
\r
65 //! Sets Interpolation Mode
\r
66 virtual void setInterpolationMode(E_INTERPOLATION_MODE mode) = 0;
\r
68 //! Animates this mesh's joints based on frame input
\r
69 virtual void animateMesh(f32 frame, f32 blend)=0;
\r
71 //! Preforms a software skin on this mesh based of joint positions
\r
72 virtual void skinMesh() = 0;
\r
74 //! converts the vertex type of all meshbuffers to tangents.
\r
75 /** E.g. used for bump mapping. */
\r
76 virtual void convertMeshToTangents() = 0;
\r
78 //! Allows to enable hardware skinning.
\r
79 /* This feature is not implemented in Irrlicht yet */
\r
80 virtual bool setHardwareSkinning(bool on) = 0;
\r
82 //! Refreshes vertex data cached in joints such as positions and normals
\r
83 virtual void refreshJointCache() = 0;
\r
85 //! Moves the mesh into static position.
\r
86 virtual void resetAnimation() = 0;
\r
91 //! Index of the mesh buffer
\r
92 u16 buffer_id; //I doubt 32bits is needed
\r
94 //! Index of the vertex
\r
95 u32 vertex_id; //Store global ID here
\r
97 //! Weight Strength/Percentage (0-1)
\r
101 //! Internal members used by CSkinnedMesh
\r
102 friend class CSkinnedMesh;
\r
104 core::vector3df StaticPos;
\r
105 core::vector3df StaticNormal;
\r
109 //! Animation keyframe which describes a new position
\r
110 struct SPositionKey
\r
113 core::vector3df position;
\r
116 //! Animation keyframe which describes a new scale
\r
120 core::vector3df scale;
\r
123 //! Animation keyframe which describes a new rotation
\r
124 struct SRotationKey
\r
127 core::quaternion rotation;
\r
133 SJoint() : UseAnimationFrom(0), GlobalSkinningSpace(false),
\r
134 positionHint(-1),scaleHint(-1),rotationHint(-1)
\r
138 //! The name of this joint
\r
139 core::stringc Name;
\r
141 //! Local matrix of this joint
\r
142 core::matrix4 LocalMatrix;
\r
144 //! List of child joints
\r
145 core::array<SJoint*> Children;
\r
147 //! List of attached meshes
\r
148 core::array<u32> AttachedMeshes;
\r
150 //! Animation keys causing translation change
\r
151 core::array<SPositionKey> PositionKeys;
\r
153 //! Animation keys causing scale change
\r
154 core::array<SScaleKey> ScaleKeys;
\r
156 //! Animation keys causing rotation change
\r
157 core::array<SRotationKey> RotationKeys;
\r
160 core::array<SWeight> Weights;
\r
162 //! Unnecessary for loaders, will be overwritten on finalize
\r
163 core::matrix4 GlobalMatrix;
\r
164 core::matrix4 GlobalAnimatedMatrix;
\r
165 core::matrix4 LocalAnimatedMatrix;
\r
166 core::vector3df Animatedposition;
\r
167 core::vector3df Animatedscale;
\r
168 core::quaternion Animatedrotation;
\r
170 core::matrix4 GlobalInversedMatrix; //the x format pre-calculates this
\r
173 //! Internal members used by CSkinnedMesh
\r
174 friend class CSkinnedMesh;
\r
176 SJoint *UseAnimationFrom;
\r
177 bool GlobalSkinningSpace;
\r
185 //Interface for the mesh loaders (finalize should lock these functions, and they should have some prefix like loader_
\r
187 //these functions will use the needed arrays, set values, etc to help the loaders
\r
189 //! exposed for loaders: to add mesh buffers
\r
190 virtual core::array<SSkinMeshBuffer*>& getMeshBuffers() = 0;
\r
192 //! exposed for loaders: joints list
\r
193 virtual core::array<SJoint*>& getAllJoints() = 0;
\r
195 //! exposed for loaders: joints list
\r
196 virtual const core::array<SJoint*>& getAllJoints() const = 0;
\r
198 //! loaders should call this after populating the mesh
\r
199 virtual void finalize() = 0;
\r
201 //! Adds a new meshbuffer to the mesh, access it as last one
\r
202 virtual SSkinMeshBuffer* addMeshBuffer() = 0;
\r
204 //! Adds a new joint to the mesh, access it as last one
\r
205 virtual SJoint* addJoint(SJoint *parent=0) = 0;
\r
207 //! Adds a new weight to the mesh, access it as last one
\r
208 virtual SWeight* addWeight(SJoint *joint) = 0;
\r
210 //! Adds a new position key to the mesh, access it as last one
\r
211 virtual SPositionKey* addPositionKey(SJoint *joint) = 0;
\r
212 //! Adds a new scale key to the mesh, access it as last one
\r
213 virtual SScaleKey* addScaleKey(SJoint *joint) = 0;
\r
214 //! Adds a new rotation key to the mesh, access it as last one
\r
215 virtual SRotationKey* addRotationKey(SJoint *joint) = 0;
\r
217 //! Check if the mesh is non-animated
\r
218 virtual bool isStatic()=0;
\r
221 } // end namespace scene
\r
222 } // end namespace irr
\r