trying to integrate legacy index buffer rendering
This commit is contained in:
@@ -177,71 +177,64 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialAss
|
||||
}
|
||||
|
||||
Array<Meshlet> meshlets;
|
||||
if (Gfx::useMeshShading)
|
||||
meshlets.reserve(indices.size() / (3ull * Gfx::numPrimitivesPerMeshlet));
|
||||
std::set<uint32> uniqueVertices;
|
||||
Meshlet current = {
|
||||
.numVertices = 0,
|
||||
.numPrimitives = 0,
|
||||
};
|
||||
auto insertAndGetIndex = [&uniqueVertices, ¤t](uint32 index) -> int8_t
|
||||
{
|
||||
meshlets.reserve(indices.size() / (3ull * Gfx::numPrimitivesPerMeshlet));
|
||||
std::set<uint32> uniqueVertices;
|
||||
Meshlet current = {
|
||||
auto [it, inserted] = uniqueVertices.insert(index);
|
||||
if (inserted)
|
||||
{
|
||||
if (current.numVertices == Gfx::numVerticesPerMeshlet)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
current.uniqueVertices[current.numVertices] = index;
|
||||
return current.numVertices++;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (uint32 i = 0; i < current.numVertices; ++i)
|
||||
{
|
||||
if (current.uniqueVertices[i] == index)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
};
|
||||
auto completeMeshlet = [&meshlets, ¤t, &uniqueVertices]() {
|
||||
meshlets.add(current);
|
||||
current = {
|
||||
.numVertices = 0,
|
||||
.numPrimitives = 0,
|
||||
};
|
||||
auto insertAndGetIndex = [&uniqueVertices, ¤t](uint32 index) -> int8_t
|
||||
{
|
||||
auto [it, inserted] = uniqueVertices.insert(index);
|
||||
if (inserted)
|
||||
{
|
||||
if (current.numVertices == Gfx::numVerticesPerMeshlet)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
current.uniqueVertices[current.numVertices] = index;
|
||||
return current.numVertices++;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (uint32 i = 0; i < current.numVertices; ++i)
|
||||
{
|
||||
if (current.uniqueVertices[i] == index)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
};
|
||||
auto completeMeshlet = [&meshlets, ¤t, &uniqueVertices]() {
|
||||
meshlets.add(current);
|
||||
current = {
|
||||
.numVertices = 0,
|
||||
.numPrimitives = 0,
|
||||
};
|
||||
uniqueVertices.clear();
|
||||
};
|
||||
for (size_t faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex)
|
||||
{
|
||||
auto i1 = insertAndGetIndex(mesh->mFaces[faceIndex].mIndices[0]);
|
||||
auto i2 = insertAndGetIndex(mesh->mFaces[faceIndex].mIndices[1]);
|
||||
auto i3 = insertAndGetIndex(mesh->mFaces[faceIndex].mIndices[2]);
|
||||
if (i1 == -1 || i2 == -1 || i3 == -1)
|
||||
{
|
||||
completeMeshlet();
|
||||
}
|
||||
current.primitiveLayout[current.numPrimitives * 3 + 0] = i1;
|
||||
current.primitiveLayout[current.numPrimitives * 3 + 1] = i2;
|
||||
current.primitiveLayout[current.numPrimitives * 3 + 2] = i3;
|
||||
current.numPrimitives++;
|
||||
if (current.numPrimitives == Gfx::numPrimitivesPerMeshlet)
|
||||
{
|
||||
completeMeshlet();
|
||||
}
|
||||
}
|
||||
vertexData->loadMesh(id, meshlets);
|
||||
}
|
||||
else
|
||||
uniqueVertices.clear();
|
||||
};
|
||||
for (size_t faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex)
|
||||
{
|
||||
// \! todo
|
||||
auto i1 = insertAndGetIndex(mesh->mFaces[faceIndex].mIndices[0]);
|
||||
auto i2 = insertAndGetIndex(mesh->mFaces[faceIndex].mIndices[1]);
|
||||
auto i3 = insertAndGetIndex(mesh->mFaces[faceIndex].mIndices[2]);
|
||||
if (i1 == -1 || i2 == -1 || i3 == -1)
|
||||
{
|
||||
completeMeshlet();
|
||||
}
|
||||
current.primitiveLayout[current.numPrimitives * 3 + 0] = i1;
|
||||
current.primitiveLayout[current.numPrimitives * 3 + 1] = i2;
|
||||
current.primitiveLayout[current.numPrimitives * 3 + 2] = i3;
|
||||
current.numPrimitives++;
|
||||
if (current.numPrimitives == Gfx::numPrimitivesPerMeshlet)
|
||||
{
|
||||
completeMeshlet();
|
||||
}
|
||||
}
|
||||
|
||||
vertexData->loadMesh(id, meshlets);
|
||||
|
||||
|
||||
collider.physicsMesh.addCollider(positions, indices, Matrix4(1.0f));
|
||||
|
||||
@@ -262,6 +255,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialAss
|
||||
});
|
||||
globalMeshes[meshIndex]->meshlets = std::move(meshlets);
|
||||
globalMeshes[meshIndex]->vertexCount = mesh->mNumVertices;
|
||||
globalMeshes[meshIndex]->indexBuffer = std::move(indexBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user