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-assimpjs.md 8.0KB

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