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
88 //! Index of the mesh buffer
\r
89 u16 buffer_id; //I doubt 32bits is needed
\r
91 //! Index of the vertex
\r
92 u32 vertex_id; //Store global ID here
\r
94 //! Weight Strength/Percentage (0-1)
\r
98 //! Internal members used by CSkinnedMesh
\r
99 friend class CSkinnedMesh;
\r
101 core::vector3df StaticPos;
\r
102 core::vector3df StaticNormal;
\r
106 //! Animation keyframe which describes a new position
\r
107 struct SPositionKey
\r
110 core::vector3df position;
\r
113 //! Animation keyframe which describes a new scale
\r
117 core::vector3df scale;
\r
120 //! Animation keyframe which describes a new rotation
\r
121 struct SRotationKey
\r
124 core::quaternion rotation;
\r
130 SJoint() : UseAnimationFrom(0), GlobalSkinningSpace(false),
\r
131 positionHint(-1),scaleHint(-1),rotationHint(-1)
\r
135 //! The name of this joint
\r
136 core::stringc Name;
\r
138 //! Local matrix of this joint
\r
139 core::matrix4 LocalMatrix;
\r
141 //! List of child joints
\r
142 core::array<SJoint*> Children;
\r
144 //! List of attached meshes
\r
145 core::array<u32> AttachedMeshes;
\r
147 //! Animation keys causing translation change
\r
148 core::array<SPositionKey> PositionKeys;
\r
150 //! Animation keys causing scale change
\r
151 core::array<SScaleKey> ScaleKeys;
\r
153 //! Animation keys causing rotation change
\r
154 core::array<SRotationKey> RotationKeys;
\r
157 core::array<SWeight> Weights;
\r
159 //! Unnecessary for loaders, will be overwritten on finalize
\r
160 core::matrix4 GlobalMatrix;
\r
161 core::matrix4 GlobalAnimatedMatrix;
\r
162 core::matrix4 LocalAnimatedMatrix;
\r
163 core::vector3df Animatedposition;
\r
164 core::vector3df Animatedscale;
\r
165 core::quaternion Animatedrotation;
\r
167 core::matrix4 GlobalInversedMatrix; //the x format pre-calculates this
\r
170 //! Internal members used by CSkinnedMesh
\r
171 friend class CSkinnedMesh;
\r
173 SJoint *UseAnimationFrom;
\r
174 bool GlobalSkinningSpace;
\r
182 //Interface for the mesh loaders (finalize should lock these functions, and they should have some prefix like loader_
\r
184 //these functions will use the needed arrays, set values, etc to help the loaders
\r
186 //! exposed for loaders: to add mesh buffers
\r
187 virtual core::array<SSkinMeshBuffer*>& getMeshBuffers() = 0;
\r
189 //! exposed for loaders: joints list
\r
190 virtual core::array<SJoint*>& getAllJoints() = 0;
\r
192 //! exposed for loaders: joints list
\r
193 virtual const core::array<SJoint*>& getAllJoints() const = 0;
\r
195 //! loaders should call this after populating the mesh
\r
196 virtual void finalize() = 0;
\r
198 //! Adds a new meshbuffer to the mesh, access it as last one
\r
199 virtual SSkinMeshBuffer* addMeshBuffer() = 0;
\r
201 //! Adds a new joint to the mesh, access it as last one
\r
202 virtual SJoint* addJoint(SJoint *parent=0) = 0;
\r
204 //! Adds a new weight to the mesh, access it as last one
\r
205 virtual SWeight* addWeight(SJoint *joint) = 0;
\r
207 //! Adds a new position key to the mesh, access it as last one
\r
208 virtual SPositionKey* addPositionKey(SJoint *joint) = 0;
\r
209 //! Adds a new scale key to the mesh, access it as last one
\r
210 virtual SScaleKey* addScaleKey(SJoint *joint) = 0;
\r
211 //! Adds a new rotation key to the mesh, access it as last one
\r
212 virtual SRotationKey* addRotationKey(SJoint *joint) = 0;
\r
214 //! Check if the mesh is non-animated
\r
215 virtual bool isStatic()=0;
\r
218 } // end namespace scene
\r
219 } // end namespace irr
\r