threepipe
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

PopmotionPlugin.md 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ---
  2. prev:
  3. text: 'GLTFAnimationPlugin'
  4. link: './GLTFAnimationPlugin'
  5. next:
  6. text: 'CameraViewPlugin'
  7. link: './CameraViewPlugin'
  8. ---
  9. # PopmotionPlugin
  10. [//]: # (todo: image)
  11. [Example](https://threepipe.org/examples/#popmotion-plugin/) —
  12. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/animation/PopmotionPlugin.ts) —
  13. [API Reference](https://threepipe.org/docs/classes/PopmotionPlugin.html)
  14. Provides animation/tweening capabilities to the viewer using the [popmotion.io](https://popmotion.io/) library.
  15. Overrides the driver in popmotion to sync with the viewer and provide ways to store and stop animations.
  16. ```typescript
  17. import {PopmotionPlugin, ThreeViewer} from 'threepipe'
  18. const viewer = new ThreeViewer({...})
  19. const cube = viewer.scene.getObjectByName('cube');
  20. const popmotion = viewer.addPluginSync(new PopmotionPlugin())
  21. // Move the object cube 1 unit up.
  22. const anim = popmotion.animateTarget(cube, 'position', {
  23. to: cube.position.clone().add(new Vector3(0,1,0)),
  24. duration: 500, // ms
  25. onComplete: () => isMovedUp = true,
  26. onStop: () => throw(new Error('Animation stopped')),
  27. })
  28. // Alternatively, set the property directly in onUpdate.
  29. const anim1 = popmotion.animate({
  30. from: cube.position.y,
  31. to: cube.position.y + 1,
  32. duration: 500, // ms
  33. onUpdate: (v) => {
  34. cube.position.setY(v)
  35. cube.setDirty()
  36. },
  37. onComplete: () => isMovedUp = true,
  38. onStop: () => throw(new Error('Animation stopped')),
  39. onEnd: () => console.log('Animation ended'), // This runs after both onComplete and onStop
  40. })
  41. // await for animation. This promise will reject only if an exception is thrown in onStop or onComplete. onStop rejects if throwOnStop is true
  42. await anim.promise.catch((e)=>{
  43. console.log(e, 'animation stopped before completion')
  44. });
  45. // or stop the animation
  46. // anim.stop()
  47. // Animate the color
  48. await popmotion.animateAsync({ // Also await for the animation.
  49. from: '#' + cube.material.color.getHexString(),
  50. to: '#' + new Color().setHSL(Math.random(), 1, 0.5).getHexString(),
  51. duration: 1000, // 1s
  52. onUpdate: (v) => {
  53. cube.material.color.set(v)
  54. cube.material.setDirty()
  55. },
  56. })
  57. ```
  58. Note: The animation is started when the animate or animateAsync function is called.