]> git.lizzy.rs Git - irrlicht.git/blob - include/ISkinnedMesh.h
Unify & improve log messages
[irrlicht.git] / include / ISkinnedMesh.h
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
4 \r
5 #ifndef __I_SKINNED_MESH_H_INCLUDED__\r
6 #define __I_SKINNED_MESH_H_INCLUDED__\r
7 \r
8 #include "irrArray.h"\r
9 #include "IBoneSceneNode.h"\r
10 #include "IAnimatedMesh.h"\r
11 #include "SSkinMeshBuffer.h"\r
12 \r
13 namespace irr\r
14 {\r
15 namespace scene\r
16 {\r
17 \r
18         enum E_INTERPOLATION_MODE\r
19         {\r
20                 // constant does use the current key-values without interpolation\r
21                 EIM_CONSTANT = 0,\r
22 \r
23                 // linear interpolation\r
24                 EIM_LINEAR,\r
25 \r
26                 //! count of all available interpolation modes\r
27                 EIM_COUNT\r
28         };\r
29 \r
30 \r
31         //! Interface for using some special functions of Skinned meshes\r
32         class ISkinnedMesh : public IAnimatedMesh\r
33         {\r
34         public:\r
35 \r
36                 //! Gets joint count.\r
37                 /** \return Amount of joints in the skeletal animated mesh. */\r
38                 virtual u32 getJointCount() const = 0;\r
39 \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
45 \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
50 \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
58 \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
62                 animated meshes. */\r
63                 virtual void updateNormalsWhenAnimating(bool on) = 0;\r
64 \r
65                 //! Sets Interpolation Mode\r
66                 virtual void setInterpolationMode(E_INTERPOLATION_MODE mode) = 0;\r
67 \r
68                 //! Animates this mesh's joints based on frame input\r
69                 virtual void animateMesh(f32 frame, f32 blend)=0;\r
70 \r
71                 //! Preforms a software skin on this mesh based of joint positions\r
72                 virtual void skinMesh() = 0;\r
73 \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
77 \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
81 \r
82                 //! Refreshes vertex data cached in joints such as positions and normals\r
83                 virtual void refreshJointCache() = 0;\r
84 \r
85                 //! Moves the mesh into static position.\r
86                 virtual void resetAnimation() = 0;\r
87 \r
88                 //! A vertex weight\r
89                 struct SWeight\r
90                 {\r
91                         //! Index of the mesh buffer\r
92                         u16 buffer_id; //I doubt 32bits is needed\r
93 \r
94                         //! Index of the vertex\r
95                         u32 vertex_id; //Store global ID here\r
96 \r
97                         //! Weight Strength/Percentage (0-1)\r
98                         f32 strength;\r
99 \r
100                 private:\r
101                         //! Internal members used by CSkinnedMesh\r
102                         friend class CSkinnedMesh;\r
103                         char *Moved;\r
104                         core::vector3df StaticPos;\r
105                         core::vector3df StaticNormal;\r
106                 };\r
107 \r
108 \r
109                 //! Animation keyframe which describes a new position\r
110                 struct SPositionKey\r
111                 {\r
112                         f32 frame;\r
113                         core::vector3df position;\r
114                 };\r
115 \r
116                 //! Animation keyframe which describes a new scale\r
117                 struct SScaleKey\r
118                 {\r
119                         f32 frame;\r
120                         core::vector3df scale;\r
121                 };\r
122 \r
123                 //! Animation keyframe which describes a new rotation\r
124                 struct SRotationKey\r
125                 {\r
126                         f32 frame;\r
127                         core::quaternion rotation;\r
128                 };\r
129 \r
130                 //! Joints\r
131                 struct SJoint\r
132                 {\r
133                         SJoint() : UseAnimationFrom(0), GlobalSkinningSpace(false),\r
134                                 positionHint(-1),scaleHint(-1),rotationHint(-1)\r
135                         {\r
136                         }\r
137 \r
138                         //! The name of this joint\r
139                         core::stringc Name;\r
140 \r
141                         //! Local matrix of this joint\r
142                         core::matrix4 LocalMatrix;\r
143 \r
144                         //! List of child joints\r
145                         core::array<SJoint*> Children;\r
146 \r
147                         //! List of attached meshes\r
148                         core::array<u32> AttachedMeshes;\r
149 \r
150                         //! Animation keys causing translation change\r
151                         core::array<SPositionKey> PositionKeys;\r
152 \r
153                         //! Animation keys causing scale change\r
154                         core::array<SScaleKey> ScaleKeys;\r
155 \r
156                         //! Animation keys causing rotation change\r
157                         core::array<SRotationKey> RotationKeys;\r
158 \r
159                         //! Skin weights\r
160                         core::array<SWeight> Weights;\r
161 \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
169 \r
170                         core::matrix4 GlobalInversedMatrix; //the x format pre-calculates this\r
171 \r
172                 private:\r
173                         //! Internal members used by CSkinnedMesh\r
174                         friend class CSkinnedMesh;\r
175 \r
176                         SJoint *UseAnimationFrom;\r
177                         bool GlobalSkinningSpace;\r
178 \r
179                         s32 positionHint;\r
180                         s32 scaleHint;\r
181                         s32 rotationHint;\r
182                 };\r
183 \r
184 \r
185                 //Interface for the mesh loaders (finalize should lock these functions, and they should have some prefix like loader_\r
186 \r
187                 //these functions will use the needed arrays, set values, etc to help the loaders\r
188 \r
189                 //! exposed for loaders: to add mesh buffers\r
190                 virtual core::array<SSkinMeshBuffer*>& getMeshBuffers() = 0;\r
191 \r
192                 //! exposed for loaders: joints list\r
193                 virtual core::array<SJoint*>& getAllJoints() = 0;\r
194 \r
195                 //! exposed for loaders: joints list\r
196                 virtual const core::array<SJoint*>& getAllJoints() const = 0;\r
197 \r
198                 //! loaders should call this after populating the mesh\r
199                 virtual void finalize() = 0;\r
200 \r
201                 //! Adds a new meshbuffer to the mesh, access it as last one\r
202                 virtual SSkinMeshBuffer* addMeshBuffer() = 0;\r
203 \r
204                 //! Adds a new joint to the mesh, access it as last one\r
205                 virtual SJoint* addJoint(SJoint *parent=0) = 0;\r
206 \r
207                 //! Adds a new weight to the mesh, access it as last one\r
208                 virtual SWeight* addWeight(SJoint *joint) = 0;\r
209 \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
216 \r
217                 //! Check if the mesh is non-animated\r
218                 virtual bool isStatic()=0;\r
219         };\r
220 \r
221 } // end namespace scene\r
222 } // end namespace irr\r
223 \r
224 #endif\r
225 \r