1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-16 18:01:40 +00:00

Split CIndexBuffer from CMeshBuffer

This commit is contained in:
sfan5 2024-08-27 17:40:29 +02:00
parent 5d6e15bc49
commit 47e4c33a50
13 changed files with 197 additions and 104 deletions

View file

@ -27,16 +27,17 @@ CBillboardSceneNode::CBillboardSceneNode(ISceneNode *parent, ISceneManager *mgr,
setSize(size);
auto &Vertices = Buffer->Vertices->Data;
auto &Indices = Buffer->Indices->Data;
Vertices.resize(4);
Buffer->Indices.resize(6);
Indices.resize(6);
Buffer->Indices[0] = 0;
Buffer->Indices[1] = 2;
Buffer->Indices[2] = 1;
Buffer->Indices[3] = 0;
Buffer->Indices[4] = 3;
Buffer->Indices[5] = 2;
Indices[0] = 0;
Indices[1] = 2;
Indices[2] = 1;
Indices[3] = 0;
Indices[4] = 3;
Indices[5] = 2;
Vertices[0].TCoords.set(1.0f, 1.0f);
Vertices[0].Color = colorBottom;

View file

@ -135,7 +135,7 @@ SMesh *CMeshManipulator::createMeshCopy(scene::IMesh *mesh) const
auto *vt = static_cast<const video::S3DVertex*>(mb->getVertices());
buffer->VertexBuffer().insert(buffer->VertexBuffer().end(), vt, vt + mb->getVertexCount());
auto *indices = mb->getIndices();
buffer->Indices.insert(buffer->Indices.end(), indices, indices + mb->getIndexCount());
buffer->IndexBuffer().insert(buffer->IndexBuffer().end(), indices, indices + mb->getIndexCount());
clone->addMeshBuffer(buffer);
buffer->drop();
} break;
@ -145,7 +145,7 @@ SMesh *CMeshManipulator::createMeshCopy(scene::IMesh *mesh) const
auto *vt = static_cast<const video::S3DVertex2TCoords*>(mb->getVertices());
buffer->VertexBuffer().insert(buffer->VertexBuffer().end(), vt, vt + mb->getVertexCount());
auto *indices = mb->getIndices();
buffer->Indices.insert(buffer->Indices.end(), indices, indices + mb->getIndexCount());
buffer->IndexBuffer().insert(buffer->IndexBuffer().end(), indices, indices + mb->getIndexCount());
clone->addMeshBuffer(buffer);
buffer->drop();
} break;
@ -155,7 +155,7 @@ SMesh *CMeshManipulator::createMeshCopy(scene::IMesh *mesh) const
auto *vt = static_cast<const video::S3DVertexTangents*>(mb->getVertices());
buffer->VertexBuffer().insert(buffer->VertexBuffer().end(), vt, vt + mb->getVertexCount());
auto *indices = mb->getIndices();
buffer->Indices.insert(buffer->Indices.end(), indices, indices + mb->getIndexCount());
buffer->IndexBuffer().insert(buffer->IndexBuffer().end(), indices, indices + mb->getIndexCount());
clone->addMeshBuffer(buffer);
buffer->drop();
} break;

View file

@ -247,15 +247,16 @@ IAnimatedMesh *COBJMeshFileLoader::createMesh(io::IReadFile *file)
}
// triangulate the face
auto &Indices = currMtl->Meshbuffer->IndexBuffer();
const int c = faceCorners[0];
for (u32 i = 1; i < faceCorners.size() - 1; ++i) {
// Add a triangle
const int a = faceCorners[i + 1];
const int b = faceCorners[i];
if (a != b && a != c && b != c) { // ignore degenerated faces. We can get them when we merge vertices above in the VertMap.
currMtl->Meshbuffer->Indices.push_back(a);
currMtl->Meshbuffer->Indices.push_back(b);
currMtl->Meshbuffer->Indices.push_back(c);
Indices.push_back(a);
Indices.push_back(b);
Indices.push_back(c);
} else {
++degeneratedFaces;
}