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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {_testFinish, IObject3D, PopmotionPlugin, ThreeViewer, TransformAnimationPlugin} from 'threepipe'
  2. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  3. import {createSimpleButtons} from '../examples-utils/simple-bottom-buttons.js'
  4. async function init() {
  5. const viewer = new ThreeViewer({
  6. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  7. plugins: [PopmotionPlugin],
  8. })
  9. const transformAnimPlugin = viewer.addPluginSync(TransformAnimationPlugin)
  10. console.log(transformAnimPlugin)
  11. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  12. const model = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  13. autoCenter: true,
  14. autoScale: true,
  15. })
  16. if (!model) return
  17. // Save the initial transform
  18. transformAnimPlugin.addTransform(model, 'front')
  19. // Rotate/Move the model and save other transform states
  20. // left
  21. model.rotation.set(0, Math.PI / 2, 0)
  22. model.setDirty?.()
  23. transformAnimPlugin.addTransform(model, 'left')
  24. // top
  25. model.rotation.set(Math.PI / 2, 0, 0)
  26. model.setDirty?.()
  27. transformAnimPlugin.addTransform(model, 'top')
  28. // up
  29. model.position.set(0, 2, 0)
  30. model.lookAt(viewer.scene.mainCamera.position)
  31. model.setDirty?.()
  32. transformAnimPlugin.addTransform(model, 'up')
  33. // reset
  34. transformAnimPlugin.setTransform(model, 'front')
  35. createSimpleButtons({
  36. ['Reset']: async() => transformAnimPlugin.animateTransform(model, 'front', 1000),
  37. ['Left']: async() => transformAnimPlugin.animateTransform(model, 'left', 1000),
  38. ['Top']: async() => transformAnimPlugin.animateTransform(model, 'top', 1000),
  39. ['Up']: async() => transformAnimPlugin.animateTransform(model, 'up', 1000),
  40. })
  41. const ui = viewer.addPluginSync(TweakpaneUiPlugin, true)
  42. ui.appendChild(model.uiConfig)
  43. ui.setupPluginUi(TransformAnimationPlugin, {expanded: true})
  44. }
  45. init().finally(_testFinish)