"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Core = require("@intelligentgraphics/ig.gfx.core");
var BlueprintIGXCBuilder = /** @class */ (function () {
    function BlueprintIGXCBuilder(_a) {
        var _b = _a.wallHeight, wallHeight = _b === void 0 ? 1.5 : _b, _c = _a.wallThickness, wallThickness = _c === void 0 ? 0.2 : _c, wallBackMaterial = _a.wallBackMaterial, wallFrontMaterial = _a.wallFrontMaterial, floorMaterial = _a.floorMaterial;
        this.scene = Core.IGXC.createScene();
        // necessary parameters for the scene to be processed
        this.scene.Format = "1.0";
        this.scene.Geometry = "OBJ";
        // default height and thickness
        this.wallHeight = wallHeight;
        this.wallThickness = wallThickness;
        this.wallFrontMaterial = wallFrontMaterial;
        this.wallBackMaterial = wallBackMaterial;
        this.floorMaterial = floorMaterial;
        this.corners = [];
        this.walls = [];
        this.rooms = [];
    }
    /**
     * Builds the Scene from the given corners, walls and rooms.
     * @returns {Core.IGXC.Scene}
     */
    BlueprintIGXCBuilder.prototype.build = function () {
        this.makeObjects();
        this.makeCategories();
        return this.scene;
    };
    /**
     * Add the categories to the scene object
     */
    BlueprintIGXCBuilder.prototype.makeCategories = function () {
        this.scene.Categories["Room.Base"] = "Room.Base";
    };
    /**
     * Add the Objects to the scene
     */
    BlueprintIGXCBuilder.prototype.makeObjects = function () {
        this.scene.Objects.push({
            Path: ".",
            Selectable: "Self",
            OrderNumber: "0",
        });
        this.scene.Objects.push({
            Path: "o1",
            Selectable: "Parent",
            GeometryParameters: this.getGeometryParameters(),
            Transform: {
                Position: {
                    X: 0.0,
                    Y: 0,
                    Z: 0.0,
                },
                Rotation: {
                    X: 0,
                    Y: 0,
                    Z: 0,
                },
                Scale: {
                    X: 1,
                    Y: 1,
                    Z: 1,
                },
            },
            MaterialCategory: "Room.Base",
        });
    };
    /**
     * Creates the geometry parameters that contain the information about the corners and walls
     * @returns
     */
    BlueprintIGXCBuilder.prototype.getGeometryParameters = function () {
        // blueprint measures are in mm, so we need to convert them
        var scenePoints = this.corners.map(function (point) { return ({
            id: point.id,
            x: point.x / 100,
            z: point.y / 100,
        }); });
        var sceneWalls = this.walls.map(function (_a, index) {
            var _b = tslib_1.__read(_a.points, 2), startPoint = _b[0], endPoint = _b[1], frontMaterial = _a.frontMaterial, backMaterial = _a.backMaterial;
            return ({
                id: "wall" + index,
                startPoint: startPoint,
                endPoint: endPoint,
                frontMaterial: frontMaterial,
                backMaterial: backMaterial,
            });
        });
        var sceneRooms = this.rooms.map(function (_a, index) {
            var points = _a.points, floorMaterial = _a.floorMaterial;
            return ({
                id: "room" + index,
                involvedPointIds: points,
                floorMaterial: floorMaterial,
            });
        });
        var parameters = {
            Context: "BluePrint_Mesh",
            Type: "Environment",
            Version: 1,
            Thickness: this.wallThickness,
            Height: this.wallHeight,
            Points: scenePoints,
            Walls: sceneWalls,
            Rooms: sceneRooms,
            Holes: [],
        };
        return parameters;
    };
    /**
     * Add a corner to the configuration
     * @param point contains the coordinates and id of the point
     */
    BlueprintIGXCBuilder.prototype.addCorner = function (point) {
        this.corners.push(point);
    };
    /**
     * Add a wall between the two points
     * @param firstId: the id of the first point
     * @param secondId: the id of the second point
     */
    BlueprintIGXCBuilder.prototype.addWall = function (firstId, secondId, frontMaterial, backMaterial) {
        if (frontMaterial === void 0) { frontMaterial = this.wallFrontMaterial; }
        if (backMaterial === void 0) { backMaterial = this.wallBackMaterial; }
        this.walls.push({
            points: [firstId, secondId],
            frontMaterial: frontMaterial,
            backMaterial: backMaterial,
        });
    };
    /**
     * Add a room containing the points
     * @param pointIds an array of the corner points of the room
     */
    BlueprintIGXCBuilder.prototype.addRoom = function (pointIds, floorMaterial) {
        if (floorMaterial === void 0) { floorMaterial = this.floorMaterial; }
        this.rooms.push({
            points: pointIds,
            floorMaterial: floorMaterial,
        });
    };
    return BlueprintIGXCBuilder;
}());
exports.BlueprintIGXCBuilder = BlueprintIGXCBuilder;
