import { getWrapper } from './getWrapper';
/**
 * Helper to animated an objects rotation.
 * @example
 * ```
  let spr: HNode = getPrefab({ id: 'sphere_01', p: [0, 2, 8], r: [0, 0, 40] });
  spr = getSpinning(spr);
 * ```
 */
export const getSpinning = (target, options) => {
    const { duration = 2, direction = 1, progress = 0, speedMultiplier = 1, easing = 'LINEAR', loopBehaviour = 'RESTART', axis = 'y', autoWrap = true, p = undefined, r = undefined, s = undefined, } = options || {};
    let axisVec = [0, 1, 0];
    if (axis === 'x')
        axisVec = [1, 0, 0];
    else if (axis === 'z')
        axisVec = [0, 0, 1];
    const keyframe1 = {
        keyframe: {
            easing,
        },
        keyframeAxisAngleRotation: {
            angle: 0,
            axis: axisVec,
        },
        transform: {
            pos: p,
            rot: r,
            scale: s,
        },
    };
    const keyframe2 = {
        keyframe: {
            timestamp: progress + duration,
        },
        keyframeAxisAngleRotation: {
            angle: 360 * direction,
            axis: axisVec,
        },
        transform: {
            pos: p,
            rot: r,
            scale: s,
        },
    };
    target.keyframeAnimated = {
        speedMultiplier,
        loopBehaviour,
        startTimestamp: progress * duration,
    };
    target.children?.push(keyframe1, keyframe2);
    let wrapper = getWrapper(target, { p, r, s, autoWrap, offset: options?.offset });
    return wrapper;
};
//# sourceMappingURL=getSpinning.js.map