Skip to content

Commit 6fc5ccb

Browse files
committed
demo: Add a usage example for spatialClusterPoints
1 parent a103e23 commit 6fc5ccb

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

demo/main.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,35 @@ void spatialSortTriangles(const Mesh& mesh)
12371237
(end - start) * 1000);
12381238
}
12391239

1240+
void spatialClusterPoints(const Mesh& mesh, size_t cluster_size)
1241+
{
1242+
typedef PackedVertexOct PV;
1243+
1244+
double start = timestamp();
1245+
1246+
std::vector<unsigned int> index(mesh.vertices.size());
1247+
meshopt_spatialClusterPoints(&index[0], &mesh.vertices[0].px, mesh.vertices.size(), sizeof(Vertex), cluster_size);
1248+
1249+
double end = timestamp();
1250+
1251+
std::vector<PV> pv(mesh.vertices.size());
1252+
packMesh(pv, mesh.vertices);
1253+
1254+
std::vector<PV> pvo(mesh.vertices.size());
1255+
for (size_t i = 0; i < index.size(); ++i)
1256+
pvo[i] = pv[index[i]];
1257+
1258+
std::vector<unsigned char> vbuf(meshopt_encodeVertexBufferBound(mesh.vertices.size(), sizeof(PV)));
1259+
vbuf.resize(meshopt_encodeVertexBuffer(&vbuf[0], vbuf.size(), &pvo[0], mesh.vertices.size(), sizeof(PV)));
1260+
1261+
size_t csize = compress(vbuf);
1262+
1263+
printf("SpatialCP: %.1f bits/vertex (post-deflate %.1f bits/vertex); sort %.2f msec\n",
1264+
double(vbuf.size() * 8) / double(mesh.vertices.size()),
1265+
double(csize * 8) / double(mesh.vertices.size()),
1266+
(end - start) * 1000);
1267+
}
1268+
12401269
void tessellationAdjacency(const Mesh& mesh)
12411270
{
12421271
double start = timestamp();
@@ -1525,6 +1554,7 @@ void process(const char* path)
15251554

15261555
spatialSort(mesh);
15271556
spatialSortTriangles(mesh);
1557+
spatialClusterPoints(mesh, 64);
15281558

15291559
reindexFuzzy(mesh);
15301560
coverage(mesh);

0 commit comments

Comments
 (0)