simularium / simularium-viewer

NPM package to view Simularium trajectories in 3D
Apache License 2.0
2 stars 0 forks source link

Feature/orthographic camera #314

Closed frasercl closed 1 year ago

frasercl commented 1 year ago

Problem

Resolves #305: Users would like the option to switch between perspective and orthographic camera views.

Solution

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's zoom 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:

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:

  1. npm start
  2. Click new "Camera mode" button to switch between perspective and orthographic views
  3. Move/zoom the view while switching to verify that position and zoom are preserved reasonably between modes
  4. Verify zooming in/out with +/- buttons works in orthographic mode
  5. Open tweakpane with Ctrl+Alt+1, verify that setting/saving/loading camera state from there works too

Screenshots:

image image

github-actions[bot] commented 1 year ago

jest coverage report πŸ§ͺ

Total coverage

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

Show files with reduced coverage πŸ”» ### Reduced coverage | Status | Filename | Statements | Branches | Functions | Lines | | :----: | :-------------- | :----------------- | :------- | :----------------- | :----------------- | | 🟑 | src | 77.35% | 67.92% | 50% (-1.35% πŸ”») | 77.77% | | 🟒 | constants.ts | 82.35% (-4.31% πŸ”») | 100% | 57.14% (-9.52% πŸ”») | 81.25% (-4.46% πŸ”») | | πŸ”΄ | index.ts | 7.46% | 7.43% | 5.34% | 7.45% | | πŸ”΄ | src/controller | 30.24% | 16.27% | 17.85% | 30.3% | | πŸ”΄ | src/visGeometry | 19.98% | 21.97% | 25.39% | 19.98% | > Status of coverage: 🟒 - ok, 🟑 - slightly more than threshold, πŸ”΄ - under the threshold