UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

44 lines (43 loc) 1.44 kB
"use strict"; import { AnimPropertyTarget } from "../../core/animation/PropertyTarget"; import { NodeContext } from "../poly/NodeContext"; import { ObjectNamedFunction1 } from "./_Base"; import { gsapTimeline } from "../../core/thirdParty/gsap/gsapFactory"; const EVENT_ANIMATION_STARTED = { type: "onAnimationStarted" }; const EVENT_ANIMATION_COMPLETED = { type: "onAnimationCompleted" }; export class playAnimation extends ObjectNamedFunction1 { static type() { return "playAnimation"; } func(object3D, nodePath) { return new Promise(async (resolve) => { const node = this.scene.node(nodePath); if (!node) { return; } if (node.context() != NodeContext.ANIM) { return; } const container = await node.compute(); if (!container) { return; } const timelineBuilder = container.coreContent(); if (!timelineBuilder) { return; } const timeline = gsapTimeline(); if (!timeline) { return; } const propertyTarget = new AnimPropertyTarget(this.scene, { object: { list: [object3D] } }); timelineBuilder.populate(timeline, { registerproperties: true, propertyTarget }); timeline.vars.onStart = () => { object3D.dispatchEvent(EVENT_ANIMATION_STARTED); }; timeline.vars.onComplete = () => { object3D.dispatchEvent(EVENT_ANIMATION_COMPLETED); }; }); } }