"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var THREE = require("@intelligentgraphics/three");
var Core = require("@intelligentgraphics/ig.gfx.core");
var ThreeJS = require("@intelligentgraphics/ig.gfx.threejs");
var 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,
]);
var WireBox = /** @class */ (function (_super) {
    tslib_1.__extends(WireBox, _super);
    function WireBox(color) {
        if (color === void 0) { color = new THREE.Color(0xffff00); }
        var _this = _super.call(this, undefined, new THREE.LineBasicMaterial({ color: color })) || this;
        _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));
        var position = _this.geometry.attributes
            .position;
        var 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;
        return _this;
    }
    WireBox.prototype.setFromBounds = function (bounds) {
        if (!Core.areBoundsValid(bounds)) {
            return;
        }
        var 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();
    };
    return WireBox;
}(THREE.LineSegments));
exports.WireBox = WireBox;
