threepipe
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

script.ts 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import {_testFinish, GLTFAnimationPlugin, HemisphereLight, ImportAddOptions, IObject3D, ThreeViewer} from 'threepipe'
  2. import {
  3. AMFLoadPlugin,
  4. BVHLoadPlugin,
  5. ColladaLoadPlugin,
  6. GCodeLoadPlugin,
  7. LDrawLoadPlugin,
  8. MDDLoadPlugin,
  9. PCDLoadPlugin,
  10. TDSLoadPlugin,
  11. ThreeMFLoadPlugin,
  12. TiltLoadPlugin,
  13. VOXLoadPlugin,
  14. VRMLLoadPlugin,
  15. VTKLoadPlugin,
  16. XYZLoadPlugin,
  17. } from '@threepipe/plugin-extra-importers'
  18. async function init() {
  19. const viewer = new ThreeViewer({
  20. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  21. msaa: true,
  22. dropzone: {
  23. addOptions: {
  24. disposeSceneObjects: true,
  25. },
  26. },
  27. })
  28. viewer.addPluginsSync([
  29. GLTFAnimationPlugin,
  30. TDSLoadPlugin,
  31. ThreeMFLoadPlugin,
  32. ColladaLoadPlugin,
  33. AMFLoadPlugin,
  34. GCodeLoadPlugin,
  35. BVHLoadPlugin,
  36. VOXLoadPlugin,
  37. MDDLoadPlugin,
  38. PCDLoadPlugin,
  39. TiltLoadPlugin,
  40. VRMLLoadPlugin,
  41. LDrawLoadPlugin,
  42. VTKLoadPlugin,
  43. XYZLoadPlugin,
  44. ])
  45. viewer.getPlugin(GLTFAnimationPlugin)!.autoplayOnLoad = true
  46. viewer.scene.mainCamera.autoNearFar = false
  47. viewer.scene.setBackgroundColor('#555555')
  48. viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 2))
  49. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  50. const urls = [
  51. 'https://threejs.org/examples/models/3ds/portalgun/portalgun.3ds',
  52. 'https://threejs.org/examples/models/3mf/cube_gears.3mf',
  53. 'https://threejs.org/examples/models/collada/elf/elf.dae',
  54. 'https://threejs.org/examples/models/amf/rook.amf',
  55. 'https://threejs.org/examples/models/gcode/benchy.gcode',
  56. 'https://threejs.org/examples/models/bvh/pirouette.bvh',
  57. 'https://threejs.org/examples/models/vox/monu10.vox',
  58. 'https://threejs.org/examples/models/mdd/cube.mdd',
  59. 'https://threejs.org/examples/models/pcd/binary/Zaghetto.pcd',
  60. 'https://threejs.org/examples/models/tilt/BRUSH_DOME.tilt',
  61. 'https://threejs.org/examples/models/ldraw/officialLibrary/models/car.ldr_Packed.mpd',
  62. 'https://threejs.org/examples/models/vtk/bunny.vtk',
  63. 'https://threejs.org/examples/models/vtk/cube_binary.vtp',
  64. 'https://threejs.org/examples/models/xyz/helix_201.xyz',
  65. ]
  66. const options: ImportAddOptions = {
  67. autoScale: true,
  68. autoCenter: true,
  69. autoScaleRadius: 0.5,
  70. clearSceneObjects: false,
  71. }
  72. let i = 0
  73. const models = await Promise.allSettled(urls.map(async url =>
  74. viewer.load<IObject3D>(url, options).then(res => {
  75. if (!res) return
  76. res.position.set(i % 4 - 1.5, 0, Math.floor(i / 4) - 1.5).multiplyScalar(1)
  77. res.setDirty()
  78. i++
  79. return res
  80. })))
  81. console.log(models)
  82. }
  83. init().finally(_testFinish)