1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

Split CVertexBuffer from CMeshBuffer

This commit is contained in:
sfan5 2024-08-27 16:50:41 +02:00
parent 538b8b9b34
commit 5d6e15bc49
10 changed files with 246 additions and 78 deletions

View file

@ -26,7 +26,9 @@ CBillboardSceneNode::CBillboardSceneNode(ISceneNode *parent, ISceneManager *mgr,
setSize(size);
Buffer->Vertices.resize(4);
auto &Vertices = Buffer->Vertices->Data;
Vertices.resize(4);
Buffer->Indices.resize(6);
Buffer->Indices[0] = 0;
@ -36,17 +38,17 @@ CBillboardSceneNode::CBillboardSceneNode(ISceneNode *parent, ISceneManager *mgr,
Buffer->Indices[4] = 3;
Buffer->Indices[5] = 2;
Buffer->Vertices[0].TCoords.set(1.0f, 1.0f);
Buffer->Vertices[0].Color = colorBottom;
Vertices[0].TCoords.set(1.0f, 1.0f);
Vertices[0].Color = colorBottom;
Buffer->Vertices[1].TCoords.set(1.0f, 0.0f);
Buffer->Vertices[1].Color = colorTop;
Vertices[1].TCoords.set(1.0f, 0.0f);
Vertices[1].Color = colorTop;
Buffer->Vertices[2].TCoords.set(0.0f, 0.0f);
Buffer->Vertices[2].Color = colorTop;
Vertices[2].TCoords.set(0.0f, 0.0f);
Vertices[2].Color = colorTop;
Buffer->Vertices[3].TCoords.set(0.0f, 1.0f);
Buffer->Vertices[3].Color = colorBottom;
Vertices[3].TCoords.set(0.0f, 1.0f);
Vertices[3].Color = colorBottom;
}
CBillboardSceneNode::~CBillboardSceneNode()
@ -114,7 +116,7 @@ void CBillboardSceneNode::updateMesh(const irr::scene::ICameraSceneNode *camera)
view *= -1.0f;
auto *vertices = Buffer->Vertices.data();
auto &vertices = Buffer->Vertices->Data;
for (s32 i = 0; i < 4; ++i)
vertices[i].Normal = view;
@ -211,8 +213,9 @@ void CBillboardSceneNode::getSize(f32 &height, f32 &bottomEdgeWidth,
//! \param overallColor: the color to set
void CBillboardSceneNode::setColor(const video::SColor &overallColor)
{
auto &vertices = Buffer->Vertices->Data;
for (u32 vertex = 0; vertex < 4; ++vertex)
Buffer->Vertices[vertex].Color = overallColor;
vertices[vertex].Color = overallColor;
}
//! Set the color of the top and bottom vertices of the billboard
@ -221,10 +224,11 @@ void CBillboardSceneNode::setColor(const video::SColor &overallColor)
void CBillboardSceneNode::setColor(const video::SColor &topColor,
const video::SColor &bottomColor)
{
Buffer->Vertices[0].Color = bottomColor;
Buffer->Vertices[1].Color = topColor;
Buffer->Vertices[2].Color = topColor;
Buffer->Vertices[3].Color = bottomColor;
auto &vertices = Buffer->Vertices->Data;
vertices[0].Color = bottomColor;
vertices[1].Color = topColor;
vertices[2].Color = topColor;
vertices[3].Color = bottomColor;
}
//! Gets the color of the top and bottom vertices of the billboard
@ -233,8 +237,9 @@ void CBillboardSceneNode::setColor(const video::SColor &topColor,
void CBillboardSceneNode::getColor(video::SColor &topColor,
video::SColor &bottomColor) const
{
bottomColor = Buffer->Vertices[0].Color;
topColor = Buffer->Vertices[1].Color;
auto &vertices = Buffer->Vertices->Data;
bottomColor = vertices[0].Color;
topColor = vertices[1].Color;
}
//! Creates a clone of this scene node and its children.

View file

@ -133,7 +133,7 @@ SMesh *CMeshManipulator::createMeshCopy(scene::IMesh *mesh) const
SMeshBuffer *buffer = new SMeshBuffer();
buffer->Material = mb->getMaterial();
auto *vt = static_cast<const video::S3DVertex*>(mb->getVertices());
buffer->Vertices.insert(buffer->Vertices.end(), vt, vt + mb->getVertexCount());
buffer->VertexBuffer().insert(buffer->VertexBuffer().end(), vt, vt + mb->getVertexCount());
auto *indices = mb->getIndices();
buffer->Indices.insert(buffer->Indices.end(), indices, indices + mb->getIndexCount());
clone->addMeshBuffer(buffer);
@ -143,7 +143,7 @@ SMesh *CMeshManipulator::createMeshCopy(scene::IMesh *mesh) const
SMeshBufferLightMap *buffer = new SMeshBufferLightMap();
buffer->Material = mb->getMaterial();
auto *vt = static_cast<const video::S3DVertex2TCoords*>(mb->getVertices());
buffer->Vertices.insert(buffer->Vertices.end(), vt, vt + mb->getVertexCount());
buffer->VertexBuffer().insert(buffer->VertexBuffer().end(), vt, vt + mb->getVertexCount());
auto *indices = mb->getIndices();
buffer->Indices.insert(buffer->Indices.end(), indices, indices + mb->getIndexCount());
clone->addMeshBuffer(buffer);
@ -153,7 +153,7 @@ SMesh *CMeshManipulator::createMeshCopy(scene::IMesh *mesh) const
SMeshBufferTangents *buffer = new SMeshBufferTangents();
buffer->Material = mb->getMaterial();
auto *vt = static_cast<const video::S3DVertexTangents*>(mb->getVertices());
buffer->Vertices.insert(buffer->Vertices.end(), vt, vt + mb->getVertexCount());
buffer->VertexBuffer().insert(buffer->VertexBuffer().end(), vt, vt + mb->getVertexCount());
auto *indices = mb->getIndices();
buffer->Indices.insert(buffer->Indices.end(), indices, indices + mb->getIndexCount());
clone->addMeshBuffer(buffer);

View file

@ -228,8 +228,8 @@ IAnimatedMesh *COBJMeshFileLoader::createMesh(io::IReadFile *file)
if (n != currMtl->VertMap.end()) {
vertLocation = n->second;
} else {
currMtl->Meshbuffer->Vertices.push_back(v);
vertLocation = currMtl->Meshbuffer->Vertices.size() - 1;
currMtl->Meshbuffer->VertexBuffer().push_back(v);
vertLocation = currMtl->Meshbuffer->VertexBuffer().size() - 1;
currMtl->VertMap.emplace(v, vertLocation);
}