Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zeux authored Oct 7, 2024
1 parent b2f957b commit bae1942
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit bae1942

Please sign in to comment.