SuperTuxKart
Loading...
Searching...
No Matches
sp_mesh_node.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_NODE_HPP
19#define HEADER_SP_MESH_NODE_HPP
20
21#include "../../../lib/irrlicht/source/Irrlicht/CAnimatedMeshSceneNode.h"
22#include <array>
23#include <cassert>
24#include <string>
25#include <memory>
26#include <vector>
27#include <unordered_map>
28
29using namespace irr;
30using namespace scene;
31namespace GE { class GERenderInfo; }
32
33namespace SP
34{
35class SPMesh;
36class SPShader;
37
38class SPMeshNode : public irr::scene::CAnimatedMeshSceneNode
39{
40private:
41 std::vector<std::shared_ptr<GE::GERenderInfo> > m_render_info;
42
43 std::shared_ptr<GE::GERenderInfo> m_first_render_info;
44
45 std::unordered_map<std::string, IBoneSceneNode*> m_joint_nodes;
46
47 SPMesh* m_mesh;
48
49 int m_skinning_offset;
50
51 bool m_animated;
52
53 bool m_is_in_shadowpass;
54
55 float m_saved_transition_frame;
56
57 std::vector<core::matrix4> m_skinning_matrices;
58
59 video::SColorf m_glow_color;
60
61 std::vector<std::array<float, 2> > m_texture_matrices;
62
63 // ------------------------------------------------------------------------
64 void cleanRenderInfo();
65 // ------------------------------------------------------------------------
66 void cleanJoints()
67 {
68 for (auto& p : m_joint_nodes)
69 {
70 removeChild(p.second);
71 }
72 m_joint_nodes.clear();
73 m_skinning_matrices.clear();
74 }
75
76public:
77 // ------------------------------------------------------------------------
78 SPMeshNode(IAnimatedMesh* mesh, ISceneNode* parent, ISceneManager* mgr,
79 s32 id, const std::string& debug_name,
80 const core::vector3df& position = core::vector3df(),
81 const core::vector3df& rotation = core::vector3df(),
82 const core::vector3df& scale = core::vector3df(1, 1, 1),
83 std::shared_ptr<GE::GERenderInfo> render_info = nullptr);
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
87 virtual void render() {}
88 // ------------------------------------------------------------------------
89 virtual void setMesh(irr::scene::IAnimatedMesh* mesh);
90 // ------------------------------------------------------------------------
91 virtual void OnAnimate(u32 time_ms);
92 // ------------------------------------------------------------------------
93 virtual void animateJoints(bool calculate_absolute_positions = true) {}
94 // ------------------------------------------------------------------------
95 virtual irr::scene::IMesh* getMeshForCurrentFrame();
96 // ------------------------------------------------------------------------
97 virtual IBoneSceneNode* getJointNode(const c8* joint_name);
98 // ------------------------------------------------------------------------
99 virtual IBoneSceneNode* getJointNode(u32 joint_id)
100 {
101 // SPM uses joint_name only
102 assert(false);
103 return NULL;
104 }
105 // ------------------------------------------------------------------------
106 virtual void setJointMode(E_JOINT_UPDATE_ON_RENDER mode) {}
107 // ------------------------------------------------------------------------
108 virtual void checkJoints() {}
109 // ------------------------------------------------------------------------
110 SPMesh* getSPM() const { return m_mesh; }
111 // ------------------------------------------------------------------------
112 int getTotalJoints() const;
113 // ------------------------------------------------------------------------
114 void setSkinningOffset(int offset) { m_skinning_offset = offset; }
115 // ------------------------------------------------------------------------
116 int getSkinningOffset() const { return m_skinning_offset; }
117 // ------------------------------------------------------------------------
118 void setAnimationState(bool val);
119 // ------------------------------------------------------------------------
120 bool getAnimationState() const { return m_animated; }
121 // ------------------------------------------------------------------------
122 bool isInShadowPass() const { return m_is_in_shadowpass; }
123 // ------------------------------------------------------------------------
124 void setInShadowPass(const bool is_in_shadowpass)
125 {
126 m_is_in_shadowpass = is_in_shadowpass;
127 }
128 // ------------------------------------------------------------------------
129 SPShader* getShader(unsigned mesh_buffer_id) const;
130 // ------------------------------------------------------------------------
131 const core::matrix4* getSkinningMatrices() const
132 { return m_skinning_matrices.data(); }
133 // ------------------------------------------------------------------------
134 GE::GERenderInfo* getRenderInfo(unsigned mb_id) const
135 {
136 if (m_render_info.size() > mb_id && m_render_info[mb_id].get())
137 {
138 return m_render_info[mb_id].get();
139 }
140 return NULL;
141 }
142 // ------------------------------------------------------------------------
143 virtual void resetFirstRenderInfo(std::shared_ptr<GE::GERenderInfo> ri)
144 {
145 m_render_info.clear();
146 m_first_render_info = ri;
147 m_render_info.resize(getMesh()->getMeshBufferCount(),
148 m_first_render_info);
149 }
150 // ------------------------------------------------------------------------
151 void setGlowColor(const video::SColorf& color) { m_glow_color = color; }
152 // ------------------------------------------------------------------------
153 const video::SColorf& getGlowColor() const { return m_glow_color; }
154 // ------------------------------------------------------------------------
155 bool hasGlowColor() const
156 {
157 return !(m_glow_color.r == 0.0f && m_glow_color.g == 0.0f &&
158 m_glow_color.b == 0.0f);
159 }
160 // ------------------------------------------------------------------------
161 std::array<float, 2>& getTextureMatrix(unsigned mb_id)
162 {
163 assert(mb_id < m_texture_matrices.size());
164 return m_texture_matrices[mb_id];
165 }
166 // ------------------------------------------------------------------------
167 void setTextureMatrix(unsigned mb_id, const std::array<float, 2>& tm)
168 {
169 assert(mb_id < m_texture_matrices.size());
170 m_texture_matrices[mb_id] = tm;
171 }
172 // ------------------------------------------------------------------------
173 virtual void setTransitionTime(f32 Time);
174};
175
176}
177
178#endif
Definition: sp_mesh_node.hpp:39
Definition: sp_mesh.hpp:44
Definition: sp_shader.hpp:81