threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 1 година
преди 1 година
преди 1 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ---
  2. prev:
  3. text: 'PopmotionPlugin'
  4. link: './PopmotionPlugin'
  5. next:
  6. text: 'TransformAnimationPlugin'
  7. link: './TransformAnimationPlugin'
  8. ---
  9. # CameraViewPlugin
  10. [//]: # (todo: image)
  11. [Example](https://threepipe.org/examples/#camera-view-plugin/) —
  12. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/animation/CameraViewPlugin.ts) —
  13. [API Reference](https://threepipe.org/docs/classes/CameraViewPlugin.html)
  14. `CameraViewPlugin` adds support to save and load camera views, which can then be animated to.
  15. It uses `PopmotionPlugin` internally to animate any camera to a saved view or to loop through all the saved views.
  16. It also provides a UI to manage the views.
  17. ```typescript
  18. import {CameraViewPlugin, ThreeViewer, CameraView, Vector3, Quaternion, EasingFunctions, timeout} from 'threepipe'
  19. const viewer = new ThreeViewer({...})
  20. const cameraViewPlugin = viewer.addPluginSync(new CameraViewPlugin())
  21. const intialView = cameraViewPlugin.getView()
  22. // or = viewer.scene.mainCamera.getView()
  23. // create a new view
  24. const view = new CameraView(
  25. 'My View', // name
  26. new Vector3(0, 0, 10), // position
  27. new Vector3(0, 0, 0), // target
  28. new Quaternion(0, 0, 0, 1), // quaternion rotation
  29. 1 // zoom
  30. )
  31. // or clone a view
  32. const view2 = intialView.clone()
  33. view2.position.add(new Vector3(0, 5, 0)) // move up 5 units
  34. // animate the main camera to a view
  35. await cameraViewPlugin.animateToView(
  36. view,
  37. 2000, // in ms, = 2sec
  38. EasingFunctions.easeInOut,
  39. ).catch(()=>console.log('Animation stopped'))
  40. // stop any/all animations
  41. cameraViewPlugin.stopAllAnimations()
  42. // add views to the plugin
  43. cameraViewPlugin.addView(view)
  44. cameraViewPlugin.addView(view2)
  45. cameraViewPlugin.addView(intialView)
  46. cameraViewPlugin.addCurrentView() // adds the current view of the main camera
  47. // loop through all the views once
  48. cameraViewPlugin.animDuration = 2000 // default duration
  49. cameraViewPlugin.animEase = EasingFunctions.easeInOutSine // default easing
  50. await cameraViewPlugin.animateAllViews()
  51. // loop through all the views forever
  52. cameraViewPlugin.viewLooping = true
  53. await timeout(10000) // wait for some time
  54. // stop looping
  55. cameraViewPlugin.viewLooping = false
  56. ```