import Tag from "../../../../ecs/components/Tag.js";
import { EntityNode } from "../../../../ecs/parent/EntityNode.js";
import { Transform } from "../../../../ecs/transform/Transform.js";
import { sh3_make_shaded_geometry } from "../../visualise_spherical_harmonic_sphere.js";

/**
 *
 * @param {LightProbeVolume} volume
 * @param {number} size
 * @param {boolean} shadow
 * @returns {EntityNode}
 */
export function lpv_visualize_probes({ volume, size = 0.2, shadow = false }) {
    const parent = new EntityNode();
    parent.entity.add(new Transform());

    const count = volume.count;
    for (let i = 0; i < count; i++) {
        const probe_node = new EntityNode();


        const entity = probe_node.entity;

        entity.add(new Transform());
        entity.add(
            sh3_make_shaded_geometry(volume.harmonics, i * 3 * 9, shadow)
        );
        entity.add(Tag.fromOne('LPV/probe'));

        probe_node.transform.position.fromArray(volume.points, i * 3);
        probe_node.transform.scale.setScalar(size);

        parent.addChild(probe_node);
    }

    return parent;
}