only use camera objects in the scene#236
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the Viewport camera management system to use camera objects from the scene database rather than maintaining separate ANARI camera objects. The title "only use camera objects in the scene" accurately describes this fundamental change.
Changes:
- Removed direct ANARI camera management (m_perspCamera, m_orthoCamera, m_omniCamera) in favor of using scene Camera objects
- Introduced new
ManipulatorToTSDmodule to bidirectionally sync between the camera manipulator and scene Camera objects - Enhanced Scene to provide a default camera via
defaultCamera()method similar todefaultMaterial() - Reorganized viewport menu structure into separate methods for better maintainability
Reviewed changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| Viewport.h/cpp | Refactored camera management to use scene objects; reorganized UI menus into separate methods |
| ManipulatorToTSD.hpp/cpp | New module for syncing manipulator state with Camera objects via metadata |
| Camera.hpp/cpp | Added CameraAppRef typedef; updated default FOV to 40 degrees |
| Scene.hpp/cpp | Added defaultCamera() method and default object tracking infrastructure |
| ObjectVersion.hpp | New utility for change tracking using version numbers |
| RenderIndex.hpp/cpp | Added camera() accessor and computeDefaultView() helper |
| AnariObjectCache | Added camera cache support |
| Application.cpp | Refactored menu bar into separate methods |
| LayerTree.cpp | Minor menu reorganization; typo in new menu item |
| Various tool files | Updated to use RenderIndex::computeDefaultView() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1556,7 +1262,6 @@ void Viewport::ui_gizmo() | |||
| const auto view = linalg::lookat_matrix(eye, at, up); | |||
|
|
|||
| const float aspect = m_viewportSize.x / float(m_viewportSize.y); | |||
| const float fovRadians = math::radians(m_fov); | |||
| math::mat4 proj; | |||
|
|
|||
| // Try and get some legroom for ImGuizmo get precision on depth. | |||
| @@ -1572,15 +1277,18 @@ void Viewport::ui_gizmo() | |||
| float near = std::max(1e-8f, distanceToSelectedObject * 1e-2f); | |||
| float far = std::max(1e-6f, distanceToSelectedObject * 1e2f); | |||
|
|
|||
| if (m_currentCamera == m_perspCamera) { | |||
| if (m_currentCamera->subtype() == core::tokens::camera::perspective) { | |||
| const float fovRadians = | |||
| m_currentCamera->parameterValueAs<float>("fovy").value_or( | |||
| math::radians(40.f)); | |||
| float oneOverTanFov = 1.0f / tan(fovRadians / 2.0f); | |||
| proj = math::mat4{ | |||
| {oneOverTanFov / aspect, 0.0f, 0.0f, 0.0f}, | |||
| {0.0f, oneOverTanFov, 0.0f, 0.0f}, | |||
| {0.0f, 0.0f, -(far + near) / (far - near), -1.0f}, | |||
| {0.0f, 0.0f, -2.0f * far * near / (far - near), 0.0f}, | |||
| }; | |||
| } else if (m_currentCamera == m_orthoCamera) { | |||
| } else if (m_currentCamera->subtype() == core::tokens::camera::orthographic) { | |||
There was a problem hiding this comment.
Potential null pointer dereference: At lines 1246, 1280, 1282, and 1291, 'm_currentCamera' is dereferenced without null checks. The 'canShowGizmo()' check on line 1227 doesn't verify that 'm_currentCamera' is non-null. If the camera is null during gizmo rendering, this will crash. Consider adding a null check in 'canShowGizmo()' or at the beginning of this function.
713319c to
46ca3ba
Compare
No description provided.