import * as Core from "@intelligentgraphics/ig.gfx.core";
export class BlueprintIGXCBuilder {
    constructor({ wallHeight = 1.5, wallThickness = 0.2, wallBackMaterial, wallFrontMaterial, 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}
     */
    build() {
        this.makeObjects();
        this.makeCategories();
        return this.scene;
    }
    /**
     * Add the categories to the scene object
     */
    makeCategories() {
        this.scene.Categories["Room.Base"] = "Room.Base";
    }
    /**
     * Add the Objects to the scene
     */
    makeObjects() {
        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
     */
    getGeometryParameters() {
        // blueprint measures are in mm, so we need to convert them
        const scenePoints = this.corners.map((point) => ({
            id: point.id,
            x: point.x / 100,
            z: point.y / 100,
        }));
        const sceneWalls = this.walls.map(({ points: [startPoint, endPoint], frontMaterial, backMaterial }, index) => ({
            id: `wall${index}`,
            startPoint,
            endPoint,
            frontMaterial,
            backMaterial,
        }));
        const sceneRooms = this.rooms.map(({ points, floorMaterial }, index) => ({
            id: `room${index}`,
            involvedPointIds: points,
            floorMaterial,
        }));
        const 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
     */
    addCorner(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
     */
    addWall(firstId, secondId, frontMaterial = this.wallFrontMaterial, backMaterial = this.wallBackMaterial) {
        this.walls.push({
            points: [firstId, secondId],
            frontMaterial,
            backMaterial,
        });
    }
    /**
     * Add a room containing the points
     * @param pointIds an array of the corner points of the room
     */
    addRoom(pointIds, floorMaterial = this.floorMaterial) {
        this.rooms.push({
            points: pointIds,
            floorMaterial,
        });
    }
}
