Commit 0aa958f4 authored by hybrid's avatar hybrid

Exposed the MS3D MeshBuffer as SharedMeshBuffer, providing mesh buffers with a shared vertex array.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@836 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 01c43247
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __S_SHARED_MESH_BUFFER_H_INCLUDED__
#define __S_SHARED_MESH_BUFFER_H_INCLUDED__
#include "irrArray.h"
#include "IMeshBuffer.h"
namespace irr
{
namespace scene
{
//! Implementation of the IMeshBuffer interface with shared vertex list
struct SSharedMeshBuffer : public IMeshBuffer
{
//! constructor
SSharedMeshBuffer() : IMeshBuffer(), Vertices(0)
{
#ifdef _DEBUG
setDebugName("SSharedMeshBuffer");
#endif
}
SSharedMeshBuffer(core::array<video::S3DVertex> *vertices) : IMeshBuffer(), Vertices(vertices)
{
#ifdef _DEBUG
setDebugName("SSharedMeshBuffer");
#endif
}
//! destructor
virtual ~SSharedMeshBuffer() { }
//! returns the material of this meshbuffer
virtual const video::SMaterial& getMaterial() const
{
return Material;
}
//! returns the material of this meshbuffer
virtual video::SMaterial& getMaterial()
{
return Material;
}
//! returns pointer to vertices
virtual const void* getVertices() const
{
if (Vertices)
return Vertices->const_pointer();
else
return 0;
}
//! returns pointer to vertices
virtual void* getVertices()
{
if (Vertices)
return Vertices->pointer();
else
return 0;
}
//! returns amount of vertices
virtual u32 getVertexCount() const
{
if (Vertices)
return Vertices->size();
else
return 0;
}
//! returns pointer to Indices
virtual const u16* getIndices() const
{
return Indices.const_pointer();
}
//! returns pointer to Indices
virtual u16* getIndices()
{
return Indices.pointer();
}
//! returns amount of indices
virtual u32 getIndexCount() const
{
return Indices.size();
}
//! returns an axis aligned bounding box
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return BoundingBox;
}
//! set user axis aligned bounding box
virtual void setBoundingBox( const core::aabbox3df& box)
{
BoundingBox = box;
}
//! returns which type of vertex data is stored.
virtual video::E_VERTEX_TYPE getVertexType() const
{
return video::EVT_STANDARD;
}
//! returns the byte size (stride, pitch) of the vertex
virtual u32 getVertexPitch() const
{
return sizeof(video::S3DVertex);
}
//! recalculates the bounding box. should be called if the mesh changed.
virtual void recalculateBoundingBox()
{
if (!Vertices || Vertices->empty() || Indices.empty())
BoundingBox.reset(0,0,0);
else
{
BoundingBox.reset((*Vertices)[Indices[0]].Pos);
for (u32 i=1; i<Indices.size(); ++i)
BoundingBox.addInternalPoint((*Vertices)[Indices[i]].Pos);
}
}
//! append the vertices and indices to the current buffer
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) {}
//! append the meshbuffer to the current buffer
virtual void append(const IMeshBuffer* const other) {}
video::SMaterial Material; //! material of this meshBuffer
core::array<video::S3DVertex> *Vertices;//! Shared Array of vertices
core::array<u16> Indices; //! Array of Indices
core::aabbox3df BoundingBox; //! Bounding box
};
} // end namespace scene
} // end namespace irr
#endif
This diff is collapsed.
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "IReadFile.h" #include "IReadFile.h"
#include "S3DVertex.h" #include "S3DVertex.h"
#include "irrString.h" #include "irrString.h"
#include "SMeshBuffer.h" #include "SSharedMeshBuffer.h"
namespace irr namespace irr
{ {
...@@ -47,8 +47,8 @@ namespace scene ...@@ -47,8 +47,8 @@ namespace scene
virtual IMeshBuffer* getMeshBuffer(u32 nr) const; virtual IMeshBuffer* getMeshBuffer(u32 nr) const;
//! Returns pointer to a mesh buffer which fits a material //! Returns pointer to a mesh buffer which fits a material
/** \param material: material to search for /** \param material: material to search for
\return Returns the pointer to the mesh buffer or \return Returns the pointer to the mesh buffer or
NULL if there is no such mesh buffer. */ NULL if there is no such mesh buffer. */
virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const; virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const;
...@@ -64,7 +64,7 @@ namespace scene ...@@ -64,7 +64,7 @@ namespace scene
//! Returns the type of the animated mesh. //! Returns the type of the animated mesh.
virtual E_ANIMATED_MESH_TYPE getMeshType() const; virtual E_ANIMATED_MESH_TYPE getMeshType() const;
//! Returns a pointer to a transformation matrix of a part of the //! Returns a pointer to a transformation matrix of a part of the
//! mesh based on a frame time. //! mesh based on a frame time.
virtual core::matrix4* getMatrixOfJoint(s32 jointNumber, s32 frame); virtual core::matrix4* getMatrixOfJoint(s32 jointNumber, s32 frame);
...@@ -78,99 +78,39 @@ namespace scene ...@@ -78,99 +78,39 @@ namespace scene
virtual s32 getJointNumber(const c8* name) const; virtual s32 getJointNumber(const c8* name) const;
private: private:
struct SKeyframe struct SKeyframe
{ {
f32 timeindex; f32 timeindex;
core::vector3df data; // translation or rotation core::vector3df data; // translation or rotation
}; };
struct SJoint struct SJoint
{ {
core::stringc Name; core::stringc Name;
s32 Index; s32 Index;
core::vector3df Rotation; core::vector3df Rotation;
core::vector3df Translation; core::vector3df Translation;
core::matrix4 RelativeTransformation; core::matrix4 RelativeTransformation;
core::matrix4 AbsoluteTransformation; core::matrix4 AbsoluteTransformation;
core::matrix4 AbsoluteTransformationAnimated; core::matrix4 AbsoluteTransformationAnimated;
core::array<SKeyframe> TranslationKeys; core::array<SKeyframe> TranslationKeys;
core::array<SKeyframe> RotationKeys; core::array<SKeyframe> RotationKeys;
core::array<u16> VertexIds; core::array<u16> VertexIds;
s32 Parent; s32 Parent;
core::stringc ParentName; core::stringc ParentName;
}; };
struct SGroup struct SGroup
{ {
core::stringc Name; core::stringc Name;
core::array<u16> VertexIds; core::array<u16> VertexIds;
u16 MaterialIdx;
};
//! Simple implementation of the IMeshBuffer interface with S3DVertex vertices.
struct SMS3DMeshBuffer : public IMeshBuffer
{
//! constructor
SMS3DMeshBuffer();
//! destructor
~SMS3DMeshBuffer();
//! returns the material of this meshbuffer
virtual const video::SMaterial& getMaterial() const;
//! returns the material of this meshbuffer
virtual video::SMaterial& getMaterial();
//! returns pointer to vertices
virtual const void* getVertices() const;
//! returns pointer to vertices
virtual void* getVertices();
//! returns amount of vertices
virtual u32 getVertexCount() const;
//! returns pointer to Indices
virtual const u16* getIndices() const;
//! returns pointer to Indices
virtual u16* getIndices();
//! returns amount of indices
virtual u32 getIndexCount() const;
//! returns an axis aligned bounding box
virtual const core::aabbox3d<f32>& getBoundingBox() const;
//! set user axis aligned bounding box
virtual void setBoundingBox( const core::aabbox3df& box);
//! returns which type of vertex data is stored.
virtual video::E_VERTEX_TYPE getVertexType() const;
//! returns the byte size (stride, pitch) of the vertex
virtual u32 getVertexPitch() const;
//! recalculates the bounding box. should be called if the mesh changed.
virtual void recalculateBoundingBox() {}
//! append the vertices and indices to the current buffer
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) {}
//! append the meshbuffer to the current buffer
virtual void append(const IMeshBuffer* const other) {}
video::SMaterial Material; //! material for this meshBuffer. u16 MaterialIdx;
core::array<video::S3DVertex> *Vertices; //! Array of vertices };
core::array<u16> Indices; //! Array of the Indices.
core::aabbox3d<f32> *BoundingBox;
};
void animate(s32 frame); void animate(s32 frame);
void getKeyframeData(const core::array<SKeyframe>& keys, f32 time, core::vector3df& outdata) const; void getKeyframeData(const core::array<SKeyframe>& keys, f32 time, core::vector3df& outdata) const;
...@@ -181,10 +121,10 @@ namespace scene ...@@ -181,10 +121,10 @@ namespace scene
core::array<video::S3DVertex> Vertices; core::array<video::S3DVertex> Vertices;
core::array<video::S3DVertex> AnimatedVertices; core::array<video::S3DVertex> AnimatedVertices;
core::array<u16> Indices; core::array<u16> Indices;
core::array<SJoint> Joints; core::array<SJoint> Joints;
core::array<SGroup> Groups; core::array<SGroup> Groups;
core::array<SMS3DMeshBuffer> Buffers; core::array<SSharedMeshBuffer> Buffers;
f32 totalTime; f32 totalTime;
bool HasAnimation; bool HasAnimation;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment