import { Vector3, BoundingInfo } from './loader/babylonjs-import';
import { Projection } from './camera/ViewerCamera';
import { BimIfcObject } from './loader/bim-ifc-object';
export class BimCamera {
    _viewer;
    _api;
    /**
     * @internal NOTE: Internal API. Subject to change. Use of these APIs in production applications is not supported.
     */
    constructor(_viewer, _api) {
        this._viewer = _viewer;
        this._api = _api;
    }
    /**
     * Sets camera projection.
     * @param projection The camera projection to set.
     */
    setProjection(projection) {
        this._viewer.camera.projection =
            projection === 'perspective' ? Projection.Perspective : Projection.Orthographic;
    }
    /**
     * Sets camera position at eye and rotation to look towards target.
     * @param eye Point to look from.
     * @param target Point to look towards.
     */
    lookAt(eye, target) {
        this._viewer.camera.position = eye;
        this._viewer.camera.target = target;
    }
    /**
     * Sets camera rotation to look towards the specified direction and zooms to extent of visible objects.
     * @param direction The direction to look from (top = -Z, bottom = +Z, front = +Y, back = -Y, left = +X, right = -X).
     */
    lookFrom(direction) {
        this._viewer.camera.activeCamera.twinfinity.pivot.lookFrom(direction);
    }
    /**
     * Zooms camera to the extent of the specified bounding box.
     * @param extent Bounding box in format [minX, minY, minZ, maxX, maxY, maxZ].
     * @param direction [Optional]. If set, the camera is positioned according to the direction during zoom. Otherwise, the current direction is kept.
     */
    zoomToExtent(extent, direction) {
        this._viewer.camera.zoomToExtent(new BoundingInfo(new Vector3(...extent.slice(0, 3)), new Vector3(...extent.slice(3, 6))), direction);
    }
    /**
     * Resets the camera to the default view. Camera is positioned to view entire building
     * @param direction Optional. Direction camera should look at building from. Default is a angled top position.
     */
    defaultView(direction) {
        if (direction === undefined) {
            direction = this._viewer.camera.topDownMode ? 'top' : 'default';
        }
        this._viewer.camera.zoomToExtent(this._api.ifc.regionBoundingInfo, direction);
    }
    /**
     * Returns camera forward vector.
     */
    forwardVector() {
        return this._viewer.camera.forwardVector;
    }
    /**
     * @deprecated Use {@link cameraOptions}  instead
     * Locks camera to prevent user interaction.
     */
    lock() {
        this.setLock(true);
    }
    /**
     * @deprecated Use Use {@link cameraOptions} instead
     * Unlocks camera to allow for user interaction.
     */
    unlock() {
        this.setLock(false);
    }
    /**
     * @deprecated Use {@link cameraOptions} instead
     * Sets whether camera should prevent user interaction or not.
     * @param locked Whether camera should be locked or not.
     */
    setLock(locked) {
        this.cameraOptions.isPanEnabled = !locked;
        this.cameraOptions.isRotationEnabled = !locked;
        this.cameraOptions.isZoomEnabled = !locked;
        this.cameraOptions.isKeyboardMoveEnabled = !locked;
    }
    /**
     * @deprecated Use the mode property instead
     * Sets camera mode.
     * @param mode The camera mode to set.
     */
    setMode(mode) {
        this.mode = mode;
    }
    /**
     * Sets the camera mode (pivot, fps or all). See {@link CameraMode} for more information
     */
    set mode(mode) {
        this._viewer.camera.mode = mode;
    }
    /**
     * Gets the camera mode (pivot, fps or all). See {@link CameraMode} for more information
     */
    get mode() {
        return this._viewer.camera.mode;
    }
    setPivot(mode, pivot) {
        if (pivot instanceof BimIfcObject) {
            pivot = pivot.boundingInfo().boundingBox.center;
        }
        this._viewer.camera.setPivot(mode, pivot);
    }
    /**
     * Returns the current camera position and target as a string
     */
    getViewAsString() {
        const p = this._viewer.camera.position.asArray();
        const t = this._viewer.camera.target.asArray();
        return [...p, ...t].map((x) => x.toFixed(2)).join(',');
    }
    /**
     * Sets the camera's position and target from given string
     * @param viewString A string generated by {@link getViewAsString}
     */
    setViewFromString(viewString) {
        const coordinates = viewString.split(',').map((s) => parseFloat(s));
        if (coordinates.length !== 6) {
            throw new Error('Malformed view string');
        }
        this._viewer.camera.position = new Vector3(...coordinates.slice(0, 3));
        this._viewer.camera.target = new Vector3(...coordinates.slice(3, 6));
    }
    /**
     * Attaches a behavior to the camera.
     * @param behavior The behavior to be attached to the camera.
     * @returns true if the behavior was successfully attached to the camera, otherwise false.
     */
    attachBehavior(behavior) {
        return this._viewer.camera.attachBehavior(behavior);
    }
    /**
     * Detaches a behavior from the camera.
     * @param behavior The behavior to be detached from the camera.
     * @returns true if the behavior was successfully detached to the camera, otherwise false.
     */
    detachBehavior(behavior) {
        return this._viewer.camera.detachBehavior(behavior);
    }
    /**
     * Gets or sets options for camera pivot control.
     */
    get cameraOptions() {
        return this._viewer.camera.options;
    }
    /**
     * @deprecated Same as {@link cameraOptions}.
     */
    get pivotOptions() {
        return this.cameraOptions;
    }
}
//# sourceMappingURL=BimCamera.js.map