|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import {_testFinish, IObject3D, PopmotionPlugin, ThreeViewer, TransformAnimationPlugin} from 'threepipe'
- import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
- import {createSimpleButtons} from '../examples-utils/simple-bottom-buttons.js'
-
- async function init() {
-
- const viewer = new ThreeViewer({
- canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
- plugins: [PopmotionPlugin],
- })
- const transformAnimPlugin = viewer.addPluginSync(TransformAnimationPlugin)
- console.log(transformAnimPlugin)
-
- await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
-
- const model = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
- autoCenter: true,
- autoScale: true,
- })
- if (!model) return
-
- // Save the initial transform
- transformAnimPlugin.addTransform(model, 'front')
-
- // Rotate/Move the model and save other transform states
-
- // left
- model.rotation.set(0, Math.PI / 2, 0)
- model.setDirty?.()
- transformAnimPlugin.addTransform(model, 'left')
-
- // top
- model.rotation.set(Math.PI / 2, 0, 0)
- model.setDirty?.()
- transformAnimPlugin.addTransform(model, 'top')
-
- // up
- model.position.set(0, 2, 0)
- model.lookAt(viewer.scene.mainCamera.position)
- model.setDirty?.()
- transformAnimPlugin.addTransform(model, 'up')
-
- // reset
- transformAnimPlugin.setTransform(model, 'front')
-
- createSimpleButtons({
- ['Reset']: async() => transformAnimPlugin.animateTransform(model, 'front', 1000),
- ['Left']: async() => transformAnimPlugin.animateTransform(model, 'left', 1000),
- ['Top']: async() => transformAnimPlugin.animateTransform(model, 'top', 1000),
- ['Up']: async() => transformAnimPlugin.animateTransform(model, 'up', 1000),
- })
-
- const ui = viewer.addPluginSync(TweakpaneUiPlugin, true)
- ui.appendChild(model.uiConfig)
-
- ui.setupPluginUi(TransformAnimationPlugin, {expanded: true})
-
- }
-
- init().finally(_testFinish)
|