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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {_testFinish, BoxGeometry, Color, Mesh, PhysicalMaterial, PopmotionPlugin, ThreeViewer} from 'threepipe'
  2. import {createSimpleButtons} from '../examples-utils/simple-bottom-buttons.js'
  3. async function init() {
  4. const viewer = new ThreeViewer({
  5. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  6. })
  7. const popmotion = viewer.addPluginSync(PopmotionPlugin)
  8. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  9. const cube = viewer.scene.addObject(new Mesh(
  10. new BoxGeometry(1, 1, 1),
  11. new PhysicalMaterial({color: 0xff0000})
  12. ))
  13. let isMovedUp = false
  14. createSimpleButtons({
  15. ['Move Up/Down']: async(btn) => {
  16. btn.disabled = true
  17. await popmotion.animateAsync({
  18. from: cube.position.y,
  19. to: cube.position.y + (isMovedUp ? -1 : 1),
  20. duration: 500, // ms
  21. onUpdate: (v) => {
  22. cube.position.setY(v)
  23. cube.setDirty()
  24. },
  25. onComplete: () => isMovedUp = !isMovedUp,
  26. })
  27. btn.disabled = false
  28. },
  29. ['Rotate +90deg']: async(btn) => {
  30. btn.disabled = true
  31. await popmotion.animateAsync({
  32. from: cube.rotation.y,
  33. to: cube.rotation.y + Math.PI / 2,
  34. duration: 500,
  35. onUpdate: (v) => {
  36. cube.rotation.y = v
  37. cube.setDirty()
  38. },
  39. })
  40. btn.disabled = false
  41. },
  42. ['Change Color']: async(btn)=>{
  43. btn.disabled = true
  44. await popmotion.animateAsync({
  45. from: '#' + cube.material.color.getHexString(),
  46. to: '#' + new Color().setHSL(Math.random(), 1, 0.5).getHexString(),
  47. duration: 500,
  48. onUpdate: (v) => {
  49. cube.material.color.set(v)
  50. cube.material.setDirty()
  51. },
  52. })
  53. btn.disabled = false
  54. },
  55. })
  56. }
  57. init().then(_testFinish)