threepipe
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {_testFinish, BoxGeometry, Color, Mesh, PhysicalMaterial, PopmotionPlugin, ThreeViewer, Vector3} 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.animateTargetAsync(cube, 'position', {
  18. to: cube.position.clone().add(new Vector3(0, isMovedUp ? -1 : 1, 0)),
  19. duration: 500, // ms
  20. onComplete: () => isMovedUp = !isMovedUp,
  21. }) // setDirty is automatically called on the cube since it's the target
  22. btn.disabled = false
  23. },
  24. ['Rotate +90deg']: async(btn) => {
  25. btn.disabled = true
  26. await popmotion.animateAsync({
  27. from: cube.rotation.y,
  28. to: cube.rotation.y + Math.PI / 2,
  29. duration: 500,
  30. onUpdate: (v) => {
  31. cube.rotation.y = v
  32. cube.setDirty()
  33. },
  34. })
  35. btn.disabled = false
  36. },
  37. ['Change Color']: async(btn)=>{
  38. btn.disabled = true
  39. await popmotion.animateAsync({
  40. from: '#' + cube.material.color.getHexString(),
  41. to: '#' + new Color().setHSL(Math.random(), 1, 0.5).getHexString(),
  42. duration: 500,
  43. onUpdate: (v) => {
  44. cube.material.color.set(v)
  45. cube.material.setDirty()
  46. },
  47. })
  48. btn.disabled = false
  49. },
  50. })
  51. }
  52. init().finally(_testFinish)