threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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

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