SuperTuxKart
Loading...
Searching...
No Matches
b3d_mesh_loader.hpp
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#ifndef HEADER_STK_MESH_LOADER_HPP
6#define HEADER_STK_MESH_LOADER_HPP
7
8#include "../lib/irrlicht/source/Irrlicht/CSkinnedMesh.h"
9
10#include <IMeshLoader.h>
11#include <ISceneManager.h>
12#include <IReadFile.h>
13#include <string>
14#include <unordered_map>
15
16using namespace irr;
17
18namespace SP
19{
20 class SPMesh;
21}
22
23
24class B3DMeshLoader : public scene::IMeshLoader
25{
26public:
27 static int m_straight_frame;
28
30 B3DMeshLoader(scene::ISceneManager* smgr);
31
34 virtual bool isALoadableFileExtension(const io::path& filename) const;
35
40 virtual scene::IAnimatedMesh* createMesh(io::IReadFile* file);
41
42private:
44 {
45 public:
46 int joint_idx;
47 float weight;
48 };
49
50 static bool sortJointInfluenceFunc(const JointInfluence& a,
51 const JointInfluence& b)
52 {
53 return a.weight > b.weight;
54 }
55
56 typedef core::array<core::array <core::array<JointInfluence> > >
57 WeightInfluence;
58
59 SP::SPMesh* toSPM(scene::CSkinnedMesh* mesh);
60
61 std::unordered_map<scene::IMeshBuffer*, std::pair<std::string, std::string> > m_texture_string;
62
64 {
65 c8 name[4];
66 s32 size;
67 };
68
69 struct SB3dChunk
70 {
71 SB3dChunk(const SB3dChunkHeader& header, long sp)
72 : length(header.size+8), startposition(sp)
73 {
74 name[0]=header.name[0];
75 name[1]=header.name[1];
76 name[2]=header.name[2];
77 name[3]=header.name[3];
78 }
79
80 c8 name[4];
81 s32 length;
82 long startposition;
83 };
84
86 {
87 core::stringc TextureName;
88 s32 Flags;
89 s32 Blend;
90 f32 Xpos;
91 f32 Ypos;
92 f32 Xscale;
93 f32 Yscale;
94 f32 Angle;
95 };
96
98 {
99 SB3dMaterial() : red(1.0f), green(1.0f),
100 blue(1.0f), alpha(1.0f), shininess(0.0f), blend(1),
101 fx(0)
102 {
103 for (u32 i=0; i<video::MATERIAL_MAX_TEXTURES; ++i)
104 Textures[i]=0;
105 }
106 video::SMaterial Material;
107 f32 red, green, blue, alpha;
108 f32 shininess;
109 s32 blend,fx;
110 SB3dTexture *Textures[video::MATERIAL_MAX_TEXTURES];
111 };
112
113 void computeWeightInfluence(scene::CSkinnedMesh::SJoint* joint,
114 unsigned& index, WeightInfluence& wi);
115
116 void addSPAnimation(SP::SPMesh* spm, scene::CSkinnedMesh::SJoint* joint,
117 unsigned& index, unsigned frame);
118
119 bool load();
120 bool readChunkNODE(scene::CSkinnedMesh::SJoint* InJoint);
121 bool readChunkMESH(scene::CSkinnedMesh::SJoint* InJoint);
122 bool readChunkVRTS(scene::CSkinnedMesh::SJoint* InJoint);
123 bool readChunkTRIS(scene::SSkinMeshBuffer *MeshBuffer, u32 MeshBufferID, s32 Vertices_Start);
124 bool readChunkBONE(scene::CSkinnedMesh::SJoint* InJoint);
125 bool readChunkKEYS(scene::CSkinnedMesh::SJoint* InJoint);
126 bool readChunkANIM();
127 bool readChunkTEXS();
128 bool readChunkBRUS();
129
130 void loadTextures(SB3dMaterial& material, scene::IMeshBuffer* mb);
131
132 void readString(core::stringc& newstring);
133 void readFloats(f32* vec, u32 count);
134
135 core::array<SB3dChunk> B3dStack;
136
137 core::array<SB3dMaterial> Materials;
138 core::array<SB3dTexture> Textures;
139
140 core::array<s32> AnimatedVertices_VertexID;
141
142 core::array<s32> AnimatedVertices_BufferID;
143
144 core::array<video::S3DVertex2TCoords> BaseVertices;
145
146 scene::ISceneManager* SceneManager;
147 scene::CSkinnedMesh* AnimatedMesh;
148 io::IReadFile* B3DFile;
149
150 //B3Ds have Vertex ID's local within the mesh I don't want this
151 // Variable needs to be class member due to recursion in calls
152 u32 VerticesStart;
153
154 bool NormalsInFile;
155 bool HasVertexColors;
156 bool ShowWarning;
157};
158
159#endif
160
Definition: b3d_mesh_loader.hpp:44
Definition: b3d_mesh_loader.hpp:25
virtual scene::IAnimatedMesh * createMesh(io::IReadFile *file)
creates/loads an animated mesh from the file.
Definition: b3d_mesh_loader.cpp:55
virtual bool isALoadableFileExtension(const io::path &filename) const
returns true if the file maybe is able to be loaded by this class based on the file extension (e....
Definition: b3d_mesh_loader.cpp:45
Definition: material.hpp:48
Definition: sp_mesh.hpp:44
Definition: b3d_mesh_loader.hpp:64
Definition: b3d_mesh_loader.hpp:70
Definition: b3d_mesh_loader.hpp:98
Definition: b3d_mesh_loader.hpp:86