From bae19420d7bdddd2a165f661f78a0b06682741e3 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 7 Oct 2024 15:51:44 -0700 Subject: [PATCH] Update README.md Fix code example for `reorderMesh` that was missing handling of 0xffff_ffff, which indicates the source index is not used by the index buffer so the vertex does not need to be preserved. --- js/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/js/README.md b/js/README.md index 43bad76e8..f115fc12c 100644 --- a/js/README.md +++ b/js/README.md @@ -69,12 +69,13 @@ reorderMesh: (indices: Uint32Array, triangles: boolean, optsize: boolean) => [Ui The function optimizes the input array for locality of reference (make sure to pass `triangles=true` for triangle lists, and `false` otherwise). `optsize` can choose whether the order should be optimal for transmission size (recommended for Web) or for GPU rendering performance. The function changes the `indices` array in place and returns an additional remap array and the total number of unique vertices. -After this function returns, to maintain correct rendering the application should reorder all vertex streams - including morph targets if applicable - according to the remap array. For each original index, remap array contains the new location for that index, so the remapping pseudocode looks like this: +After this function returns, to maintain correct rendering the application should reorder all vertex streams - including morph targets if applicable - according to the remap array. For each original index, remap array contains the new location for that index (or `0xffffffff` if the value is unused), so the remapping pseudocode looks like this: ```ts let newvertices = new VertexArray(unique); // unique is returned by reorderMesh for (let i = 0; i < oldvertices.length; ++i) - newvertices[remap[i]] = oldvertices[i]; + if (remap[i] != 0xffffffff) + newvertices[remap[i]] = oldvertices[i]; ``` When the input is a point cloud and not a triangle mesh, it is recommended to reorder the points using a specialized function that performs spatial sorting that can result in significant improvements in compression ratio by the subsequent processing: