Add GE spm code
This commit is contained in:
parent
350773d316
commit
e666e08f2d
@ -34,6 +34,7 @@ set(GE_SOURCES
|
||||
src/ge_vulkan_shader_manager.cpp
|
||||
src/ge_vulkan_texture.cpp
|
||||
src/ge_gl_texture.cpp
|
||||
src/ge_spm.cpp
|
||||
)
|
||||
|
||||
if(NOT APPLE OR DLOPEN_MOLTENVK)
|
||||
|
75
lib/graphics_engine/include/ge_spm.hpp
Normal file
75
lib/graphics_engine/include/ge_spm.hpp
Normal file
@ -0,0 +1,75 @@
|
||||
#ifndef HEADER_GE_SPM_HPP
|
||||
#define HEADER_GE_SPM_HPP
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <IAnimatedMesh.h>
|
||||
#include <vector>
|
||||
|
||||
using namespace irr;
|
||||
using namespace scene;
|
||||
|
||||
class B3DMeshLoader;
|
||||
class SPMeshLoader;
|
||||
|
||||
namespace GE
|
||||
{
|
||||
class GESPMBuffer;
|
||||
|
||||
class GESPM : public IAnimatedMesh
|
||||
{
|
||||
friend class ::B3DMeshLoader;
|
||||
friend class ::SPMeshLoader;
|
||||
private:
|
||||
std::vector<GESPMBuffer*> m_buffer;
|
||||
|
||||
core::aabbox3d<f32> m_bounding_box;
|
||||
|
||||
float m_fps;
|
||||
|
||||
unsigned m_bind_frame, m_total_joints, m_joint_using, m_frame_count;
|
||||
|
||||
public:
|
||||
// ------------------------------------------------------------------------
|
||||
GESPM();
|
||||
// ------------------------------------------------------------------------
|
||||
virtual ~GESPM();
|
||||
// ------------------------------------------------------------------------
|
||||
virtual u32 getFrameCount() const { return m_frame_count; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual f32 getAnimationSpeed() const { return m_fps; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void setAnimationSpeed(f32 fps) { m_fps = fps; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual IMesh* getMesh(s32 frame, s32 detailLevel=255,
|
||||
s32 startFrameLoop=-1, s32 endFrameLoop=-1)
|
||||
{ return this; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual u32 getMeshBufferCount() const
|
||||
{ return (unsigned)m_buffer.size(); }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual IMeshBuffer* getMeshBuffer(u32 nr) const;
|
||||
// ------------------------------------------------------------------------
|
||||
virtual IMeshBuffer* getMeshBuffer(const video::SMaterial &material) const;
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const core::aabbox3d<f32>& getBoundingBox() const
|
||||
{ return m_bounding_box; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void setBoundingBox(const core::aabbox3df& box)
|
||||
{ m_bounding_box = box; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) {}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint,
|
||||
E_BUFFER_TYPE buffer) {}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) {}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual E_ANIMATED_MESH_TYPE getMeshType() const { return EAMT_SPM; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void finalize();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
149
lib/graphics_engine/include/ge_spm_buffer.hpp
Normal file
149
lib/graphics_engine/include/ge_spm_buffer.hpp
Normal file
@ -0,0 +1,149 @@
|
||||
#ifndef HEADER_GE_SPM_BUFFER_HPP
|
||||
#define HEADER_GE_SPM_BUFFER_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "IMeshBuffer.h"
|
||||
|
||||
class B3DMeshLoader;
|
||||
class SPMeshLoader;
|
||||
|
||||
namespace GE
|
||||
{
|
||||
class GESPMBuffer : public irr::scene::IMeshBuffer
|
||||
{
|
||||
friend class ::B3DMeshLoader;
|
||||
friend class ::SPMeshLoader;
|
||||
private:
|
||||
irr::video::SMaterial m_material;
|
||||
|
||||
std::vector<irr::video::S3DVertexSkinnedMesh> m_vertices;
|
||||
|
||||
std::vector<irr::u16> m_indices;
|
||||
|
||||
irr::core::aabbox3d<irr::f32> m_bounding_box;
|
||||
public:
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const irr::video::SMaterial& getMaterial() const
|
||||
{ return m_material; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::video::SMaterial& getMaterial() { return m_material; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const void* getVertices() const
|
||||
{ return m_vertices.data(); }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void* getVertices() { return m_vertices.data(); }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::u32 getVertexCount() const { return m_vertices.size(); }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::video::E_INDEX_TYPE getIndexType() const
|
||||
{ return irr::video::EIT_16BIT; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const irr::u16* getIndices() const { return m_indices.data(); }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::u16* getIndices() { return m_indices.data(); }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::u32 getIndexCount() const { return m_indices.size(); }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const irr::core::aabbox3d<irr::f32>& getBoundingBox() const
|
||||
{ return m_bounding_box; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void setBoundingBox(const irr::core::aabbox3df& box)
|
||||
{ m_bounding_box = box; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void recalculateBoundingBox()
|
||||
{
|
||||
if (m_vertices.empty())
|
||||
m_bounding_box.reset(0, 0, 0);
|
||||
else
|
||||
{
|
||||
m_bounding_box.reset(m_vertices[0].m_position);
|
||||
for (irr::u32 i = 1; i < m_vertices.size(); i++)
|
||||
m_bounding_box.addInternalPoint(m_vertices[i].m_position);
|
||||
}
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::video::E_VERTEX_TYPE getVertexType() const
|
||||
{ return irr::video::EVT_SKINNED_MESH; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const irr::core::vector3df& getPosition(irr::u32 i) const
|
||||
{ return m_vertices[i].m_position; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::core::vector3df& getPosition(irr::u32 i)
|
||||
{ return m_vertices[i].m_position; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const irr::core::vector3df& getNormal(irr::u32 i) const
|
||||
{
|
||||
static irr::core::vector3df unused;
|
||||
return unused;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::core::vector3df& getNormal(irr::u32 i)
|
||||
{
|
||||
static irr::core::vector3df unused;
|
||||
return unused;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const irr::core::vector2df& getTCoords(irr::u32 i) const
|
||||
{
|
||||
static irr::core::vector2df unused;
|
||||
return unused;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::core::vector2df& getTCoords(irr::u32 i)
|
||||
{
|
||||
static irr::core::vector2df unused;
|
||||
return unused;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::scene::E_PRIMITIVE_TYPE getPrimitiveType() const
|
||||
{ return irr::scene::EPT_TRIANGLES; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void append(const void* const vertices, irr::u32 num_vertices,
|
||||
const irr::u16* const indices, irr::u32 num_indices)
|
||||
{
|
||||
if (vertices == getVertices())
|
||||
return;
|
||||
|
||||
irr::u32 vertex_count = getVertexCount();
|
||||
m_vertices.reserve(vertex_count + num_vertices);
|
||||
for (irr::u32 i = 0; i < num_vertices; i++)
|
||||
{
|
||||
m_vertices.push_back(reinterpret_cast<
|
||||
const irr::video::S3DVertexSkinnedMesh*>(vertices)[i]);
|
||||
m_bounding_box.addInternalPoint(reinterpret_cast<
|
||||
const irr::video::S3DVertexSkinnedMesh*>(vertices)[i].m_position);
|
||||
}
|
||||
|
||||
m_indices.reserve(getIndexCount() + num_indices);
|
||||
for (irr::u32 i = 0; i < num_indices; i++)
|
||||
m_indices.push_back(indices[i] + vertex_count);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void append(const IMeshBuffer* const other) {}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::scene::E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const
|
||||
{ return irr::scene::EHM_NEVER; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::scene::E_HARDWARE_MAPPING getHardwareMappingHint_Index() const
|
||||
{ return irr::scene::EHM_NEVER; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void setHardwareMappingHint(irr::scene::E_HARDWARE_MAPPING NewMappingHint,
|
||||
irr::scene::E_BUFFER_TYPE Buffer = irr::scene::EBT_VERTEX_AND_INDEX)
|
||||
{}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void setDirty(irr::scene::E_BUFFER_TYPE Buffer = irr::scene::EBT_VERTEX_AND_INDEX)
|
||||
{}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::u32 getChangedID_Vertex() const { return 0; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::u32 getChangedID_Index() const { return 0; }
|
||||
|
||||
};
|
||||
|
||||
} // end namespace irr
|
||||
|
||||
#endif
|
||||
|
||||
|
47
lib/graphics_engine/src/ge_spm.cpp
Normal file
47
lib/graphics_engine/src/ge_spm.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include "ge_spm.hpp"
|
||||
#include "ge_spm_buffer.hpp"
|
||||
|
||||
namespace GE
|
||||
{
|
||||
GESPM::GESPM()
|
||||
: m_fps(0.0f), m_bind_frame(0), m_total_joints(0), m_joint_using(0),
|
||||
m_frame_count(0)
|
||||
{
|
||||
} // GESPM
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GESPM::~GESPM()
|
||||
{
|
||||
for (unsigned i = 0; i < m_buffer.size(); i++)
|
||||
m_buffer[i]->drop();
|
||||
} // ~GESPM
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
IMeshBuffer* GESPM::getMeshBuffer(u32 nr) const
|
||||
{
|
||||
if (nr < m_buffer.size())
|
||||
return m_buffer[nr];
|
||||
else
|
||||
return NULL;
|
||||
} // getMeshBuffer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
IMeshBuffer* GESPM::getMeshBuffer(const video::SMaterial &material) const
|
||||
{
|
||||
for (unsigned i = 0; i < m_buffer.size(); i++)
|
||||
{
|
||||
if (m_buffer[i]->getMaterial() == material)
|
||||
return m_buffer[i];
|
||||
}
|
||||
return NULL;
|
||||
} // getMeshBuffer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GESPM::finalize()
|
||||
{
|
||||
m_bounding_box.reset(0.0f, 0.0f, 0.0f);
|
||||
for (unsigned i = 0; i < m_buffer.size(); i++)
|
||||
m_bounding_box.addInternalBox(m_buffer[i]->getBoundingBox());
|
||||
} // finalize
|
||||
|
||||
}
|
@ -50,6 +50,9 @@ namespace scene
|
||||
//! Halflife MDL model file
|
||||
EAMT_MDL_HALFLIFE,
|
||||
|
||||
//! STK .spm file
|
||||
EAMT_SPM,
|
||||
|
||||
//! generic skinned mesh
|
||||
EAMT_SKINNED
|
||||
};
|
||||
@ -106,6 +109,9 @@ namespace scene
|
||||
{
|
||||
return EAMT_UNKNOWN;
|
||||
}
|
||||
|
||||
//! loaders should call this after populating the mesh
|
||||
virtual void finalize() = 0;
|
||||
};
|
||||
|
||||
} // end namespace scene
|
||||
|
@ -185,9 +185,6 @@ namespace scene
|
||||
//! exposed for loaders: joints list
|
||||
virtual const core::array<SJoint*>& getAllJoints() const = 0;
|
||||
|
||||
//! loaders should call this after populating the mesh
|
||||
virtual void finalize() = 0;
|
||||
|
||||
//! Adds a new meshbuffer to the mesh, access it as last one
|
||||
virtual SSkinMeshBuffer* addMeshBuffer() = 0;
|
||||
|
||||
|
@ -168,6 +168,11 @@ namespace scene
|
||||
Meshes[i]->setDirty(buffer);
|
||||
}
|
||||
|
||||
//! loaders should call this after populating the mesh
|
||||
virtual void finalize()
|
||||
{
|
||||
}
|
||||
|
||||
//! All meshes defining the animated mesh
|
||||
core::array<IMesh*> Meshes;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user