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 3.2KB

пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ---
  2. prev:
  3. text: '@threepipe/plugin-3d-tiles-renderer'
  4. link: './plugin-3d-tiles-renderer'
  5. next:
  6. text: '@threepipe/plugin-path-tracing'
  7. link: './plugin-path-tracing'
  8. ---
  9. # @threepipe/plugin-assimpjs
  10. This package exports [AssimpJsPlugin](https://threepipe.org/plugins/assimpjs/docs/classes/AssimpJsPlugin.html) which loads the assimpjs library and provides `ajs` interface.
  11. [Example](https://threepipe.org/examples/#assimpjs-plugin/) —
  12. [Source Code](https://github.com/repalash/threepipe/blob/master/plugins/assimpjs/src/index.ts) —
  13. [API Reference](https://threepipe.org/plugins/assimpjs/docs)
  14. [![NPM Package](https://img.shields.io/npm/v/@threepipe/plugin-assimpjs.svg)](https://www.npmjs.com/package/@threepipe/plugin-assimpjs)
  15. 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
  16. ```bash
  17. npm install @threepipe/plugin-assimpjs
  18. ```
  19. ## Sample Usage
  20. ### Convert any format to glTF/glb and load in viewer
  21. 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.
  22. ```typescript
  23. import {ThreeViewer} from 'threepipe'
  24. import {AssimpJsPlugin} from '@threepipe/plugin-assimpjs'
  25. const viewer = new ThreeViewer({...})
  26. const assimpjs = viewer.addPluginSync(AssimpJsPlugin)
  27. 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.
  28. // Prepare a list of files to load
  29. const files = [
  30. 'https://threejs.org/examples/models/obj/male02/male02.obj',
  31. ]
  32. // Download the files
  33. const fe = files.map(async f=>fetch(`${f}`).then(async t=>t.arrayBuffer()))
  34. const responses = await Promise.all(fe)
  35. const fileList: Record<string, ArrayBuffer> = {}
  36. for (let i = 0; i < files.length; i++) {
  37. fileList[files[i]] = responses[i]
  38. }
  39. const fbx = assimp.convertFiles(fileList, 'glb2')
  40. if (!fbx) {
  41. console.error('Failed to convert files to glb')
  42. return
  43. }
  44. // load the glb file
  45. await viewer.load<IObject3D>({path: 'file.glb', file: glb})
  46. ```
  47. Check the [assimpjs-plugin](https://threepipe.org/examples/#assimpjs-plugin/) example for a live demo.
  48. ### Export to FBX / Convert to FBX
  49. Assimp includes a FBX exporter, which can be used to convert any 3D file format to FBX.
  50. 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.
  51. ```typescript
  52. import {ThreeViewer, downloadBlob} from 'threepipe'
  53. import {AssimpJsPlugin} from '@threepipe/plugin-assimpjs'
  54. const viewer = new ThreeViewer({...})
  55. const assimpjs = viewer.addPluginSync(AssimpJsPlugin)
  56. 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.
  57. // load some models
  58. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf')
  59. const fbxBlob = await assimp.exportModel('fbx', result, {
  60. embedUrlImages: true,
  61. })
  62. // download the fbx file
  63. downloadBlob(fbxBlob, 'model.fbx')
  64. ```
  65. Check full example - [fbx-export](https://threepipe.org/examples/#fbx-export/).