The xeokit SceneGeometry Compression/Decompression Utilities library provides functions used internally within
SceneModel.createGeometry implementations to compress geometry. These functions are also
provided for users who want to pre-compress their geometry "offline" and then
use SceneModel.createGeometryCompressed
to create compressed geometry directly.
The compression techniques used include simplifying geometry by combining duplicate positions and adjusting indices, generating edge
indices for triangle meshes, ignoring normals (as shaders auto-generate them), converting positions to relative-to-center (RTC)
coordinates, quantizing positions and UVs as 16-bit unsigned integers, and splitting geometry into buckets to enable indices to use
the minimum bits for storage. The bucketing technique was developed for xeokit by Toni Marti with support from Tribia AG.
An example usage includes compressing a SceneGeometryParams into a @xeokit/scene!SceneGeometryCompressedParams using the
@xeokit/scene!compressGeometryParams function. In this example, the geometry is simple, and only one bucket is
needed. However, if the positions array was large enough to require some indices to use more than 16 bits for storage, the
bucketing mechanism would split the geometry into smaller buckets, each with smaller indices that index a subset of the
positions.
The resulting SceneGeometryCompressedParams object shows that we have one bucket with vertex positions relative to the origin
and quantized to 16-bit integers, duplicate positions removed, and adjusted indices. Additionally, edge indices are
generated for the @xeokit/constants!TrianglesPrimitive, and a positionsDecompressMatrix is included to de-quantize
the positions within the Viewer.
This library provides a set of functions that are used internally within
SceneModel.createGeometry implementations to
compress geometry. The functions are provided here in case users instead want to pre-compress their geometry "offline",
and then use SceneModel.createGeometryCompressed
to create the compressed geometry directly.
The bucketing technique mentioned above was developed for xeokit by Toni Marti, with support from Tribia AG. Read the slides from Toni's presentation at WebGL Meetup 2022.
In this example, our geometry is very simple, and our SceneGeometryCompressedParams only gets a single
SceneGeometryBucketParams. Note that if the
SceneGeometryParams.positions array was large enough to require
some of the indices to use more than 16 bits for storage, then that's when the function's bucketing mechanism would
kick in, to split the geometry into smaller buckets, each with smaller indices that index a subset of the positions.
xeokit SceneGeometry Compression / Decompression Utilities
Tools for geometry compression and decompression
The xeokit SceneGeometry Compression/Decompression Utilities library provides functions used internally within SceneModel.createGeometry implementations to compress geometry. These functions are also provided for users who want to pre-compress their geometry "offline" and then use SceneModel.createGeometryCompressed to create compressed geometry directly.
The compression techniques used include simplifying geometry by combining duplicate positions and adjusting indices, generating edge indices for triangle meshes, ignoring normals (as shaders auto-generate them), converting positions to relative-to-center (RTC) coordinates, quantizing positions and UVs as 16-bit unsigned integers, and splitting geometry into buckets to enable indices to use the minimum bits for storage. The bucketing technique was developed for xeokit by Toni Marti with support from Tribia AG.
An example usage includes compressing a SceneGeometryParams into a @xeokit/scene!SceneGeometryCompressedParams using the @xeokit/scene!compressGeometryParams function. In this example, the geometry is simple, and only one bucket is needed. However, if the positions array was large enough to require some indices to use more than 16 bits for storage, the bucketing mechanism would split the geometry into smaller buckets, each with smaller indices that index a subset of the positions.
The resulting SceneGeometryCompressedParams object shows that we have one bucket with vertex positions relative to the origin and quantized to 16-bit integers, duplicate positions removed, and adjusted indices. Additionally, edge indices are generated for the @xeokit/constants!TrianglesPrimitive, and a positionsDecompressMatrix is included to de-quantize the positions within the Viewer.
This library provides a set of functions that are used internally within SceneModel.createGeometry implementations to compress geometry. The functions are provided here in case users instead want to pre-compress their geometry "offline", and then use SceneModel.createGeometryCompressed to create the compressed geometry directly.
Compression Techniques Used
Aknowledgements
Installation
Usage
In the example below, we'll use @xeokit/scene!compressGeometryParams to compress a SceneGeometryParams into a SceneGeometryCompressedParams.
In this example, our geometry is very simple, and our SceneGeometryCompressedParams only gets a single SceneGeometryBucketParams. Note that if the SceneGeometryParams.positions array was large enough to require some of the indices to use more than 16 bits for storage, then that's when the function's bucketing mechanism would kick in, to split the geometry into smaller buckets, each with smaller indices that index a subset of the positions.
The value of our new SceneGeometryCompressedParams is shown below.
We can see that:
origin
and quantized to 16-bit integerspositionsDecompressMatrix
to de-quantize the positions within the ViewerIn the next example, we'll again use @xeokit/scene!compressGeometryParams to compress a SceneGeometryParams into a SceneGeometryCompressedParams, which we'll then use to create a compressed geometry within a SceneModel.