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