threepipe
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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

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