import { colorToVec3, namedColors } from '@hiberworld/code-kit';
import { addTo } from './addTo';
import { getGroup } from './getGroup';
import { getPrefab } from './getPrefab';
import { getMesh } from './getMesh';
import { getSpinning } from './getSpinning';
import { addPointLight } from './addPointLight';
import { pop3 } from './utils/pop3';
import { addParticles } from './addParticles';
import { PARTICLE_PRESETS } from './PARTICLE_PRESETS';
import { getMaterialKeyFromColor } from './utils/getMaterialKeyFromColor';
/**
 * Returns an animated laser
 * @example
 * ```ts
  addTo(root, getLaser({ p: [0, 0, 5], angle: 20, spinDuration: 16 }));
 * ```
 */
export const getLaser = (options = {}) => {
    const { length = 10, width = 0.05, angle = 20, spinDuration = 8, progress = 0, physical = false, distanceToImpactObject = 5, color = 'random', } = options;
    const wrapper = getGroup(options);
    const laserWrapper = getGroup({
        r: [angle, 0, 0],
        p: [0, -0.1, 0],
    });
    const materialKey = getMaterialKeyFromColor(color);
    const laser = getMesh({
        id: 'en_b_cylinder_01',
        physical,
        s: [width, length, width],
        material: ('tron_trim_' + materialKey),
    });
    addTo(laserWrapper, laser);
    let lgthSource;
    const visibleSource = false;
    if (visibleSource)
        lgthSource = getPrefab({ p: [0, distanceToImpactObject, 0], s: pop3(0.3) });
    else
        lgthSource = getGroup({ p: [0, distanceToImpactObject, 0] });
    addPointLight(lgthSource, {
        strength: 1,
        radius: 20,
        color: colorToVec3(namedColors[materialKey]),
    });
    addParticles(lgthSource, {
        ...PARTICLE_PRESETS.starDust,
        ...{
            particleTexture: 'particle_dust_albedo',
            sizeStart: 0.08,
            sizeEnd: 0.02,
            size: [0, 0, 0],
            inheritVelocity: 1,
            velocity: [0, 10, 0],
            randomVelocity: [10, 10, 10],
            forceAirRes: 5,
        },
    });
    // const lgthSource = getPointLight();
    addTo(laserWrapper, lgthSource);
    addTo(wrapper, getSpinning(laserWrapper, { axis: 'y', duration: spinDuration, progress }));
    return wrapper;
};
//# sourceMappingURL=getLaser.js.map