Add b3d loader for SP

This commit is contained in:
Benau 2018-01-06 12:07:22 +08:00
parent a06d9e858b
commit 5293a0dbef
10 changed files with 1548 additions and 10 deletions

View File

@ -3,11 +3,11 @@
<config>
<!-- Minimum and maximum kart versions that can be used by this binary.
Older version will be ignored. -->
<kart-version min="3" max="3"/>
<kart-version min="2" max="3"/>
<!-- Minimum and maxium track versions that be be read by this binary.
Older versions will be ignored. -->
<track-version min="7" max="7"/>
<track-version min="6" max="7"/>
<!-- Maximum number of karts to be used at the same time. This limit
can easily be increased, but some tracks might not have valid start

View File

@ -172,10 +172,14 @@ namespace scene
void convertForSkinning();
void computeWeightInfluence(SJoint *joint, size_t &index, WeightInfluence& wi);
void buildAllGlobalAnimatedMatrices(SJoint *Joint=0, SJoint *ParentJoint=0);
u32 getTotalJoints() const { return m_total_joints; }
f32 AnimationFrames;
core::array<SJoint*> RootJoints;
private:
void toStaticPose();
@ -186,8 +190,6 @@ private:
void buildAllLocalAnimatedMatrices();
void buildAllGlobalAnimatedMatrices(SJoint *Joint=0, SJoint *ParentJoint=0);
void getFrameData(f32 frame, SJoint *Node,
core::vector3df &position, s32 &positionHint,
core::vector3df &scale, s32 &scaleHint,
@ -211,7 +213,6 @@ private:
core::array<SSkinMeshBuffer*> LocalBuffers;
core::array<SJoint*> AllJoints;
core::array<SJoint*> RootJoints;
core::array< core::array<bool> > Vertices_Moved;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,160 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef HEADER_STK_MESH_LOADER_HPP
#define HEADER_STK_MESH_LOADER_HPP
#include "../lib/irrlicht/source/Irrlicht/CSkinnedMesh.h"
#include <IMeshLoader.h>
#include <ISceneManager.h>
#include <IReadFile.h>
#include <string>
#include <unordered_map>
using namespace irr;
namespace SP
{
class SPMesh;
}
class B3DMeshLoader : public scene::IMeshLoader
{
public:
static int m_straight_frame;
//! Constructor
B3DMeshLoader(scene::ISceneManager* smgr);
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".bsp")
virtual bool isALoadableFileExtension(const io::path& filename) const;
//! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
//! See IReferenceCounted::drop() for more information.
virtual scene::IAnimatedMesh* createMesh(io::IReadFile* file);
private:
class JointInfluence
{
public:
int joint_idx;
float weight;
};
static bool sortJointInfluenceFunc(const JointInfluence& a,
const JointInfluence& b)
{
return a.weight > b.weight;
}
typedef core::array<core::array <core::array<JointInfluence> > >
WeightInfluence;
SP::SPMesh* toSPM(scene::CSkinnedMesh* mesh);
std::unordered_map<scene::IMeshBuffer*, std::pair<std::string, std::string> > m_texture_string;
struct SB3dChunkHeader
{
c8 name[4];
s32 size;
};
struct SB3dChunk
{
SB3dChunk(const SB3dChunkHeader& header, long sp)
: length(header.size+8), startposition(sp)
{
name[0]=header.name[0];
name[1]=header.name[1];
name[2]=header.name[2];
name[3]=header.name[3];
}
c8 name[4];
s32 length;
long startposition;
};
struct SB3dTexture
{
core::stringc TextureName;
s32 Flags;
s32 Blend;
f32 Xpos;
f32 Ypos;
f32 Xscale;
f32 Yscale;
f32 Angle;
};
struct SB3dMaterial
{
SB3dMaterial() : red(1.0f), green(1.0f),
blue(1.0f), alpha(1.0f), shininess(0.0f), blend(1),
fx(0)
{
for (u32 i=0; i<video::MATERIAL_MAX_TEXTURES; ++i)
Textures[i]=0;
}
video::SMaterial Material;
f32 red, green, blue, alpha;
f32 shininess;
s32 blend,fx;
SB3dTexture *Textures[video::MATERIAL_MAX_TEXTURES];
};
void computeWeightInfluence(scene::CSkinnedMesh::SJoint* joint,
unsigned& index, WeightInfluence& wi);
void addSPAnimation(SP::SPMesh* spm, scene::CSkinnedMesh::SJoint* joint,
unsigned& index, unsigned frame);
bool load();
bool readChunkNODE(scene::CSkinnedMesh::SJoint* InJoint);
bool readChunkMESH(scene::CSkinnedMesh::SJoint* InJoint);
bool readChunkVRTS(scene::CSkinnedMesh::SJoint* InJoint);
bool readChunkTRIS(scene::SSkinMeshBuffer *MeshBuffer, u32 MeshBufferID, s32 Vertices_Start);
bool readChunkBONE(scene::CSkinnedMesh::SJoint* InJoint);
bool readChunkKEYS(scene::CSkinnedMesh::SJoint* InJoint);
bool readChunkANIM();
bool readChunkTEXS();
bool readChunkBRUS();
void loadTextures(SB3dMaterial& material, scene::IMeshBuffer* mb);
void readString(core::stringc& newstring);
void readFloats(f32* vec, u32 count);
core::array<SB3dChunk> B3dStack;
core::array<SB3dMaterial> Materials;
core::array<SB3dTexture> Textures;
core::array<s32> AnimatedVertices_VertexID;
core::array<s32> AnimatedVertices_BufferID;
core::array<video::S3DVertex2TCoords> BaseVertices;
scene::ISceneManager* SceneManager;
scene::CSkinnedMesh* AnimatedMesh;
io::IReadFile* B3DFile;
//B3Ds have Vertex ID's local within the mesh I don't want this
// Variable needs to be class member due to recursion in calls
u32 VerticesStart;
bool NormalsInFile;
bool HasVertexColors;
bool ShowWarning;
};
#endif

