UNPKG

lingo3d

Version:

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

90 lines 3.1 kB
import MeshAppendable from "../MeshAppendable"; import AnimationManager from "./AnimationManager"; import { STANDARD_FRAME } from "../../../globals"; import AnimationStates from "./AnimationStates"; const animationValueToData = (val, uuid) => { const entries = Object.entries(val); let maxLength = 0; for (const [, { length }] of entries) length > maxLength && (maxLength = length); const duration = 1000; const timeStep = (duration * 0.001) / maxLength; const data = {}; const result = (data[uuid] ??= {}); for (const [name, values] of entries) result[name] = Object.fromEntries(values.map((v, i) => [Math.ceil(i * timeStep * STANDARD_FRAME), v])); return data; }; const getAnimation = (self, name) => { let animation = self.animations[name]; if (animation && typeof animation !== "string") return animation; self.append((animation = self.animations[name] = new AnimationManager(name, undefined, self, self.$animationStates))); return animation; }; const setAnimation = (self, val) => { if (typeof val === "string" || typeof val === "number" || val === true) { const animationManager = (self.$animationStates.manager = typeof val === "string" ? self.animations[val] : Object.values(self.animations)[val === true ? 0 : val]); self.$mixer = animationManager?.$mixer; return; } if (!val) { self.$animationStates.manager = undefined; self.$mixer = undefined; self.animationPaused = true; return; } const animationManager = getAnimation(self, "animation"); animationManager.data = animationValueToData(val, self.uuid); self.$animationStates.manager = animationManager; self.$mixer = animationManager.$mixer; }; export default class AnimatedObjectManager extends MeshAppendable { _animationStates; get $animationStates() { return (this._animationStates ??= new AnimationStates()); } get animations() { return this.$animationStates.managerRecord; } set animations(val) { this.$animationStates.managerRecord = val; } get animationPaused() { return this.$animationStates.paused; } set animationPaused(value) { this.$animationStates.paused = value; } get animationLoop() { return this.$animationStates.loop; } set animationLoop(value) { this.$animationStates.loop = value; } get serializeAnimation() { return typeof this.animation !== "object" ? this.animation : undefined; } $mixer; _animation; get animation() { return this._animation; } set animation(val) { this._animation = val; setAnimation(this, val); this.animationPaused = this.animationPaused; } get animationFrame() { const time = this.$mixer?.time ?? 0; return Math.ceil(time * STANDARD_FRAME); } set animationFrame(val) { this.$animationStates.gotoFrame = val; } } //# sourceMappingURL=index.js.map