import * as THREE from "@intelligentgraphics/three";
import * as Core from "@intelligentgraphics/ig.gfx.core";
import * as ThreeJS from "@intelligentgraphics/ig.gfx.threejs";
const indices = new Uint16Array([
    0,
    1,
    1,
    2,
    2,
    3,
    3,
    0,
    4,
    5,
    5,
    6,
    6,
    7,
    7,
    4,
    0,
    4,
    1,
    5,
    2,
    6,
    3,
    7,
]);
export class WireBox extends THREE.LineSegments {
    constructor(color = new THREE.Color(0xffff00)) {
        super(undefined, new THREE.LineBasicMaterial({ color }));
        this.positions = new Float32Array(8 * 3);
        this.geometry = new THREE.BufferGeometry();
        this.geometry.setIndex(new THREE.BufferAttribute(indices, 1));
        this.geometry.addAttribute("position", new THREE.BufferAttribute(this.positions, 3));
        const position = this.geometry.attributes
            .position;
        const array = position.array;
        /*
    5____4
  1/___0/|
  | 6__|_7
  2/___3/
  0: max.x, max.y, max.z
  1: min.x, max.y, max.z
  2: min.x, min.y, max.z
  3: max.x, min.y, max.z
  4: max.x, max.y, min.z
  5: min.x, max.y, min.z
  6: min.x, min.y, min.z
  7: max.x, min.y, min.z
  */
        array[0] = 1;
        array[1] = 1;
        array[2] = 1;
        array[3] = 0;
        array[4] = 1;
        array[5] = 1;
        array[6] = 0;
        array[7] = 0;
        array[8] = 1;
        array[9] = 1;
        array[10] = 0;
        array[11] = 1;
        array[12] = 1;
        array[13] = 1;
        array[14] = 0;
        array[15] = 0;
        array[16] = 1;
        array[17] = 0;
        array[18] = 0;
        array[19] = 0;
        array[20] = 0;
        array[21] = 1;
        array[22] = 0;
        array[23] = 0;
        this.matrixAutoUpdate = false;
    }
    setFromBounds(bounds) {
        if (!Core.areBoundsValid(bounds)) {
            return;
        }
        const size = Core.Vector.Sub3(bounds.max, bounds.min);
        this.scale.copy(ThreeJS.ThreeVector3FromVec3(size));
        this.position.copy(ThreeJS.ThreeVector3FromVec3(bounds.min));
        this.updateMatrix();
        this.geometry.computeBoundingSphere();
    }
}
