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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {
  2. _testFinish,
  3. _testStart,
  4. downloadBlob,
  5. IObject3D,
  6. LoadingScreenPlugin,
  7. Rhino3dmLoadPlugin,
  8. ThreeViewer,
  9. } from 'threepipe'
  10. const viewer = new ThreeViewer({
  11. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  12. msaa: true,
  13. plugins: [LoadingScreenPlugin],
  14. })
  15. async function init() {
  16. viewer.addPluginSync(Rhino3dmLoadPlugin)
  17. // load a 3dm file
  18. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/3dm/Rhino_Logo.3dm', {
  19. autoCenter: true,
  20. autoScale: true,
  21. })
  22. // export to glb
  23. const blob = await viewer.export(result)
  24. // const blob = await viewer.exportScene(); // its possible to export the whole scene also
  25. if (!blob || blob.ext !== 'glb') {
  26. console.error('Unable to export scene')
  27. return
  28. }
  29. // clear scene
  30. viewer.scene.disposeSceneModels()
  31. // load environment map and glb
  32. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  33. await viewer.load({
  34. path: 'file.glb',
  35. file: blob,
  36. })
  37. // add download button
  38. const downloadButton = document.createElement('button')
  39. downloadButton.innerText = 'Download .glb'
  40. downloadButton.style.position = 'absolute'
  41. downloadButton.style.bottom = '3rem'
  42. downloadButton.style.right = '3rem'
  43. downloadButton.style.zIndex = '10000'
  44. downloadButton.onclick = () => downloadBlob(blob, 'file.glb')
  45. document.body.appendChild(downloadButton)
  46. }
  47. _testStart()
  48. init().finally(_testFinish)