@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
17 lines (16 loc) • 591 B
JavaScript
;
import { LineCurve, Vector2 } from "three";
export const curve = new LineCurve(new Vector2(), new Vector2());
export const setCurveFromKeyframePairLinear = (keyframeStart, keyframeEnd) => {
curve.v1.x = keyframeStart.pos;
curve.v1.y = keyframeStart.value;
curve.v2.x = keyframeEnd.pos;
curve.v2.y = keyframeEnd.value;
};
export function getValueLinear(pos) {
const curveStartPos = curve.v1.x;
const curveEndPos = curve.v2.x;
const t = (pos - curveStartPos) / (curveEndPos - curveStartPos);
const value = t * curve.v2.y + (1 - t) * curve.v1.y;
return value;
}