threepipe
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {
  2. _testFinish,
  3. _testStart,
  4. downloadBlob, HemisphereLight,
  5. IObject3D,
  6. LoadingScreenPlugin,
  7. ThreeViewer,
  8. } from 'threepipe'
  9. import {AssimpJsPlugin} from '@threepipe/plugin-assimpjs'
  10. const viewer = new ThreeViewer({
  11. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  12. msaa: true,
  13. plugins: [LoadingScreenPlugin],
  14. })
  15. async function init() {
  16. const assimp = viewer.addPluginSync(AssimpJsPlugin)
  17. await assimp.init()
  18. console.log('AssimpJsPlugin initialized:', assimp.ajs)
  19. // Direct way to convert without using the viewer
  20. const files = [
  21. 'https://threejs.org/examples/models/obj/male02/male02.obj',
  22. 'https://threejs.org/examples/models/obj/male02/male02.mtl', // mtl doesnt work?
  23. ]
  24. const fe = files.map(async f=>fetch(`${f}`).then(async t=>t.arrayBuffer()))
  25. const responses = await Promise.all(fe)
  26. const fileList: Record<string, ArrayBuffer> = {}
  27. for (let i = 0; i < files.length; i++) {
  28. fileList[files[i]] = responses[i]
  29. }
  30. const fbx = assimp.convertFiles(fileList, 'fbx')
  31. if (!fbx) {
  32. console.error('Failed to convert files to fbx')
  33. return
  34. }
  35. // load the fbx file
  36. await viewer.load<IObject3D>({path: 'file.fbx', file: fbx}, {
  37. autoCenter: true,
  38. autoScale: true,
  39. })
  40. viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 2))
  41. // add download button
  42. const downloadButton = document.createElement('button')
  43. downloadButton.innerText = 'Download .fbx'
  44. downloadButton.style.position = 'absolute'
  45. downloadButton.style.bottom = '3rem'
  46. downloadButton.style.right = '3rem'
  47. downloadButton.style.zIndex = '10000'
  48. downloadButton.onclick = () => downloadBlob(fbx, 'file.fbx')
  49. document.body.appendChild(downloadButton)
  50. }
  51. _testStart()
  52. init().finally(_testFinish)