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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {
  2. _testFinish,
  3. ITexture,
  4. KTX2LoadPlugin,
  5. LoadingScreenPlugin,
  6. Mesh,
  7. PlaneGeometry,
  8. SRGBColorSpace,
  9. ThreeViewer,
  10. UnlitMaterial,
  11. BufferGeometry, _testStart,
  12. } from 'threepipe'
  13. async function init() {
  14. const viewer = new ThreeViewer({
  15. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  16. msaa: true,
  17. dropzone: {
  18. allowedExtensions: ['ktx2'],
  19. },
  20. plugins: [KTX2LoadPlugin, LoadingScreenPlugin],
  21. })
  22. viewer.scene.setBackgroundColor('#555555')
  23. const urls = [
  24. 'https://cdn.jsdelivr.net/gh/repalash/three.js-modded@v0.153.1001/examples/textures/compressed/sample_etc1s.ktx2',
  25. 'https://cdn.jsdelivr.net/gh/repalash/three.js-modded@v0.153.1001/examples/textures/compressed/sample_uastc.ktx2',
  26. 'https://cdn.jsdelivr.net/gh/repalash/three.js-modded@v0.153.1001/examples/textures/compressed/sample_uastc_zstd.ktx2',
  27. ]
  28. // PlaneGeometry UVs assume flipY=true, which compressed textures don't support.
  29. const geometry = flipY(new PlaneGeometry(1, 1))
  30. let i = 0
  31. for (const url of urls) {
  32. // Load the url as a Texture
  33. const texture = await viewer.load<ITexture>(url)
  34. if (!texture) continue
  35. texture.colorSpace = SRGBColorSpace
  36. const material = new UnlitMaterial({
  37. map: texture,
  38. transparent: true,
  39. })
  40. const plane = new Mesh(geometry, material)
  41. plane.position.set(i % 3 - 1, -Math.floor(i / 3) + 1, 0)
  42. viewer.scene.addObject(plane)
  43. i++
  44. }
  45. // Listen to when a file is dropped
  46. viewer.assetManager.addEventListener('loadAsset', (e)=>{
  47. if (!e.data?.isTexture) return
  48. const texture = e.data as ITexture
  49. texture.colorSpace = SRGBColorSpace
  50. const material = new UnlitMaterial({
  51. map: texture,
  52. transparent: true,
  53. })
  54. const plane = new Mesh(geometry, material)
  55. plane.position.set(i % 3 - 1, -Math.floor(i / 3) + 1, 0)
  56. viewer.scene.addObject(plane)
  57. i++
  58. })
  59. }
  60. _testStart()
  61. init().finally(_testFinish)
  62. /** Correct UVs to be compatible with `flipY=false` textures. */
  63. function flipY(geometry: BufferGeometry) {
  64. const uv = geometry.attributes.uv
  65. for (let i = 0; i < uv.count; i++) {
  66. uv.setY(i, 1 - uv.getY(i))
  67. }
  68. return geometry
  69. }