Closed frasercl closed 1 year ago
Status | Category | Percentage | Covered / Total |
---|---|---|---|
π΄ | Statements | 40.05% | 1951/4871 |
π΄ | Branches | 43.97% | 814/1851 |
π΄ | Functions | 36.76% | 400/1088 |
π΄ | Lines | 40.31% | 1869/4636 |
Status of coverage: π’ - ok, π‘ - slightly more than threshold, π΄ - under the threshold
Problem
Resolves #305: Users would like the option to switch between perspective and orthographic camera views.
Solution
perspectiveCamera
andorthographicCamera
properties toVisGeometry
setCameraType
to switch which of these is active in thecamera
propertydolly
,storeCamera
,loadCamera
)Orthographic cameras render all objects in the scene at a consistent size regardless of distance, while the size of objects in perspective cameras decreases with size. Keeping sizes of objects looking reasonably consistent when switching views requires picking a distance at which both cameras will render the same object at the same size. After some testing, I found that picking the default distance from the camera to the origin kept things looking reasonable.
Additionally,
OrbitControls
handles zoom differently between perspective and orthographic cameras. To zoom a perspective camera, it physically moves the camera closer to or farther from the target. To zoom an orthographic camera, it doesn't touch the distance from the camera to the target and instead modifies the camera'szoom
property. A lot of the technical challenge here was a result of having to reconcile these two zoom methods sharing one controller.Given the notes above, I added a few private methods to
VisGeometry
:getDefaultOrbitRadius
: Derives the default/initial distance between the camera and the target fromcameraDefault
. 98% of the time this ought to be equal toDEFAULT_CAMERA_Z_POSITION
(120), but trajectories with non-standard units or camera positions will expect the app to notice and keep things consistent.updateOrthographicFrustum
: The default "size" of the orthographic camera varies with the aspect of the frame, the FOV of the perspective camera (in other words, how fast objects get smaller as they get farther from the camera), and the default orbit radius. This method updates that if anything changes.updateControlsZoomBounds
:OrbitControls
bounds how much the camera can zoom in/out by distance for perspective cameras but by zoom level for orthographic cameras. These could all be set as constants, but the relationship between them will vary if the default orbit radius changes. So this method is here to keep things consistent should that change.I also had to make some pretty significant changes to the
dolly
method to handle both ways of zooming a camera.Type of change
Steps to Verify:
npm start
Screenshots: