SuperTuxKart
sp_mesh.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2018 SuperTuxKart-Team
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 3
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 
18 #ifndef HEADER_SP_MESH_HPP
19 #define HEADER_SP_MESH_HPP
20 
21 #include <array>
22 #include <cassert>
23 #include <IAnimatedMeshSceneNode.h>
24 #include <ISkinnedMesh.h>
25 #include <vector>
26 
27 
28 using namespace irr;
29 using namespace scene;
30 
31 class B3DMeshLoader;
32 class SPMeshLoader;
33 
34 namespace SP
35 {
36 class SPMeshBuffer;
37 struct Armature;
38 
39 class SPMesh : public ISkinnedMesh
40 {
41 friend class ::B3DMeshLoader;
42 friend class ::SPMeshLoader;
43 private:
44  std::vector<SPMeshBuffer*> m_buffer;
45 
46  core::aabbox3d<f32> m_bounding_box;
47 
48  float m_fps;
49 
50  unsigned m_bind_frame, m_total_joints, m_joint_using, m_frame_count;
51 
52  std::vector<SP::Armature> m_all_armatures;
53 
54 public:
55  // ------------------------------------------------------------------------
56  SPMesh();
57  // ------------------------------------------------------------------------
58  virtual ~SPMesh();
59  // ------------------------------------------------------------------------
60  virtual u32 getFrameCount() const { return m_frame_count; }
61  // ------------------------------------------------------------------------
62  virtual f32 getAnimationSpeed() const { return m_fps; }
63  // ------------------------------------------------------------------------
64  virtual void setAnimationSpeed(f32 fps) { m_fps = fps; }
65  // ------------------------------------------------------------------------
66  virtual IMesh* getMesh(s32 frame, s32 detailLevel=255,
67  s32 startFrameLoop=-1, s32 endFrameLoop=-1)
68  { return this; }
69  // ------------------------------------------------------------------------
70  virtual void animateMesh(f32 frame, f32 blend) {}
71  // ------------------------------------------------------------------------
72  virtual void skinMesh(f32 strength = 1.0f) {}
73  // ------------------------------------------------------------------------
74  virtual u32 getMeshBufferCount() const
75  { return (unsigned)m_buffer.size(); }
76  // ------------------------------------------------------------------------
77  virtual IMeshBuffer* getMeshBuffer(u32 nr) const;
78  // ------------------------------------------------------------------------
79  virtual IMeshBuffer* getMeshBuffer(const video::SMaterial &material) const;
80  // ------------------------------------------------------------------------
81  virtual const core::aabbox3d<f32>& getBoundingBox() const
82  { return m_bounding_box; }
83  // ------------------------------------------------------------------------
84  virtual void setBoundingBox(const core::aabbox3df& box)
85  { m_bounding_box = box; }
86  // ------------------------------------------------------------------------
87  virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) {}
88  // ------------------------------------------------------------------------
89  virtual void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint,
90  E_BUFFER_TYPE buffer) {}
91  // ------------------------------------------------------------------------
92  virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) {}
93  // ------------------------------------------------------------------------
94  virtual E_ANIMATED_MESH_TYPE getMeshType() const { return EAMT_SKINNED; }
95  // ------------------------------------------------------------------------
96  virtual u32 getJointCount() const { return m_joint_using; }
97  // ------------------------------------------------------------------------
98  virtual const c8* getJointName(u32 number) const;
99  // ------------------------------------------------------------------------
100  virtual s32 getJointNumber(const c8* name) const
101  {
102  // Real SPM doesn't use this
103  return -1;
104  }
105  // ------------------------------------------------------------------------
106  virtual bool useAnimationFrom(const ISkinnedMesh *mesh) { return true; }
107  // ------------------------------------------------------------------------
108  virtual void updateNormalsWhenAnimating(bool on) {}
109  // ------------------------------------------------------------------------
110  virtual void setInterpolationMode(E_INTERPOLATION_MODE mode) {}
111  // ------------------------------------------------------------------------
112  virtual bool isStatic() { return m_all_armatures.empty(); }
113  // ------------------------------------------------------------------------
114  virtual bool setHardwareSkinning(bool on) { return true; }
115  // ------------------------------------------------------------------------
116  virtual core::array<SSkinMeshBuffer*>& getMeshBuffers()
117  {
118  assert(false);
119  static auto unused = core::array<SSkinMeshBuffer*>();
120  return unused;
121  }
122  // ------------------------------------------------------------------------
123  virtual core::array<SJoint*>& getAllJoints()
124  {
125  assert(false);
126  static auto unused = core::array<SJoint*>();
127  return unused;
128  }
129  // ------------------------------------------------------------------------
130  virtual const core::array<SJoint*>& getAllJoints() const
131  {
132  assert(false);
133  static auto unused = core::array<SJoint*>();
134  return unused;
135  }
136  // ------------------------------------------------------------------------
137  virtual void finalize();
138  // ------------------------------------------------------------------------
139  virtual SSkinMeshBuffer *addMeshBuffer() { return NULL; }
140  // ------------------------------------------------------------------------
141  virtual SJoint *addJoint(SJoint *parent) { return NULL; }
142  // ------------------------------------------------------------------------
143  virtual SPositionKey *addPositionKey(SJoint *joint) { return NULL; }
144  // ------------------------------------------------------------------------
145  virtual SRotationKey *addRotationKey(SJoint *joint) { return NULL; }
146  // ------------------------------------------------------------------------
147  virtual SScaleKey *addScaleKey(SJoint *joint) { return NULL; }
148  // ------------------------------------------------------------------------
149  virtual SWeight *addWeight(SJoint *joint) { return NULL; }
150  // ------------------------------------------------------------------------
151  virtual void updateBoundingBox(void);
152  // ------------------------------------------------------------------------
153  std::vector<Armature>& getArmatures() { return m_all_armatures; }
154  // ------------------------------------------------------------------------
155  void getSkinningMatrices(f32 frame, std::array<float, 16>* dest);
156  // ------------------------------------------------------------------------
157  s32 getJointIDWithArm(const c8* name, unsigned* arm_id) const;
158  // ------------------------------------------------------------------------
159  void addSPMeshBuffer(SPMeshBuffer* spmb) { m_buffer.push_back(spmb); }
160  // ------------------------------------------------------------------------
161  SPMeshBuffer* getSPMeshBuffer(u32 nr) const;
162 
163 };
164 
165 }
166 #endif
SP::SPMeshBuffer
Definition: sp_mesh_buffer.hpp:48
B3DMeshLoader
Definition: b3d_mesh_loader.hpp:25
SPMeshLoader
Definition: sp_mesh_loader.hpp:35
SP::SPMesh
Definition: sp_mesh.hpp:40