|
| 1 | +# @threebird/loader-3d-tiles |
| 2 | +  |
| 3 | + |
| 4 | +[Demos](#demos) — |
| 5 | +[Usage](#basic-usage) — |
| 6 | +[Roadmap](#roadmap) — |
| 7 | +[Contributing](#contributing) — |
| 8 | +[Docs](#docs) — |
| 9 | +[Alternatives](#alternatives) |
| 10 | + |
| 11 | + |
| 12 | +This is a [Three.js](https://threejs.org/) loader module for handling [OGC 3D Tiles](https://www.ogc.org/standards/3DTiles), created by [Cesium](https://github.com/CesiumGS/3d-tiles). It currently supports the two main formats: |
| 13 | + |
| 14 | +1. Batched 3D Model (b3dm) - based on glTF. |
| 15 | +2. Point cloud. |
| 16 | + |
| 17 | +Internally, the loader uses the [loaders.gl library](https://github.com/visgl/loaders.gl), which is part of the [vis.gl platform](https://vis.gl/), openly governed by the [Urban Computing Foundation](https://uc.foundation/). Cesium has [worked closely with loaders.gl](https://cesium.com/blog/2019/11/06/cesium-uber/) to create a platform-independent implementation of their 3D Tiles viewer. |
| 18 | + |
| 19 | +Development of this library started at The New York Times R&D as an effort to create a clean bridge between the 3D Tiles specification and the widely used 3D library Three.js. The library helps us deliver massive 3D and Geographical journalism to desktops and mobile readers alike. From **Re**porting to **Tele**porting! |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Demos |
| 24 | +* [Photogrammetry exported to 3D Tiles in RealityCapture](https://automatic-lamp-fd84a7c4.pages.github.io/examples/demos/realitycapture) |
| 25 | +* [LiDAR Point Cloud hosted as 3D Tiles in Cesium ION](https://automatic-lamp-fd84a7c4.pages.github.io/examples/demos/cesium) |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +## Basic Usage |
| 30 | +Here is a simple example using the `Loader3DTiles` module to view a `tileset.json` containing a 3d tile hierarchy. |
| 31 | + |
| 32 | +```javascript |
| 33 | +import { |
| 34 | + Scene, |
| 35 | + PerspectiveCamera, |
| 36 | + WebGLRenderer, |
| 37 | + Clock |
| 38 | +} from 'three' |
| 39 | +import { Loader3DTiles } from '@threebird/loader-3d-tiles'; |
| 40 | + |
| 41 | +const scene = new Scene() |
| 42 | +const camera = new PerspectiveCamera() |
| 43 | +const renderer = new WebGLRenderer() |
| 44 | +const clock = new Clock() |
| 45 | + |
| 46 | +renderer.setSize(window.innerWidth, window.innerHeight) |
| 47 | +document.body.appendChild(renderer.domElement) |
| 48 | + |
| 49 | +let tilesRuntime = null; |
| 50 | + |
| 51 | +async function loadTileset() { |
| 52 | + const result = await Loader3DTiles.load( |
| 53 | + url: 'https://<TILESET URL>/tileset.json', |
| 54 | + renderer: renderer, |
| 55 | + options: { |
| 56 | + dracoDecoderPath : 'https://unpkg.com/[email protected]/examples/js/libs/draco', |
| 57 | + basisTranscoderPath : 'https://unpkg.com/[email protected]/examples/js/libs/basis' |
| 58 | + } |
| 59 | + ) |
| 60 | + const {model, runtime} = result |
| 61 | + tilesRuntime = runtime |
| 62 | + scene.add(model) |
| 63 | +} |
| 64 | + |
| 65 | +function render(t) { |
| 66 | + const dt = clock.getDelta() |
| 67 | + if (tilesRuntime) { |
| 68 | + tilesRuntime.update(dt, renderer, camera) |
| 69 | + } |
| 70 | + renderer.render(scene, camera) |
| 71 | + window.requestAnimationFrame(render) |
| 72 | +} |
| 73 | + |
| 74 | +render() |
| 75 | +``` |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## Installation |
| 80 | + |
| 81 | +The library depends on [three.js](https://threejs.org/) r129 and uses its GLTF, Draco, and KTX2/Basis loaders. |
| 82 | +Refer to the `browserslist` field in [package.json](./package.json) for target browsers. |
| 83 | + |
| 84 | +### 1. ES Module |
| 85 | +Download [dist/threebird-loader-3d-tiles.esm.min.js](dist/threebird-loader-3d-tiles.esm.min.js) and use an `importmap-shim` to import the dependencies. See [here](examples/installation/es-module) for a full example. The [demos](examples/demos) also use this method of installation: |
| 86 | + |
| 87 | +#### **`index.html`** |
| 88 | + ```html |
| 89 | + < script async src= "https://unpkg.com/[email protected]/dist/es-module-shims.js"></ script> |
| 90 | + <script type="importmap-shim"> |
| 91 | + { |
| 92 | + "imports": { |
| 93 | + "three": "https://cdn.skypack.dev/[email protected]", |
| 94 | + "three/examples/jsm/loaders/GLTFLoader": "https://cdn.skypack.dev/[email protected]/examples/jsm/loaders/GLTFLoader", |
| 95 | + "three/examples/jsm/loaders/DRACOLoader": "https://cdn.skypack.dev/[email protected]/examples/jsm/loaders/DRACOLoader", |
| 96 | + "three/examples/jsm/loaders/KTX2Loader": "https://cdn.skypack.dev/[email protected]/examples/jsm/loaders/KTX2Loader", |
| 97 | + "@threebird/loader-3d-tiles" : "./threebird-loader-3d-tiles.esm.min.js" |
| 98 | + } |
| 99 | + } |
| 100 | + </script> |
| 101 | + <script src='index.js' type='module-shim'> |
| 102 | +
|
| 103 | + ``` |
| 104 | +#### **`index.js`** |
| 105 | + ```javascript |
| 106 | + import { Scene, PerspectiveCamera } from 'three'; |
| 107 | + import { Loader3DTiles } from '@threebird/loader-3d-tiles'; |
| 108 | + ``` |
| 109 | +
|
| 110 | +### 3. NPM |
| 111 | +If you use a build system such as Webpack / Parcel / Rollup etc, you should also install the library along with three.js from npm: |
| 112 | +``` |
| 113 | +npm install -s three @threebird/loader-3d-tiles |
| 114 | +``` |
| 115 | +The application script would be the same as in the ES Module example (when using `importmap-shim`). |
| 116 | +
|
| 117 | +See [here](examples/installation/webpack) for a complete webpack example. |
| 118 | +
|
| 119 | +--- |
| 120 | +## Roadmap |
| 121 | +
|
| 122 | +### Geo-referencing and layering: WGS84. |
| 123 | +
|
| 124 | +Currently the library does not use geo-referenced locations of tiled models, instead transforming them to Point `[0,0,0]`. We should support maintaining *WGS84* coordinates, so that models could be layered on top of maps and terrains. |
| 125 | +
|
| 126 | +## Skip-traversal |
| 127 | +Implementing the [Skip traversal mechanism](https://cesium.com/blog/2017/05/05/skipping-levels-of-detail/) could greatly improve performance of b3dm (mesh) tiles, but requires a shader/Stencil buffer-based implementation which manually manges Z-culling. This is a very wanted features and contributions would be greatly appreciated. |
| 128 | +
|
| 129 | +
|
| 130 | +## Contributing |
| 131 | +
|
| 132 | +Refer to [CONTRIBUTING.MD](./CONTRIBUTING.md) for general contribution instructions. |
| 133 | +
|
| 134 | +### Developing |
| 135 | +The library is built using rollup. To run a simple development server type: |
| 136 | +``` |
| 137 | +npm run dev |
| 138 | +``` |
| 139 | +It is also possible to develop the library while developing loaders.gl. Just clone the source of loaders.gl and run: |
| 140 | +``` |
| 141 | +LOADERS_GL_SRC=<path to loaders.gl> npm run dev |
| 142 | +``` |
| 143 | +
|
| 144 | +### Building |
| 145 | +To build the library run: |
| 146 | +``` |
| 147 | +npm run build |
| 148 | +``` |
| 149 | +To build the production minified version run: |
| 150 | +``` |
| 151 | +npm run build:production |
| 152 | +``` |
| 153 | +And to build the API documentation run: |
| 154 | +``` |
| 155 | +npm run build:docs |
| 156 | +``` |
| 157 | +
|
| 158 | +
|
| 159 | +### Tests |
| 160 | +A rudimentary test spec is available at [./test](./test). To run it type: |
| 161 | +``` |
| 162 | +npm run test |
| 163 | +``` |
| 164 | +
|
| 165 | +
|
| 166 | +## Docs |
| 167 | +* API documentation is available [here](docs/loader-3d-tiles.md). |
| 168 | +* Code for the demos is in [`examples/demos`](examples/demos). |
| 169 | +
|
| 170 | +## Alternatives |
| 171 | +To our knowledge, this is the only [loaders.gl](https://github.com/visgl/loaders.gl)-based Three.js library, but there are several implementations of 3D Tiles for Three.js. Notable examples: |
| 172 | +
|
| 173 | + - [NASSA-AMMOS / 3DTilesRendererJS](https://github.com/NASA-AMMOS/3DTilesRendererJS) |
| 174 | + - [ebeaufay / 3DTilesViewer](https://github.com/ebeaufay/3DTilesViewer) |
| 175 | + - [iTowns](https://github.com/iTowns/itowns) |
| 176 | +
|
| 177 | + --- |
| 178 | +
|
| 179 | +> This repository is maintained by the Research & Development team at The New York Times and is provided as-is for your own use. For more information about R&D at the Times visit [rd.nytimes.com](https://rd.nytimes.com) |
0 commit comments