-
Notifications
You must be signed in to change notification settings - Fork 24
Fix orthographic camera near and far parameters #743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arjxn-py
wants to merge
11
commits into
jupytercad:main
Choose a base branch
from
arjxn-py:orthographic-zoom
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
812930a
Fix orthographic camera zoom
arjxn-py 8b3c0aa
remove extra code
arjxn-py c9a9db3
lint
arjxn-py 21e4c09
Start with camera from settings and update camera params in updateref…
arjxn-py dd6494a
lint
arjxn-py 3f2cd50
Update packages/base/src/3dview/mainview.tsx
arjxn-py 1bc2a74
Update packages/base/src/3dview/mainview.tsx
arjxn-py 74341bb
Update camera position as well based upon reflength
arjxn-py e8a2b42
Push it to just try
arjxn-py c2f08f8
Apply suggestions from code review
arjxn-py 5f39ecd
Apply suggestions from code review
arjxn-py File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,7 @@ import { ViewHelper } from 'three/examples/jsm/helpers/ViewHelper'; | |
|
||
import { FloatingAnnotation } from '../annotation'; | ||
import { getCSSVariableColor, throttle } from '../tools'; | ||
import { | ||
CameraSettings, | ||
ClipSettings, | ||
ExplodedView, | ||
SplitScreenSettings | ||
} from '../types'; | ||
import { ClipSettings, ExplodedView, SplitScreenSettings } from '../types'; | ||
import { FollowIndicator } from './followindicator'; | ||
import { | ||
BasicMesh, | ||
|
@@ -254,28 +249,12 @@ export class MainView extends React.Component<IProps, IStates> { | |
SPLITVIEW_BACKGROUND_COLOR.set( | ||
getCSSVariableColor(SPLITVIEW_BACKGROUND_COLOR_CSS) | ||
); | ||
if (this._mainViewModel.viewSettings.cameraSettings) { | ||
const cameraSettings = this._mainViewModel.viewSettings | ||
.cameraSettings as CameraSettings; | ||
if (cameraSettings.type === 'Perspective') { | ||
this._camera = new THREE.PerspectiveCamera( | ||
50, | ||
2, | ||
CAMERA_NEAR, | ||
CAMERA_FAR | ||
); | ||
} else if (cameraSettings.type === 'Orthographic') { | ||
const width = this._divRef.current?.clientWidth || 0; | ||
const height = this._divRef.current?.clientHeight || 0; | ||
this._camera = new THREE.OrthographicCamera( | ||
width / -2, | ||
width / 2, | ||
height / 2, | ||
height / -2 | ||
); | ||
this._camera.updateProjectionMatrix(); | ||
} | ||
} | ||
this._camera = new THREE.PerspectiveCamera( | ||
50, | ||
2, | ||
CAMERA_NEAR, | ||
CAMERA_FAR | ||
); | ||
this._camera.position.set(8, 8, 8); | ||
this._camera.up.set(0, 0, 1); | ||
|
||
|
@@ -1075,6 +1054,8 @@ export class MainView extends React.Component<IProps, IStates> { | |
} else { | ||
this._refLength = null; | ||
} | ||
|
||
this._updateCamera(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If possible, we shouldn't reset the camera entirely here (note we're already have some code in this method that updates some camera parameters). |
||
} | ||
|
||
private async _objToMesh( | ||
|
@@ -1756,11 +1737,17 @@ export class MainView extends React.Component<IProps, IStates> { | |
const distance = position.distanceTo(target); | ||
const zoomFactor = 1000 / distance; | ||
|
||
const refLength = this._refLength ?? 1000; // Fallback value if undefined | ||
const near = Math.max(refLength / 20, 0.01); | ||
const far = refLength * 20; | ||
|
||
this._camera = new THREE.OrthographicCamera( | ||
width / -2, | ||
width / 2, | ||
height / 2, | ||
height / -2 | ||
height / -2, | ||
near, | ||
far | ||
); | ||
this._camera.zoom = zoomFactor; | ||
this._camera.updateProjectionMatrix(); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why we're removing the check for the current camera setting?