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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {
  2. _testFinish,
  3. ITexture,
  4. KTXLoadPlugin,
  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: ['ktx'],
  17. },
  18. })
  19. viewer.addPluginSync(KTXLoadPlugin)
  20. viewer.scene.setBackgroundColor('#555555')
  21. const urls = []
  22. // Checking which ktx formats are supported by the browser
  23. const formats = {
  24. astc: viewer.renderManager.renderer.extensions.has('WEBGL_compressed_texture_astc'),
  25. etc1: viewer.renderManager.renderer.extensions.has('WEBGL_compressed_texture_etc1'),
  26. s3tc: viewer.renderManager.renderer.extensions.has('WEBGL_compressed_texture_s3tc'),
  27. pvrtc: viewer.renderManager.renderer.extensions.has('WEBGL_compressed_texture_pvrtc'),
  28. }
  29. if (formats.pvrtc) urls.push(
  30. 'https://threejs.org/examples/textures/compressed/disturb_PVR2bpp.ktx',
  31. 'https://threejs.org/examples/textures/compressed/lensflare_PVR4bpp.ktx'
  32. )
  33. if (formats.s3tc) urls.push(
  34. 'https://threejs.org/examples/textures/compressed/disturb_BC1.ktx',
  35. 'https://threejs.org/examples/textures/compressed/lensflare_BC3.ktx'
  36. )
  37. if (formats.etc1) urls.push(
  38. 'https://threejs.org/examples/textures/compressed/disturb_ETC1.ktx'
  39. )
  40. if (formats.astc) urls.push(
  41. 'https://threejs.org/examples/textures/compressed/disturb_ASTC4x4.ktx',
  42. 'https://threejs.org/examples/textures/compressed/lensflare_ASTC8x8.ktx'
  43. )
  44. const geometry = new PlaneGeometry(1, 1)
  45. let i = 0
  46. for (const url of urls) {
  47. // Load the url as a Texture
  48. const texture = await viewer.load<ITexture>(url)
  49. if (!texture) continue
  50. texture.colorSpace = SRGBColorSpace
  51. const material = new UnlitMaterial({
  52. map: texture,
  53. transparent: true,
  54. })
  55. const plane = new Mesh(geometry, material)
  56. plane.position.set(i % 3 - 1, -Math.floor(i / 3) + 1, 0)
  57. viewer.scene.addObject(plane)
  58. i++
  59. }
  60. // Listen to when a file is dropped
  61. viewer.assetManager.addEventListener('loadAsset', (e)=>{
  62. if (!e.data?.isTexture) return
  63. const texture = e.data as ITexture
  64. texture.colorSpace = SRGBColorSpace
  65. const material = new UnlitMaterial({
  66. map: texture,
  67. transparent: true,
  68. })
  69. const plane = new Mesh(geometry, material)
  70. plane.position.set(i % 3 - 1, -Math.floor(i / 3) + 1, 0)
  71. viewer.scene.addObject(plane)
  72. i++
  73. })
  74. }
  75. init().finally(_testFinish)