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.

script.ts 3.9KB

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