import { addTo } from '../addTo';
import { getGroup } from '../getGroup';
import { getMoving } from '../getMoving';
import { getSpinning } from '../getSpinning';
import { basicVortex } from './presets/basicVortex';
/**
 * getVortex generates a visual effect that appears as an endlessly looping tunnel of objects
 * by repeatedly copying and placing a set of objects in front and behind the avatar.
 * This set can include animations, lights, particles, etc.
 * This technique is useful for creating mesmerizing visual effects in musical experiences.
 * By using random seed values each copy can have a slightly different look.
 * Presets can be found in [src/helpers/vortex/presets](src/helpers/vortex/presets)
 * @example
 * ```ts
  // Add an invisible ground
  addTo(root, addInvisibility(getGround({ hilly: 0 })));
  // Add the Vortex
  addTo(root, getVortex(laserVortex));

  // Use getTimeline to toggle between different Vortex over time
  addTo(root, getTimeline([getVortex(laserVortex), getVortex(cylinderVortex)], { duration: 15, p: [0, 0, 0] }));
  return draw(root, 'emissive_01');

 * ```
 * ![Vortex1](https://user-images.githubusercontent.com/1092077/214039906-50dfcdb0-518d-47b3-97ef-6b4ee1aacf30.gif)
 */
export const getVortex = (options = basicVortex, params = {}) => {
    const { onEach = () => { }, depth = 10, repeats = 11, dir = 1, duration = 64 } = options;
    const wrapper = getGroup(options);
    const totDepth = depth * repeats;
    for (let index = 0; index < repeats; index++) {
        const progress = index / (repeats - 1);
        const item = onEach({ index, progress, params });
        const mover = getMoving(item, {
            duration,
            p: [0, 0, totDepth * 0.5 * dir],
            to: [0, 0, totDepth * -1 * dir],
            loopBehaviour: 'RESTART',
            progress,
            easing: 'LINEAR',
        });
        addTo(wrapper, mover);
    }
    return wrapper;
};
export const onePrefabGen = (info, options) => {
    const id = options.prefab;
    const offset = options.offset;
    const depth = options.depth;
    const size = options.size;
    const spinDuration = options.spinDuration;
    const child = {
        prefabId: id,
        transform: {
            pos: [0, options.offset, 0],
        },
    };
    const prefabGroup = getGroup({ s: [size, size, depth], children: [child] });
    const spinner = getSpinning(prefabGroup, { axis: 'z', duration: spinDuration, progress: info.progress });
    return spinner;
};
export const prefabFromProgress = (prefabs, progress, freq = 1) => {
    const progressAlt = (progress * freq) % 1;
    const prefabIndex = Math.floor(0.999 * progressAlt * prefabs.length);
    const prefab = prefabs[prefabIndex];
    return prefab;
};
export const spinIt = (target, duration, info) => {
    const res = getSpinning(target, {
        axis: 'z',
        direction: 1,
        duration: duration,
        progress: info.progress,
    });
    return res;
};
//# sourceMappingURL=getVortex.js.map