UNPKG

@shopware-ag/dive

Version:

Shopware Spatial Framework

94 lines (93 loc) 2.95 kB
var e = Object.defineProperty; var m = (o, t, a) => t in o ? e(o, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : o[t] = a; var s = (o, t, a) => m(o, typeof t != "symbol" ? t + "" : t, a); import { Easing as c } from "@tweenjs/tween.js"; import { Easing as g } from "@tweenjs/tween.js"; import { MathUtils as p } from "three/webgpu"; class l { constructor() { s(this, "uuid", p.generateUUID()); s(this, "Easing", c); s(this, "_animators", /* @__PURE__ */ new Map()); } dispose() { for (const t of this._animators.values()) t.dispose(); this._animators.clear(); } tick(t) { for (const a of this._animators.values()) a.update(t); } /** * Creates a TargetAnimator and returns it asynchronously. * * @example * // Animate a single target (e.g. position). * const animator = await animationSystem.fromTargets( * { position: { x: 0, y: 0, z: 0 }, to: { x: 10, y: 10, z: 10 } }, * 1000, * ); * // animate the target * animator.play(); * * @example * // Animate multiple targets (e.g. position and rotation) at once using an array. * const animator = await animationSystem.fromTargets( * [ * { position: { x: 0, y: 0, z: 0 }, to: { x: 10, y: 10, z: 10 } }, * { rotation: { x: 0, y: 0, z: 0 }, to: { x: 0, y: Math.PI / 2, z: 0 } }, * ], * 1000, * ); * // animate all targets in the array at once * animator.play(); * @param targets - The targets to animate. * @param duration - The duration of the animation in milliseconds. * @param options - The options for the animation. * @returns Promise<TargetAnimator>. */ async fromTargets(t, a, n) { const { TargetAnimator: i } = await import("../../chunks/TargetAnimator-DL_9b921.mjs"), r = new i(t, a, n); return this._animators.set(r.uuid, r), r; } /** * Creates a ClipAnimator and returns it asynchronously. * * @example * // Animate a single clip (e.g. a single animation) at once. * const animator = await animationSystem.fromClips( * model, * model.animations, * ); * // plays first clip by default * animator.play(); * // plays plays "Idle" clip by name * animator.play("Idle"); * * @param root - The root object to animate. * @param clips - The animation clips to animate. * @returns Promise<ClipAnimator>. */ async fromClips(t, a) { const { ClipAnimator: n } = await import("../../chunks/ClipAnimator-D8Gho4Ec.mjs"), i = new n(t, a); return this._animators.set(i.uuid, i), i; } /** * Removes an animator from the system. * * @param uuid - The UUID of the animator to remove. */ remove(t) { const a = this._animators.get(t); if (!a) { console.warn(`Animator with uuid ${t} not found`); return; } a.dispose(), this._animators.delete(t); } } export { l as AnimationSystem, g as Easing };