UNPKG

lingo3d

Version:

Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor

92 lines 3.11 kB
import { AnimationMixer } from "three"; import { forceGetInstance, merge } from "@lincode/utils"; import { animationManagerDefaults, animationManagerSchema } from "../../../interface/IAnimationManager"; import Appendable from "../Appendable"; import { STANDARD_FRAME } from "../../../globals"; import getClipAction from "../../../memo/getClipAction"; import { configAnimationDataSystem } from "../../../systems/configSystems/configAnimationDataSystem"; import { configAnimationPlaybackSystem } from "../../../systems/configSystems/configAnimationPlaybackSystem"; const targetMixerMap = new WeakMap(); class AnimationManager extends Appendable { $loadedClip; $animationStates; static componentName = "animation"; static defaults = animationManagerDefaults; static schema = animationManagerSchema; $action; $mixer; _clip; get $clip() { return this._clip; } set $clip(val) { if (this._clip) { this.$action?.stop(); this.$mixer.uncacheClip(this._clip); } this._clip = val; if (val) this.$action = getClipAction(this.$mixer, val); configAnimationPlaybackSystem.add(this.$animationStates); this.lastFrame = val ? Math.ceil(val.duration * STANDARD_FRAME) : 0; } get paused() { return (this.$animationStates.paused || this.$animationStates.manager !== this); } set paused(val) { if (!val) this.$animationStates.manager = this; this.$animationStates.paused = val; } get loop() { return this.$animationStates.loop; } set loop(val) { this.$animationStates.loop = val; } lastFrame = 0; constructor(name, $loadedClip, target, $animationStates) { super(); this.$loadedClip = $loadedClip; this.$animationStates = $animationStates; this.$disableSerialize = true; this.name = name; configAnimationDataSystem.add(this); this.$mixer = forceGetInstance(targetMixerMap, target ?? this, AnimationMixer, [target]); } retarget(target, animationStates) { const newClip = this.$clip?.clone(); if (!newClip) return this; const targetName = target.name + "."; newClip.tracks = newClip.tracks.filter((track) => track.name.startsWith(targetName)); const animation = new AnimationManager(this.name, newClip, target, animationStates); target.append(animation); return animation; } _data; get data() { return this._data; } set data(val) { this._data = val; configAnimationDataSystem.add(this); } mergeData(data) { if (!this.data) { this.data = data; return; } merge(this.data, data); this.data = { ...this.data }; } get frame() { return Math.ceil(this.$mixer.time * STANDARD_FRAME); } set frame(val) { this.$animationStates.gotoFrame = val; } } export default AnimationManager; //# sourceMappingURL=AnimationManager.js.map