SuperTuxKart
Loading...
Searching...
No Matches
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
28using namespace irr;
29using namespace scene;
30
31class B3DMeshLoader;
32class SPMeshLoader;
33
34namespace GE
35{
36 struct Armature;
37}
38
39namespace SP
40{
41class SPMeshBuffer;
42
43class SPMesh : public ISkinnedMesh
44{
45friend class ::B3DMeshLoader;
46friend class ::SPMeshLoader;
47private:
48 std::vector<SPMeshBuffer*> m_buffer;
49
50 core::aabbox3d<f32> m_bounding_box;
51
52 float m_fps;
53
54 unsigned m_bind_frame, m_total_joints, m_joint_using, m_frame_count;
55
56 std::vector<GE::Armature> m_all_armatures;
57
58public:
59 // ------------------------------------------------------------------------
60 SPMesh();
61 // ------------------------------------------------------------------------
62 virtual ~SPMesh();
63 // ------------------------------------------------------------------------
64 virtual u32 getFrameCount() const { return m_frame_count; }
65 // ------------------------------------------------------------------------
66 virtual f32 getAnimationSpeed() const { return m_fps; }
67 // ------------------------------------------------------------------------
68 virtual void setAnimationSpeed(f32 fps) { m_fps = fps; }
69 // ------------------------------------------------------------------------
70 virtual IMesh* getMesh(s32 frame, s32 detailLevel=255,
71 s32 startFrameLoop=-1, s32 endFrameLoop=-1)
72 { return this; }
73 // ------------------------------------------------------------------------
74 virtual void animateMesh(f32 frame, f32 blend) {}
75 // ------------------------------------------------------------------------
76 virtual void skinMesh(f32 strength = 1.0f) {}
77 // ------------------------------------------------------------------------
78 virtual u32 getMeshBufferCount() const
79 { return (unsigned)m_buffer.size(); }
80 // ------------------------------------------------------------------------
81 virtual IMeshBuffer* getMeshBuffer(u32 nr) const;
82 // ------------------------------------------------------------------------
83 virtual IMeshBuffer* getMeshBuffer(const video::SMaterial &material) const;
84 // ------------------------------------------------------------------------
85 virtual const core::aabbox3d<f32>& getBoundingBox() const
86 { return m_bounding_box; }
87 // ------------------------------------------------------------------------
88 virtual void setBoundingBox(const core::aabbox3df& box)
89 { m_bounding_box = box; }
90 // ------------------------------------------------------------------------
91 virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) {}
92 // ------------------------------------------------------------------------
93 virtual void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint,
94 E_BUFFER_TYPE buffer) {}
95 // ------------------------------------------------------------------------
96 virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) {}
97 // ------------------------------------------------------------------------
98 virtual E_ANIMATED_MESH_TYPE getMeshType() const { return EAMT_SKINNED; }
99 // ------------------------------------------------------------------------
100 virtual u32 getJointCount() const { return m_joint_using; }
101 // ------------------------------------------------------------------------
102 virtual const c8* getJointName(u32 number) const;
103 // ------------------------------------------------------------------------
104 virtual s32 getJointNumber(const c8* name) const
105 {
106 // Real SPM doesn't use this
107 return -1;
108 }
109 // ------------------------------------------------------------------------
110 virtual bool useAnimationFrom(const ISkinnedMesh *mesh) { return true; }
111 // ------------------------------------------------------------------------
112 virtual void updateNormalsWhenAnimating(bool on) {}
113 // ------------------------------------------------------------------------
114 virtual void setInterpolationMode(E_INTERPOLATION_MODE mode) {}
115 // ------------------------------------------------------------------------
116 virtual bool isStatic() { return m_all_armatures.empty(); }
117 // ------------------------------------------------------------------------
118 virtual bool setHardwareSkinning(bool on) { return true; }
119 // ------------------------------------------------------------------------
120 virtual core::array<SSkinMeshBuffer*>& getMeshBuffers()
121 {
122 assert(false);
123 static auto unused = core::array<SSkinMeshBuffer*>();
124 return unused;
125 }
126 // ------------------------------------------------------------------------
127 virtual core::array<SJoint*>& getAllJoints()
128 {
129 assert(false);
130 static auto unused = core::array<SJoint*>();
131 return unused;
132 }
133 // ------------------------------------------------------------------------
134 virtual const core::array<SJoint*>& getAllJoints() const
135 {
136 assert(false);
137 static auto unused = core::array<SJoint*>();
138 return unused;
139 }
140 // ------------------------------------------------------------------------
141 virtual void finalize();
142 // ------------------------------------------------------------------------
143 virtual SSkinMeshBuffer *addMeshBuffer() { return NULL; }
144 // ------------------------------------------------------------------------
145 virtual SJoint *addJoint(SJoint *parent) { return NULL; }
146 // ------------------------------------------------------------------------
147 virtual SPositionKey *addPositionKey(SJoint *joint) { return NULL; }
148 // ------------------------------------------------------------------------
149 virtual SRotationKey *addRotationKey(SJoint *joint) { return NULL; }
150 // ------------------------------------------------------------------------
151 virtual SScaleKey *addScaleKey(SJoint *joint) { return NULL; }
152 // ------------------------------------------------------------------------
153 virtual SWeight *addWeight(SJoint *joint) { return NULL; }
154 // ------------------------------------------------------------------------
155 virtual void updateBoundingBox(void);
156 // ------------------------------------------------------------------------
157 std::vector<GE::Armature>& getArmatures() { return m_all_armatures; }
158 // ------------------------------------------------------------------------
159 void getSkinningMatrices(f32 frame, std::vector<core::matrix4>& dest,
160 float frame_interpolating = -1.0f, float rate = -1.0f);
161 // ------------------------------------------------------------------------
162 s32 getJointIDWithArm(const c8* name, unsigned* arm_id) const;
163 // ------------------------------------------------------------------------
164 void addSPMeshBuffer(SPMeshBuffer* spmb) { m_buffer.push_back(spmb); }
165 // ------------------------------------------------------------------------
166 SPMeshBuffer* getSPMeshBuffer(u32 nr) const;
167
168};
169
170}
171#endif
Definition: b3d_mesh_loader.hpp:25
Definition: sp_mesh_loader.hpp:35
Definition: sp_mesh_buffer.hpp:48
Definition: sp_mesh.hpp:44