import { State as ThreeJSState } from "@intelligentgraphics/ig.gfx.threejs";
import * as THREE from "@intelligentgraphics/three";
export var CAMERA_NAME_2D = "ORTHOGRAPHIC";
export var CAMERA_NAME_3D = "PERSPECTIVE";
var SceneManager = /** @class */ (function () {
    function SceneManager(options) {
        this.container = options.container;
        this.canvas = options.canvas;
        this.init(options);
    }
    SceneManager.prototype.onResize = function () {
        var _this = this;
        this.dimensions = this.calculateViewFrame();
        this.updateViewFrame();
        this.cameras.forEach(function (view) {
            view.setFrame(_this.dimensions);
        });
    };
    SceneManager.prototype.getViewFrame = function () {
        return this.dimensions;
    };
    SceneManager.prototype.setPerspective = function (newPerspective) {
        this.cameras.forEach(function (view, perspective) {
            var enabled = perspective === newPerspective;
            view.settings.active = enabled;
            view.orbitControls.enabled = enabled;
        });
    };
    SceneManager.prototype.getActiveOrbitControls = function () {
        return this.getActiveCameraView().orbitControls;
    };
    SceneManager.prototype.getActiveCameraView = function () {
        return this.cameras.get(this.getCurrentSceneState().activePerspective);
    };
    SceneManager.prototype.getCameraNameFromPerspective = function (perspective) {
        return perspective === "3D" ? CAMERA_NAME_3D : CAMERA_NAME_2D;
    };
    SceneManager.prototype.init = function (_a) {
        var container = _a.container, perspectives = _a.perspectives, initialPerspective = _a.initialPerspective;
        this.scene = ThreeJSState.scene = new THREE.Scene();
        this.renderer = ThreeJSState.renderer = this.createRenderer(this.canvas);
        this.updateViewFrame();
        this.cameras = this.createCameras({
            perspectives: perspectives,
            container: container,
            initialPerspective: initialPerspective,
            viewFrame: this.dimensions,
            cameraName2D: CAMERA_NAME_2D,
            cameraName3D: CAMERA_NAME_3D,
            onControlChange: function () { return console.log("control update"); }
        });
        this.createEnvironment({
            scene: this.scene,
            renderer: this.renderer
        });
    };
    SceneManager.prototype.updateViewFrame = function () {
        this.dimensions = this.calculateViewFrame();
        this.renderer.setSize(this.dimensions.width, this.dimensions.height, true);
    };
    SceneManager.prototype.calculateViewFrame = function () {
        var _a = {
            width: this.container.clientWidth || 400,
            height: this.container.clientHeight || 300,
            left: this.container.clientLeft || 0,
            top: this.container.clientTop || 0
        }, width = _a.width, height = _a.height, top = _a.top, left = _a.left;
        return {
            width: width,
            height: height,
            x: left,
            y: top
        };
    };
    return SceneManager;
}());
export { SceneManager };
