Skip to main content

Popmotion animation/tween

Popmotion is integrated within WebGi and is used by various plugins for scheduling animations.

PopmotionPlugin provides some helpers and state management for playing animations through popmotion First, add the plugin to the viewer:

import {EasingFunctions, PopmotionPlugin, timeout} from 'webgi'
const popmotion = await viewer.addPlugin(PopmotionPlugin)

Start an animation:

const anim = popmotion.animate({
from: 0,
to: 1,
duration: 3000,
repeat: 3,
repeatType: "mirror",
ease: EasingFunctions.linear,
onUpdate: (v)=>{
// Update object position
obj.modelObject.position.x = v;
// or
// obj.modelObject.userData.setDirty();

}) // Returned animation is started.

// Wait for the animation to finish
await anim.promise

Check Popmotion docs for information and options:

To stop an animation in between:


PopmotionPlugin attaches a default driver to all the animations (if not provided). This default driver sync the animation with the render loop, recording and other plugins.

Check the full example on codepen with PopmotionPlugin used to animate a sphere: