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.

TransformAnimationPlugin.md 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ---
  2. prev:
  3. text: 'CameraViewPlugin'
  4. link: './CameraViewPlugin'
  5. next:
  6. text: 'RenderTargetPreviewPlugin'
  7. link: './RenderTargetPreviewPlugin'
  8. ---
  9. # TransformAnimationPlugin
  10. [//]: # (todo: image)
  11. [Example](https://threepipe.org/examples/#transform-animation-plugin/) —
  12. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/animation/TransformAnimationPlugin.ts) —
  13. [API Reference](https://threepipe.org/docs/classes/TransformAnimationPlugin.html)
  14. TransformAnimationPlugin adds support to save and load transform(position, rotation, scale) states for objects in the scene, which can then be animated to.
  15. It uses PopmotionPlugin internally to animate any object to a saved transform object.
  16. The transformations are saved in the object userData, and can be created and interacted with from the plugin.
  17. It also provides a UI to manage the states, this UI is added to the object's uiConfig and can be accessed using the object UI or PickingPlugin. Check the example for a working demo.
  18. Sample Usage -
  19. ```javascript
  20. import {TransformAnimationPlugin, ThreeViewer, Vector3, Quaternion, EasingFunctions, timeout} from 'threepipe'
  21. const viewer = new ThreeViewer({...})
  22. const model = viewer.scene.getObjectByName('model')
  23. const transformAnim = viewer.addPluginSync(new TransformAnimationPlugin())
  24. // Save the current state of the model as a transform
  25. transformAnim.addTransform(model, 'initial')
  26. // Rotate/Move the model and save other transform states
  27. // left
  28. model.rotation.set(0, Math.PI / 2, 0)
  29. model.setDirty?.()
  30. transformAnim.addTransform(model, 'left')
  31. // top
  32. model.rotation.set(Math.PI / 2, 0, 0)
  33. model.setDirty?.()
  34. transformAnim.addTransform(model, 'top')
  35. // up
  36. model.position.set(0, 2, 0)
  37. model.lookAt(viewer.scene.mainCamera.position)
  38. model.setDirty?.()
  39. transformAnim.addTransform(model, 'up')
  40. // animate to a transform(from current position) in 1 sec
  41. const anim = transformAnim.animateTransform(model, 'left', 1000)
  42. // to stop the animation
  43. // anim.stop()
  44. // wait for the animation to finish
  45. await anim.promise
  46. // set a transform without animation
  47. transformAnim.setTransform(model, 'top')
  48. // await directly.
  49. await transformAnim.animateToTransform(model, 'up', 1000)?.promise
  50. ```