Commit 60e4d621 authored by hybrid's avatar hybrid

Made the MeshBuffers be based on a template class. The original headers do...

Made the MeshBuffers be based on a template class. The original headers do still exist for compatibility reasons. The SMeshBuffer... structs are now typedefs of the template.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@676 dfc29bdd-3216-0410-991c-e03cc46cb475
parent b6b7cfd1
// 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 __T_MESH_BUFFER_H_INCLUDED__
#define __T_MESH_BUFFER_H_INCLUDED__
#include "irrArray.h"
#include "IMeshBuffer.h"
namespace irr
{
namespace scene
{
//! Template implementation of the IMeshBuffer interface
template <class T>
class CMeshBuffer : public IMeshBuffer
{
public:
//! constructor
CMeshBuffer() // everything's default constructed
{
#ifdef _DEBUG
setDebugName("SMeshBuffer");
#endif
}
//! destructor
~CMeshBuffer() {};
//! 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
{
return Vertices.const_pointer();
}
//! returns pointer to vertices
virtual void* getVertices()
{
return Vertices.pointer();
}
//! returns amount of vertices
virtual u32 getVertexCount() const
{
return Vertices.size();
}
//! 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;
}
//! recalculates the bounding box. should be called if the mesh changed.
virtual void recalculateBoundingBox()
{
if (Vertices.empty())
BoundingBox.reset(0,0,0);
else
{
BoundingBox.reset(Vertices[0].Pos);
for (u32 i=1; i<Vertices.size(); ++i)
BoundingBox.addInternalPoint(Vertices[i].Pos);
}
}
//! returns which type of vertex data is stored.
virtual video::E_VERTEX_TYPE getVertexType() const
{
return T().getType();
}
//! returns the byte size (stride, pitch) of the vertex
virtual u32 getVertexPitch() const
{
return sizeof ( T );
}
//! Material for this meshbuffer.
video::SMaterial Material;
//! Vertices of this buffer
core::array<T> Vertices;
//! Indices into the vertices of this buffer.
core::array<u16> Indices;
//! Bounding box of this meshbuffer.
core::aabbox3d<f32> BoundingBox;
};
typedef CMeshBuffer<video::S3DVertex> SMeshBuffer;
typedef CMeshBuffer<video::S3DVertex2TCoords> SMeshBufferLightMap;
typedef CMeshBuffer<video::S3DVertexTangents> SMeshBufferTangents;
} // end namespace scene
} // end namespace irr
#endif
......@@ -67,6 +67,11 @@ struct S3DVertex
return (Pos != other.Pos || Normal != other.Normal ||
Color != other.Color || TCoords != other.TCoords);
}
E_VERTEX_TYPE getType() const
{
return EVT_STANDARD;
}
};
......@@ -137,6 +142,10 @@ struct S3DVertex2TCoords
TCoords2 != other.TCoords2);
}
E_VERTEX_TYPE getType() const
{
return EVT_2TCOORDS;
}
};
......@@ -188,6 +197,11 @@ struct S3DVertexTangents
Color != other.Color || TCoords != other.TCoords ||
Tangent != other.Tangent || Binormal != other.Binormal);
}
E_VERTEX_TYPE getType() const
{
return EVT_TANGENTS;
}
};
......
......@@ -2,129 +2,6 @@
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __S_MESH_BUFFER_H_INCLUDED__
#define __S_MESH_BUFFER_H_INCLUDED__
#include "irrArray.h"
#include "IMeshBuffer.h"
namespace irr
{
namespace scene
{
//! Simple implementation of the IMeshBuffer interface with S3DVertex vertices.
struct SMeshBuffer : public IMeshBuffer
{
//! constructor
SMeshBuffer()
{
#ifdef _DEBUG
setDebugName("SMeshBuffer");
#endif
}
//! destructor
~SMeshBuffer() {};
//! 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
{
return Vertices.const_pointer();
}
//! returns pointer to vertices
virtual void* getVertices()
{
return Vertices.pointer();
}
//! returns amount of vertices
virtual u32 getVertexCount() const
{
return Vertices.size();
}
//! 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;
}
//! recalculates the bounding box. should be called if the mesh changed.
void recalculateBoundingBox()
{
if (Vertices.empty())
BoundingBox.reset(0,0,0);
else
{
BoundingBox.reset(Vertices[0].Pos);
for (u32 i=1; i<Vertices.size(); ++i)
BoundingBox.addInternalPoint(Vertices[i].Pos);
}
}
//! 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 );
}
//! Material for this meshbuffer.
video::SMaterial Material;
//! Vertices of this buffer
core::array<video::S3DVertex> Vertices;
//! Indices into the vertices of this buffer.
core::array<u16> Indices;
//! Bounding box of this meshbuffer.
core::aabbox3d<f32> BoundingBox;
};
} // end namespace scene
} // end namespace irr
#endif
// replaced by template
#include "CMeshBuffer.h"
......@@ -2,130 +2,6 @@
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __S_MESH_BUFFER_LIGHT_MAP_H_INCLUDED__
#define __S_MESH_BUFFER_LIGHT_MAP_H_INCLUDED__
#include "irrArray.h"
#include "IMeshBuffer.h"
namespace irr
{
namespace scene
{
//! Simple implementation of the IMeshBuffer interface with S3DVertex2TCoords vertices.
struct SMeshBufferLightMap : public IMeshBuffer
{
//! constructor
SMeshBufferLightMap()
{
#ifdef _DEBUG
setDebugName("SMeshBufferLightMap");
#endif
}
//! destructor
~SMeshBufferLightMap() {};
//! returns the material of this meshbuffer
virtual const video::SMaterial& getMaterial() const
{
return Material;
}
//! returns the material of this meshbuffer
video::SMaterial& getMaterial()
{
return Material;
}
//! returns pointer to vertices
virtual const void* getVertices() const
{
return Vertices.const_pointer();
}
//! returns pointer to vertices
virtual void* getVertices()
{
return Vertices.pointer();
}
//! returns amount of vertices
virtual u32 getVertexCount() const
{
return Vertices.size();
}
//! 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;
}
//! recalculates the bounding box. should be called if the mesh changed.
void recalculateBoundingBox()
{
if (Vertices.empty())
BoundingBox.reset(0,0,0);
else
{
BoundingBox.reset(Vertices[0].Pos);
for (u32 i=1; i<Vertices.size(); ++i)
BoundingBox.addInternalPoint(Vertices[i].Pos);
}
}
//! returns which type of vertex data is stored.
virtual video::E_VERTEX_TYPE getVertexType() const
{
return video::EVT_2TCOORDS;
}
//! returns the byte size (stride, pitch) of the vertex
virtual u32 getVertexPitch() const
{
return sizeof ( video::S3DVertex2TCoords );
}
//! Material for this meshbuffer.
video::SMaterial Material;
//! Vertices of this buffer.
core::array<video::S3DVertex2TCoords> Vertices;
//! Indices into the vertices of this buffer.
core::array<u16> Indices;
//! Bounding box of this meshbuffer.
core::aabbox3d<f32> BoundingBox;
};
} // end namespace scene
} // end namespace irr
#endif
// replaced by template
#include "CMeshBuffer.h"
......@@ -2,129 +2,6 @@
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __S_MESH_BUFFER_TANGENTS_H_INCLUDED__
#define __S_MESH_BUFFER_TANGENTS_H_INCLUDED__
#include "irrArray.h"
#include "IMeshBuffer.h"
namespace irr
{
namespace scene
{
//! Simple implementation of the IMeshBuffer interface with S3DVertexTangents vertices.
struct SMeshBufferTangents : public IMeshBuffer
{
//! constructor
SMeshBufferTangents()
{
#ifdef _DEBUG
setDebugName("SMeshBufferTangents");
#endif
}
//! destructor
~SMeshBufferTangents() {};
//! 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
{
return Vertices.const_pointer();
}
//! returns pointer to vertices
virtual void* getVertices()
{
return Vertices.pointer();
}
//! returns amount of vertices
virtual u32 getVertexCount() const
{
return Vertices.size();
}
//! 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;
}
//! recalculates the bounding box. should be called if the mesh changed.
void recalculateBoundingBox()
{
if (Vertices.empty())
BoundingBox.reset(0,0,0);
else
{
BoundingBox.reset(Vertices[0].Pos);
for (u32 i=1; i<Vertices.size(); ++i)
BoundingBox.addInternalPoint(Vertices[i].Pos);
}
}
//! returns which type of vertex data is stored.
virtual video::E_VERTEX_TYPE getVertexType() const
{
return video::EVT_TANGENTS;
}
//! returns the byte size (stride, pitch) of the vertex
virtual u32 getVertexPitch() const
{
return sizeof ( video::S3DVertexTangents );
}
//! Material for this meshbuffer.
video::SMaterial Material;
//! Vertices of this buffer.
core::array<video::S3DVertexTangents> Vertices;
//! Indices into the vertices of this buffer.
core::array<u16> Indices;
//! Bounding box of this meshbuffer.
core::aabbox3d<f32> BoundingBox;
};
} // end namespace scene
} // end namespace irr
#endif
// replaced by template
#include "CMeshBuffer.h"
......@@ -891,7 +891,7 @@ void C3DSMeshFileLoader::composeObject(io::IReadFile* file, const core::stringc&
Materials.push_back(m);
SMeshBuffer* mb = new scene::SMeshBuffer();
Mesh->addMeshBuffer(mb);
mb->Material = Materials[0].Material;
mb->getMaterial() = Materials[0].Material;
mb->drop();
// add an empty mesh buffer name
core::stringc c = "";
......@@ -941,7 +941,7 @@ void C3DSMeshFileLoader::composeObject(io::IReadFile* file, const core::stringc&
IMeshBuffer* tmp = mb;
mb=(SMeshBuffer*)(Mesh->MeshBuffers[mbPos]=Mesh->MeshBuffers.getLast());
Mesh->MeshBuffers[Mesh->MeshBuffers.size()-1]=tmp;
mb->Material=*mat;
mb->getMaterial() = *mat;
vtxCount=0;
}
......@@ -1022,94 +1022,95 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
SMeshBuffer* m = new scene::SMeshBuffer();
Mesh->addMeshBuffer(m);
m->Material = Materials[i].Material;
m->getMaterial() = Materials[i].Material;
if (Materials[i].Filename[0].size())
{
m->Material.Textures[0] = Driver->getTexture(Materials[i].Filename[0].c_str());
if (!m->Material.Textures[0])
video::ITexture* texture = Driver->getTexture(Materials[i].Filename[0].c_str());
if (!texture)
{
core::stringc fname = getTextureFileName(
Materials[i].Filename[0], modelFilename);
if (fname.size())
m->Material.Textures[0] = Driver->getTexture(fname.c_str());
texture = Driver->getTexture(fname.c_str());
}
if (!m->Material.Textures[0])
if (!texture)
os::Printer::log("Could not load a texture for entry in 3ds file",
Materials[i].Filename[0].c_str(), ELL_WARNING);
else
m->getMaterial().Textures[0] = texture;
}
if (Materials[i].Filename[2].size())
{
m->Material.Textures[0] = Driver->getTexture(Materials[i].Filename[2].c_str());
video::ITexture* texture = Driver->getTexture(Materials[i].Filename[2].c_str());
if (!m->Material.Textures[0])
if (!texture)
{
core::stringc fname = getTextureFileName(
Materials[i].Filename[2], modelFilename);
if (fname.size())
m->Material.Textures[0] = Driver->getTexture(fname.c_str());
texture = Driver->getTexture(fname.c_str());
}
if (!m->Material.Textures[0])
if (!texture)
{
os::Printer::log("Could not load a texture for entry in 3ds file",
Materials[i].Filename[2].c_str(), ELL_WARNING);
}
else
{
m->Material.MaterialType=video::EMT_TRANSPARENT_ADD_COLOR;
m->getMaterial().Textures[0] = texture;
m->getMaterial().MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
}
}
if (Materials[i].Filename[3].size())
{
m->Material.Textures[1]=m->Material.Textures[0];
m->Material.Textures[0]=0;
m->Material.Textures[0] = Driver->getTexture(Materials[i].Filename[3].c_str());
video::ITexture* texture = Driver->getTexture(Materials[i].Filename[3].c_str());
if (!m->Material.Textures[0])
if (!texture)
{
core::stringc fname = getTextureFileName(
Materials[i].Filename[3], modelFilename);
if (fname.size())
m->Material.Textures[0] = Driver->getTexture(fname.c_str());
texture = Driver->getTexture(fname.c_str());
}
if (!m->Material.Textures[0])
if (!texture)
{
os::Printer::log("Could not load a texture for entry in 3ds file",
Materials[i].Filename[3].c_str(), ELL_WARNING);
m->Material.Textures[0]=m->Material.Textures[1];
m->Material.Textures[1]=0;
}
else
{
m->Material.MaterialType=video::EMT_REFLECTION_2_LAYER;
m->getMaterial().Textures[1] = m->getMaterial().Textures[0];
m->getMaterial().Textures[0] = texture;
m->getMaterial().MaterialType = video::EMT_REFLECTION_2_LAYER;
}
}
if (Materials[i].Filename[4].size())
{
m->Material.Textures[1] = Driver->getTexture(Materials[i].Filename[4].c_str());
video::ITexture* texture = Driver->getTexture(Materials[i].Filename[4].c_str());
if (!m->Material.Textures[1])
if (!texture)
{
core::stringc fname = getTextureFileName(
Materials[i].Filename[4], modelFilename);
if (fname.size())
m->Material.Textures[1] = Driver->getTexture(fname.c_str());
texture = Driver->getTexture(fname.c_str());
}
if (!m->Material.Textures[1])
if (!texture)
os::Printer::log("Could not load a texture for entry in 3ds file",
Materials[i].Filename[4].c_str(), ELL_WARNING);
else
{
Driver->makeNormalMapTexture(m->Material.Textures[1], 9.0f);
m->Material.MaterialType=video::EMT_PARALLAX_MAP_SOLID;
m->Material.MaterialTypeParam=0.035f;
m->getMaterial().Textures[1] = texture;
Driver->makeNormalMapTexture(texture, 9.0f);
m->getMaterial().MaterialType=video::EMT_PARALLAX_MAP_SOLID;
m->getMaterial().MaterialTypeParam=0.035f;
}
}
......
......@@ -9,6 +9,7 @@
#include "IReadFile.h"
#include "IFileSystem.h"
#include "SMesh.h"
#include "SMeshBufferLightMap.h"
#include "IVideoDriver.h"
#include "irrString.h"
#include "ISceneManager.h"
......@@ -18,8 +19,6 @@ namespace irr
{
namespace scene
{
struct SMeshBufferLightMap;
class CQ3LevelMesh : public IQ3LevelMesh
{
public:
......
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