Skip to content

Commit

Permalink
properly update aspect ratio of 3D viewport when layout changes (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
philippotto committed Feb 21, 2019
1 parent 523d04c commit f76913c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
40 changes: 30 additions & 10 deletions frontend/javascripts/oxalis/controller/camera_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ import * as THREE from "three";
import TWEEN from "tween.js";
import _ from "lodash";

import { getInputCatcherAspectRatio } from "oxalis/model/accessors/view_mode_accessor";
import {
type OrthoView,
type OrthoViewMap,
type OrthoViewRects,
OrthoViewValuesWithoutTDView,
OrthoViews,
type Vector3,
} from "oxalis/constants";
import { getBoundaries } from "oxalis/model/accessors/dataset_accessor";
import { getInputCatcherAspectRatio } from "oxalis/model/accessors/view_mode_accessor";
import {
getPlaneExtentInVoxelFromStore,
getPosition,
Expand All @@ -20,13 +28,6 @@ import { voxelToNm, getBaseVoxel } from "oxalis/model/scaleinfo";
import Dimensions from "oxalis/model/dimensions";
import Store, { type CameraData } from "oxalis/store";
import api from "oxalis/api/internal_api";
import {
type OrthoView,
type OrthoViewMap,
OrthoViewValuesWithoutTDView,
OrthoViews,
type Vector3,
} from "oxalis/constants";

type Props = {
cameras: OrthoViewMap<THREE.OrthographicCamera>,
Expand Down Expand Up @@ -59,7 +60,7 @@ class CameraController extends React.PureComponent<Props> {

// Non-TD-View methods

updateCamViewport(): void {
updateCamViewport(inputCatcherRects?: OrthoViewRects): void {
const state = Store.getState();
const { clippingDistance } = state.userConfiguration;
const scaleFactor = getBaseVoxel(state.dataset.dataSource.scale);
Expand All @@ -79,6 +80,25 @@ class CameraController extends React.PureComponent<Props> {
this.props.cameras[planeId].near = -clippingDistance;
this.props.cameras[planeId].updateProjectionMatrix();
}

if (inputCatcherRects != null) {
// Update td camera's aspect ratio
const tdCamera = this.props.cameras[OrthoViews.TDView];

const oldMid = (tdCamera.right + tdCamera.left) / 2;
const oldWidth = tdCamera.right - tdCamera.left;
const oldHeight = tdCamera.top - tdCamera.bottom;

const oldAspectRatio = oldWidth / oldHeight;
const tdRect = inputCatcherRects[OrthoViews.TDView];
const newAspectRatio = tdRect.width / tdRect.height;

const newWidth = (oldWidth * newAspectRatio) / oldAspectRatio;

tdCamera.left = oldMid - newWidth / 2;
tdCamera.right = oldMid + newWidth / 2;
tdCamera.updateProjectionMatrix();
}
}

update(): void {
Expand All @@ -105,7 +125,7 @@ class CameraController extends React.PureComponent<Props> {
),
listenToStoreProperty(
storeState => storeState.viewModeData.plane.inputCatcherRects,
() => this.updateCamViewport(),
inputCatcherRects => this.updateCamViewport(inputCatcherRects),
),
listenToStoreProperty(
storeState => storeState.flycam.currentMatrix,
Expand Down
3 changes: 3 additions & 0 deletions frontend/stylesheets/_variables.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
@standardViewportWidth: 380px;
@mainColor: #2a3a48;
@action-bar-height: 44px;
@xyRed: rgb(200, 20, 20);
@yzBlue: rgb(20, 20, 200);
@xzGreen: rgb(20, 200, 20);
17 changes: 9 additions & 8 deletions frontend/stylesheets/trace_view/_tracing_view.less
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
opacity: 0.85;

&.PLANE_XY {
border-color: rgb(200, 20, 20);
border-color: @xyRed;
}
&.PLANE_YZ {
border-color: rgb(20, 20, 200);
border-color: @yzBlue;
}
&.PLANE_XZ {
border-color: rgb(20, 200, 20);
border-color: @xzGreen;
}
&.TDView {
border-color: white;
Expand All @@ -50,15 +50,16 @@
position: relative;
}
#TDViewControls {
float: left;
text-align: right;
height: 20px;
position: absolute;
top: 0px;
z-index: 30;
width: 100%;

.ant-btn {
width: 25%;
width: 60px;
line-height: 26px;
& > .colored-dot {
display: inline-block;
width: 10px;
Expand All @@ -67,13 +68,13 @@
margin-right: 5px;
}
&:nth-child(2) .colored-dot {
background-color: red;
background-color: @xyRed;
}
&:nth-child(3) .colored-dot {
background-color: blue;
background-color: @yzBlue;
}
&:nth-child(4) .colored-dot {
background-color: #0f0;
background-color: @xzGreen;
}
}
}
Expand Down

0 comments on commit f76913c

Please sign in to comment.