Initial commit xmarticaims
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var registry = require('./registry.cjs');
|
||||
|
||||
|
||||
|
||||
exports.registerAdapter = registry.registerAdapter;
|
||||
@@ -0,0 +1 @@
|
||||
export { registerAdapter } from "./registry.js";
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
export { registerAdapter } from './registry.js';
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Anime.js adapter API. Each library or class group that wants to extend `animate()` and `utils.set()` calls `registerAdapter()` to create its own `Adapter`. The returned `Adapter` exposes `registerTargetAdapter(detect)` for per-class detection and `registerPropertyResolver(fn)` for global Color / Vector / pattern-based fallbacks.
|
||||
*
|
||||
* import { registerAdapter } from 'animejs/adapters';
|
||||
*
|
||||
* const myAdapter = registerAdapter();
|
||||
* const widget = myAdapter.registerTargetAdapter((t) => t instanceof MyWidget);
|
||||
* widget.registerProperty('value',
|
||||
* (t) => t.getValue(),
|
||||
* (target, value) => target.setValue(value),
|
||||
* );
|
||||
*
|
||||
* For scalar tweens, `value` is the interpolated number. For color and complex tweens it is `undefined`; read `tween._numbers` instead. `gate(target)` scopes the prop to a subset of matching targets.
|
||||
*
|
||||
* Resolution order: every Adapter's target adapters in registration order (first match wins) then every Adapter's property resolvers (first non-null wins) then engine direct property path.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef TargetAdapterEntry
|
||||
* @property {(t: any) => any} get
|
||||
* @property {(target: any, value: number, tween: any) => void} set
|
||||
* @property {(t: any) => boolean} [gate]
|
||||
*/
|
||||
|
||||
const alwaysTrue = () => true;
|
||||
|
||||
class TargetAdapter {
|
||||
/**
|
||||
* @param {(t: any) => boolean} detect
|
||||
*/
|
||||
constructor(detect) {
|
||||
this.detect = detect;
|
||||
/** @type {Record<string, TargetAdapterEntry>} */
|
||||
this.props = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a property the adapter handles. `setter` receives `(target, value, tween)`. For color and complex tweens `value` is `undefined`, read `tween._numbers` instead. `gate(target)` scopes the prop to a subset of matching targets.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {(t: any) => any} getter
|
||||
* @param {(target: any, value: number, tween: any) => void} setter
|
||||
* @param {(t: any) => boolean} [gate]
|
||||
*/
|
||||
registerProperty(name, getter, setter, gate) {
|
||||
this.props[name] = {
|
||||
get: getter,
|
||||
set: setter,
|
||||
gate: gate || alwaysTrue,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class Adapter {
|
||||
/**
|
||||
* @param {((t: any) => boolean) | null} [detect]
|
||||
* Optional gate. When provided, every lookup against this Adapter's target adapters and resolvers is skipped if `detect(target)` returns falsy. Lets the Adapter as a whole short-circuit on unrelated targets.
|
||||
*/
|
||||
constructor(detect) {
|
||||
/** @type {((t: any) => boolean) | null} */
|
||||
this.detect = detect || null;
|
||||
/** @type {TargetAdapter[]} */
|
||||
this.targetAdapters = [];
|
||||
/** @type {((target: any, name: string) => TargetAdapterEntry | null)[]} */
|
||||
this.propertyResolvers = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and registers a `TargetAdapter` scoped to this Adapter.
|
||||
*
|
||||
* @param {(t: any) => boolean} detect
|
||||
* @return {TargetAdapter}
|
||||
*/
|
||||
registerTargetAdapter(detect) {
|
||||
const ta = new TargetAdapter(detect);
|
||||
this.targetAdapters.push(ta);
|
||||
return ta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a property resolver scoped to this Adapter. Resolvers are functions invoked at tween creation when no target adapter has claimed the name; the function returns an entry for names it handles or `null` to defer. Use for runtime-matched patterns (Color / Vector axis detection, name-prefix conventions, etc.).
|
||||
*
|
||||
* @param {(target: any, name: string) => TargetAdapterEntry | null} resolver
|
||||
*/
|
||||
registerPropertyResolver(resolver) {
|
||||
if (this.propertyResolvers.indexOf(resolver) === -1) this.propertyResolvers.push(resolver);
|
||||
}
|
||||
}
|
||||
|
||||
const adapters = /** @type {Adapter[]} */([]);
|
||||
|
||||
/**
|
||||
* Creates and registers an Adapter. Each library extending `animate()` calls this once and uses the returned Adapter to wire up its target adapters and property resolvers. The optional `detect` short-circuits all lookups against the Adapter when the target is unrelated.
|
||||
*
|
||||
* @param {(t: any) => boolean} [detect]
|
||||
* @return {Adapter}
|
||||
*/
|
||||
function registerAdapter(detect) {
|
||||
const a = new Adapter(detect);
|
||||
adapters.push(a);
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal resolution. Tries every Adapter's target adapters first (in registration order, first match wins), then every Adapter's property resolvers.
|
||||
*
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @return {TargetAdapterEntry | null}
|
||||
*/
|
||||
function resolveAdapterEntry(target, name) {
|
||||
if (!target) return null;
|
||||
const al = adapters.length;
|
||||
outer: for (let i = 0; i < al; i++) {
|
||||
const a = adapters[i];
|
||||
if (a.detect && !a.detect(target)) continue;
|
||||
const tas = a.targetAdapters;
|
||||
for (let j = 0, m = tas.length; j < m; j++) {
|
||||
const ta = tas[j];
|
||||
if (ta.detect(target)) {
|
||||
const entry = ta.props[name];
|
||||
if (entry && (!entry.gate || entry.gate(target))) return entry;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < al; i++) {
|
||||
const a = adapters[i];
|
||||
if (a.detect && !a.detect(target)) continue;
|
||||
const rs = a.propertyResolvers;
|
||||
for (let j = 0, m = rs.length; j < m; j++) {
|
||||
const entry = rs[j](target, name);
|
||||
if (entry) return entry;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
exports.registerAdapter = registerAdapter;
|
||||
exports.resolveAdapterEntry = resolveAdapterEntry;
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Creates and registers an Adapter. Each library extending `animate()` calls this once and uses the returned Adapter to wire up its target adapters and property resolvers. The optional `detect` short-circuits all lookups against the Adapter when the target is unrelated.
|
||||
*
|
||||
* @param {(t: any) => boolean} [detect]
|
||||
* @return {Adapter}
|
||||
*/
|
||||
export function registerAdapter(detect?: (t: any) => boolean): Adapter;
|
||||
/**
|
||||
* Internal resolution. Tries every Adapter's target adapters first (in registration order, first match wins), then every Adapter's property resolvers.
|
||||
*
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @return {TargetAdapterEntry | null}
|
||||
*/
|
||||
export function resolveAdapterEntry(target: any, name: string): TargetAdapterEntry | null;
|
||||
export type TargetAdapterEntry = {
|
||||
get: (t: any) => any;
|
||||
set: (target: any, value: number, tween: any) => void;
|
||||
gate?: (t: any) => boolean;
|
||||
};
|
||||
declare class Adapter {
|
||||
/**
|
||||
* @param {((t: any) => boolean) | null} [detect]
|
||||
* Optional gate. When provided, every lookup against this Adapter's target adapters and resolvers is skipped if `detect(target)` returns falsy. Lets the Adapter as a whole short-circuit on unrelated targets.
|
||||
*/
|
||||
constructor(detect?: ((t: any) => boolean) | null);
|
||||
/** @type {((t: any) => boolean) | null} */
|
||||
detect: ((t: any) => boolean) | null;
|
||||
/** @type {TargetAdapter[]} */
|
||||
targetAdapters: TargetAdapter[];
|
||||
/** @type {((target: any, name: string) => TargetAdapterEntry | null)[]} */
|
||||
propertyResolvers: ((target: any, name: string) => TargetAdapterEntry | null)[];
|
||||
/**
|
||||
* Creates and registers a `TargetAdapter` scoped to this Adapter.
|
||||
*
|
||||
* @param {(t: any) => boolean} detect
|
||||
* @return {TargetAdapter}
|
||||
*/
|
||||
registerTargetAdapter(detect: (t: any) => boolean): TargetAdapter;
|
||||
/**
|
||||
* Registers a property resolver scoped to this Adapter. Resolvers are functions invoked at tween creation when no target adapter has claimed the name; the function returns an entry for names it handles or `null` to defer. Use for runtime-matched patterns (Color / Vector axis detection, name-prefix conventions, etc.).
|
||||
*
|
||||
* @param {(target: any, name: string) => TargetAdapterEntry | null} resolver
|
||||
*/
|
||||
registerPropertyResolver(resolver: (target: any, name: string) => TargetAdapterEntry | null): void;
|
||||
}
|
||||
declare class TargetAdapter {
|
||||
/**
|
||||
* @param {(t: any) => boolean} detect
|
||||
*/
|
||||
constructor(detect: (t: any) => boolean);
|
||||
detect: (t: any) => boolean;
|
||||
/** @type {Record<string, TargetAdapterEntry>} */
|
||||
props: Record<string, TargetAdapterEntry>;
|
||||
/**
|
||||
* Registers a property the adapter handles. `setter` receives `(target, value, tween)`. For color and complex tweens `value` is `undefined`, read `tween._numbers` instead. `gate(target)` scopes the prop to a subset of matching targets.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {(t: any) => any} getter
|
||||
* @param {(target: any, value: number, tween: any) => void} setter
|
||||
* @param {(t: any) => boolean} [gate]
|
||||
*/
|
||||
registerProperty(name: string, getter: (t: any) => any, setter: (target: any, value: number, tween: any) => void, gate?: (t: any) => boolean): void;
|
||||
}
|
||||
export {};
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Anime.js adapter API. Each library or class group that wants to extend `animate()` and `utils.set()` calls `registerAdapter()` to create its own `Adapter`. The returned `Adapter` exposes `registerTargetAdapter(detect)` for per-class detection and `registerPropertyResolver(fn)` for global Color / Vector / pattern-based fallbacks.
|
||||
*
|
||||
* import { registerAdapter } from 'animejs/adapters';
|
||||
*
|
||||
* const myAdapter = registerAdapter();
|
||||
* const widget = myAdapter.registerTargetAdapter((t) => t instanceof MyWidget);
|
||||
* widget.registerProperty('value',
|
||||
* (t) => t.getValue(),
|
||||
* (target, value) => target.setValue(value),
|
||||
* );
|
||||
*
|
||||
* For scalar tweens, `value` is the interpolated number. For color and complex tweens it is `undefined`; read `tween._numbers` instead. `gate(target)` scopes the prop to a subset of matching targets.
|
||||
*
|
||||
* Resolution order: every Adapter's target adapters in registration order (first match wins) then every Adapter's property resolvers (first non-null wins) then engine direct property path.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef TargetAdapterEntry
|
||||
* @property {(t: any) => any} get
|
||||
* @property {(target: any, value: number, tween: any) => void} set
|
||||
* @property {(t: any) => boolean} [gate]
|
||||
*/
|
||||
|
||||
const alwaysTrue = () => true;
|
||||
|
||||
class TargetAdapter {
|
||||
/**
|
||||
* @param {(t: any) => boolean} detect
|
||||
*/
|
||||
constructor(detect) {
|
||||
this.detect = detect;
|
||||
/** @type {Record<string, TargetAdapterEntry>} */
|
||||
this.props = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a property the adapter handles. `setter` receives `(target, value, tween)`. For color and complex tweens `value` is `undefined`, read `tween._numbers` instead. `gate(target)` scopes the prop to a subset of matching targets.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {(t: any) => any} getter
|
||||
* @param {(target: any, value: number, tween: any) => void} setter
|
||||
* @param {(t: any) => boolean} [gate]
|
||||
*/
|
||||
registerProperty(name, getter, setter, gate) {
|
||||
this.props[name] = {
|
||||
get: getter,
|
||||
set: setter,
|
||||
gate: gate || alwaysTrue,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class Adapter {
|
||||
/**
|
||||
* @param {((t: any) => boolean) | null} [detect]
|
||||
* Optional gate. When provided, every lookup against this Adapter's target adapters and resolvers is skipped if `detect(target)` returns falsy. Lets the Adapter as a whole short-circuit on unrelated targets.
|
||||
*/
|
||||
constructor(detect) {
|
||||
/** @type {((t: any) => boolean) | null} */
|
||||
this.detect = detect || null;
|
||||
/** @type {TargetAdapter[]} */
|
||||
this.targetAdapters = [];
|
||||
/** @type {((target: any, name: string) => TargetAdapterEntry | null)[]} */
|
||||
this.propertyResolvers = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and registers a `TargetAdapter` scoped to this Adapter.
|
||||
*
|
||||
* @param {(t: any) => boolean} detect
|
||||
* @return {TargetAdapter}
|
||||
*/
|
||||
registerTargetAdapter(detect) {
|
||||
const ta = new TargetAdapter(detect);
|
||||
this.targetAdapters.push(ta);
|
||||
return ta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a property resolver scoped to this Adapter. Resolvers are functions invoked at tween creation when no target adapter has claimed the name; the function returns an entry for names it handles or `null` to defer. Use for runtime-matched patterns (Color / Vector axis detection, name-prefix conventions, etc.).
|
||||
*
|
||||
* @param {(target: any, name: string) => TargetAdapterEntry | null} resolver
|
||||
*/
|
||||
registerPropertyResolver(resolver) {
|
||||
if (this.propertyResolvers.indexOf(resolver) === -1) this.propertyResolvers.push(resolver);
|
||||
}
|
||||
}
|
||||
|
||||
const adapters = /** @type {Adapter[]} */([]);
|
||||
|
||||
/**
|
||||
* Creates and registers an Adapter. Each library extending `animate()` calls this once and uses the returned Adapter to wire up its target adapters and property resolvers. The optional `detect` short-circuits all lookups against the Adapter when the target is unrelated.
|
||||
*
|
||||
* @param {(t: any) => boolean} [detect]
|
||||
* @return {Adapter}
|
||||
*/
|
||||
function registerAdapter(detect) {
|
||||
const a = new Adapter(detect);
|
||||
adapters.push(a);
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal resolution. Tries every Adapter's target adapters first (in registration order, first match wins), then every Adapter's property resolvers.
|
||||
*
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @return {TargetAdapterEntry | null}
|
||||
*/
|
||||
function resolveAdapterEntry(target, name) {
|
||||
if (!target) return null;
|
||||
const al = adapters.length;
|
||||
outer: for (let i = 0; i < al; i++) {
|
||||
const a = adapters[i];
|
||||
if (a.detect && !a.detect(target)) continue;
|
||||
const tas = a.targetAdapters;
|
||||
for (let j = 0, m = tas.length; j < m; j++) {
|
||||
const ta = tas[j];
|
||||
if (ta.detect(target)) {
|
||||
const entry = ta.props[name];
|
||||
if (entry && (!entry.gate || entry.gate(target))) return entry;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < al; i++) {
|
||||
const a = adapters[i];
|
||||
if (a.detect && !a.detect(target)) continue;
|
||||
const rs = a.propertyResolvers;
|
||||
for (let j = 0, m = rs.length; j < m; j++) {
|
||||
const entry = rs[j](target, name);
|
||||
if (entry) return entry;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export { registerAdapter, resolveAdapterEntry };
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var registry = require('../registry.cjs');
|
||||
|
||||
// Duck-typed gate for three.js targets, used as threeAdapter's Adapter-level detect.
|
||||
// Early-rejects DOM nodes via nodeType so the OR chain only runs on non-DOM objects.
|
||||
// Includes the isAnimejsInstanceProxy marker set in instance.js for per-instance wrappers.
|
||||
const isThreeTarget = (t) => !!(
|
||||
t && !t.nodeType && (
|
||||
t.isObject3D || t.isMaterial || t.isTexture ||
|
||||
t.isFog || t.isFogExp2 || t.isUniformNode ||
|
||||
t.isColor || t.isVector2 || t.isVector3 || t.isVector4 ||
|
||||
t.isAnimejsInstanceProxy
|
||||
)
|
||||
);
|
||||
|
||||
const threeAdapter = registry.registerAdapter(isThreeTarget);
|
||||
|
||||
exports.threeAdapter = threeAdapter;
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
export const threeAdapter: {
|
||||
detect: (t: any) => boolean;
|
||||
targetAdapters: {
|
||||
detect: (t: any) => boolean;
|
||||
props: Record<string, import("../registry.js").TargetAdapterEntry>;
|
||||
registerProperty(name: string, getter: (t: any) => any, setter: (target: any, value: number, tween: any) => void, gate?: (t: any) => boolean): void;
|
||||
}[];
|
||||
propertyResolvers: ((target: any, name: string) => import("../registry.js").TargetAdapterEntry | null)[];
|
||||
registerTargetAdapter(detect: (t: any) => boolean): {
|
||||
detect: (t: any) => boolean;
|
||||
props: Record<string, import("../registry.js").TargetAdapterEntry>;
|
||||
registerProperty(name: string, getter: (t: any) => any, setter: (target: any, value: number, tween: any) => void, gate?: (t: any) => boolean): void;
|
||||
};
|
||||
registerPropertyResolver(resolver: (target: any, name: string) => TargetAdapterEntry | null): void;
|
||||
};
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { registerAdapter } from '../registry.js';
|
||||
|
||||
// Duck-typed gate for three.js targets, used as threeAdapter's Adapter-level detect.
|
||||
// Early-rejects DOM nodes via nodeType so the OR chain only runs on non-DOM objects.
|
||||
// Includes the isAnimejsInstanceProxy marker set in instance.js for per-instance wrappers.
|
||||
const isThreeTarget = (t) => !!(
|
||||
t && !t.nodeType && (
|
||||
t.isObject3D || t.isMaterial || t.isTexture ||
|
||||
t.isFog || t.isFogExp2 || t.isUniformNode ||
|
||||
t.isColor || t.isVector2 || t.isVector3 || t.isVector4 ||
|
||||
t.isAnimejsInstanceProxy
|
||||
)
|
||||
);
|
||||
|
||||
const threeAdapter = registerAdapter(isThreeTarget);
|
||||
|
||||
export { threeAdapter };
|
||||
+297
@@ -0,0 +1,297 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var three = require('three');
|
||||
var number = require('../../utils/number.cjs');
|
||||
|
||||
/**
|
||||
* Generic read/write helpers for the three.js bindings. Each operates on a target (or target array) and walks to the leaf via a path tag - direct (`target[name]`), uniform (`target.uniforms[name].value`), or TSL node (`target[name].value`). Adapter and resolver files pass the matching `PATH_*` constant; the JIT specializes each call site so the branch in `leafAt` / `writeLeafScalar` constant-folds.
|
||||
*/
|
||||
|
||||
|
||||
const COLOR_NORM = 1 / 255;
|
||||
|
||||
const AXIS_MAP = /** @type {Record<string, 'x' | 'y' | 'z' | 'w'>} */({ X: 'x', Y: 'y', Z: 'z', W: 'w' });
|
||||
|
||||
const PATH_DIRECT = 0;
|
||||
const PATH_UNIFORM = 1;
|
||||
const PATH_NODE = 2;
|
||||
|
||||
const KIND_COLOR = 0;
|
||||
const KIND_SCALAR = 1;
|
||||
const KIND_VECTOR = 2;
|
||||
|
||||
// Reuse one mutable descriptor across calls, callers must consume immediately since the next call mutates it.
|
||||
const desc = { kind: 0, path: 0, base: '', axis: /** @type {'x' | 'y' | 'z' | 'w'} */('x') };
|
||||
|
||||
/**
|
||||
* Patches a column-major `Matrix4.elements` array in place with CSS-style `skewX(α)` / `skewY(β)`, the 3D extension `skewZ(γ)` (shears z by x), and a `transform-origin` shift.
|
||||
*
|
||||
* @param {number[]} e
|
||||
* @param {number} skewX
|
||||
* @param {number} skewY
|
||||
* @param {number} skewZ
|
||||
* @param {number} ox
|
||||
* @param {number} oy
|
||||
* @param {number} oz
|
||||
*/
|
||||
function applySkewOrigin(e, skewX, skewY, skewZ, ox, oy, oz) {
|
||||
if (skewX !== 0) {
|
||||
const t = Math.tan(number.degToRad(skewX));
|
||||
e[4] += e[0] * t;
|
||||
e[5] += e[1] * t;
|
||||
e[6] += e[2] * t;
|
||||
}
|
||||
if (skewY !== 0) {
|
||||
const t = Math.tan(number.degToRad(skewY));
|
||||
e[0] += e[4] * t;
|
||||
e[1] += e[5] * t;
|
||||
e[2] += e[6] * t;
|
||||
}
|
||||
if (skewZ !== 0) {
|
||||
const t = Math.tan(number.degToRad(skewZ));
|
||||
e[0] += e[8] * t;
|
||||
e[1] += e[9] * t;
|
||||
e[2] += e[10] * t;
|
||||
}
|
||||
if (ox !== 0 || oy !== 0 || oz !== 0) {
|
||||
e[12] += ox - (e[0] * ox + e[4] * oy + e[8] * oz);
|
||||
e[13] += oy - (e[1] * ox + e[5] * oy + e[9] * oz);
|
||||
e[14] += oz - (e[2] * ox + e[6] * oy + e[10] * oz);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} c
|
||||
* @return {String | null}
|
||||
*/
|
||||
function readColorHex(c) {
|
||||
return c ? `#${c.getHexString(three.SRGBColorSpace)}` : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` when `v` is a `Vector2/3/4` instance whose dimension covers `axis`. `Quaternion` and plain `{x,y,z,w}`-shaped objects are intentionally rejected.
|
||||
*
|
||||
* @param {any} v
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isVectorWith(v, axis) {
|
||||
if (!v) return false;
|
||||
if (axis === 'x' || axis === 'y') return !!(v.isVector2 || v.isVector3 || v.isVector4);
|
||||
if (axis === 'z') return !!(v.isVector3 || v.isVector4);
|
||||
return !!v.isVector4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Classifies `target[name]` and returns a descriptor `{ kind, path, base, axis }` (or `null`). Used by the resolver entries in `resolvers.js` and by the `Object3D` adapter to build the matching access pattern for any three.js target (Object3D, Material, Texture, Fog, UniformNode).
|
||||
*
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @return {{ kind: number, path: number, base: string, axis: 'x' | 'y' | 'z' | 'w' } | null}
|
||||
*/
|
||||
function classifyTargetProp(target, name) {
|
||||
const value = target[name];
|
||||
if (value !== undefined) {
|
||||
if (value && value.isColor) {
|
||||
desc.kind = KIND_COLOR; desc.path = PATH_DIRECT;
|
||||
return desc;
|
||||
}
|
||||
if (value && value.isUniformNode) {
|
||||
// Route TSL slot writes through node value, booleans share the scalar entry.
|
||||
const v = value.value;
|
||||
if (v && v.isColor) {
|
||||
desc.kind = KIND_COLOR; desc.path = PATH_NODE;
|
||||
return desc;
|
||||
}
|
||||
if (typeof v === 'number' || typeof v === 'boolean') {
|
||||
desc.kind = KIND_SCALAR; desc.path = PATH_NODE;
|
||||
return desc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (typeof value === 'number' || typeof value === 'boolean') {
|
||||
desc.kind = KIND_SCALAR; desc.path = PATH_DIRECT;
|
||||
return desc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const uniforms = target.uniforms;
|
||||
const u = uniforms && uniforms[name];
|
||||
if (u) {
|
||||
const uv = u.value;
|
||||
if (uv && uv.isColor) {
|
||||
desc.kind = KIND_COLOR; desc.path = PATH_UNIFORM;
|
||||
return desc;
|
||||
}
|
||||
if (typeof uv === 'number') {
|
||||
desc.kind = KIND_SCALAR; desc.path = PATH_UNIFORM;
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
// Decompose vector axis for names like posX, uOffsetY, uVec4W, colorNodeX.
|
||||
const axis = AXIS_MAP[name[name.length - 1]];
|
||||
if (axis) {
|
||||
const base = name.slice(0, -1);
|
||||
if (isVectorWith(target[base], axis)) {
|
||||
desc.kind = KIND_VECTOR; desc.path = PATH_DIRECT; desc.base = base; desc.axis = axis;
|
||||
return desc;
|
||||
}
|
||||
const baseSlot = target[base];
|
||||
if (baseSlot && baseSlot.isUniformNode && isVectorWith(baseSlot.value, axis)) {
|
||||
desc.kind = KIND_VECTOR; desc.path = PATH_NODE; desc.base = base; desc.axis = axis;
|
||||
return desc;
|
||||
}
|
||||
const ub = uniforms && uniforms[base];
|
||||
if (ub && isVectorWith(ub.value, axis)) {
|
||||
desc.kind = KIND_VECTOR; desc.path = PATH_UNIFORM; desc.base = base; desc.axis = axis;
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function leafAt(target, name, path) {
|
||||
if (path === PATH_DIRECT) return target[name];
|
||||
if (path === PATH_UNIFORM) {
|
||||
const u = target.uniforms;
|
||||
const e = u && u[name];
|
||||
return e ? e.value : null;
|
||||
}
|
||||
const n = target[name];
|
||||
return n ? n.value : null;
|
||||
}
|
||||
|
||||
function writeLeafScalar(target, name, v, path) {
|
||||
if (path === PATH_DIRECT) { target[name] = v; return; }
|
||||
if (path === PATH_UNIFORM) {
|
||||
const u = target.uniforms;
|
||||
const e = u && u[name];
|
||||
if (e) e.value = v;
|
||||
return;
|
||||
}
|
||||
const n = target[name];
|
||||
if (n) n.value = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} path
|
||||
* @param {number} [defaultValue]
|
||||
* @return {number}
|
||||
*/
|
||||
function readScalar(target, name, path, defaultValue) {
|
||||
if (defaultValue === undefined) defaultValue = 0;
|
||||
if (!target) return defaultValue;
|
||||
const first = Array.isArray(target) ? target[0] : target;
|
||||
if (!first) return defaultValue;
|
||||
const v = leafAt(first, name, path);
|
||||
return v === undefined || v === null ? defaultValue : v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} v
|
||||
* @param {number} path
|
||||
*/
|
||||
function writeScalar(target, name, v, path) {
|
||||
if (!target) return;
|
||||
if (Array.isArray(target)) {
|
||||
for (let i = 0, l = target.length; i < l; i++) writeLeafScalar(target[i], name, v, path);
|
||||
} else {
|
||||
writeLeafScalar(target, name, v, path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} path
|
||||
* @return {String | null}
|
||||
*/
|
||||
function readColorAt(target, name, path) {
|
||||
if (!target) return null;
|
||||
const first = Array.isArray(target) ? target[0] : target;
|
||||
return readColorHex(first ? leafAt(first, name, path) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {Array.<Number>} ns
|
||||
* @param {number} path
|
||||
*/
|
||||
function writeColorAt(target, name, ns, path) {
|
||||
if (!target) return;
|
||||
const r = ns[0] * COLOR_NORM;
|
||||
const g = ns[1] * COLOR_NORM;
|
||||
const b = ns[2] * COLOR_NORM;
|
||||
if (Array.isArray(target)) {
|
||||
for (let i = 0, l = target.length; i < l; i++) {
|
||||
const c = leafAt(target[i], name, path);
|
||||
if (c) c.setRGB(r, g, b, three.SRGBColorSpace);
|
||||
}
|
||||
} else {
|
||||
const c = leafAt(target, name, path);
|
||||
if (c) c.setRGB(r, g, b, three.SRGBColorSpace);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} base
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @param {number} path
|
||||
* @return {number}
|
||||
*/
|
||||
function readVectorAt(target, base, axis, path) {
|
||||
if (!target) return 0;
|
||||
const first = Array.isArray(target) ? target[0] : target;
|
||||
const vec = first ? leafAt(first, base, path) : null;
|
||||
return vec ? vec[axis] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} base
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @param {number} v
|
||||
* @param {number} path
|
||||
*/
|
||||
function writeVectorAt(target, base, axis, v, path) {
|
||||
if (!target) return;
|
||||
if (Array.isArray(target)) {
|
||||
for (let i = 0, l = target.length; i < l; i++) {
|
||||
const vec = leafAt(target[i], base, path);
|
||||
if (vec) vec[axis] = v;
|
||||
}
|
||||
} else {
|
||||
const vec = leafAt(target, base, path);
|
||||
if (vec) vec[axis] = v;
|
||||
}
|
||||
}
|
||||
|
||||
exports.AXIS_MAP = AXIS_MAP;
|
||||
exports.COLOR_NORM = COLOR_NORM;
|
||||
exports.KIND_COLOR = KIND_COLOR;
|
||||
exports.KIND_SCALAR = KIND_SCALAR;
|
||||
exports.KIND_VECTOR = KIND_VECTOR;
|
||||
exports.PATH_DIRECT = PATH_DIRECT;
|
||||
exports.applySkewOrigin = applySkewOrigin;
|
||||
exports.classifyTargetProp = classifyTargetProp;
|
||||
exports.isVectorWith = isVectorWith;
|
||||
exports.readColorAt = readColorAt;
|
||||
exports.readColorHex = readColorHex;
|
||||
exports.readScalar = readScalar;
|
||||
exports.readVectorAt = readVectorAt;
|
||||
exports.writeColorAt = writeColorAt;
|
||||
exports.writeScalar = writeScalar;
|
||||
exports.writeVectorAt = writeVectorAt;
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Patches a column-major `Matrix4.elements` array in place with CSS-style `skewX(α)` / `skewY(β)`, the 3D extension `skewZ(γ)` (shears z by x), and a `transform-origin` shift.
|
||||
*
|
||||
* @param {number[]} e
|
||||
* @param {number} skewX
|
||||
* @param {number} skewY
|
||||
* @param {number} skewZ
|
||||
* @param {number} ox
|
||||
* @param {number} oy
|
||||
* @param {number} oz
|
||||
*/
|
||||
export function applySkewOrigin(e: number[], skewX: number, skewY: number, skewZ: number, ox: number, oy: number, oz: number): void;
|
||||
/**
|
||||
* @param {any} c
|
||||
* @return {String | null}
|
||||
*/
|
||||
export function readColorHex(c: any): string | null;
|
||||
/**
|
||||
* Returns `true` when `v` is a `Vector2/3/4` instance whose dimension covers `axis`. `Quaternion` and plain `{x,y,z,w}`-shaped objects are intentionally rejected.
|
||||
*
|
||||
* @param {any} v
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @return {boolean}
|
||||
*/
|
||||
export function isVectorWith(v: any, axis: "x" | "y" | "z" | "w"): boolean;
|
||||
/**
|
||||
* Classifies `target[name]` and returns a descriptor `{ kind, path, base, axis }` (or `null`). Used by the resolver entries in `resolvers.js` and by the `Object3D` adapter to build the matching access pattern for any three.js target (Object3D, Material, Texture, Fog, UniformNode).
|
||||
*
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @return {{ kind: number, path: number, base: string, axis: 'x' | 'y' | 'z' | 'w' } | null}
|
||||
*/
|
||||
export function classifyTargetProp(target: any, name: string): {
|
||||
kind: number;
|
||||
path: number;
|
||||
base: string;
|
||||
axis: "x" | "y" | "z" | "w";
|
||||
} | null;
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} path
|
||||
* @param {number} [defaultValue]
|
||||
* @return {number}
|
||||
*/
|
||||
export function readScalar(target: any, name: string, path: number, defaultValue?: number): number;
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} v
|
||||
* @param {number} path
|
||||
*/
|
||||
export function writeScalar(target: any, name: string, v: number, path: number): void;
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} path
|
||||
* @return {String | null}
|
||||
*/
|
||||
export function readColorAt(target: any, name: string, path: number): string | null;
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {Array.<Number>} ns
|
||||
* @param {number} path
|
||||
*/
|
||||
export function writeColorAt(target: any, name: string, ns: Array<number>, path: number): void;
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} base
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @param {number} path
|
||||
* @return {number}
|
||||
*/
|
||||
export function readVectorAt(target: any, base: string, axis: "x" | "y" | "z" | "w", path: number): number;
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} base
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @param {number} v
|
||||
* @param {number} path
|
||||
*/
|
||||
export function writeVectorAt(target: any, base: string, axis: "x" | "y" | "z" | "w", v: number, path: number): void;
|
||||
export const COLOR_NORM: number;
|
||||
export const AXIS_MAP: Record<string, "x" | "y" | "z" | "w">;
|
||||
export const PATH_DIRECT: 0;
|
||||
export const KIND_COLOR: 0;
|
||||
export const KIND_SCALAR: 1;
|
||||
export const KIND_VECTOR: 2;
|
||||
+280
@@ -0,0 +1,280 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { SRGBColorSpace } from 'three';
|
||||
import { degToRad } from '../../utils/number.js';
|
||||
|
||||
/**
|
||||
* Generic read/write helpers for the three.js bindings. Each operates on a target (or target array) and walks to the leaf via a path tag - direct (`target[name]`), uniform (`target.uniforms[name].value`), or TSL node (`target[name].value`). Adapter and resolver files pass the matching `PATH_*` constant; the JIT specializes each call site so the branch in `leafAt` / `writeLeafScalar` constant-folds.
|
||||
*/
|
||||
|
||||
|
||||
const COLOR_NORM = 1 / 255;
|
||||
|
||||
const AXIS_MAP = /** @type {Record<string, 'x' | 'y' | 'z' | 'w'>} */({ X: 'x', Y: 'y', Z: 'z', W: 'w' });
|
||||
|
||||
const PATH_DIRECT = 0;
|
||||
const PATH_UNIFORM = 1;
|
||||
const PATH_NODE = 2;
|
||||
|
||||
const KIND_COLOR = 0;
|
||||
const KIND_SCALAR = 1;
|
||||
const KIND_VECTOR = 2;
|
||||
|
||||
// Reuse one mutable descriptor across calls, callers must consume immediately since the next call mutates it.
|
||||
const desc = { kind: 0, path: 0, base: '', axis: /** @type {'x' | 'y' | 'z' | 'w'} */('x') };
|
||||
|
||||
/**
|
||||
* Patches a column-major `Matrix4.elements` array in place with CSS-style `skewX(α)` / `skewY(β)`, the 3D extension `skewZ(γ)` (shears z by x), and a `transform-origin` shift.
|
||||
*
|
||||
* @param {number[]} e
|
||||
* @param {number} skewX
|
||||
* @param {number} skewY
|
||||
* @param {number} skewZ
|
||||
* @param {number} ox
|
||||
* @param {number} oy
|
||||
* @param {number} oz
|
||||
*/
|
||||
function applySkewOrigin(e, skewX, skewY, skewZ, ox, oy, oz) {
|
||||
if (skewX !== 0) {
|
||||
const t = Math.tan(degToRad(skewX));
|
||||
e[4] += e[0] * t;
|
||||
e[5] += e[1] * t;
|
||||
e[6] += e[2] * t;
|
||||
}
|
||||
if (skewY !== 0) {
|
||||
const t = Math.tan(degToRad(skewY));
|
||||
e[0] += e[4] * t;
|
||||
e[1] += e[5] * t;
|
||||
e[2] += e[6] * t;
|
||||
}
|
||||
if (skewZ !== 0) {
|
||||
const t = Math.tan(degToRad(skewZ));
|
||||
e[0] += e[8] * t;
|
||||
e[1] += e[9] * t;
|
||||
e[2] += e[10] * t;
|
||||
}
|
||||
if (ox !== 0 || oy !== 0 || oz !== 0) {
|
||||
e[12] += ox - (e[0] * ox + e[4] * oy + e[8] * oz);
|
||||
e[13] += oy - (e[1] * ox + e[5] * oy + e[9] * oz);
|
||||
e[14] += oz - (e[2] * ox + e[6] * oy + e[10] * oz);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} c
|
||||
* @return {String | null}
|
||||
*/
|
||||
function readColorHex(c) {
|
||||
return c ? `#${c.getHexString(SRGBColorSpace)}` : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` when `v` is a `Vector2/3/4` instance whose dimension covers `axis`. `Quaternion` and plain `{x,y,z,w}`-shaped objects are intentionally rejected.
|
||||
*
|
||||
* @param {any} v
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isVectorWith(v, axis) {
|
||||
if (!v) return false;
|
||||
if (axis === 'x' || axis === 'y') return !!(v.isVector2 || v.isVector3 || v.isVector4);
|
||||
if (axis === 'z') return !!(v.isVector3 || v.isVector4);
|
||||
return !!v.isVector4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Classifies `target[name]` and returns a descriptor `{ kind, path, base, axis }` (or `null`). Used by the resolver entries in `resolvers.js` and by the `Object3D` adapter to build the matching access pattern for any three.js target (Object3D, Material, Texture, Fog, UniformNode).
|
||||
*
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @return {{ kind: number, path: number, base: string, axis: 'x' | 'y' | 'z' | 'w' } | null}
|
||||
*/
|
||||
function classifyTargetProp(target, name) {
|
||||
const value = target[name];
|
||||
if (value !== undefined) {
|
||||
if (value && value.isColor) {
|
||||
desc.kind = KIND_COLOR; desc.path = PATH_DIRECT;
|
||||
return desc;
|
||||
}
|
||||
if (value && value.isUniformNode) {
|
||||
// Route TSL slot writes through node value, booleans share the scalar entry.
|
||||
const v = value.value;
|
||||
if (v && v.isColor) {
|
||||
desc.kind = KIND_COLOR; desc.path = PATH_NODE;
|
||||
return desc;
|
||||
}
|
||||
if (typeof v === 'number' || typeof v === 'boolean') {
|
||||
desc.kind = KIND_SCALAR; desc.path = PATH_NODE;
|
||||
return desc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (typeof value === 'number' || typeof value === 'boolean') {
|
||||
desc.kind = KIND_SCALAR; desc.path = PATH_DIRECT;
|
||||
return desc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const uniforms = target.uniforms;
|
||||
const u = uniforms && uniforms[name];
|
||||
if (u) {
|
||||
const uv = u.value;
|
||||
if (uv && uv.isColor) {
|
||||
desc.kind = KIND_COLOR; desc.path = PATH_UNIFORM;
|
||||
return desc;
|
||||
}
|
||||
if (typeof uv === 'number') {
|
||||
desc.kind = KIND_SCALAR; desc.path = PATH_UNIFORM;
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
// Decompose vector axis for names like posX, uOffsetY, uVec4W, colorNodeX.
|
||||
const axis = AXIS_MAP[name[name.length - 1]];
|
||||
if (axis) {
|
||||
const base = name.slice(0, -1);
|
||||
if (isVectorWith(target[base], axis)) {
|
||||
desc.kind = KIND_VECTOR; desc.path = PATH_DIRECT; desc.base = base; desc.axis = axis;
|
||||
return desc;
|
||||
}
|
||||
const baseSlot = target[base];
|
||||
if (baseSlot && baseSlot.isUniformNode && isVectorWith(baseSlot.value, axis)) {
|
||||
desc.kind = KIND_VECTOR; desc.path = PATH_NODE; desc.base = base; desc.axis = axis;
|
||||
return desc;
|
||||
}
|
||||
const ub = uniforms && uniforms[base];
|
||||
if (ub && isVectorWith(ub.value, axis)) {
|
||||
desc.kind = KIND_VECTOR; desc.path = PATH_UNIFORM; desc.base = base; desc.axis = axis;
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function leafAt(target, name, path) {
|
||||
if (path === PATH_DIRECT) return target[name];
|
||||
if (path === PATH_UNIFORM) {
|
||||
const u = target.uniforms;
|
||||
const e = u && u[name];
|
||||
return e ? e.value : null;
|
||||
}
|
||||
const n = target[name];
|
||||
return n ? n.value : null;
|
||||
}
|
||||
|
||||
function writeLeafScalar(target, name, v, path) {
|
||||
if (path === PATH_DIRECT) { target[name] = v; return; }
|
||||
if (path === PATH_UNIFORM) {
|
||||
const u = target.uniforms;
|
||||
const e = u && u[name];
|
||||
if (e) e.value = v;
|
||||
return;
|
||||
}
|
||||
const n = target[name];
|
||||
if (n) n.value = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} path
|
||||
* @param {number} [defaultValue]
|
||||
* @return {number}
|
||||
*/
|
||||
function readScalar(target, name, path, defaultValue) {
|
||||
if (defaultValue === undefined) defaultValue = 0;
|
||||
if (!target) return defaultValue;
|
||||
const first = Array.isArray(target) ? target[0] : target;
|
||||
if (!first) return defaultValue;
|
||||
const v = leafAt(first, name, path);
|
||||
return v === undefined || v === null ? defaultValue : v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} v
|
||||
* @param {number} path
|
||||
*/
|
||||
function writeScalar(target, name, v, path) {
|
||||
if (!target) return;
|
||||
if (Array.isArray(target)) {
|
||||
for (let i = 0, l = target.length; i < l; i++) writeLeafScalar(target[i], name, v, path);
|
||||
} else {
|
||||
writeLeafScalar(target, name, v, path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} path
|
||||
* @return {String | null}
|
||||
*/
|
||||
function readColorAt(target, name, path) {
|
||||
if (!target) return null;
|
||||
const first = Array.isArray(target) ? target[0] : target;
|
||||
return readColorHex(first ? leafAt(first, name, path) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {Array.<Number>} ns
|
||||
* @param {number} path
|
||||
*/
|
||||
function writeColorAt(target, name, ns, path) {
|
||||
if (!target) return;
|
||||
const r = ns[0] * COLOR_NORM;
|
||||
const g = ns[1] * COLOR_NORM;
|
||||
const b = ns[2] * COLOR_NORM;
|
||||
if (Array.isArray(target)) {
|
||||
for (let i = 0, l = target.length; i < l; i++) {
|
||||
const c = leafAt(target[i], name, path);
|
||||
if (c) c.setRGB(r, g, b, SRGBColorSpace);
|
||||
}
|
||||
} else {
|
||||
const c = leafAt(target, name, path);
|
||||
if (c) c.setRGB(r, g, b, SRGBColorSpace);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} base
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @param {number} path
|
||||
* @return {number}
|
||||
*/
|
||||
function readVectorAt(target, base, axis, path) {
|
||||
if (!target) return 0;
|
||||
const first = Array.isArray(target) ? target[0] : target;
|
||||
const vec = first ? leafAt(first, base, path) : null;
|
||||
return vec ? vec[axis] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} base
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @param {number} v
|
||||
* @param {number} path
|
||||
*/
|
||||
function writeVectorAt(target, base, axis, v, path) {
|
||||
if (!target) return;
|
||||
if (Array.isArray(target)) {
|
||||
for (let i = 0, l = target.length; i < l; i++) {
|
||||
const vec = leafAt(target[i], base, path);
|
||||
if (vec) vec[axis] = v;
|
||||
}
|
||||
} else {
|
||||
const vec = leafAt(target, base, path);
|
||||
if (vec) vec[axis] = v;
|
||||
}
|
||||
}
|
||||
|
||||
export { AXIS_MAP, COLOR_NORM, KIND_COLOR, KIND_SCALAR, KIND_VECTOR, PATH_DIRECT, applySkewOrigin, classifyTargetProp, isVectorWith, readColorAt, readColorHex, readScalar, readVectorAt, writeColorAt, writeScalar, writeVectorAt };
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var adapter = require('./adapter.cjs');
|
||||
require('./resolvers.cjs');
|
||||
require('./uniform.cjs');
|
||||
require('./object3d.cjs');
|
||||
var instance = require('./instance.cjs');
|
||||
|
||||
|
||||
|
||||
exports.threeAdapter = adapter.threeAdapter;
|
||||
exports.commitChanges = instance.commitChanges;
|
||||
exports.getInstances = instance.getInstances;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export { threeAdapter } from "./adapter.js";
|
||||
export { getInstances, commitChanges } from "./instance.js";
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
export { threeAdapter } from './adapter.js';
|
||||
import './resolvers.js';
|
||||
import './uniform.js';
|
||||
import './object3d.js';
|
||||
export { commitChanges, getInstances } from './instance.js';
|
||||
+368
@@ -0,0 +1,368 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var three = require('three');
|
||||
var number = require('../../utils/number.cjs');
|
||||
var adapter = require('./adapter.cjs');
|
||||
var helpers = require('./helpers.cjs');
|
||||
|
||||
const hasSkewOrigin = (t) => !!(t._skewX || t._skewY || t._skewZ || t._originX || t._originY || t._originZ);
|
||||
|
||||
/**
|
||||
* @import { Object3D, InstancedMesh } from 'three'
|
||||
*
|
||||
* @typedef {InstancedMesh | BatchedMesh} InstanceParent
|
||||
*/
|
||||
|
||||
const DIRTY_POS = 1;
|
||||
const DIRTY_ROT = 2;
|
||||
const DIRTY_SCALE = 4;
|
||||
const DIRTY_SKEW = 8;
|
||||
|
||||
/** @type {WeakMap<InstanceParent, InstanceBinding>} */
|
||||
const bindings = new WeakMap();
|
||||
|
||||
/**
|
||||
* Per-mesh state for `InstancedMesh` / `BatchedMesh` animations. Holds the instance array, the dirty queue, and the chained `onBeforeRender` closure.
|
||||
*/
|
||||
class InstanceBinding {
|
||||
|
||||
/** @param {InstanceParent} mesh */
|
||||
constructor(mesh) {
|
||||
this.mesh = mesh;
|
||||
this.hasInstanceMatrix = 'instanceMatrix' in mesh;
|
||||
/** @type {(Instance | null)[]} */
|
||||
this.instances = [];
|
||||
/** @type {Instance[]} */
|
||||
this.dirtyList = [];
|
||||
/** @type {Object3D['onBeforeRender'] | null} */
|
||||
this.userOnBeforeRender = mesh.onBeforeRender || null;
|
||||
this.chainedHandler = makeChainedHandler(this);
|
||||
Object.defineProperty(mesh, 'onBeforeRender', {
|
||||
configurable: true,
|
||||
get: () => this.chainedHandler,
|
||||
set: (fn) => { this.userOnBeforeRender = fn; },
|
||||
});
|
||||
}
|
||||
|
||||
flush() {
|
||||
const list = this.dirtyList;
|
||||
if (list.length === 0) return;
|
||||
for (let i = 0, l = list.length; i < l; i++) list[i]._flush();
|
||||
if (this.hasInstanceMatrix) /** @type {InstancedMesh} */(this.mesh).instanceMatrix.needsUpdate = true;
|
||||
list.length = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @return {Object3D['onBeforeRender']}
|
||||
*/
|
||||
function makeChainedHandler(binding) {
|
||||
return function (renderer, scene, camera, geometry, material, group) {
|
||||
binding.flush();
|
||||
const u = binding.userOnBeforeRender;
|
||||
if (u) u.call(binding.mesh, renderer, scene, camera, geometry, material, group);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-instance adapter for `InstancedMesh` or `BatchedMesh`. Returned by `getInstances(mesh)`. Exposes the same flat properties as the mesh adapter, applied to a single instance id. Writes are coalesced and flushed before each render via `onBeforeRender`; call `commitChanges(mesh)` if you need to read `mesh.instanceMatrix` between a tick and a render.
|
||||
*
|
||||
* Caveats:
|
||||
* - `opacity` writes the parent's shared material, every instance is affected.
|
||||
* - `visible` is backed by `BatchedMesh.setVisibleAt`. On `InstancedMesh` it is a no-op, use `scale = 0` to hide an instance.
|
||||
*/
|
||||
class Instance {
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @param {number} id
|
||||
*/
|
||||
constructor(binding, id) {
|
||||
this.isAnimejsInstanceProxy = true;
|
||||
this.parent = binding.mesh;
|
||||
this.id = id;
|
||||
this._position = new three.Vector3();
|
||||
this._rotation = new three.Euler(0, 0, 0, 'XYZ');
|
||||
this._scale = new three.Vector3(1, 1, 1);
|
||||
this._matrix = new three.Matrix4();
|
||||
this._quat = new three.Quaternion();
|
||||
// Pre-allocate _color so the hidden class stays stable, set color mutates it in place rather than re-binding the field.
|
||||
this._color = new three.Color();
|
||||
this._dirty = 0;
|
||||
// Skew in degrees and transform-origin in object-space.
|
||||
// applySkewOrigin computes Math.tan inline per non-zero axis, so we only carry the user-facing angle here.
|
||||
this._skewX = 0;
|
||||
this._skewY = 0;
|
||||
this._skewZ = 0;
|
||||
this._originX = 0;
|
||||
this._originY = 0;
|
||||
this._originZ = 0;
|
||||
// Skip the position-only fast path in _flush whenever any skew or origin is non-zero, since both modify the matrix beyond pure translation.
|
||||
this._hasSkewOrigin = false;
|
||||
// Cache the binding dirty queue once so per-frame setters skip a property hop.
|
||||
/** @type {Instance[]} */
|
||||
this._dirtyList = binding.dirtyList;
|
||||
// Cache parent capability flags once so per-frame setters skip prototype-chain in checks.
|
||||
const parent = binding.mesh;
|
||||
this._hasSetColor = 'setColorAt' in parent;
|
||||
this._hasSetVisible = 'setVisibleAt' in parent;
|
||||
this._hasGetVisible = 'getVisibleAt' in parent;
|
||||
|
||||
parent.getMatrixAt(id, this._matrix);
|
||||
if (this._matrix.elements[15] === 0) this._matrix.identity();
|
||||
this._matrix.decompose(this._position, this._quat, this._scale);
|
||||
this._rotation.setFromQuaternion(this._quat, 'XYZ');
|
||||
|
||||
if ('getColorAt' in parent && 'instanceColor' in parent && parent.instanceColor) {
|
||||
parent.getColorAt(id, this._color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} flag
|
||||
*/
|
||||
_markDirty(flag) {
|
||||
// Enqueue once per frame, later flags only OR into _dirty without re-pushing to the queue.
|
||||
if (this._dirty === 0) this._dirtyList.push(this);
|
||||
this._dirty |= flag;
|
||||
}
|
||||
|
||||
_flush() {
|
||||
const d = this._dirty;
|
||||
if (!d) return;
|
||||
const m = this._matrix;
|
||||
const p = this._position;
|
||||
if (d === DIRTY_POS && !this._hasSkewOrigin) {
|
||||
const e = m.elements;
|
||||
e[12] = p.x; e[13] = p.y; e[14] = p.z;
|
||||
} else {
|
||||
const q = this._quat;
|
||||
if (d & DIRTY_ROT) q.setFromEuler(this._rotation);
|
||||
m.compose(p, q, this._scale);
|
||||
if (this._hasSkewOrigin) {
|
||||
helpers.applySkewOrigin(m.elements, this._skewX, this._skewY, this._skewZ, this._originX, this._originY, this._originZ);
|
||||
}
|
||||
}
|
||||
this.parent.setMatrixAt(this.id, m);
|
||||
this._dirty = 0;
|
||||
}
|
||||
|
||||
get x() { return this._position.x; }
|
||||
set x(v) { this._position.x = v; this._markDirty(DIRTY_POS); }
|
||||
|
||||
get y() { return this._position.y; }
|
||||
set y(v) { this._position.y = v; this._markDirty(DIRTY_POS); }
|
||||
|
||||
get z() { return this._position.z; }
|
||||
set z(v) { this._position.z = v; this._markDirty(DIRTY_POS); }
|
||||
|
||||
get rotateX() { return number.radToDeg(this._rotation.x); }
|
||||
set rotateX(v) { this._rotation.x = number.degToRad(v); this._markDirty(DIRTY_ROT); }
|
||||
|
||||
get rotateY() { return number.radToDeg(this._rotation.y); }
|
||||
set rotateY(v) { this._rotation.y = number.degToRad(v); this._markDirty(DIRTY_ROT); }
|
||||
|
||||
get rotateZ() { return number.radToDeg(this._rotation.z); }
|
||||
set rotateZ(v) { this._rotation.z = number.degToRad(v); this._markDirty(DIRTY_ROT); }
|
||||
|
||||
get scaleX() { return this._scale.x; }
|
||||
set scaleX(v) { this._scale.x = v; this._markDirty(DIRTY_SCALE); }
|
||||
|
||||
get scaleY() { return this._scale.y; }
|
||||
set scaleY(v) { this._scale.y = v; this._markDirty(DIRTY_SCALE); }
|
||||
|
||||
get scaleZ() { return this._scale.z; }
|
||||
set scaleZ(v) { this._scale.z = v; this._markDirty(DIRTY_SCALE); }
|
||||
|
||||
get scale() { return this._scale.x; }
|
||||
set scale(v) {
|
||||
const s = this._scale;
|
||||
s.x = v; s.y = v; s.z = v;
|
||||
this._markDirty(DIRTY_SCALE);
|
||||
}
|
||||
|
||||
get skewX() { return this._skewX; }
|
||||
set skewX(v) {
|
||||
this._skewX = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get skewY() { return this._skewY; }
|
||||
set skewY(v) {
|
||||
this._skewY = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get skewZ() { return this._skewZ; }
|
||||
set skewZ(v) {
|
||||
this._skewZ = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get transformOriginX() { return this._originX; }
|
||||
set transformOriginX(v) {
|
||||
this._originX = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get transformOriginY() { return this._originY; }
|
||||
set transformOriginY(v) {
|
||||
this._originY = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get transformOriginZ() { return this._originZ; }
|
||||
set transformOriginZ(v) {
|
||||
this._originZ = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get opacity() {
|
||||
return helpers.readScalar(/** @type {any} */(this.parent).material, 'opacity', helpers.PATH_DIRECT, 1);
|
||||
}
|
||||
/** @param {number} v */
|
||||
set opacity(v) {
|
||||
helpers.writeScalar(/** @type {any} */(this.parent).material, 'opacity', v, helpers.PATH_DIRECT);
|
||||
}
|
||||
|
||||
get visible() {
|
||||
return this._hasGetVisible ? /** @type {any} */(this.parent).getVisibleAt(this.id) : true;
|
||||
}
|
||||
/** @param {boolean} v */
|
||||
set visible(v) {
|
||||
if (this._hasSetVisible) /** @type {any} */(this.parent).setVisibleAt(this.id, v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes pending matrix writes for every dirty instance of `mesh`.
|
||||
* Called automatically before each render. Call it yourself if you read
|
||||
* `mesh.instanceMatrix` between an animation tick and the next render.
|
||||
*
|
||||
* @param {InstanceParent} mesh
|
||||
*/
|
||||
function commitChanges(mesh) {
|
||||
const binding = bindings.get(mesh);
|
||||
if (binding) binding.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of per-instance adapters for `mesh`. Index by id, deleted slots on `BatchedMesh` are `null`. Pass the array (or a slice / a single element) to `animate()`.
|
||||
*
|
||||
* animate(getInstances(mesh), { x: 100, delay: stagger(5) });
|
||||
* animate(getInstances(mesh)[42], { scale: 2 });
|
||||
*
|
||||
* The same array reference is preserved across `mesh.count` / `addInstance` / `deleteInstance` calls. Entries are pushed, nulled, or truncated in place. Animations bound to an outdated reference keep tweening their original adapters.
|
||||
*
|
||||
* `mesh.onBeforeRender` is replaced with an accessor that flushes
|
||||
* pending instance writes before each render and forwards to your
|
||||
* handler. Assigning your own `mesh.onBeforeRender = fn` keeps the
|
||||
* auto-flush, but reading `mesh.onBeforeRender` afterwards returns the
|
||||
* chained dispatcher rather than `fn` itself, so identity checks
|
||||
* (`mesh.onBeforeRender === fn`) will not match.
|
||||
*
|
||||
* @param {InstanceParent} mesh
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
function getInstances(mesh) {
|
||||
let binding = bindings.get(mesh);
|
||||
if (!binding) {
|
||||
binding = new InstanceBinding(mesh);
|
||||
bindings.set(mesh, binding);
|
||||
}
|
||||
if (mesh instanceof three.BatchedMesh) {
|
||||
return refreshBatched(binding);
|
||||
}
|
||||
return refreshInstanced(binding);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
function refreshInstanced(binding) {
|
||||
const mesh = /** @type {InstancedMesh} */(binding.mesh);
|
||||
const count = mesh.count;
|
||||
const arr = binding.instances;
|
||||
if (arr.length === 0 && count > 0) {
|
||||
arr.length = count;
|
||||
for (let i = 0; i < count; i++) arr[i] = new Instance(binding, i);
|
||||
return arr;
|
||||
}
|
||||
if (arr.length < count) {
|
||||
for (let i = arr.length; i < count; i++) arr.push(new Instance(binding, i));
|
||||
} else if (arr.length > count) {
|
||||
arr.length = count;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
function refreshBatched(binding) {
|
||||
const mesh = /** @type {BatchedMesh} */(binding.mesh);
|
||||
const arr = binding.instances;
|
||||
// Read three internal _instanceInfo to skip slots marked inactive by deleteInstance.
|
||||
// Iterate the full slot count, not instanceCount, since deleted slots leave gaps but live ids past them must still be visited.
|
||||
const instanceInfo = /** @type {{ _instanceInfo?: { active: boolean }[] }} */(mesh)._instanceInfo ?? [];
|
||||
const len = instanceInfo.length;
|
||||
if (arr.length < len) arr.length = len;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const info = instanceInfo[i];
|
||||
const inactive = info && info.active === false;
|
||||
if (inactive) {
|
||||
arr[i] = null;
|
||||
} else if (!arr[i]) {
|
||||
arr[i] = new Instance(binding, i);
|
||||
}
|
||||
}
|
||||
if (arr.length > len) arr.length = len;
|
||||
return arr;
|
||||
}
|
||||
|
||||
const instanceAdapter = adapter.threeAdapter.registerTargetAdapter((t) => t instanceof Instance);
|
||||
instanceAdapter.registerProperty('color',
|
||||
(t) => helpers.readColorHex(t._color),
|
||||
(t, _, tw) => {
|
||||
if (!t._hasSetColor) return;
|
||||
const ns = tw._numbers;
|
||||
t._color.setRGB(ns[0] * helpers.COLOR_NORM, ns[1] * helpers.COLOR_NORM, ns[2] * helpers.COLOR_NORM, three.SRGBColorSpace);
|
||||
const p = /** @type {any} */(t.parent);
|
||||
p.setColorAt(t.id, t._color);
|
||||
if (p.instanceColor) p.instanceColor.needsUpdate = true;
|
||||
},
|
||||
);
|
||||
// Shorthand 3-token string x y z routed via the engine COMPLEX path.
|
||||
// The setter reads tween _numbers for the per-frame lerped triplet.
|
||||
instanceAdapter.registerProperty('transformOrigin',
|
||||
(t) => `${t._originX} ${t._originY} ${t._originZ}`,
|
||||
(t, _, tw) => {
|
||||
const ns = tw._numbers;
|
||||
t._originX = ns[0];
|
||||
t._originY = ns[1];
|
||||
t._originZ = ns[2];
|
||||
t._hasSkewOrigin = hasSkewOrigin(t);
|
||||
t._markDirty(DIRTY_SKEW);
|
||||
},
|
||||
);
|
||||
|
||||
exports.commitChanges = commitChanges;
|
||||
exports.getInstances = getInstances;
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* Flushes pending matrix writes for every dirty instance of `mesh`.
|
||||
* Called automatically before each render. Call it yourself if you read
|
||||
* `mesh.instanceMatrix` between an animation tick and the next render.
|
||||
*
|
||||
* @param {InstanceParent} mesh
|
||||
*/
|
||||
export function commitChanges(mesh: InstanceParent): void;
|
||||
/**
|
||||
* Returns an array of per-instance adapters for `mesh`. Index by id, deleted slots on `BatchedMesh` are `null`. Pass the array (or a slice / a single element) to `animate()`.
|
||||
*
|
||||
* animate(getInstances(mesh), { x: 100, delay: stagger(5) });
|
||||
* animate(getInstances(mesh)[42], { scale: 2 });
|
||||
*
|
||||
* The same array reference is preserved across `mesh.count` / `addInstance` / `deleteInstance` calls. Entries are pushed, nulled, or truncated in place. Animations bound to an outdated reference keep tweening their original adapters.
|
||||
*
|
||||
* `mesh.onBeforeRender` is replaced with an accessor that flushes
|
||||
* pending instance writes before each render and forwards to your
|
||||
* handler. Assigning your own `mesh.onBeforeRender = fn` keeps the
|
||||
* auto-flush, but reading `mesh.onBeforeRender` afterwards returns the
|
||||
* chained dispatcher rather than `fn` itself, so identity checks
|
||||
* (`mesh.onBeforeRender === fn`) will not match.
|
||||
*
|
||||
* @param {InstanceParent} mesh
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
export function getInstances(mesh: InstanceParent): (Instance | null)[];
|
||||
export type InstanceParent = InstancedMesh | BatchedMesh;
|
||||
/**
|
||||
* Per-instance adapter for `InstancedMesh` or `BatchedMesh`. Returned by `getInstances(mesh)`. Exposes the same flat properties as the mesh adapter, applied to a single instance id. Writes are coalesced and flushed before each render via `onBeforeRender`; call `commitChanges(mesh)` if you need to read `mesh.instanceMatrix` between a tick and a render.
|
||||
*
|
||||
* Caveats:
|
||||
* - `opacity` writes the parent's shared material, every instance is affected.
|
||||
* - `visible` is backed by `BatchedMesh.setVisibleAt`. On `InstancedMesh` it is a no-op, use `scale = 0` to hide an instance.
|
||||
*/
|
||||
declare class Instance {
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @param {number} id
|
||||
*/
|
||||
constructor(binding: InstanceBinding, id: number);
|
||||
isAnimejsInstanceProxy: boolean;
|
||||
parent: InstanceParent;
|
||||
id: number;
|
||||
_position: Vector3;
|
||||
_rotation: Euler;
|
||||
_scale: Vector3;
|
||||
_matrix: Matrix4;
|
||||
_quat: Quaternion;
|
||||
_color: Color;
|
||||
_dirty: number;
|
||||
_skewX: number;
|
||||
_skewY: number;
|
||||
_skewZ: number;
|
||||
_originX: number;
|
||||
_originY: number;
|
||||
_originZ: number;
|
||||
_hasSkewOrigin: boolean;
|
||||
/** @type {Instance[]} */
|
||||
_dirtyList: Instance[];
|
||||
_hasSetColor: boolean;
|
||||
_hasSetVisible: boolean;
|
||||
_hasGetVisible: boolean;
|
||||
/**
|
||||
* @param {number} flag
|
||||
*/
|
||||
_markDirty(flag: number): void;
|
||||
_flush(): void;
|
||||
set x(v: number);
|
||||
get x(): number;
|
||||
set y(v: number);
|
||||
get y(): number;
|
||||
set z(v: number);
|
||||
get z(): number;
|
||||
set rotateX(v: number);
|
||||
get rotateX(): number;
|
||||
set rotateY(v: number);
|
||||
get rotateY(): number;
|
||||
set rotateZ(v: number);
|
||||
get rotateZ(): number;
|
||||
set scaleX(v: number);
|
||||
get scaleX(): number;
|
||||
set scaleY(v: number);
|
||||
get scaleY(): number;
|
||||
set scaleZ(v: number);
|
||||
get scaleZ(): number;
|
||||
set scale(v: number);
|
||||
get scale(): number;
|
||||
set skewX(v: number);
|
||||
get skewX(): number;
|
||||
set skewY(v: number);
|
||||
get skewY(): number;
|
||||
set skewZ(v: number);
|
||||
get skewZ(): number;
|
||||
set transformOriginX(v: number);
|
||||
get transformOriginX(): number;
|
||||
set transformOriginY(v: number);
|
||||
get transformOriginY(): number;
|
||||
set transformOriginZ(v: number);
|
||||
get transformOriginZ(): number;
|
||||
/** @param {number} v */
|
||||
set opacity(v: number);
|
||||
get opacity(): number;
|
||||
/** @param {boolean} v */
|
||||
set visible(v: boolean);
|
||||
get visible(): boolean;
|
||||
}
|
||||
import type { InstancedMesh } from 'three';
|
||||
import { BatchedMesh } from 'three';
|
||||
import { Vector3 } from 'three';
|
||||
import { Euler } from 'three';
|
||||
import { Matrix4 } from 'three';
|
||||
import { Quaternion } from 'three';
|
||||
import { Color } from 'three';
|
||||
/**
|
||||
* Per-mesh state for `InstancedMesh` / `BatchedMesh` animations. Holds the instance array, the dirty queue, and the chained `onBeforeRender` closure.
|
||||
*/
|
||||
declare class InstanceBinding {
|
||||
/** @param {InstanceParent} mesh */
|
||||
constructor(mesh: InstanceParent);
|
||||
mesh: InstanceParent;
|
||||
hasInstanceMatrix: boolean;
|
||||
/** @type {(Instance | null)[]} */
|
||||
instances: (Instance | null)[];
|
||||
/** @type {Instance[]} */
|
||||
dirtyList: Instance[];
|
||||
/** @type {Object3D['onBeforeRender'] | null} */
|
||||
userOnBeforeRender: Object3D["onBeforeRender"] | null;
|
||||
chainedHandler: (renderer: import("three").WebGLRenderer, scene: import("three").Scene, camera: import("three").Camera, geometry: import("three").BufferGeometry, material: import("three").Material, group: import("three").Group) => void;
|
||||
flush(): void;
|
||||
}
|
||||
import type { Object3D } from 'three';
|
||||
export {};
|
||||
+365
@@ -0,0 +1,365 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { SRGBColorSpace, Vector3, Euler, Matrix4, Quaternion, Color, BatchedMesh } from 'three';
|
||||
import { radToDeg, degToRad } from '../../utils/number.js';
|
||||
import { threeAdapter } from './adapter.js';
|
||||
import { readColorHex, COLOR_NORM, applySkewOrigin, readScalar, PATH_DIRECT, writeScalar } from './helpers.js';
|
||||
|
||||
const hasSkewOrigin = (t) => !!(t._skewX || t._skewY || t._skewZ || t._originX || t._originY || t._originZ);
|
||||
|
||||
/**
|
||||
* @import { Object3D, InstancedMesh } from 'three'
|
||||
*
|
||||
* @typedef {InstancedMesh | BatchedMesh} InstanceParent
|
||||
*/
|
||||
|
||||
const DIRTY_POS = 1;
|
||||
const DIRTY_ROT = 2;
|
||||
const DIRTY_SCALE = 4;
|
||||
const DIRTY_SKEW = 8;
|
||||
|
||||
/** @type {WeakMap<InstanceParent, InstanceBinding>} */
|
||||
const bindings = new WeakMap();
|
||||
|
||||
/**
|
||||
* Per-mesh state for `InstancedMesh` / `BatchedMesh` animations. Holds the instance array, the dirty queue, and the chained `onBeforeRender` closure.
|
||||
*/
|
||||
class InstanceBinding {
|
||||
|
||||
/** @param {InstanceParent} mesh */
|
||||
constructor(mesh) {
|
||||
this.mesh = mesh;
|
||||
this.hasInstanceMatrix = 'instanceMatrix' in mesh;
|
||||
/** @type {(Instance | null)[]} */
|
||||
this.instances = [];
|
||||
/** @type {Instance[]} */
|
||||
this.dirtyList = [];
|
||||
/** @type {Object3D['onBeforeRender'] | null} */
|
||||
this.userOnBeforeRender = mesh.onBeforeRender || null;
|
||||
this.chainedHandler = makeChainedHandler(this);
|
||||
Object.defineProperty(mesh, 'onBeforeRender', {
|
||||
configurable: true,
|
||||
get: () => this.chainedHandler,
|
||||
set: (fn) => { this.userOnBeforeRender = fn; },
|
||||
});
|
||||
}
|
||||
|
||||
flush() {
|
||||
const list = this.dirtyList;
|
||||
if (list.length === 0) return;
|
||||
for (let i = 0, l = list.length; i < l; i++) list[i]._flush();
|
||||
if (this.hasInstanceMatrix) /** @type {InstancedMesh} */(this.mesh).instanceMatrix.needsUpdate = true;
|
||||
list.length = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @return {Object3D['onBeforeRender']}
|
||||
*/
|
||||
function makeChainedHandler(binding) {
|
||||
return function (renderer, scene, camera, geometry, material, group) {
|
||||
binding.flush();
|
||||
const u = binding.userOnBeforeRender;
|
||||
if (u) u.call(binding.mesh, renderer, scene, camera, geometry, material, group);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-instance adapter for `InstancedMesh` or `BatchedMesh`. Returned by `getInstances(mesh)`. Exposes the same flat properties as the mesh adapter, applied to a single instance id. Writes are coalesced and flushed before each render via `onBeforeRender`; call `commitChanges(mesh)` if you need to read `mesh.instanceMatrix` between a tick and a render.
|
||||
*
|
||||
* Caveats:
|
||||
* - `opacity` writes the parent's shared material, every instance is affected.
|
||||
* - `visible` is backed by `BatchedMesh.setVisibleAt`. On `InstancedMesh` it is a no-op, use `scale = 0` to hide an instance.
|
||||
*/
|
||||
class Instance {
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @param {number} id
|
||||
*/
|
||||
constructor(binding, id) {
|
||||
this.isAnimejsInstanceProxy = true;
|
||||
this.parent = binding.mesh;
|
||||
this.id = id;
|
||||
this._position = new Vector3();
|
||||
this._rotation = new Euler(0, 0, 0, 'XYZ');
|
||||
this._scale = new Vector3(1, 1, 1);
|
||||
this._matrix = new Matrix4();
|
||||
this._quat = new Quaternion();
|
||||
// Pre-allocate _color so the hidden class stays stable, set color mutates it in place rather than re-binding the field.
|
||||
this._color = new Color();
|
||||
this._dirty = 0;
|
||||
// Skew in degrees and transform-origin in object-space.
|
||||
// applySkewOrigin computes Math.tan inline per non-zero axis, so we only carry the user-facing angle here.
|
||||
this._skewX = 0;
|
||||
this._skewY = 0;
|
||||
this._skewZ = 0;
|
||||
this._originX = 0;
|
||||
this._originY = 0;
|
||||
this._originZ = 0;
|
||||
// Skip the position-only fast path in _flush whenever any skew or origin is non-zero, since both modify the matrix beyond pure translation.
|
||||
this._hasSkewOrigin = false;
|
||||
// Cache the binding dirty queue once so per-frame setters skip a property hop.
|
||||
/** @type {Instance[]} */
|
||||
this._dirtyList = binding.dirtyList;
|
||||
// Cache parent capability flags once so per-frame setters skip prototype-chain in checks.
|
||||
const parent = binding.mesh;
|
||||
this._hasSetColor = 'setColorAt' in parent;
|
||||
this._hasSetVisible = 'setVisibleAt' in parent;
|
||||
this._hasGetVisible = 'getVisibleAt' in parent;
|
||||
|
||||
parent.getMatrixAt(id, this._matrix);
|
||||
if (this._matrix.elements[15] === 0) this._matrix.identity();
|
||||
this._matrix.decompose(this._position, this._quat, this._scale);
|
||||
this._rotation.setFromQuaternion(this._quat, 'XYZ');
|
||||
|
||||
if ('getColorAt' in parent && 'instanceColor' in parent && parent.instanceColor) {
|
||||
parent.getColorAt(id, this._color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} flag
|
||||
*/
|
||||
_markDirty(flag) {
|
||||
// Enqueue once per frame, later flags only OR into _dirty without re-pushing to the queue.
|
||||
if (this._dirty === 0) this._dirtyList.push(this);
|
||||
this._dirty |= flag;
|
||||
}
|
||||
|
||||
_flush() {
|
||||
const d = this._dirty;
|
||||
if (!d) return;
|
||||
const m = this._matrix;
|
||||
const p = this._position;
|
||||
if (d === DIRTY_POS && !this._hasSkewOrigin) {
|
||||
const e = m.elements;
|
||||
e[12] = p.x; e[13] = p.y; e[14] = p.z;
|
||||
} else {
|
||||
const q = this._quat;
|
||||
if (d & DIRTY_ROT) q.setFromEuler(this._rotation);
|
||||
m.compose(p, q, this._scale);
|
||||
if (this._hasSkewOrigin) {
|
||||
applySkewOrigin(m.elements, this._skewX, this._skewY, this._skewZ, this._originX, this._originY, this._originZ);
|
||||
}
|
||||
}
|
||||
this.parent.setMatrixAt(this.id, m);
|
||||
this._dirty = 0;
|
||||
}
|
||||
|
||||
get x() { return this._position.x; }
|
||||
set x(v) { this._position.x = v; this._markDirty(DIRTY_POS); }
|
||||
|
||||
get y() { return this._position.y; }
|
||||
set y(v) { this._position.y = v; this._markDirty(DIRTY_POS); }
|
||||
|
||||
get z() { return this._position.z; }
|
||||
set z(v) { this._position.z = v; this._markDirty(DIRTY_POS); }
|
||||
|
||||
get rotateX() { return radToDeg(this._rotation.x); }
|
||||
set rotateX(v) { this._rotation.x = degToRad(v); this._markDirty(DIRTY_ROT); }
|
||||
|
||||
get rotateY() { return radToDeg(this._rotation.y); }
|
||||
set rotateY(v) { this._rotation.y = degToRad(v); this._markDirty(DIRTY_ROT); }
|
||||
|
||||
get rotateZ() { return radToDeg(this._rotation.z); }
|
||||
set rotateZ(v) { this._rotation.z = degToRad(v); this._markDirty(DIRTY_ROT); }
|
||||
|
||||
get scaleX() { return this._scale.x; }
|
||||
set scaleX(v) { this._scale.x = v; this._markDirty(DIRTY_SCALE); }
|
||||
|
||||
get scaleY() { return this._scale.y; }
|
||||
set scaleY(v) { this._scale.y = v; this._markDirty(DIRTY_SCALE); }
|
||||
|
||||
get scaleZ() { return this._scale.z; }
|
||||
set scaleZ(v) { this._scale.z = v; this._markDirty(DIRTY_SCALE); }
|
||||
|
||||
get scale() { return this._scale.x; }
|
||||
set scale(v) {
|
||||
const s = this._scale;
|
||||
s.x = v; s.y = v; s.z = v;
|
||||
this._markDirty(DIRTY_SCALE);
|
||||
}
|
||||
|
||||
get skewX() { return this._skewX; }
|
||||
set skewX(v) {
|
||||
this._skewX = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get skewY() { return this._skewY; }
|
||||
set skewY(v) {
|
||||
this._skewY = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get skewZ() { return this._skewZ; }
|
||||
set skewZ(v) {
|
||||
this._skewZ = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get transformOriginX() { return this._originX; }
|
||||
set transformOriginX(v) {
|
||||
this._originX = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get transformOriginY() { return this._originY; }
|
||||
set transformOriginY(v) {
|
||||
this._originY = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get transformOriginZ() { return this._originZ; }
|
||||
set transformOriginZ(v) {
|
||||
this._originZ = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get opacity() {
|
||||
return readScalar(/** @type {any} */(this.parent).material, 'opacity', PATH_DIRECT, 1);
|
||||
}
|
||||
/** @param {number} v */
|
||||
set opacity(v) {
|
||||
writeScalar(/** @type {any} */(this.parent).material, 'opacity', v, PATH_DIRECT);
|
||||
}
|
||||
|
||||
get visible() {
|
||||
return this._hasGetVisible ? /** @type {any} */(this.parent).getVisibleAt(this.id) : true;
|
||||
}
|
||||
/** @param {boolean} v */
|
||||
set visible(v) {
|
||||
if (this._hasSetVisible) /** @type {any} */(this.parent).setVisibleAt(this.id, v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes pending matrix writes for every dirty instance of `mesh`.
|
||||
* Called automatically before each render. Call it yourself if you read
|
||||
* `mesh.instanceMatrix` between an animation tick and the next render.
|
||||
*
|
||||
* @param {InstanceParent} mesh
|
||||
*/
|
||||
function commitChanges(mesh) {
|
||||
const binding = bindings.get(mesh);
|
||||
if (binding) binding.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of per-instance adapters for `mesh`. Index by id, deleted slots on `BatchedMesh` are `null`. Pass the array (or a slice / a single element) to `animate()`.
|
||||
*
|
||||
* animate(getInstances(mesh), { x: 100, delay: stagger(5) });
|
||||
* animate(getInstances(mesh)[42], { scale: 2 });
|
||||
*
|
||||
* The same array reference is preserved across `mesh.count` / `addInstance` / `deleteInstance` calls. Entries are pushed, nulled, or truncated in place. Animations bound to an outdated reference keep tweening their original adapters.
|
||||
*
|
||||
* `mesh.onBeforeRender` is replaced with an accessor that flushes
|
||||
* pending instance writes before each render and forwards to your
|
||||
* handler. Assigning your own `mesh.onBeforeRender = fn` keeps the
|
||||
* auto-flush, but reading `mesh.onBeforeRender` afterwards returns the
|
||||
* chained dispatcher rather than `fn` itself, so identity checks
|
||||
* (`mesh.onBeforeRender === fn`) will not match.
|
||||
*
|
||||
* @param {InstanceParent} mesh
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
function getInstances(mesh) {
|
||||
let binding = bindings.get(mesh);
|
||||
if (!binding) {
|
||||
binding = new InstanceBinding(mesh);
|
||||
bindings.set(mesh, binding);
|
||||
}
|
||||
if (mesh instanceof BatchedMesh) {
|
||||
return refreshBatched(binding);
|
||||
}
|
||||
return refreshInstanced(binding);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
function refreshInstanced(binding) {
|
||||
const mesh = /** @type {InstancedMesh} */(binding.mesh);
|
||||
const count = mesh.count;
|
||||
const arr = binding.instances;
|
||||
if (arr.length === 0 && count > 0) {
|
||||
arr.length = count;
|
||||
for (let i = 0; i < count; i++) arr[i] = new Instance(binding, i);
|
||||
return arr;
|
||||
}
|
||||
if (arr.length < count) {
|
||||
for (let i = arr.length; i < count; i++) arr.push(new Instance(binding, i));
|
||||
} else if (arr.length > count) {
|
||||
arr.length = count;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
function refreshBatched(binding) {
|
||||
const mesh = /** @type {BatchedMesh} */(binding.mesh);
|
||||
const arr = binding.instances;
|
||||
// Read three internal _instanceInfo to skip slots marked inactive by deleteInstance.
|
||||
// Iterate the full slot count, not instanceCount, since deleted slots leave gaps but live ids past them must still be visited.
|
||||
const instanceInfo = /** @type {{ _instanceInfo?: { active: boolean }[] }} */(mesh)._instanceInfo ?? [];
|
||||
const len = instanceInfo.length;
|
||||
if (arr.length < len) arr.length = len;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const info = instanceInfo[i];
|
||||
const inactive = info && info.active === false;
|
||||
if (inactive) {
|
||||
arr[i] = null;
|
||||
} else if (!arr[i]) {
|
||||
arr[i] = new Instance(binding, i);
|
||||
}
|
||||
}
|
||||
if (arr.length > len) arr.length = len;
|
||||
return arr;
|
||||
}
|
||||
|
||||
const instanceAdapter = threeAdapter.registerTargetAdapter((t) => t instanceof Instance);
|
||||
instanceAdapter.registerProperty('color',
|
||||
(t) => readColorHex(t._color),
|
||||
(t, _, tw) => {
|
||||
if (!t._hasSetColor) return;
|
||||
const ns = tw._numbers;
|
||||
t._color.setRGB(ns[0] * COLOR_NORM, ns[1] * COLOR_NORM, ns[2] * COLOR_NORM, SRGBColorSpace);
|
||||
const p = /** @type {any} */(t.parent);
|
||||
p.setColorAt(t.id, t._color);
|
||||
if (p.instanceColor) p.instanceColor.needsUpdate = true;
|
||||
},
|
||||
);
|
||||
// Shorthand 3-token string x y z routed via the engine COMPLEX path.
|
||||
// The setter reads tween _numbers for the per-frame lerped triplet.
|
||||
instanceAdapter.registerProperty('transformOrigin',
|
||||
(t) => `${t._originX} ${t._originY} ${t._originZ}`,
|
||||
(t, _, tw) => {
|
||||
const ns = tw._numbers;
|
||||
t._originX = ns[0];
|
||||
t._originY = ns[1];
|
||||
t._originZ = ns[2];
|
||||
t._hasSkewOrigin = hasSkewOrigin(t);
|
||||
t._markDirty(DIRTY_SKEW);
|
||||
},
|
||||
);
|
||||
|
||||
export { commitChanges, getInstances };
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var three = require('three');
|
||||
var number = require('../../utils/number.cjs');
|
||||
var adapter = require('./adapter.cjs');
|
||||
var helpers = require('./helpers.cjs');
|
||||
|
||||
/**
|
||||
* `Object3D` adapter. Maps flat properties (position, rotation, scale, opacity, color, visible, light / audio / camera specifics) onto the matching three.js fields, and auto-detects material props (direct / uniform / TSL `UniformNode`) on the target's `material` at tween creation.
|
||||
*/
|
||||
|
||||
|
||||
const colorTarget = (t) => t.isLight ? t : t.material;
|
||||
|
||||
// Per-mesh skew and transformOrigin state, stored under a private symbol so we add one hidden property instead of polluting the Object3D surface with seven underscored fields.
|
||||
const skewSymbol = Symbol('animejs.skewOrigin');
|
||||
|
||||
// Fallback opacity storage for Object3D targets without a material such as Groups or CSS2DObjects.
|
||||
// Without it reads always return the default 1, so reverse-direction tweens between two non-default values collapse to a no-op delta and the visibility flip never fires on the way back.
|
||||
const opacitySymbol = Symbol('animejs.opacity');
|
||||
|
||||
/**
|
||||
* Sets `o.visible` based on opacity and current scale. If `opacity` is omitted, reads it from `o.material` (defaults to `1` when no material is present).
|
||||
*
|
||||
* @param {Object3D & { material?: import('three').Material | import('three').Material[] }} o
|
||||
* @param {number} [opacity]
|
||||
*/
|
||||
function setVisibility(o, opacity) {
|
||||
if (opacity === undefined) {
|
||||
if (o.material) {
|
||||
opacity = helpers.readScalar(o.material, 'opacity', helpers.PATH_DIRECT, 1);
|
||||
} else {
|
||||
const v = o[opacitySymbol];
|
||||
opacity = v === undefined ? 1 : v;
|
||||
}
|
||||
}
|
||||
const s = o.scale;
|
||||
o.visible = !!(opacity && s.x && s.y && s.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a per-mesh `updateMatrix` override on first skew / transformOrigin write. The override calls the original three.js compose, then patches the result with `applySkewOrigin` whenever any axis is non-zero. Idempotent.
|
||||
*
|
||||
* @param {any} mesh
|
||||
* @return {{ skewX: number, skewY: number, skewZ: number, originX: number, originY: number, originZ: number }}
|
||||
*/
|
||||
function installSkewMatrix(mesh) {
|
||||
let s = mesh[skewSymbol];
|
||||
if (s) return s;
|
||||
s = mesh[skewSymbol] = { skewX: 0, skewY: 0, skewZ: 0, originX: 0, originY: 0, originZ: 0 };
|
||||
const original = mesh.updateMatrix;
|
||||
mesh.updateMatrix = function () {
|
||||
original.call(this);
|
||||
const st = this[skewSymbol];
|
||||
if (st.skewX !== 0 || st.skewY !== 0 || st.skewZ !== 0 || st.originX !== 0 || st.originY !== 0 || st.originZ !== 0) {
|
||||
helpers.applySkewOrigin(this.matrix.elements, st.skewX, st.skewY, st.skewZ, st.originX, st.originY, st.originZ);
|
||||
}
|
||||
};
|
||||
return s;
|
||||
}
|
||||
|
||||
const threeObject3D = adapter.threeAdapter.registerTargetAdapter((t) => t instanceof three.Object3D);
|
||||
|
||||
// Position
|
||||
threeObject3D.registerProperty('x', (t) => t.position.x, (t, v) => { t.position.x = v; });
|
||||
threeObject3D.registerProperty('y', (t) => t.position.y, (t, v) => { t.position.y = v; });
|
||||
threeObject3D.registerProperty('z', (t) => t.position.z, (t, v) => { t.position.z = v; });
|
||||
|
||||
// Rotation in degrees
|
||||
threeObject3D.registerProperty('rotateX', (t) => number.radToDeg(t.rotation.x), (t, v) => { t.rotation.x = number.degToRad(v); });
|
||||
threeObject3D.registerProperty('rotateY', (t) => number.radToDeg(t.rotation.y), (t, v) => { t.rotation.y = number.degToRad(v); });
|
||||
threeObject3D.registerProperty('rotateZ', (t) => number.radToDeg(t.rotation.z), (t, v) => { t.rotation.z = number.degToRad(v); });
|
||||
|
||||
// Scale per-axis and uniform
|
||||
threeObject3D.registerProperty('scaleX', (t) => t.scale.x, (t, v) => { t.scale.x = v; setVisibility(t); });
|
||||
threeObject3D.registerProperty('scaleY', (t) => t.scale.y, (t, v) => { t.scale.y = v; setVisibility(t); });
|
||||
threeObject3D.registerProperty('scaleZ', (t) => t.scale.z, (t, v) => { t.scale.z = v; setVisibility(t); });
|
||||
threeObject3D.registerProperty('scale',
|
||||
(t) => t.scale.x,
|
||||
(t, v) => {
|
||||
t.scale.x = v; t.scale.y = v; t.scale.z = v;
|
||||
setVisibility(t);
|
||||
},
|
||||
);
|
||||
|
||||
// Material
|
||||
threeObject3D.registerProperty('visible', (t) => t.visible, (t, v) => { t.visible = !!v; });
|
||||
threeObject3D.registerProperty('opacity',
|
||||
(t) => {
|
||||
if (t.material) return helpers.readScalar(t.material, 'opacity', helpers.PATH_DIRECT, 1);
|
||||
const v = t[opacitySymbol];
|
||||
return v === undefined ? 1 : v;
|
||||
},
|
||||
(t, v) => {
|
||||
if (t.material) helpers.writeScalar(t.material, 'opacity', v, helpers.PATH_DIRECT);
|
||||
else t[opacitySymbol] = v;
|
||||
setVisibility(t, v);
|
||||
},
|
||||
(t) => !t.isLight,
|
||||
);
|
||||
threeObject3D.registerProperty('color',
|
||||
(t) => helpers.readColorAt(colorTarget(t), 'color', helpers.PATH_DIRECT),
|
||||
(t, _, tw) => helpers.writeColorAt(colorTarget(t), 'color', tw._numbers, helpers.PATH_DIRECT),
|
||||
);
|
||||
|
||||
// HemisphereLight
|
||||
threeObject3D.registerProperty('groundColor',
|
||||
(t) => helpers.readColorAt(t, 'groundColor', helpers.PATH_DIRECT),
|
||||
(t, _, tw) => helpers.writeColorAt(t, 'groundColor', tw._numbers, helpers.PATH_DIRECT),
|
||||
(t) => !!t.groundColor,
|
||||
);
|
||||
|
||||
// Scene background, lazily initializes scene background to a Color on first write so the user does not have to set one upfront.
|
||||
threeObject3D.registerProperty('background',
|
||||
(t) => {
|
||||
const bg = /** @type {any} */(t).background;
|
||||
return bg && bg.isColor ? helpers.readColorHex(bg) : '#000000';
|
||||
},
|
||||
(t, _, tw) => {
|
||||
const scene = /** @type {any} */(t);
|
||||
let bg = scene.background;
|
||||
if (!bg || !bg.isColor) {
|
||||
bg = new three.Color();
|
||||
scene.background = bg;
|
||||
}
|
||||
const ns = tw._numbers;
|
||||
bg.setRGB(ns[0] * helpers.COLOR_NORM, ns[1] * helpers.COLOR_NORM, ns[2] * helpers.COLOR_NORM, three.SRGBColorSpace);
|
||||
},
|
||||
(t) => !!t.isScene,
|
||||
);
|
||||
|
||||
// Method-bridged props for Audio and PerspectiveCamera focalLength, read via getXxx and write via setXxx.
|
||||
const registerMethodProp = (apiName, getter, setter, gate) => {
|
||||
threeObject3D.registerProperty(apiName,
|
||||
(t) => t[getter](),
|
||||
(t, v) => { t[setter](v); },
|
||||
(t) => !!t[gate],
|
||||
);
|
||||
};
|
||||
registerMethodProp('volume', 'getVolume', 'setVolume', 'setVolume');
|
||||
// PositionalAudio
|
||||
registerMethodProp('refDistance', 'getRefDistance', 'setRefDistance', 'setRefDistance');
|
||||
registerMethodProp('rolloffFactor', 'getRolloffFactor', 'setRolloffFactor', 'setRefDistance');
|
||||
registerMethodProp('maxDistance', 'getMaxDistance', 'setMaxDistance', 'setRefDistance');
|
||||
// PerspectiveCamera
|
||||
registerMethodProp('focalLength', 'getFocalLength', 'setFocalLength', 'setFocalLength');
|
||||
|
||||
// Camera projection-update props, setter writes the value then calls updateProjectionMatrix.
|
||||
const registerCameraProp = (apiName, gate) => {
|
||||
threeObject3D.registerProperty(apiName,
|
||||
(t) => t[apiName],
|
||||
(t, v) => { t[apiName] = v; t.updateProjectionMatrix(); },
|
||||
gate,
|
||||
);
|
||||
};
|
||||
const isPersp = (t) => !!t.isPerspectiveCamera;
|
||||
const isOrtho = (t) => !!t.isOrthographicCamera;
|
||||
registerCameraProp('fov', isPersp);
|
||||
registerCameraProp('aspect', isPersp);
|
||||
registerCameraProp('left', isOrtho);
|
||||
registerCameraProp('right', isOrtho);
|
||||
registerCameraProp('top', isOrtho);
|
||||
registerCameraProp('bottom', isOrtho);
|
||||
|
||||
// Skew in degrees and transform-origin in object-space.
|
||||
// Patches mesh updateMatrix on first write so the standard PRS compose is followed by an in-place skew and origin shift.
|
||||
// Reads default to 0 for meshes that have never been written.
|
||||
/**
|
||||
* @param {String} apiName
|
||||
* @param {String} key
|
||||
*/
|
||||
const registerSkewProp = (apiName, key) => {
|
||||
threeObject3D.registerProperty(apiName,
|
||||
(t) => { const s = /** @type {any} */(t)[skewSymbol]; return s ? s[key] : 0; },
|
||||
(t, v) => { installSkewMatrix(t)[key] = v; },
|
||||
);
|
||||
};
|
||||
registerSkewProp('skewX', 'skewX');
|
||||
registerSkewProp('skewY', 'skewY');
|
||||
registerSkewProp('skewZ', 'skewZ');
|
||||
registerSkewProp('transformOriginX', 'originX');
|
||||
registerSkewProp('transformOriginY', 'originY');
|
||||
registerSkewProp('transformOriginZ', 'originZ');
|
||||
|
||||
// Shorthand 3-token string x y z or 2-string from-to array routed via the engine COMPLEX path.
|
||||
// The setter reads tween _numbers for the per-frame lerped triplet.
|
||||
threeObject3D.registerProperty('transformOrigin',
|
||||
(t) => {
|
||||
const s = /** @type {any} */(t)[skewSymbol];
|
||||
return s ? `${s.originX} ${s.originY} ${s.originZ}` : '0 0 0';
|
||||
},
|
||||
(t, _, tw) => {
|
||||
const s = installSkewMatrix(t);
|
||||
const ns = tw._numbers;
|
||||
s.originX = ns[0];
|
||||
s.originY = ns[1];
|
||||
s.originZ = ns[2];
|
||||
},
|
||||
);
|
||||
|
||||
// Shared by both camera types.
|
||||
const isCamera = (t) => !!t.isPerspectiveCamera || !!t.isOrthographicCamera;
|
||||
registerCameraProp('near', isCamera);
|
||||
registerCameraProp('far', isCamera);
|
||||
registerCameraProp('zoom', isCamera);
|
||||
|
||||
// Auto-detection for material props on meshes and direct Vector / Color fields on the target is provided by the shared resolvers in resolvers.js.
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { Object3D, Color, SRGBColorSpace } from 'three';
|
||||
import { radToDeg, degToRad } from '../../utils/number.js';
|
||||
import { threeAdapter } from './adapter.js';
|
||||
import { readScalar, PATH_DIRECT, writeScalar, readColorAt, writeColorAt, readColorHex, COLOR_NORM, applySkewOrigin } from './helpers.js';
|
||||
|
||||
/**
|
||||
* `Object3D` adapter. Maps flat properties (position, rotation, scale, opacity, color, visible, light / audio / camera specifics) onto the matching three.js fields, and auto-detects material props (direct / uniform / TSL `UniformNode`) on the target's `material` at tween creation.
|
||||
*/
|
||||
|
||||
|
||||
const colorTarget = (t) => t.isLight ? t : t.material;
|
||||
|
||||
// Per-mesh skew and transformOrigin state, stored under a private symbol so we add one hidden property instead of polluting the Object3D surface with seven underscored fields.
|
||||
const skewSymbol = Symbol('animejs.skewOrigin');
|
||||
|
||||
// Fallback opacity storage for Object3D targets without a material such as Groups or CSS2DObjects.
|
||||
// Without it reads always return the default 1, so reverse-direction tweens between two non-default values collapse to a no-op delta and the visibility flip never fires on the way back.
|
||||
const opacitySymbol = Symbol('animejs.opacity');
|
||||
|
||||
/**
|
||||
* Sets `o.visible` based on opacity and current scale. If `opacity` is omitted, reads it from `o.material` (defaults to `1` when no material is present).
|
||||
*
|
||||
* @param {Object3D & { material?: import('three').Material | import('three').Material[] }} o
|
||||
* @param {number} [opacity]
|
||||
*/
|
||||
function setVisibility(o, opacity) {
|
||||
if (opacity === undefined) {
|
||||
if (o.material) {
|
||||
opacity = readScalar(o.material, 'opacity', PATH_DIRECT, 1);
|
||||
} else {
|
||||
const v = o[opacitySymbol];
|
||||
opacity = v === undefined ? 1 : v;
|
||||
}
|
||||
}
|
||||
const s = o.scale;
|
||||
o.visible = !!(opacity && s.x && s.y && s.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a per-mesh `updateMatrix` override on first skew / transformOrigin write. The override calls the original three.js compose, then patches the result with `applySkewOrigin` whenever any axis is non-zero. Idempotent.
|
||||
*
|
||||
* @param {any} mesh
|
||||
* @return {{ skewX: number, skewY: number, skewZ: number, originX: number, originY: number, originZ: number }}
|
||||
*/
|
||||
function installSkewMatrix(mesh) {
|
||||
let s = mesh[skewSymbol];
|
||||
if (s) return s;
|
||||
s = mesh[skewSymbol] = { skewX: 0, skewY: 0, skewZ: 0, originX: 0, originY: 0, originZ: 0 };
|
||||
const original = mesh.updateMatrix;
|
||||
mesh.updateMatrix = function () {
|
||||
original.call(this);
|
||||
const st = this[skewSymbol];
|
||||
if (st.skewX !== 0 || st.skewY !== 0 || st.skewZ !== 0 || st.originX !== 0 || st.originY !== 0 || st.originZ !== 0) {
|
||||
applySkewOrigin(this.matrix.elements, st.skewX, st.skewY, st.skewZ, st.originX, st.originY, st.originZ);
|
||||
}
|
||||
};
|
||||
return s;
|
||||
}
|
||||
|
||||
const threeObject3D = threeAdapter.registerTargetAdapter((t) => t instanceof Object3D);
|
||||
|
||||
// Position
|
||||
threeObject3D.registerProperty('x', (t) => t.position.x, (t, v) => { t.position.x = v; });
|
||||
threeObject3D.registerProperty('y', (t) => t.position.y, (t, v) => { t.position.y = v; });
|
||||
threeObject3D.registerProperty('z', (t) => t.position.z, (t, v) => { t.position.z = v; });
|
||||
|
||||
// Rotation in degrees
|
||||
threeObject3D.registerProperty('rotateX', (t) => radToDeg(t.rotation.x), (t, v) => { t.rotation.x = degToRad(v); });
|
||||
threeObject3D.registerProperty('rotateY', (t) => radToDeg(t.rotation.y), (t, v) => { t.rotation.y = degToRad(v); });
|
||||
threeObject3D.registerProperty('rotateZ', (t) => radToDeg(t.rotation.z), (t, v) => { t.rotation.z = degToRad(v); });
|
||||
|
||||
// Scale per-axis and uniform
|
||||
threeObject3D.registerProperty('scaleX', (t) => t.scale.x, (t, v) => { t.scale.x = v; setVisibility(t); });
|
||||
threeObject3D.registerProperty('scaleY', (t) => t.scale.y, (t, v) => { t.scale.y = v; setVisibility(t); });
|
||||
threeObject3D.registerProperty('scaleZ', (t) => t.scale.z, (t, v) => { t.scale.z = v; setVisibility(t); });
|
||||
threeObject3D.registerProperty('scale',
|
||||
(t) => t.scale.x,
|
||||
(t, v) => {
|
||||
t.scale.x = v; t.scale.y = v; t.scale.z = v;
|
||||
setVisibility(t);
|
||||
},
|
||||
);
|
||||
|
||||
// Material
|
||||
threeObject3D.registerProperty('visible', (t) => t.visible, (t, v) => { t.visible = !!v; });
|
||||
threeObject3D.registerProperty('opacity',
|
||||
(t) => {
|
||||
if (t.material) return readScalar(t.material, 'opacity', PATH_DIRECT, 1);
|
||||
const v = t[opacitySymbol];
|
||||
return v === undefined ? 1 : v;
|
||||
},
|
||||
(t, v) => {
|
||||
if (t.material) writeScalar(t.material, 'opacity', v, PATH_DIRECT);
|
||||
else t[opacitySymbol] = v;
|
||||
setVisibility(t, v);
|
||||
},
|
||||
(t) => !t.isLight,
|
||||
);
|
||||
threeObject3D.registerProperty('color',
|
||||
(t) => readColorAt(colorTarget(t), 'color', PATH_DIRECT),
|
||||
(t, _, tw) => writeColorAt(colorTarget(t), 'color', tw._numbers, PATH_DIRECT),
|
||||
);
|
||||
|
||||
// HemisphereLight
|
||||
threeObject3D.registerProperty('groundColor',
|
||||
(t) => readColorAt(t, 'groundColor', PATH_DIRECT),
|
||||
(t, _, tw) => writeColorAt(t, 'groundColor', tw._numbers, PATH_DIRECT),
|
||||
(t) => !!t.groundColor,
|
||||
);
|
||||
|
||||
// Scene background, lazily initializes scene background to a Color on first write so the user does not have to set one upfront.
|
||||
threeObject3D.registerProperty('background',
|
||||
(t) => {
|
||||
const bg = /** @type {any} */(t).background;
|
||||
return bg && bg.isColor ? readColorHex(bg) : '#000000';
|
||||
},
|
||||
(t, _, tw) => {
|
||||
const scene = /** @type {any} */(t);
|
||||
let bg = scene.background;
|
||||
if (!bg || !bg.isColor) {
|
||||
bg = new Color();
|
||||
scene.background = bg;
|
||||
}
|
||||
const ns = tw._numbers;
|
||||
bg.setRGB(ns[0] * COLOR_NORM, ns[1] * COLOR_NORM, ns[2] * COLOR_NORM, SRGBColorSpace);
|
||||
},
|
||||
(t) => !!t.isScene,
|
||||
);
|
||||
|
||||
// Method-bridged props for Audio and PerspectiveCamera focalLength, read via getXxx and write via setXxx.
|
||||
const registerMethodProp = (apiName, getter, setter, gate) => {
|
||||
threeObject3D.registerProperty(apiName,
|
||||
(t) => t[getter](),
|
||||
(t, v) => { t[setter](v); },
|
||||
(t) => !!t[gate],
|
||||
);
|
||||
};
|
||||
registerMethodProp('volume', 'getVolume', 'setVolume', 'setVolume');
|
||||
// PositionalAudio
|
||||
registerMethodProp('refDistance', 'getRefDistance', 'setRefDistance', 'setRefDistance');
|
||||
registerMethodProp('rolloffFactor', 'getRolloffFactor', 'setRolloffFactor', 'setRefDistance');
|
||||
registerMethodProp('maxDistance', 'getMaxDistance', 'setMaxDistance', 'setRefDistance');
|
||||
// PerspectiveCamera
|
||||
registerMethodProp('focalLength', 'getFocalLength', 'setFocalLength', 'setFocalLength');
|
||||
|
||||
// Camera projection-update props, setter writes the value then calls updateProjectionMatrix.
|
||||
const registerCameraProp = (apiName, gate) => {
|
||||
threeObject3D.registerProperty(apiName,
|
||||
(t) => t[apiName],
|
||||
(t, v) => { t[apiName] = v; t.updateProjectionMatrix(); },
|
||||
gate,
|
||||
);
|
||||
};
|
||||
const isPersp = (t) => !!t.isPerspectiveCamera;
|
||||
const isOrtho = (t) => !!t.isOrthographicCamera;
|
||||
registerCameraProp('fov', isPersp);
|
||||
registerCameraProp('aspect', isPersp);
|
||||
registerCameraProp('left', isOrtho);
|
||||
registerCameraProp('right', isOrtho);
|
||||
registerCameraProp('top', isOrtho);
|
||||
registerCameraProp('bottom', isOrtho);
|
||||
|
||||
// Skew in degrees and transform-origin in object-space.
|
||||
// Patches mesh updateMatrix on first write so the standard PRS compose is followed by an in-place skew and origin shift.
|
||||
// Reads default to 0 for meshes that have never been written.
|
||||
/**
|
||||
* @param {String} apiName
|
||||
* @param {String} key
|
||||
*/
|
||||
const registerSkewProp = (apiName, key) => {
|
||||
threeObject3D.registerProperty(apiName,
|
||||
(t) => { const s = /** @type {any} */(t)[skewSymbol]; return s ? s[key] : 0; },
|
||||
(t, v) => { installSkewMatrix(t)[key] = v; },
|
||||
);
|
||||
};
|
||||
registerSkewProp('skewX', 'skewX');
|
||||
registerSkewProp('skewY', 'skewY');
|
||||
registerSkewProp('skewZ', 'skewZ');
|
||||
registerSkewProp('transformOriginX', 'originX');
|
||||
registerSkewProp('transformOriginY', 'originY');
|
||||
registerSkewProp('transformOriginZ', 'originZ');
|
||||
|
||||
// Shorthand 3-token string x y z or 2-string from-to array routed via the engine COMPLEX path.
|
||||
// The setter reads tween _numbers for the per-frame lerped triplet.
|
||||
threeObject3D.registerProperty('transformOrigin',
|
||||
(t) => {
|
||||
const s = /** @type {any} */(t)[skewSymbol];
|
||||
return s ? `${s.originX} ${s.originY} ${s.originZ}` : '0 0 0';
|
||||
},
|
||||
(t, _, tw) => {
|
||||
const s = installSkewMatrix(t);
|
||||
const ns = tw._numbers;
|
||||
s.originX = ns[0];
|
||||
s.originY = ns[1];
|
||||
s.originZ = ns[2];
|
||||
},
|
||||
);
|
||||
|
||||
// Shared by both camera types.
|
||||
const isCamera = (t) => !!t.isPerspectiveCamera || !!t.isOrthographicCamera;
|
||||
registerCameraProp('near', isCamera);
|
||||
registerCameraProp('far', isCamera);
|
||||
registerCameraProp('zoom', isCamera);
|
||||
|
||||
// Auto-detection for material props on meshes and direct Vector / Color fields on the target is provided by the shared resolvers in resolvers.js.
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var adapter = require('./adapter.cjs');
|
||||
var number = require('../../utils/number.cjs');
|
||||
var helpers = require('./helpers.cjs');
|
||||
|
||||
/**
|
||||
* Global property resolvers for three.js targets. Auto-detect `Color`-typed properties, `Vector2/3/4` axis components, shader uniforms, and TSL `UniformNode` slots on any three.js object. For mesh-like targets, a second resolver walks to `target.material` and runs the same detection there.
|
||||
*/
|
||||
|
||||
|
||||
const identity = (t) => t;
|
||||
const getMaterial = (t) => t.material;
|
||||
|
||||
const directColorCache = [{}, {}, {}];
|
||||
const directScalarCache = [{}, {}, {}];
|
||||
const directVectorCache = [{}, {}, {}];
|
||||
|
||||
const materialColorCache = [{}, {}, {}];
|
||||
const materialScalarCache = [{}, {}, {}];
|
||||
const materialVectorCache = [{}, {}, {}];
|
||||
|
||||
const buildEntry = (name, d, getHost, colorCaches, scalarCaches, vectorCaches) => {
|
||||
const path = d.path;
|
||||
if (d.kind === helpers.KIND_COLOR) {
|
||||
const cache = colorCaches[path];
|
||||
return cache[name] || (cache[name] = {
|
||||
get: (t) => helpers.readColorAt(getHost(t), name, path),
|
||||
set: (t, _, tw) => helpers.writeColorAt(getHost(t), name, tw._numbers, path),
|
||||
});
|
||||
}
|
||||
if (d.kind === helpers.KIND_SCALAR) {
|
||||
const cache = scalarCaches[path];
|
||||
return cache[name] || (cache[name] = {
|
||||
get: (t) => helpers.readScalar(getHost(t), name, path),
|
||||
set: (t, v) => helpers.writeScalar(getHost(t), name, v, path),
|
||||
});
|
||||
}
|
||||
// KIND_VECTOR
|
||||
const base = d.base;
|
||||
const axis = d.axis;
|
||||
const cache = vectorCaches[path];
|
||||
return cache[name] || (cache[name] = {
|
||||
get: (t) => helpers.readVectorAt(getHost(t), base, axis, path),
|
||||
set: (t, v) => helpers.writeVectorAt(getHost(t), base, axis, v, path),
|
||||
});
|
||||
};
|
||||
|
||||
// Detect direct Color, Vector axis, uniforms, and UniformNode slots on the target.
|
||||
// Numeric or boolean direct fields fall through to the engine OBJECT path.
|
||||
adapter.threeAdapter.registerPropertyResolver((target, name) => {
|
||||
const d = helpers.classifyTargetProp(target, name);
|
||||
if (!d) return null;
|
||||
if (d.kind === helpers.KIND_SCALAR && d.path === helpers.PATH_DIRECT) return null;
|
||||
return buildEntry(name, d, identity, directColorCache, directScalarCache, directVectorCache);
|
||||
});
|
||||
|
||||
// Walk to target.material for meshes and other Object3D subclasses with a material field.
|
||||
// Skip when the target already exposes the name directly so a mesh-level mapping wins.
|
||||
adapter.threeAdapter.registerPropertyResolver((target, name) => {
|
||||
if (target[name] !== undefined) return null;
|
||||
const m = target.material;
|
||||
if (!m) return null;
|
||||
const first = Array.isArray(m) ? m[0] : m;
|
||||
if (!first) return null;
|
||||
const d = helpers.classifyTargetProp(first, name);
|
||||
if (!d) return null;
|
||||
return buildEntry(name, d, getMaterial, materialColorCache, materialScalarCache, materialVectorCache);
|
||||
});
|
||||
|
||||
// Convert angle-named scalar fields between degrees and radians so users animate in degrees on any three.js target.
|
||||
// Object3D Euler rotation is excluded because Euler is not a number, the rotateX/Y/Z mappings handle it.
|
||||
const ANGLE_NAMES = { rotation: 1, angle: 1 };
|
||||
const angleEntries = {};
|
||||
adapter.threeAdapter.registerPropertyResolver((target, name) => {
|
||||
if (!ANGLE_NAMES[name]) return null;
|
||||
if (typeof target[name] !== 'number') return null;
|
||||
return angleEntries[name] || (angleEntries[name] = {
|
||||
get: (t) => number.radToDeg(t[name]),
|
||||
set: (t, v) => { t[name] = number.degToRad(v); },
|
||||
});
|
||||
});
|
||||
|
||||
// Decompose Euler-typed angle fields to axis components in degrees, like rotationX, rotationY, rotationZ when rotation is an Euler.
|
||||
// Object3D mappings win because static adapter props beat resolvers, so this only catches non-Object3D targets with an Euler rotation field.
|
||||
const eulerAxisEntries = {};
|
||||
adapter.threeAdapter.registerPropertyResolver((target, name) => {
|
||||
const axis = helpers.AXIS_MAP[name[name.length - 1]];
|
||||
if (!axis) return null;
|
||||
const base = name.slice(0, -1);
|
||||
if (!ANGLE_NAMES[base]) return null;
|
||||
const v = target[base];
|
||||
if (!v || !v.isEuler) return null;
|
||||
return eulerAxisEntries[name] || (eulerAxisEntries[name] = {
|
||||
get: (t) => number.radToDeg(t[base][axis]),
|
||||
set: (t, v) => { t[base][axis] = number.degToRad(v); },
|
||||
});
|
||||
});
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { threeAdapter } from './adapter.js';
|
||||
import { radToDeg, degToRad } from '../../utils/number.js';
|
||||
import { classifyTargetProp, KIND_SCALAR, PATH_DIRECT, AXIS_MAP, KIND_COLOR, writeColorAt, readColorAt, writeScalar, readScalar, writeVectorAt, readVectorAt } from './helpers.js';
|
||||
|
||||
/**
|
||||
* Global property resolvers for three.js targets. Auto-detect `Color`-typed properties, `Vector2/3/4` axis components, shader uniforms, and TSL `UniformNode` slots on any three.js object. For mesh-like targets, a second resolver walks to `target.material` and runs the same detection there.
|
||||
*/
|
||||
|
||||
|
||||
const identity = (t) => t;
|
||||
const getMaterial = (t) => t.material;
|
||||
|
||||
const directColorCache = [{}, {}, {}];
|
||||
const directScalarCache = [{}, {}, {}];
|
||||
const directVectorCache = [{}, {}, {}];
|
||||
|
||||
const materialColorCache = [{}, {}, {}];
|
||||
const materialScalarCache = [{}, {}, {}];
|
||||
const materialVectorCache = [{}, {}, {}];
|
||||
|
||||
const buildEntry = (name, d, getHost, colorCaches, scalarCaches, vectorCaches) => {
|
||||
const path = d.path;
|
||||
if (d.kind === KIND_COLOR) {
|
||||
const cache = colorCaches[path];
|
||||
return cache[name] || (cache[name] = {
|
||||
get: (t) => readColorAt(getHost(t), name, path),
|
||||
set: (t, _, tw) => writeColorAt(getHost(t), name, tw._numbers, path),
|
||||
});
|
||||
}
|
||||
if (d.kind === KIND_SCALAR) {
|
||||
const cache = scalarCaches[path];
|
||||
return cache[name] || (cache[name] = {
|
||||
get: (t) => readScalar(getHost(t), name, path),
|
||||
set: (t, v) => writeScalar(getHost(t), name, v, path),
|
||||
});
|
||||
}
|
||||
// KIND_VECTOR
|
||||
const base = d.base;
|
||||
const axis = d.axis;
|
||||
const cache = vectorCaches[path];
|
||||
return cache[name] || (cache[name] = {
|
||||
get: (t) => readVectorAt(getHost(t), base, axis, path),
|
||||
set: (t, v) => writeVectorAt(getHost(t), base, axis, v, path),
|
||||
});
|
||||
};
|
||||
|
||||
// Detect direct Color, Vector axis, uniforms, and UniformNode slots on the target.
|
||||
// Numeric or boolean direct fields fall through to the engine OBJECT path.
|
||||
threeAdapter.registerPropertyResolver((target, name) => {
|
||||
const d = classifyTargetProp(target, name);
|
||||
if (!d) return null;
|
||||
if (d.kind === KIND_SCALAR && d.path === PATH_DIRECT) return null;
|
||||
return buildEntry(name, d, identity, directColorCache, directScalarCache, directVectorCache);
|
||||
});
|
||||
|
||||
// Walk to target.material for meshes and other Object3D subclasses with a material field.
|
||||
// Skip when the target already exposes the name directly so a mesh-level mapping wins.
|
||||
threeAdapter.registerPropertyResolver((target, name) => {
|
||||
if (target[name] !== undefined) return null;
|
||||
const m = target.material;
|
||||
if (!m) return null;
|
||||
const first = Array.isArray(m) ? m[0] : m;
|
||||
if (!first) return null;
|
||||
const d = classifyTargetProp(first, name);
|
||||
if (!d) return null;
|
||||
return buildEntry(name, d, getMaterial, materialColorCache, materialScalarCache, materialVectorCache);
|
||||
});
|
||||
|
||||
// Convert angle-named scalar fields between degrees and radians so users animate in degrees on any three.js target.
|
||||
// Object3D Euler rotation is excluded because Euler is not a number, the rotateX/Y/Z mappings handle it.
|
||||
const ANGLE_NAMES = { rotation: 1, angle: 1 };
|
||||
const angleEntries = {};
|
||||
threeAdapter.registerPropertyResolver((target, name) => {
|
||||
if (!ANGLE_NAMES[name]) return null;
|
||||
if (typeof target[name] !== 'number') return null;
|
||||
return angleEntries[name] || (angleEntries[name] = {
|
||||
get: (t) => radToDeg(t[name]),
|
||||
set: (t, v) => { t[name] = degToRad(v); },
|
||||
});
|
||||
});
|
||||
|
||||
// Decompose Euler-typed angle fields to axis components in degrees, like rotationX, rotationY, rotationZ when rotation is an Euler.
|
||||
// Object3D mappings win because static adapter props beat resolvers, so this only catches non-Object3D targets with an Euler rotation field.
|
||||
const eulerAxisEntries = {};
|
||||
threeAdapter.registerPropertyResolver((target, name) => {
|
||||
const axis = AXIS_MAP[name[name.length - 1]];
|
||||
if (!axis) return null;
|
||||
const base = name.slice(0, -1);
|
||||
if (!ANGLE_NAMES[base]) return null;
|
||||
const v = target[base];
|
||||
if (!v || !v.isEuler) return null;
|
||||
return eulerAxisEntries[name] || (eulerAxisEntries[name] = {
|
||||
get: (t) => radToDeg(t[base][axis]),
|
||||
set: (t, v) => { t[base][axis] = degToRad(v); },
|
||||
});
|
||||
});
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var three = require('three');
|
||||
var adapter = require('./adapter.cjs');
|
||||
var helpers = require('./helpers.cjs');
|
||||
|
||||
/**
|
||||
* Bare `UniformNode` adapter. Auto-detects `UniformNode` instances and exposes their `.value` for animation. Scalars and booleans animate via `value`, `Color` uniforms via `color`, and `Vector2/3/4` uniforms via `x` / `y` / `z` / `w` axes.
|
||||
*
|
||||
* import 'animejs/bindings/three';
|
||||
* import { uniform } from 'three/tsl';
|
||||
* animate(uniform(0), { value: 1 });
|
||||
* animate(uniform(new Color()), { color: '#0f0' });
|
||||
* animate(uniform(new Vector3()), { x: 1, y: 0.5 });
|
||||
*
|
||||
* `UniformNode` slots assigned to `NodeMaterial` (`material.colorNode`, `material.offsetNode`, ...) are auto-detected by the shared resolvers in `resolvers.js`. Non-uniform nodes (`mix`, `add`, computed expressions), `Matrix3/4` and `Texture` valued uniforms, and `UniformArrayNode` / `BufferNode` are out of scope and fall through to the engine's direct property path.
|
||||
*/
|
||||
|
||||
|
||||
const uniformNode = adapter.threeAdapter.registerTargetAdapter((t) => !!(t && t.isUniformNode));
|
||||
|
||||
// Scalar and bool uniforms animate via the engine OBJECT fallthrough on value, no adapter prop needed since the engine writes uniform value natively.
|
||||
uniformNode.registerProperty('color',
|
||||
(t) => helpers.readColorHex(t.value),
|
||||
(t, _, tw) => {
|
||||
const ns = tw._numbers;
|
||||
t.value.setRGB(ns[0] * helpers.COLOR_NORM, ns[1] * helpers.COLOR_NORM, ns[2] * helpers.COLOR_NORM, three.SRGBColorSpace);
|
||||
},
|
||||
(t) => !!(t.value && t.value.isColor),
|
||||
);
|
||||
uniformNode.registerProperty('x', (t) => t.value.x, (t, v) => { t.value.x = v; }, (t) => helpers.isVectorWith(t.value, 'x'));
|
||||
uniformNode.registerProperty('y', (t) => t.value.y, (t, v) => { t.value.y = v; }, (t) => helpers.isVectorWith(t.value, 'y'));
|
||||
uniformNode.registerProperty('z', (t) => t.value.z, (t, v) => { t.value.z = v; }, (t) => helpers.isVectorWith(t.value, 'z'));
|
||||
uniformNode.registerProperty('w', (t) => t.value.w, (t, v) => { t.value.w = v; }, (t) => helpers.isVectorWith(t.value, 'w'));
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { SRGBColorSpace } from 'three';
|
||||
import { threeAdapter } from './adapter.js';
|
||||
import { readColorHex, COLOR_NORM, isVectorWith } from './helpers.js';
|
||||
|
||||
/**
|
||||
* Bare `UniformNode` adapter. Auto-detects `UniformNode` instances and exposes their `.value` for animation. Scalars and booleans animate via `value`, `Color` uniforms via `color`, and `Vector2/3/4` uniforms via `x` / `y` / `z` / `w` axes.
|
||||
*
|
||||
* import 'animejs/bindings/three';
|
||||
* import { uniform } from 'three/tsl';
|
||||
* animate(uniform(0), { value: 1 });
|
||||
* animate(uniform(new Color()), { color: '#0f0' });
|
||||
* animate(uniform(new Vector3()), { x: 1, y: 0.5 });
|
||||
*
|
||||
* `UniformNode` slots assigned to `NodeMaterial` (`material.colorNode`, `material.offsetNode`, ...) are auto-detected by the shared resolvers in `resolvers.js`. Non-uniform nodes (`mix`, `add`, computed expressions), `Matrix3/4` and `Texture` valued uniforms, and `UniformArrayNode` / `BufferNode` are out of scope and fall through to the engine's direct property path.
|
||||
*/
|
||||
|
||||
|
||||
const uniformNode = threeAdapter.registerTargetAdapter((t) => !!(t && t.isUniformNode));
|
||||
|
||||
// Scalar and bool uniforms animate via the engine OBJECT fallthrough on value, no adapter prop needed since the engine writes uniform value natively.
|
||||
uniformNode.registerProperty('color',
|
||||
(t) => readColorHex(t.value),
|
||||
(t, _, tw) => {
|
||||
const ns = tw._numbers;
|
||||
t.value.setRGB(ns[0] * COLOR_NORM, ns[1] * COLOR_NORM, ns[2] * COLOR_NORM, SRGBColorSpace);
|
||||
},
|
||||
(t) => !!(t.value && t.value.isColor),
|
||||
);
|
||||
uniformNode.registerProperty('x', (t) => t.value.x, (t, v) => { t.value.x = v; }, (t) => isVectorWith(t.value, 'x'));
|
||||
uniformNode.registerProperty('y', (t) => t.value.y, (t, v) => { t.value.y = v; }, (t) => isVectorWith(t.value, 'y'));
|
||||
uniformNode.registerProperty('z', (t) => t.value.z, (t, v) => { t.value.z = v; }, (t) => isVectorWith(t.value, 'z'));
|
||||
uniformNode.registerProperty('w', (t) => t.value.w, (t, v) => { t.value.w = v; }, (t) => isVectorWith(t.value, 'w'));
|
||||
Reference in New Issue
Block a user