UNPKG

@itwin/core-frontend

Version:
79 lines 4.57 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Views */ import { Matrix3d } from "@itwin/core-geometry"; /** Describes a set of commonly-used view rotations. * @public * @extensions */ export var StandardViewId; (function (StandardViewId) { /** Any rotation which does not match one of the standard rotations. * Invalid as an argument to StandardView.getStandardRotation() - used as a return value only. */ StandardViewId[StandardViewId["NotStandard"] = -1] = "NotStandard"; StandardViewId[StandardViewId["Top"] = 0] = "Top"; StandardViewId[StandardViewId["Bottom"] = 1] = "Bottom"; StandardViewId[StandardViewId["Left"] = 2] = "Left"; StandardViewId[StandardViewId["Right"] = 3] = "Right"; StandardViewId[StandardViewId["Front"] = 4] = "Front"; StandardViewId[StandardViewId["Back"] = 5] = "Back"; StandardViewId[StandardViewId["Iso"] = 6] = "Iso"; StandardViewId[StandardViewId["RightIso"] = 7] = "RightIso"; })(StandardViewId || (StandardViewId = {})); let standardViewMatrices; function getMatrices() { if (undefined !== standardViewMatrices) return standardViewMatrices; standardViewMatrices = []; standardViewMatrices[StandardViewId.Top] = Matrix3d.identity; standardViewMatrices[StandardViewId.Bottom] = Matrix3d.createRowValues(1, 0, 0, 0, -1, 0, 0, 0, -1); standardViewMatrices[StandardViewId.Left] = Matrix3d.createRowValues(0, -1, 0, 0, 0, 1, -1, 0, 0); standardViewMatrices[StandardViewId.Right] = Matrix3d.createRowValues(0, 1, 0, 0, 0, 1, 1, 0, 0); standardViewMatrices[StandardViewId.Front] = Matrix3d.createRowValues(1, 0, 0, 0, 0, 1, 0, -1, 0); standardViewMatrices[StandardViewId.Back] = Matrix3d.createRowValues(-1, 0, 0, 0, 0, 1, 0, 1, 0); standardViewMatrices[StandardViewId.Iso] = Matrix3d.createRowValues(0.707106781186548, -0.70710678118654757, 0.00000000000000000, 0.408248290463863, 0.40824829046386302, 0.81649658092772603, -0.577350269189626, -0.57735026918962573, 0.57735026918962573); standardViewMatrices[StandardViewId.RightIso] = Matrix3d.createRowValues(0.707106781186548, 0.70710678118654757, 0.00000000000000000, -0.408248290463863, 0.40824829046386302, 0.81649658092772603, 0.577350269189626, -0.57735026918962573, 0.57735026918962573); standardViewMatrices.forEach((mat) => Object.freeze(mat)); return standardViewMatrices; } /** Supplies access to a set of commonly-used view rotations. * @public */ export class StandardView { static get top() { return this.getStandardRotation(StandardViewId.Top); } static get bottom() { return this.getStandardRotation(StandardViewId.Bottom); } static get left() { return this.getStandardRotation(StandardViewId.Left); } static get right() { return this.getStandardRotation(StandardViewId.Right); } static get front() { return this.getStandardRotation(StandardViewId.Front); } static get back() { return this.getStandardRotation(StandardViewId.Back); } static get iso() { return this.getStandardRotation(StandardViewId.Iso); } static get rightIso() { return this.getStandardRotation(StandardViewId.RightIso); } /** Obtain a [[Matrix3d]] corresponding to the specified [[StandardViewId]]. * @param id The ID of the desired rotation. * @return A rotation matrix corresponding to the requested standard view ID, or a "top" view rotation if the input does not correspond to a standard rotation. */ static getStandardRotation(id) { if (id < StandardViewId.Top || id > StandardViewId.RightIso) id = StandardViewId.Top; return getMatrices()[id]; } /** Attempts to adjust the supplied rotation matrix to match the standard view rotation it most closely matches. * If a matching standard rotation exists, the input matrix will be modified in-place to precisely match it. * Otherwise, the input matrix will be unmodified. * @param matrix The rotation matrix to adjust. */ static adjustToStandardRotation(matrix) { getMatrices().some((test) => { if (test.maxDiff(matrix) > 1.0e-7) return false; matrix.setFrom(test); return true; }); } } //# sourceMappingURL=StandardView.js.map