]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CSkinnedMesh.h
Add OpenGL3 renderer
[irrlicht.git] / source / Irrlicht / CSkinnedMesh.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 //New skinned mesh\r
6 \r
7 #ifndef __C_SKINNED_MESH_H_INCLUDED__\r
8 #define __C_SKINNED_MESH_H_INCLUDED__\r
9 \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
16 \r
17 namespace irr\r
18 {\r
19 namespace scene\r
20 {\r
21 \r
22         class IAnimatedMeshSceneNode;\r
23         class IBoneSceneNode;\r
24 \r
25         class CSkinnedMesh: public ISkinnedMesh\r
26         {\r
27         public:\r
28 \r
29                 //! constructor\r
30                 CSkinnedMesh();\r
31 \r
32                 //! destructor\r
33                 virtual ~CSkinnedMesh();\r
34 \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
37 \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
41 \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
46 \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
49 \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
53 \r
54                 //! Preforms a software skin on this mesh based of joint positions\r
55                 void skinMesh() override;\r
56 \r
57                 //! returns amount of mesh buffers.\r
58                 u32 getMeshBufferCount() const override;\r
59 \r
60                 //! returns pointer to a mesh buffer\r
61                 IMeshBuffer* getMeshBuffer(u32 nr) const override;\r
62 \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
68 \r
69                 //! returns an axis aligned bounding box\r
70                 const core::aabbox3d<f32>& getBoundingBox() const override;\r
71 \r
72                 //! set user axis aligned bounding box\r
73                 void setBoundingBox( const core::aabbox3df& box) override;\r
74 \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
77 \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
80 \r
81                 //! flags the meshbuffer as changed, reloads hardware buffers\r
82                 void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) override;\r
83 \r
84                 //! Returns the type of the animated mesh.\r
85                 E_ANIMATED_MESH_TYPE getMeshType() const override;\r
86 \r
87                 //! Gets joint count.\r
88                 u32 getJointCount() const override;\r
89 \r
90                 //! Gets the name of a joint.\r
91                 const c8* getJointName(u32 number) const override;\r
92 \r
93                 //! Gets a joint number from its name\r
94                 s32 getJointNumber(const c8* name) const override;\r
95 \r
96                 //! uses animation from another mesh\r
97                 bool useAnimationFrom(const ISkinnedMesh *mesh) override;\r
98 \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
103 \r
104                 //! Sets Interpolation Mode\r
105                 void setInterpolationMode(E_INTERPOLATION_MODE mode) override;\r
106 \r
107                 //! Convertes the mesh to contain tangent information\r
108                 void convertMeshToTangents() override;\r
109 \r
110                 //! Does the mesh have no animation\r
111                 bool isStatic() override;\r
112 \r
113                 //! (This feature is not implemented in irrlicht yet)\r
114                 bool setHardwareSkinning(bool on) override;\r
115 \r
116                 //! Refreshes vertex data cached in joints such as positions and normals\r
117                 void refreshJointCache() override;\r
118 \r
119                 //! Moves the mesh into static position.\r
120                 void resetAnimation() override;\r
121 \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
124 \r
125                 //! exposed for loaders to add mesh buffers\r
126                 core::array<SSkinMeshBuffer*> &getMeshBuffers() override;\r
127 \r
128                 //! alternative method for adding joints\r
129                 core::array<SJoint*> &getAllJoints() override;\r
130 \r
131                 //! alternative method for adding joints\r
132                 const core::array<SJoint*> &getAllJoints() const override;\r
133 \r
134                 //! loaders should call this after populating the mesh\r
135                 void finalize() override;\r
136 \r
137                 //! Adds a new meshbuffer to the mesh, access it as last one\r
138                 SSkinMeshBuffer *addMeshBuffer() override;\r
139 \r
140                 //! Adds a new joint to the mesh, access it as last one\r
141                 SJoint *addJoint(SJoint *parent=0) override;\r
142 \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
149 \r
150                 //! Adds a new weight to the mesh, access it as last one\r
151                 SWeight *addWeight(SJoint *joint) override;\r
152 \r
153                 virtual void updateBoundingBox(void);\r
154 \r
155                 //! Recovers the joints from the mesh\r
156                 void recoverJointsFromMesh(core::array<IBoneSceneNode*> &jointChildSceneNodes);\r
157 \r
158                 //! Tranfers the joint data to the mesh\r
159                 void transferJointsToMesh(const core::array<IBoneSceneNode*> &jointChildSceneNodes);\r
160 \r
161                 //! Tranfers the joint hints to the mesh\r
162                 void transferOnlyJointsHintsToMesh(const core::array<IBoneSceneNode*> &jointChildSceneNodes);\r
163 \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
168 \r
169 private:\r
170                 void checkForAnimation();\r
171 \r
172                 void normalizeWeights();\r
173 \r
174                 void buildAllLocalAnimatedMatrices();\r
175 \r
176                 void buildAllGlobalAnimatedMatrices(SJoint *Joint=0, SJoint *ParentJoint=0);\r
177 \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
182 \r
183                 void calculateGlobalMatrices(SJoint *Joint,SJoint *ParentJoint);\r
184 \r
185                 void skinJoint(SJoint *Joint, SJoint *ParentJoint);\r
186 \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
191 \r
192                 core::array<SSkinMeshBuffer*> *SkinningBuffers; //Meshbuffer to skin, default is to skin localBuffers\r
193 \r
194                 core::array<SSkinMeshBuffer*> LocalBuffers;\r
195 \r
196                 core::array<SJoint*> AllJoints;\r
197                 core::array<SJoint*> RootJoints;\r
198 \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
202 \r
203                 core::aabbox3d<f32> BoundingBox;\r
204 \r
205                 f32 EndFrame;\r
206                 f32 FramesPerSecond;\r
207 \r
208                 f32 LastAnimatedFrame;\r
209                 bool SkinnedLastFrame;\r
210 \r
211                 E_INTERPOLATION_MODE InterpolationMode:8;\r
212 \r
213                 bool HasAnimation;\r
214                 bool PreparedForSkinning;\r
215                 bool AnimateNormals;\r
216                 bool HardwareSkinning;\r
217         };\r
218 \r
219 } // end namespace scene\r
220 } // end namespace irr\r
221 \r
222 #endif\r
223 \r