threepipe
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

script.ts 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {
  2. _testFinish,
  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. init().finally(_testFinish)