threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import {
  2. _testFinish, _testStart,
  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. _testStart()
  66. init().finally(_testFinish)