2019-12-12 17:32:41 +01:00
|
|
|
// Copyright (C) 2008-2012 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
2021-08-27 17:03:34 +02:00
|
|
|
#ifndef IRR_C_DYNAMIC_MESHBUFFER_H_INCLUDED
|
|
|
|
#define IRR_C_DYNAMIC_MESHBUFFER_H_INCLUDED
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
#include "IDynamicMeshBuffer.h"
|
|
|
|
|
|
|
|
#include "CVertexBuffer.h"
|
|
|
|
#include "CIndexBuffer.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace scene
|
|
|
|
{
|
|
|
|
|
|
|
|
class CDynamicMeshBuffer: public IDynamicMeshBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//! constructor
|
|
|
|
CDynamicMeshBuffer(video::E_VERTEX_TYPE vertexType, video::E_INDEX_TYPE indexType)
|
|
|
|
: PrimitiveType(EPT_TRIANGLES)
|
|
|
|
{
|
|
|
|
VertexBuffer=new CVertexBuffer(vertexType);
|
|
|
|
IndexBuffer=new CIndexBuffer(indexType);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
virtual ~CDynamicMeshBuffer()
|
|
|
|
{
|
|
|
|
if (VertexBuffer)
|
|
|
|
VertexBuffer->drop();
|
|
|
|
if (IndexBuffer)
|
|
|
|
IndexBuffer->drop();
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual IVertexBuffer& getVertexBuffer() const IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
return *VertexBuffer;
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual IIndexBuffer& getIndexBuffer() const IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
return *IndexBuffer;
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setVertexBuffer(IVertexBuffer *newVertexBuffer) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
if (newVertexBuffer)
|
|
|
|
newVertexBuffer->grab();
|
|
|
|
if (VertexBuffer)
|
|
|
|
VertexBuffer->drop();
|
|
|
|
|
|
|
|
VertexBuffer=newVertexBuffer;
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setIndexBuffer(IIndexBuffer *newIndexBuffer) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
if (newIndexBuffer)
|
|
|
|
newIndexBuffer->grab();
|
|
|
|
if (IndexBuffer)
|
|
|
|
IndexBuffer->drop();
|
|
|
|
|
|
|
|
IndexBuffer=newIndexBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Get Material of this buffer.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual const video::SMaterial& getMaterial() const IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
return Material;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Get Material of this buffer.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual video::SMaterial& getMaterial() IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
return Material;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Get bounding box
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual const core::aabbox3d<f32>& getBoundingBox() const IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
return BoundingBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Set bounding box
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setBoundingBox( const core::aabbox3df& box) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
BoundingBox = box;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Recalculate bounding box
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void recalculateBoundingBox() IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
if (!getVertexBuffer().size())
|
|
|
|
BoundingBox.reset(0,0,0);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BoundingBox.reset(getVertexBuffer()[0].Pos);
|
|
|
|
for (u32 i=1; i<getVertexBuffer().size(); ++i)
|
|
|
|
BoundingBox.addInternalPoint(getVertexBuffer()[i].Pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Describe what kind of primitive geometry is used by the meshbuffer
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
PrimitiveType = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Get the kind of primitive geometry which is used by the meshbuffer
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual E_PRIMITIVE_TYPE getPrimitiveType() const IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
return PrimitiveType;
|
|
|
|
}
|
|
|
|
|
2022-04-11 16:36:49 +02:00
|
|
|
//! Returns type of the class implementing the IMeshBuffer
|
|
|
|
virtual EMESH_BUFFER_TYPE getType() const IRR_OVERRIDE
|
|
|
|
{
|
|
|
|
return EMBT_DYNAMIC;
|
|
|
|
}
|
|
|
|
|
2019-12-12 17:32:41 +01:00
|
|
|
video::SMaterial Material;
|
|
|
|
core::aabbox3d<f32> BoundingBox;
|
|
|
|
//! Primitive type used for rendering (triangles, lines, ...)
|
|
|
|
E_PRIMITIVE_TYPE PrimitiveType;
|
|
|
|
private:
|
|
|
|
CDynamicMeshBuffer(const CDynamicMeshBuffer&); // = delete in c++11, prevent copying
|
|
|
|
|
|
|
|
IVertexBuffer *VertexBuffer;
|
|
|
|
IIndexBuffer *IndexBuffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace scene
|
|
|
|
} // end namespace irr
|
|
|
|
|
|
|
|
#endif
|