threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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