Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/viewer/scene/camera/Ortho.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Ortho extends Component {
this.scale = cfg.scale;
this.near = cfg.near;
this.far = cfg.far;
this.scaleAxis = cfg.scaleAxis ?? "max";

this._onCanvasBoundary = this.scene.canvas.on("boundary", this._needUpdate, this);
}
Expand All @@ -74,7 +75,7 @@ class Ortho extends Component {
let top;
let bottom;

if (boundaryWidth > boundaryHeight) {
if (this._scaleAxis === "x" || ((this._scaleAxis === "max") && (boundaryWidth > boundaryHeight))) {
left = -halfSize;
right = halfSize;
top = halfSize / aspect;
Expand Down Expand Up @@ -133,6 +134,43 @@ class Ortho extends Component {
return this._scale;
}

/**
* Sets Ortho's scale axis.
*
* If it's not set = max scale axis is enabled.
*
* Possible values:
*
* "max" = scale would be applied for longer dimension available (either horizontal or vertical),
*
* "x" = scale is applied in horizontal dimension,
*
* "y" = scale is applied in vertical dimension.
*
* @param {String} value New scale axis value.
*/
set scaleAxis(value) {
if (value === "max" || value === "y" || value === "x") {
this._scaleAxis = value;
}
else {
console.error("Ortho.js Camera scaleAxis not recognized, setting to \"max\".");
this._scaleAxis = "max";
}

this._needUpdate(0);
this.fire("scaleAxis", this._scaleAxis);
}

/**
* Gets scale axis.
*
* @returns {String} Scale axis.
*/
get scaleAxis() {
return this._scaleAxis;
}

/**
* Sets the position of the Ortho's near plane on the positive View-space Z-axis.
*
Expand Down
24 changes: 24 additions & 0 deletions types/viewer/scene/camera/Ortho.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ export declare class Ortho extends Component {
*/
get scale(): number;

/**
* Sets Ortho's scale axis.
*
* If it's not set = max scale axis is enabled.
*
* Possible values:
*
* "max" = scale would be applied for longer dimension available (either horizontal or vertical),
*
* "x" = scale is applied in horizontal dimension,
*
* "y" = scale is applied in vertical dimension.
*
* @param {String} value New scale axis value.
*/
set scaleAxis(arg: string);

/**
* Gets scale axis.
*
* @returns {String} Scale axis.
*/
get scaleAxis(): string;

/**
* Sets the position of the Ortho's near plane on the positive View-space Z-axis.
*
Expand Down
Loading