UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

33 lines (24 loc) 1.14 kB
import { Keyframe } from "../curve/Keyframe.js"; /** * * @param {AnimationCurve} curve * @param {number[]} values * @param {number[]} times * @param {number} component_count * @param {number} component_index */ export function curve_from_track_data_cubic_tangents(curve, values, times, component_count, component_index) { const key_count = times.length; for (let k = 0; k < key_count; k++) { const component_position = k * component_count; // 3 corresponds to 3 parts of a keyframe: inTangent, value, outTangent const base_offset = 3 * component_position; // Layout of keyframe output values for CUBICSPLINE animations: // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ] const inTangent = values[base_offset + component_index]; const value = values[base_offset + component_count + component_index]; const outTangent = values[base_offset + component_count * 2 + component_index]; const time = times[k]; curve.add(Keyframe.from(time, value, inTangent, outTangent)); } }