threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plugin-3d-tiles-renderer.md 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. ---
  2. prev:
  3. text: '@threepipe/plugin-svg-renderer'
  4. link: './plugin-svg-renderer'
  5. next:
  6. text: '@threepipe/plugin-assimpjs'
  7. link: './plugin-assimpjs'
  8. ---
  9. # @threepipe/plugin-3d-tiles-renderer
  10. Exports
  11. - [TilesRendererPlugin](https://threepipe.org/plugins/3d-tiles-renderer/docs/classes/TilesRendererPlugin.html) - adds support for loading and rendering [OGC 3D Tiles](https://www.ogc.org/standards/3dtiles/) json files.
  12. - [EnvironmentControlsPlugin](https://threepipe.org/plugins/3d-tiles-renderer/docs/classes/EnvironmentControlsPlugin.html) - adds support for using `EnvironmentControls` with the `mainCamera` as a `controlsMode`
  13. - [GlobeControlsPlugin](https://threepipe.org/plugins/3d-tiles-renderer/docs/classes/GlobeControlsPlugin.html) - adds support for using `EnvironmentControls` with the `mainCamera` as a `controlsMode`
  14. - [B3DMLoadPlugin](https://threepipe.org/plugins/3d-tiles-renderer/docs/classes/B3DMLoadPlugin.html) - adds support for loading b3dm(Batched 3D Model) files using the Asset Manager.
  15. - [CMPTLoadPlugin](https://threepipe.org/plugins/3d-tiles-renderer/docs/classes/CMPTLoadPlugin.html) - adds support for loading cmpt(Composite Model) files using the Asset Manager.
  16. - [I3DMLoadPlugin](https://threepipe.org/plugins/3d-tiles-renderer/docs/classes/I3DMLoadPlugin.html) - adds support for loading i3dm(Instanced 3D Model) files using the Asset Manager.
  17. - [PNTSLoadPlugin](https://threepipe.org/plugins/3d-tiles-renderer/docs/classes/PNTSLoadPlugin.html) - adds support for loading pnts(Point Cloud) files using the Asset Manager.
  18. - [DeepZoomImageLoadPlugin](https://threepipe.org/plugins/3d-tiles-renderer/docs/classes/DeepZoomImageLoadPlugin.html) - adds support for loading dzi(Deep Zoom Image) files.
  19. - [SlippyMapTilesLoadPlugin](https://threepipe.org/plugins/3d-tiles-renderer/docs/classes/SlippyMapTilesLoadPlugin.html) - adds support for loading slippy map tiles (open street map).
  20. This package acts as an interface to the [`3d-tiles-renderer`](https://github.com/NASA-AMMOS/3DTilesRendererJS) package.
  21. [Example](https://threepipe.org/examples/#3d-tiles-renderer/) —
  22. [Source Code](https://github.com/repalash/threepipe/blob/master/plugins/3d-tiles-renderer/src/index.ts) —
  23. [API Reference](https://threepipe.org/plugins/3d-tiles-renderer/docs)
  24. [![NPM Package](https://img.shields.io/npm/v/@threepipe/plugin-3d-tiles-renderer.svg)](https://www.npmjs.com/package/@threepipe/plugin-3d-tiles-renderer)
  25. ```bash
  26. npm install @threepipe/plugin-3d-tiles-renderer
  27. ```
  28. ::: warning Note
  29. This is still a WIP.
  30. :::
  31. :::tip Editor
  32. Any tileset can also be loaded into the tweakpane editor by adding the url and extension to the query params like -
  33. https://threepipe.org/examples/tweakpane-editor/?m=https://raw.githubusercontent.com/NASA-AMMOS/3DTilesRendererJS/c7a9a7f7607e8759d16c26fb83815ad1cd1fd865/example/data/tileset.json&ext=tileset
  34. The controls(environment, globe) can be picked from the UI above by going to Viewer -> Scene -> Camera -> Controls
  35. :::
  36. ## Sample Usage
  37. ### Load and render tileset
  38. To import a tileset, simply add the `TilesRendererPlugin` and load the root json with the plugin or the viewer.
  39. The near, far plane of the camera can be set based on the file.
  40. ```typescript
  41. import {ThreeViewer} from 'threepipe'
  42. import {TilesRendererPlugin, TilesRendererGroup} from '@threepipe/plugin-3d-tiles-renderer'
  43. const viewer = new ThreeViewer({...})
  44. const tiles = viewer.addPluginSync(TilesRendererPlugin)
  45. viewer.scene.mainCamera.position.set(300, 300, 300)
  46. // optional. (Required for GlobeControls)
  47. viewer.scene.mainCamera.autoNearFar = false
  48. viewer.scene.mainCamera.minNearPlane = 1
  49. viewer.scene.mainCamera.maxFarPlane = 1000
  50. // Now load any tileset json file.
  51. const group = await tiles.load('https://raw.githubusercontent.com/NASA-AMMOS/3DTilesRendererJS/c7a9a7f7607e8759d16c26fb83815ad1cd1fd865/example/data/tileset.json', {
  52. autoScale: true,
  53. autoCenter: true,
  54. autoScaleRadius: 100,
  55. })
  56. // or load directly from the viewer. A custom fileExtension or fileHandler must be passed, to tell the viewer the type of the json file.
  57. const group1 = await viewer.load<TilesRendererGroup>('https://raw.githubusercontent.com/NASA-AMMOS/3DTilesRendererJS/c7a9a7f7607e8759d16c26fb83815ad1cd1fd865/example/data/tileset.json', {
  58. fileExtension: TilesRendererPlugin.DUMMY_EXT,
  59. autoScale: true,
  60. autoCenter: true,
  61. autoScaleRadius: 100,
  62. })
  63. ```
  64. Check the [3d-tiles-renderer](https://threepipe.com/examples/#3d-tiles-renderer/), [ogc-tiles-mars](https://threepipe.com/examples/#ogc-tiles-mars/) examples for a live demo.
  65. ### Use `EnvironmentControls` with `TilesRendererPlugin`
  66. ```typescript
  67. import {TilesRendererPlugin, TilesRendererGroup, EnvironmentControlsPlugin, EnvironmentControls2, GlobeControlsPlugin, GlobeControls2} from '@threepipe/plugin-3d-tiles-renderer'
  68. const viewer = new ThreeViewer({...})
  69. const tiles = viewer.addPluginSync(TilesRendererPlugin)
  70. const group = await tiles.load('...')
  71. viewer.addPluginSync(EnvironmentControlsPlugin)
  72. viewer.addPluginSync(GlobeControlsPlugin)
  73. viewer.scene.mainCamera.controlsMode = 'environment'
  74. viewer.scene.mainCamera.lookAt(0, 0, 0)
  75. let controls = viewer.scene.mainCamera.controls as EnvironmentControls2
  76. controls.minDistance = 0.25;
  77. // For globe controls
  78. viewer.scene.mainCamera.controlsMode = 'globe'
  79. viewer.scene.mainCamera.lookAt(0, 0, 0)
  80. controls = viewer.scene.mainCamera.controls as GlobeControls2
  81. // optional. (Required for GlobeControls)
  82. controls.setTilesRenderer(group.tilesRenderer)
  83. ```
  84. ### Additional `TilesRenderer` Plugins
  85. Some plugins are used by default in the `TilesRendererPlugin` to load and render the tileset. These can be disabled/configured when loading a file and more can be added.
  86. Custom plugins can be added to the individual `TilesRenderer` when loading a tileset file.
  87. ```typescript
  88. import {UnloadTilesPlugin, TileCompressionPlugin} from '@threepipe/plugin-3d-tiles-renderer'
  89. const result = await tiles.load('url', {
  90. autoCenter: true,
  91. autoScale: false,
  92. tiles: {
  93. TilesFadePlugin: {
  94. fadeDuration: 0.5,
  95. },
  96. plugins: [
  97. ()=>new UnloadTilesPlugin(),
  98. ()=>new TileCompressionPlugin(),
  99. ],
  100. },
  101. })
  102. ```
  103. ### Loading Cesium Ion Assets
  104. Cesium Ion assets like Google Maps can be loaded with the `loadCesiumIon` function in the plugin, or by passing a custom plugin in the viewer.
  105. ```typescript
  106. const tiles = viewer.getPlugin(TilesRendererPlugin)
  107. const result = await tiles.loadCesiumIon({
  108. assetId: '2275207',
  109. apiToken: CESIUM_ION_API_TOKEN,
  110. autoRefreshToken: true,
  111. }, {
  112. autoCenter: false,
  113. // more options
  114. tiles: {
  115. TilesFadePlugin: true,
  116. plugins: [
  117. ()=>new TileCompressionPlugin(),
  118. ()=>new UnloadTilesPlugin(),
  119. ],
  120. },
  121. })
  122. // or
  123. const result2 = await viewer.load('file.tileset', {
  124. tiles: {
  125. CesiumIonAuthPlugin: {
  126. assetId: '2275207',
  127. apiToken: CESIUM_ION_API_TOKEN,
  128. autoRefreshToken: true,
  129. },
  130. TilesFadePlugin: true,
  131. plugins: [
  132. ()=>new TileCompressionPlugin(),
  133. ()=>new UnloadTilesPlugin(),
  134. ],
  135. },
  136. })
  137. ```
  138. Note - `TilesRendererPlugin.DUMMY_EXT` = `tileset`
  139. :::info
  140. Get the `CESIUM_ION_API_TOKEN` for free from [cesium ion](https://ion.cesium.com/)
  141. :::
  142. Check the Google Maps examples - [ogc-tiles-google-maps](https://threepipe.com/examples/#ogc-tiles-google-maps/), [ogc-tiles-google-maps-3d](https://threepipe.com/examples/#ogc-tiles-google-maps-3d/) examples for sample usage
  143. ### Loading 3d tiles files
  144. To load any individual tile file format, add the plugin to the viewer and load the file directly as you would with any other file. The plugin will automatically detect the type of the file and load it.
  145. ```typescript
  146. import {ThreeViewer} from 'threepipe'
  147. import {B3DMLoadPlugin, CMPTLoadPlugin, I3DMLoadPlugin, PNTSLoadPlugin} from '@threepipe/plugin-3d-tiles-renderer'
  148. const viewer = new ThreeViewer({...})
  149. viewer.addPluginsSync([B3DMLoadPlugin, CMPTLoadPlugin, I3DMLoadPlugin, PNTSLoadPlugin, LoadingScreenPlugin])
  150. // Now load any file
  151. const b3dm = await viewer.load<IObject3D>('https://example.com/file.b3dm')
  152. const cmpt = await viewer.load<IObject3D>('https://example.com/file.cmpt')
  153. const i3dm = await viewer.load<IObject3D>('https://example.com/file.i3dm')
  154. const pnts = await viewer.load<IObject3D>('https://example.com/file.pnts')
  155. // Load file by data url
  156. const model = await viewer.load<IObject3D>('data:application/octet-stream;base64,...', {
  157. fileExtension: 'b3dm',
  158. })
  159. // or by using `model/<extension>` mime type
  160. const model2 = await viewer.load<IObject3D>('data:model/b3dm;base64,...')
  161. ```
  162. The asset importer will automatically detect the type of the file and load it.
  163. Checkout the examples [b3dm-load](https://threepipe.org/examples/#b3dm-load/),
  164. [cmpt-load](https://threepipe.org/examples/#cmpt-load/),
  165. [pnts-load](https://threepipe.org/examples/#pnts-load/),
  166. [i3dm-load](https://threepipe.org/examples/#i3dm-load/) for more details.
  167. ### Loading Image tiles
  168. The package exports plugins `DeepZoomImageLoadPlugin` and `SlippyMapTilesLoadPlugin` to load deep zoom images and slippy map tiles respectively.
  169. They add and use the `TilesRendererPlugin` automatically.
  170. The plugins can be added to the viewer and files can be loaded directly from the viewer or asset manager.
  171. ```typescript
  172. import {ThreeViewer} from 'threepipe'
  173. import {TilesRendererPlugin, DeepZoomImageLoadPlugin, SlippyMapTilesLoadPlugin} from '@threepipe/plugin-3d-tiles-renderer'
  174. const viewer = new ThreeViewer({...})
  175. viewer.addPluginsSync([TilesRendererPlugin, DeepZoomImageLoadPlugin, SlippyMapTilesLoadPlugin])
  176. // Load deep zoom image
  177. const result = await viewer.load('https://openseadragon.github.io/example-images/duomo/duomo.dzi', {
  178. autoCenter: true,
  179. autoScale: true,
  180. autoScaleRadius: 30,
  181. tiles: {
  182. DeepZoomImagePlugin: {
  183. center: true
  184. },
  185. errorTarget: 1,
  186. }
  187. })
  188. const result2 = await viewer.load('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
  189. autoCenter: true,
  190. autoScale: true,
  191. autoScaleRadius: 30,
  192. fileExtension: SlippyMapTilesLoadPlugin.DUMMY_EXT,
  193. tiles: {
  194. errorTarget: 1,
  195. XYZTilesPlugin: {
  196. projection: 'planar',
  197. center: true
  198. },
  199. }
  200. })
  201. ```
  202. Checkout the examples [dzi-load](https://threepipe.org/examples/#dzi-load/),
  203. [slippy-map-tiles](https://threepipe.org/examples/#slippy-map-tiles/) for a demo.