Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add enableMeshoptDecoder function for GLTFs #2481

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions examples/3dtiles_loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@
"three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/"
}
}
</script>
</script>

<script type="module">
import { AmbientLight } from 'three';
import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js';
import {
zoomToLayer,
fillHTMLWithPickingInfo,
Expand Down Expand Up @@ -95,9 +96,11 @@

// Enable various compression support for 3D Tiles tileset:
// - `KHR_draco_mesh_compression` mesh compression extension
// - `KHR_texture_basisu` texture compresion extension
// - `KHR_texture_basisu` texture compression extension
// - `EXT_meshopt_compression` data compression extension
itowns.enableDracoLoader('./libs/draco/');
itowns.enableKtx2Loader('./lib/basis/', view.renderer);
itowns.enableMeshoptDecoder(MeshoptDecoder);

// Add ambient light to globally illuminates all objects
const light = new AmbientLight(0x404040, 40);
Expand Down
21 changes: 21 additions & 0 deletions src/Layer/OGC3DTilesLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,27 @@ export function enableKtx2Loader(path, renderer) {
itownsGLTFLoader.setKTX2Loader(ktx2Loader);
}

/**
* Enable loading 3D Tiles and GLTF with
* [meshopt](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_meshopt_compression/README.md) compression extension.
*
* @param {MeshOptDecoder.constructor} MeshOptDecoder - The Meshopt decoder
* module.
*
* @example
* import * as itowns from 'itowns';
* import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js';
*
* // Enable support of EXT_meshopt_compression
* itowns.enableMeshoptDecoder(MeshoptDecoder);
*/
export function enableMeshoptDecoder(MeshOptDecoder) {
if (!MeshOptDecoder) {
throw new Error('MeshOptDecoder module is mandatory');
}
itownsGLTFLoader.setMeshoptDecoder(MeshOptDecoder);
}

class OGC3DTilesLayer extends GeometryLayer {
/**
* Layer for [3D Tiles](https://www.ogc.org/standard/3dtiles/) datasets.
Expand Down
8 changes: 7 additions & 1 deletion src/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ export { default as PointCloudLayer } from 'Layer/PointCloudLayer';
export { default as PotreeLayer } from 'Layer/PotreeLayer';
export { default as Potree2Layer } from 'Layer/Potree2Layer';
export { default as C3DTilesLayer, C3DTILES_LAYER_EVENTS } from 'Layer/C3DTilesLayer';
export { default as OGC3DTilesLayer, OGC3DTILES_LAYER_EVENTS, enableDracoLoader, enableKtx2Loader } from 'Layer/OGC3DTilesLayer';
export {
default as OGC3DTilesLayer,
OGC3DTILES_LAYER_EVENTS,
enableDracoLoader,
enableKtx2Loader,
enableMeshoptDecoder,
} from 'Layer/OGC3DTilesLayer';
export { default as TiledGeometryLayer } from 'Layer/TiledGeometryLayer';
export { default as OrientedImageLayer } from 'Layer/OrientedImageLayer';
export { STRATEGY_MIN_NETWORK_TRAFFIC, STRATEGY_GROUP, STRATEGY_PROGRESSIVE, STRATEGY_DICHOTOMY } from 'Layer/LayerUpdateStrategy';
Expand Down
Loading