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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. This package uses a custom fork of [assimpjs](https://github.com/kovacsv/assimpjs) with custom build to support fbx export etc - https://github.com/repalash/assimpjs
  14. ```bash
  15. npm install @threepipe/plugin-assimpjs
  16. ```
  17. ## Sample Usage
  18. ### Convert any format to glTF/glb and load in viewer
  19. Any set of 3d files can be loaded into assimp, and converted to glTF/glb format. The converted files can then be loaded into the viewer as blobs.
  20. ```typescript
  21. import {ThreeViewer} from 'threepipe'
  22. import {AssimpJsPlugin} from '@threepipe/plugin-assimpjs'
  23. const viewer = new ThreeViewer({...})
  24. const assimpjs = viewer.addPluginSync(AssimpJsPlugin)
  25. await assimp.init() // load the assimpjs library and wait for it to be ready. It also loads automatically when plugin is added to the viewer if autoInit is true.
  26. // Prepare a list of files to load
  27. const files = [
  28. 'https://threejs.org/examples/models/obj/male02/male02.obj',
  29. ]
  30. // Download the files
  31. const fe = files.map(async f=>fetch(`${f}`).then(async t=>t.arrayBuffer()))
  32. const responses = await Promise.all(fe)
  33. const fileList: Record<string, ArrayBuffer> = {}
  34. for (let i = 0; i < files.length; i++) {
  35. fileList[files[i]] = responses[i]
  36. }
  37. const fbx = assimp.convertFiles(fileList, 'glb2')
  38. if (!fbx) {
  39. console.error('Failed to convert files to glb')
  40. return
  41. }
  42. // load the glb file
  43. await viewer.load<IObject3D>({path: 'file.glb', file: glb})
  44. ```
  45. Check the [assimpjs-plugin](https://threepipe.org/examples/#assimpjs-plugin/) example for a live demo.
  46. ### Export to FBX / Convert to FBX
  47. Assimp includes a FBX exporter, which can be used to convert any 3D file format to FBX.
  48. To export the current scene to FBX, the scene can be exported to glTF/glb format, and then converted to FBX using the `AssimpJsPlugin`'s `convertFiles` function.
  49. ```typescript
  50. import {ThreeViewer, downloadBlob} from 'threepipe'
  51. import {AssimpJsPlugin} from '@threepipe/plugin-assimpjs'
  52. const viewer = new ThreeViewer({...})
  53. const assimpjs = viewer.addPluginSync(AssimpJsPlugin)
  54. await assimp.init() // load the assimpjs library and wait for it to be ready. It also loads automatically when plugin is added to the viewer if autoInit is true.
  55. // load some models
  56. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf')
  57. const fbxBlob = await assimp.exportModel('fbx', result, {
  58. embedUrlImages: true,
  59. })
  60. // download the fbx file
  61. downloadBlob(fbxBlob, 'model.fbx')
  62. ```
  63. Check full example - [fbx-export](https://threepipe.org/examples/#fbx-export/).