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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {
  2. _testFinish,
  3. ITexture,
  4. LoadingScreenPlugin,
  5. Mesh,
  6. PlaneGeometry,
  7. SRGBColorSpace,
  8. ThreeViewer,
  9. UnlitMaterial,
  10. } from 'threepipe'
  11. async function init() {
  12. const viewer = new ThreeViewer({
  13. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  14. msaa: true,
  15. dropzone: {
  16. allowedExtensions: ['png', 'jpg', 'jpeg', 'svg', 'webp', 'avif', 'ico'],
  17. addOptions: {
  18. disposeSceneObjects: false,
  19. autoSetEnvironment: false, // when hdr is dropped
  20. autoSetBackground: false,
  21. },
  22. },
  23. plugins: [LoadingScreenPlugin],
  24. })
  25. viewer.scene.setBackgroundColor('#555555')
  26. const urls = [
  27. 'https://cdn.jsdelivr.net/gh/repalash/three.js-modded@v0.157.1004/examples/textures/sprite0.png',
  28. 'https://cdn.jsdelivr.net/gh/repalash/three.js-modded@v0.157.1004/examples/textures/uv_grid_opengl.jpg',
  29. 'https://cdn.jsdelivr.net/gh/repalash/three.js-modded@v0.157.1004/examples/models/svg/style-css-inside-defs.svg',
  30. 'https://cdn.jsdelivr.net/gh/repalash/three.js-modded@v0.157.1004/examples/textures/tiltbrush/Light.webp',
  31. // todo: avif
  32. 'https://threepipe.org/favicon.ico',
  33. ]
  34. const geometry = new PlaneGeometry(1, 1)
  35. let i = 0
  36. for (const url of urls) {
  37. // Load the url as a Texture
  38. const texture = await viewer.load<ITexture>(url)
  39. if (!texture) continue
  40. texture.colorSpace = SRGBColorSpace
  41. const material = new UnlitMaterial({
  42. map: texture,
  43. transparent: true,
  44. })
  45. const plane = new Mesh(geometry, material)
  46. plane.position.set(i % 3 - 1, -Math.floor(i / 3) + 1, 0)
  47. viewer.scene.addObject(plane)
  48. i++
  49. }
  50. // Listen to when a file is dropped
  51. viewer.assetManager.addEventListener('loadAsset', (e)=>{
  52. if (!e.data?.isTexture) return
  53. const texture = e.data as ITexture
  54. texture.colorSpace = SRGBColorSpace
  55. const material = new UnlitMaterial({
  56. map: texture,
  57. transparent: true,
  58. })
  59. const plane = new Mesh(geometry, material)
  60. plane.position.set(i % 3 - 1, -Math.floor(i / 3) + 1, 0)
  61. viewer.scene.addObject(plane)
  62. i++
  63. })
  64. }
  65. init().finally(_testFinish)