View File

@ -35,6 +35,7 @@
#include "graphics/render_target.hpp"
#include "graphics/shader_based_renderer.hpp"
#include "graphics/shaders.hpp"
#include "graphics/b3d_mesh_loader.hpp"
#include "graphics/sp_mesh_loader.hpp"
#include "graphics/sp/sp_base.hpp"
#include "graphics/sp/sp_dynamic_draw_call.hpp"
@ -510,6 +511,11 @@ void IrrDriver::initDevice()
m_scene_manager = m_device->getSceneManager();
m_gui_env = m_device->getGUIEnvironment();
m_video_driver = m_device->getVideoDriver();
B3DMeshLoader* b3dl = new B3DMeshLoader(m_scene_manager);
m_scene_manager->addExternalMeshLoader(b3dl);
b3dl->drop();
SPMeshLoader* spml = new SPMeshLoader(m_scene_manager);
m_scene_manager->addExternalMeshLoader(spml);
spml->drop();

View File

@ -28,6 +28,7 @@
using namespace irr;
using namespace scene;
class B3DMeshLoader;
class SPMeshLoader;
namespace SP
@ -37,6 +38,7 @@ struct Armature;
class SPMesh : public ISkinnedMesh
{
friend class ::B3DMeshLoader;
friend class ::SPMeshLoader;
private:
std::vector<SPMeshBuffer*> m_buffer;

View File

@ -148,7 +148,7 @@ public:
// ------------------------------------------------------------------------
virtual void uploadInstanceData();
// ------------------------------------------------------------------------
bool combineMeshBuffer(SPMeshBuffer* spmb)
bool combineMeshBuffer(SPMeshBuffer* spmb, bool different_material = true)
{
// We only use 16bit vertices
if (spmb->m_vertices.size() + m_vertices.size() > 65536)
@ -162,8 +162,15 @@ public:
{
idx += old_vtx_count;
}
m_stk_material.emplace_back(getIndexCount(), spmb->getIndexCount(),
std::get<2>(spmb->m_stk_material[0]));
if (different_material)
{
m_stk_material.emplace_back(getIndexCount(), spmb->getIndexCount(),
std::get<2>(spmb->m_stk_material[0]));
}
else
{
std::get<1>(m_stk_material[0]) += spmb->m_indices.size();
}
m_indices.insert(m_indices.end(), spmb->m_indices.begin(),
spmb->m_indices.end());
return true;

View File

@ -20,7 +20,6 @@
#include "graphics/sp/sp_mesh.hpp"
#include "graphics/sp/sp_mesh_buffer.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/material.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/stk_tex_manager.hpp"
#include "utils/constants.hpp"

View File

@ -25,6 +25,7 @@
#include "config/stk_config.hpp"
#include "config/user_config.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/b3d_mesh_loader.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/lod_node.hpp"
#include "graphics/material.hpp"
@ -565,7 +566,13 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
{
assert(m_is_master);
std::string full_path = kart_properties.getKartDir()+m_model_filename;
// For b3d loader only
if (m_animation_frame[AF_STRAIGHT] > -1)
{
B3DMeshLoader::m_straight_frame = m_animation_frame[AF_STRAIGHT];
}
m_mesh = irr_driver->getAnimatedMesh(full_path);
B3DMeshLoader::m_straight_frame = 0;
if(!m_mesh)
{
Log::error("Kart_Model", "Problems loading mesh '%s' - kart '%s' will"

View File

@ -1152,7 +1152,11 @@ bool Track::loadMainTrack(const XMLNode &root)
scene::ISceneNode* scene_node = NULL;
scene::IMesh* tangent_mesh = NULL;
if (m_version < 7)
#ifdef SERVER_ONLY
if (false)
#else
if (m_version < 7 && !CVS->isGLSL())
#endif
{
// The mesh as returned does not have all mesh buffers with the same
// texture combined. This can result in a _HUGE_ overhead. E.g. instead