Fixing tree and adding unit tests
This commit is contained in:
@@ -117,6 +117,7 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
|
||||
.primitiveCount = m.numPrimitives,
|
||||
.vertexOffset = vertexOffset,
|
||||
.primitiveOffset = primitiveOffset,
|
||||
.color = Vector((float)rand() / RAND_MAX,(float)rand() / RAND_MAX,(float)rand() / RAND_MAX),
|
||||
});
|
||||
}
|
||||
meshData[id].add(MeshData{
|
||||
@@ -245,73 +246,3 @@ VertexData::VertexData()
|
||||
, dirty(false)
|
||||
{
|
||||
}
|
||||
|
||||
void Meshlet::build(const Array<uint32>& indices, Array<Meshlet>& meshlets)
|
||||
{
|
||||
Map<uint32, Set<uint32>> connectivity;
|
||||
for (uint32 i = 0; i < indices.size(); i+=3)
|
||||
{
|
||||
connectivity[indices[i]].insert(indices[i + 1]);
|
||||
connectivity[indices[i]].insert(indices[i + 2]);
|
||||
}
|
||||
Meshlet current = {
|
||||
.numVertices = 0,
|
||||
.numPrimitives = 0,
|
||||
};
|
||||
auto findIndex = [¤t](uint32 index) -> int {
|
||||
for (uint32 i = 0; i < current.numVertices; ++i)
|
||||
{
|
||||
if (current.uniqueVertices[i] == index)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
if (current.numVertices == Gfx::numVerticesPerMeshlet)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
current.uniqueVertices[current.numVertices] = index;
|
||||
return current.numVertices++;
|
||||
};
|
||||
auto completeMeshlet = [&meshlets, ¤t]() {
|
||||
meshlets.add(current);
|
||||
current = {
|
||||
.numVertices = 0,
|
||||
.numPrimitives = 0,
|
||||
};
|
||||
};
|
||||
for (size_t faceIndex = 0; faceIndex < indices.size() / 3; ++faceIndex)
|
||||
{
|
||||
int f1 = findIndex(indices[faceIndex * 3 + 0]);
|
||||
int f2 = findIndex(indices[faceIndex * 3 + 1]);
|
||||
int f3 = findIndex(indices[faceIndex * 3 + 2]);
|
||||
|
||||
if (f1 == -1 || f2 == -1 || f1 == -1)
|
||||
{
|
||||
completeMeshlet();
|
||||
f1 = findIndex(indices[faceIndex * 3 + 0]);
|
||||
f2 = findIndex(indices[faceIndex * 3 + 1]);
|
||||
f3 = findIndex(indices[faceIndex * 3 + 2]);
|
||||
}
|
||||
current.primitiveLayout[current.numPrimitives * 3 + 0] = uint8(f1);
|
||||
current.primitiveLayout[current.numPrimitives * 3 + 1] = uint8(f2);
|
||||
current.primitiveLayout[current.numPrimitives * 3 + 2] = uint8(f3);
|
||||
current.numPrimitives++;
|
||||
if (current.numPrimitives == Gfx::numPrimitivesPerMeshlet)
|
||||
{
|
||||
completeMeshlet();
|
||||
}
|
||||
}
|
||||
if (current.numVertices > 0)
|
||||
{
|
||||
completeMeshlet();
|
||||
}
|
||||
}
|
||||
|
||||
void Meshlet::calcBoundingBox(const Array<Vector>& positions)
|
||||
{
|
||||
for (uint32 i = 0; i < numVertices; ++i)
|
||||
{
|
||||
boundingBox.adjust(positions[uniqueVertices[i]]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user