animejs
Version:
JavaScript animation engine
42 lines (35 loc) • 2.16 kB
JavaScript
/**
* Anime.js - adapters - CJS
* @version v4.5.0
* @license MIT
* @copyright 2026 - Julian Garnier
*/
;
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'));