threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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