threepipe
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {
  2. _testFinish, _testStart,
  3. BoxGeometry,
  4. FrameFadePlugin,
  5. LoadingScreenPlugin,
  6. Mesh,
  7. PhysicalMaterial,
  8. ThreeViewer,
  9. } from 'threepipe'
  10. import {createSimpleButtons} from '../examples-utils/simple-bottom-buttons.js'
  11. async function init() {
  12. const viewer = new ThreeViewer({
  13. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  14. renderScale: 'auto',
  15. plugins: [LoadingScreenPlugin],
  16. })
  17. viewer.addPluginSync(FrameFadePlugin)
  18. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  19. const cube = viewer.scene.addObject(new Mesh(
  20. new BoxGeometry(1, 1, 1),
  21. new PhysicalMaterial({color: 0xff0000})
  22. ))
  23. createSimpleButtons({
  24. ['Change Color']: ()=>{
  25. cube.material.color.setHSL(Math.random(), 1, 0.5)
  26. cube.material.setDirty() // this will trigger frame fade
  27. },
  28. ['Change Size']: ()=>{
  29. cube.scale.setScalar(Math.random() * 1.5 + 0.5)
  30. cube.setDirty({fadeDuration: 1000}) // duration can be controlled by an option like this.
  31. },
  32. ['Change Color (no fade)']: ()=>{
  33. cube.material.color.setHSL(Math.random(), 1, 0.5)
  34. cube.material.setDirty({frameFade: false}) // disable frame fade for this update but re-render the scene.
  35. },
  36. })
  37. }
  38. _testStart()
  39. init().finally(_testFinish)