Commit 43b6bb65 authored by hybrid's avatar hybrid

Made the MeshBuffer an explicit member instead of a base class.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@832 dfc29bdd-3216-0410-991c-e03cc46cb475
parent a26aa2c5
...@@ -351,94 +351,20 @@ u32 CAnimatedMeshMD2::getMeshBufferCount() const ...@@ -351,94 +351,20 @@ u32 CAnimatedMeshMD2::getMeshBufferCount() const
//! returns pointer to a mesh buffer //! returns pointer to a mesh buffer
IMeshBuffer* CAnimatedMeshMD2::getMeshBuffer(u32 nr) const IMeshBuffer* CAnimatedMeshMD2::getMeshBuffer(u32 nr) const
{ {
return (IMeshBuffer*) this; return const_cast<IMeshBuffer*>(reinterpret_cast<const IMeshBuffer*>(&InterpolationBuffer));
} }
//! Returns pointer to a mesh buffer which fits a material //! Returns pointer to a mesh buffer which fits a material
IMeshBuffer* CAnimatedMeshMD2::getMeshBuffer( const video::SMaterial &material) const IMeshBuffer* CAnimatedMeshMD2::getMeshBuffer(const video::SMaterial &material) const
{ {
if (Material == material) if (InterpolationBuffer.Material == material)
return (IMeshBuffer*) this; return const_cast<IMeshBuffer*>(reinterpret_cast<const IMeshBuffer*>(&InterpolationBuffer));
else else
return 0; return 0;
} }
//! returns the material of this meshbuffer
const video::SMaterial& CAnimatedMeshMD2::getMaterial() const
{
return Material;
}
//! returns the material of this meshbuffer
video::SMaterial& CAnimatedMeshMD2::getMaterial()
{
return Material;
}
//! returns pointer to vertices
const void* CAnimatedMeshMD2::getVertices() const
{
return InterpolateBuffer.const_pointer();
}
//! returns pointer to vertices
void* CAnimatedMeshMD2::getVertices()
{
return InterpolateBuffer.pointer();
}
//! returns which type of vertex data is stored.
video::E_VERTEX_TYPE CAnimatedMeshMD2::getVertexType() const
{
return video::EVT_STANDARD;
}
//! returns the byte size (stride, pitch) of the vertex
u32 CAnimatedMeshMD2::getVertexPitch() const
{
return sizeof ( video::S3DVertex );
}
//! returns amount of vertices
u32 CAnimatedMeshMD2::getVertexCount() const
{
return FrameList[0].size();
}
//! returns pointer to Indices
const u16* CAnimatedMeshMD2::getIndices() const
{
return Indices.const_pointer();
}
//! returns pointer to Indices
u16* CAnimatedMeshMD2::getIndices()
{
return Indices.pointer();
}
//! returns amount of indices
u32 CAnimatedMeshMD2::getIndexCount() const
{
return Indices.size();
}
// updates the interpolation buffer // updates the interpolation buffer
void CAnimatedMeshMD2::updateInterpolationBuffer(s32 frame, s32 startFrameLoop, s32 endFrameLoop) void CAnimatedMeshMD2::updateInterpolationBuffer(s32 frame, s32 startFrameLoop, s32 endFrameLoop)
...@@ -471,7 +397,7 @@ void CAnimatedMeshMD2::updateInterpolationBuffer(s32 frame, s32 startFrameLoop, ...@@ -471,7 +397,7 @@ void CAnimatedMeshMD2::updateInterpolationBuffer(s32 frame, s32 startFrameLoop,
div = frame * MD2_FRAME_SHIFT_RECIPROCAL; div = frame * MD2_FRAME_SHIFT_RECIPROCAL;
} }
video::S3DVertex* target = &InterpolateBuffer[0]; video::S3DVertex* target = reinterpret_cast<video::S3DVertex*>(InterpolationBuffer.getVertices());
video::S3DVertex* first = FrameList[firstFrame].pointer(); video::S3DVertex* first = FrameList[firstFrame].pointer();
video::S3DVertex* second = FrameList[secondFrame].pointer(); video::S3DVertex* second = FrameList[secondFrame].pointer();
...@@ -489,7 +415,7 @@ void CAnimatedMeshMD2::updateInterpolationBuffer(s32 frame, s32 startFrameLoop, ...@@ -489,7 +415,7 @@ void CAnimatedMeshMD2::updateInterpolationBuffer(s32 frame, s32 startFrameLoop,
} }
//update bounding box //update bounding box
BoundingBox = BoxList[secondFrame].getInterpolated(BoxList[firstFrame], div); InterpolationBuffer.setBoundingBox(BoxList[secondFrame].getInterpolated(BoxList[firstFrame], div));
} }
...@@ -693,25 +619,25 @@ bool CAnimatedMeshMD2::loadFile(io::IReadFile* file) ...@@ -693,25 +619,25 @@ bool CAnimatedMeshMD2::loadFile(io::IReadFile* file)
// create indices // create indices
Indices.reallocate(header.numVertices); InterpolationBuffer.Indices.reallocate(header.numVertices);
s16 count = TriangleCount*3; s16 count = TriangleCount*3;
for (s16 n=0; n<count; n+=3) for (s16 n=0; n<count; n+=3)
{ {
Indices.push_back(n); InterpolationBuffer.Indices.push_back(n);
Indices.push_back(n+1); InterpolationBuffer.Indices.push_back(n+1);
Indices.push_back(n+2); InterpolationBuffer.Indices.push_back(n+2);
} }
// reallocate interpolate buffer // reallocate interpolate buffer
if (header.numFrames) if (header.numFrames)
{ {
s32 currCount = FrameList[0].size(); u32 currCount = FrameList[0].size();
InterpolateBuffer.set_used(currCount); InterpolationBuffer.Vertices.set_used(currCount);
for (i=0; i<currCount; ++i) for (u32 num=0; num<currCount; ++num)
{ {
InterpolateBuffer[i].TCoords = FrameList[0].pointer()[i].TCoords; InterpolationBuffer.Vertices[num].TCoords = FrameList[0].pointer()[num].TCoords;
InterpolateBuffer[i].Color = vtx.Color; InterpolationBuffer.Vertices[num].Color = vtx.Color;
} }
} }
...@@ -734,7 +660,7 @@ bool CAnimatedMeshMD2::loadFile(io::IReadFile* file) ...@@ -734,7 +660,7 @@ bool CAnimatedMeshMD2::loadFile(io::IReadFile* file)
//! calculates the bounding box //! calculates the bounding box
void CAnimatedMeshMD2::calculateBoundingBox() void CAnimatedMeshMD2::calculateBoundingBox()
{ {
BoundingBox.reset(0,0,0); InterpolationBuffer.BoundingBox.reset(0,0,0);
if (FrameCount) if (FrameCount)
{ {
...@@ -744,7 +670,7 @@ void CAnimatedMeshMD2::calculateBoundingBox() ...@@ -744,7 +670,7 @@ void CAnimatedMeshMD2::calculateBoundingBox()
defaultFrame = 0; defaultFrame = 0;
for (u32 j=0; j<FrameList[defaultFrame].size(); ++j) for (u32 j=0; j<FrameList[defaultFrame].size(); ++j)
BoundingBox.addInternalPoint(FrameList[defaultFrame].pointer()[j].Pos); InterpolationBuffer.BoundingBox.addInternalPoint(FrameList[defaultFrame].pointer()[j].Pos);
} }
} }
...@@ -752,7 +678,7 @@ void CAnimatedMeshMD2::calculateBoundingBox() ...@@ -752,7 +678,7 @@ void CAnimatedMeshMD2::calculateBoundingBox()
//! sets a flag of all contained materials to a new value //! sets a flag of all contained materials to a new value
void CAnimatedMeshMD2::setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) void CAnimatedMeshMD2::setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
{ {
Material.setFlag(flag, newvalue); InterpolationBuffer.Material.setFlag(flag, newvalue);
} }
...@@ -760,37 +686,17 @@ void CAnimatedMeshMD2::setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalu ...@@ -760,37 +686,17 @@ void CAnimatedMeshMD2::setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalu
//! returns an axis aligned bounding box //! returns an axis aligned bounding box
const core::aabbox3d<f32>& CAnimatedMeshMD2::getBoundingBox() const const core::aabbox3d<f32>& CAnimatedMeshMD2::getBoundingBox() const
{ {
return BoundingBox; return InterpolationBuffer.BoundingBox;
} }
//! set user axis aligned bounding box //! set user axis aligned bounding box
void CAnimatedMeshMD2::setBoundingBox( const core::aabbox3df& box) void CAnimatedMeshMD2::setBoundingBox( const core::aabbox3df& box)
{ {
BoundingBox = box; InterpolationBuffer.BoundingBox = box;
} }
//! calculates normals
void CAnimatedMeshMD2::calculateNormals()
{
for (u32 i=0; i<FrameCount; ++i)
{
video::S3DVertex* vtx = FrameList[i].pointer();
for (u32 j=0; j<Indices.size(); j+=3)
{
core::plane3d<f32> plane(
vtx[Indices[j]].Pos, vtx[Indices[j+1]].Pos, vtx[Indices[j+2]].Pos);
vtx[Indices[j]].Normal = plane.Normal;
vtx[Indices[j+1]].Normal = plane.Normal;
vtx[Indices[j+2]].Normal = plane.Normal;
}
}
}
//! Returns the type of the animated mesh. //! Returns the type of the animated mesh.
E_ANIMATED_MESH_TYPE CAnimatedMeshMD2::getMeshType() const E_ANIMATED_MESH_TYPE CAnimatedMeshMD2::getMeshType() const
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "IAnimatedMeshMD2.h" #include "IAnimatedMeshMD2.h"
#include "IMesh.h" #include "IMesh.h"
#include "IMeshBuffer.h" #include "CMeshBuffer.h"
#include "IReadFile.h" #include "IReadFile.h"
#include "S3DVertex.h" #include "S3DVertex.h"
#include "irrArray.h" #include "irrArray.h"
...@@ -18,7 +18,7 @@ namespace irr ...@@ -18,7 +18,7 @@ namespace irr
namespace scene namespace scene
{ {
class CAnimatedMeshMD2 : public IAnimatedMeshMD2, public IMesh, public IMeshBuffer class CAnimatedMeshMD2 : public IAnimatedMeshMD2, public IMesh
{ {
public: public:
...@@ -49,36 +49,6 @@ namespace scene ...@@ -49,36 +49,6 @@ namespace scene
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;
//! 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 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;
//! 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 //! returns an axis aligned bounding box
virtual const core::aabbox3d<f32>& getBoundingBox() const; virtual const core::aabbox3d<f32>& getBoundingBox() const;
...@@ -114,18 +84,12 @@ namespace scene ...@@ -114,18 +84,12 @@ namespace scene
//! calculates the bounding box //! calculates the bounding box
virtual void calculateBoundingBox(); virtual void calculateBoundingBox();
//! calculates normals
void calculateNormals();
core::array<u16> Indices;
core::array<video::S3DVertex> *FrameList; core::array<video::S3DVertex> *FrameList;
core::array<core::aabbox3d<f32> > BoxList; core::array<core::aabbox3d<f32> > BoxList;
u32 FrameCount; u32 FrameCount;
s32 TriangleCount; s32 TriangleCount;
video::SMaterial Material;
core::array<video::S3DVertex> InterpolateBuffer; SMeshBuffer InterpolationBuffer;
core::aabbox3d<f32> BoundingBox;
struct SFrameData struct SFrameData
{ {
......
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