4.0 KiB
4.0 KiB
1. ViewportCamera
- 1.1 Create
src/core/ViewportCamera.hwith class declaration: eye, focalPoint, up vector, fov, nearClip, farClip, aspectRatio; methods for orbit/pan/zoom, view matrix, projection matrix computation - 1.2 Implement
src/core/ViewportCamera.cpp:LookAtview matrix, perspective projection matrix, orbit (spherical coords around focal point), pan (translate eye+focal in view plane), zoom (adjust distance to focal point proportionally) - 1.3 Add
FrameBoundingBox(bounding box)method that positions the camera to view the entire scene
2. UsdSceneRenderer
- 2.1 Create
src/core/UsdSceneRenderer.hwith class declaration: stage ref, OpenGL buffer handles, methods forSetStage(),Rebuild(),Render(),Cleanup() - 2.2 Implement
src/core/UsdSceneRenderer.cpp— stage traversal: iterate prims, filterUsdGeomMesh, extractpoints,faceVertexCounts,faceVertexIndices,normals - 2.3 Implement geometry upload: create VAO/VBO per mesh, handle triangulation from
faceVertexCounts, compute flat normals when authored normals are missing - 2.4 Implement material color extraction: read
UsdShadeMaterialbinding diffuse color, fall back toprimvars:displayColor, fall back to default gray (0.7, 0.7, 0.7) - 2.5 Implement GLSL #version 130 shaders: vertex shader (MVP transform + normal transform), fragment shader (directional light + ambient + diffuse color)
- 2.6 Implement
Render()method: bind shader, set view/projection uniforms, iterate meshes and draw with their material colors - 2.7 Implement
Cleanup()andRebuild(): delete old OpenGL buffers, re-traverse stage, re-upload geometry
3. ViewportPanel (FBO + ImGui Integration)
- 3.1 Create
src/ui/ViewportPanel.hwith class declaration: FBO/color/depth texture handles,ViewportCamera,UsdSceneRenderer, dimensions; methods forSetStage(),Render(),HandleInput() - 3.2 Implement FBO creation and resize logic: create color + depth attachments, detect dimension changes from
ImGui::GetContentRegionAvail(), resize FBO only when dimensions change - 3.3 Implement
Render(): bind FBO, clear with background color, callUsdSceneRenderer::Render()with camera matrices, unbind FBO, display color texture viaImGui::Image() - 3.4 Implement mouse input routing: detect viewport hover via
ImGui::IsWindowHovered(), capture left-drag (orbit), middle-drag/shift+left-drag (pan), scroll (zoom), forward deltas toViewportCamera
4. Viewport Overlay (Grid + Gizmo + Context Menu)
- 4.1 Implement ground grid rendering: draw lines on Y=0 plane at regular intervals using GL_LINES in the scene renderer pass
- 4.2 Implement axis gizmo rendering: draw RGB (XYZ) lines in the lower-left viewport corner using an orthographic overlay pass independent of the scene camera
- 4.3 Implement background color configuration: store background color, use it for
glClearin the FBO render pass - 4.4 Implement viewport right-click context menu with "Show Grid" toggle and "Background" color preset submenu
5. Application Integration
- 5.1 Add
ViewportPanelmember toApplication, initialize inApplication::Initialize(), wire toUsdStageManagerviaSetStage() - 5.2 Replace the placeholder Viewport
ImGui::Begin/Endblock inApplication::RenderUI()withViewportPanel::Render() - 5.3 Call
ViewportCamera::FrameBoundingBox()inRefreshManagers()when a new stage is loaded so the camera frames the scene - 5.4 Verify all existing panels (Scene Hierarchy, Layer Panel, Property Panel) still render correctly alongside the new ViewportPanel
6. Build and Test
- 6.1 Run
cmake --preset defaultandcmake --buildto verify compilation with new source files - 6.2 Launch the application, open a USD file with mesh geometry, verify geometry renders in the Viewport panel
- 6.3 Test orbit, pan, zoom interactions in the viewport
- 6.4 Test grid toggle and background color from context menu
- 6.5 Test FBO resize by docking/undocking/resizing the Viewport panel