@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
3 lines (2 loc) • 3.9 kB
JavaScript
import{a as t}from"./KHR_interactivity-CKt1TdMW.esm.min.js";import{f as n,h as i,R as e}from"./declarationMapper-13w1YGqM.esm.min.js";import{R as o}from"./index-Bw2N6w1y.esm.min.js";import{AnimationGroup as r}from"./animationGroup-BCmgrfVT.esm.min.js";import"./objectModelMapping-DX92iJ8M.esm.min.js";import"./bone-BwMp7T0B.esm.min.js";class a extends t{constructor(t){super(t,["animationLoop","animationEnd","animationGroupLoop"]),this.config=t,this.speed=this.registerDataInput("speed",n),this.loop=this.registerDataInput("loop",i),this.from=this.registerDataInput("from",n,0),this.to=this.registerDataInput("to",n),this.currentFrame=this.registerDataOutput("currentFrame",n),this.currentTime=this.registerDataOutput("currentTime",n),this.currentAnimationGroup=this.registerDataOutput("currentAnimationGroup",e),this.animationGroup=this.registerDataInput("animationGroup",e,t?.animationGroup),this.animation=this.registerDataInput("animation",e),this.object=this.registerDataInput("object",e)}_preparePendingTasks(t){const n=this.animationGroup.getValue(t),i=this.animation.getValue(t);if(!n&&!i)return this._reportError(t,"No animation or animation group provided");{const e=this.currentAnimationGroup.getValue(t);e&&e!==n&&e.dispose();let o=n;if(i&&!o){const n=this.object.getValue(t);if(!n)return this._reportError(t,"No target object provided");const e=Array.isArray(i)?i:[i],a=e[0].name;o=new r("flowGraphAnimationGroup-"+a+"-"+n.name,t.configuration.scene);let s=!1;const u=t._getGlobalContextVariable("interpolationAnimations",[]);for(const t of e)o.addTargetedAnimation(t,n),-1!==u.indexOf(t.uniqueId)&&(s=!0);s&&this._checkInterpolationDuplications(t,e,n)}const a=this.speed.getValue(t)||1,s=this.from.getValue(t)??0,u=this.to.getValue(t)||o.to,p=!isFinite(u)||this.loop.getValue(t);this.currentAnimationGroup.setValue(o,t);const m=t._getGlobalContextVariable("currentlyRunningAnimationGroups",[]);-1!==m.indexOf(o.uniqueId)&&o.stop();try{o.start(p,a,s,u),o.onAnimationGroupEndObservable.add((()=>this._onAnimationGroupEnd(t))),o.onAnimationEndObservable.add((()=>this._eventsSignalOutputs.animationEnd._activateSignal(t))),o.onAnimationLoopObservable.add((()=>this._eventsSignalOutputs.animationLoop._activateSignal(t))),o.onAnimationGroupLoopObservable.add((()=>this._eventsSignalOutputs.animationGroupLoop._activateSignal(t))),m.push(o.uniqueId),t._setGlobalContextVariable("currentlyRunningAnimationGroups",m)}catch(n){this._reportError(t,n)}}}_reportError(t,n){super._reportError(t,n),this.currentFrame.setValue(-1,t),this.currentTime.setValue(-1,t)}_executeOnTick(t){const n=this.currentAnimationGroup.getValue(t);n&&(this.currentFrame.setValue(n.getCurrentFrame(),t),this.currentTime.setValue(n.animatables[0]?.elapsedTime??0,t))}_execute(t){this._startPendingTasks(t)}_onAnimationGroupEnd(t){this._removeFromCurrentlyRunning(t,this.currentAnimationGroup.getValue(t)),this._resetAfterCanceled(t),this.done._activateSignal(t)}_checkInterpolationDuplications(t,n,i){const e=t._getGlobalContextVariable("currentlyRunningAnimationGroups",[]);for(const o of e){const e=t.assetsContext.animationGroups.find((t=>t.uniqueId===o));if(e)for(const o of e.targetedAnimations)for(const r of n)o.animation.targetProperty===r.targetProperty&&o.target===i&&this._stopAnimationGroup(t,e)}}_stopAnimationGroup(t,n){n.stop(!0),n.dispose(),this._removeFromCurrentlyRunning(t,n)}_removeFromCurrentlyRunning(t,n){const i=t._getGlobalContextVariable("currentlyRunningAnimationGroups",[]),e=i.indexOf(n.uniqueId);-1!==e&&(i.splice(e,1),t._setGlobalContextVariable("currentlyRunningAnimationGroups",i))}_cancelPendingTasks(t){const n=this.currentAnimationGroup.getValue(t);n&&this._stopAnimationGroup(t,n)}getClassName(){return"FlowGraphPlayAnimationBlock"}}o("FlowGraphPlayAnimationBlock",a);export{a as FlowGraphPlayAnimationBlock};
//# sourceMappingURL=flowGraphPlayAnimationBlock-DQY9C679.esm.min.js.map