UsdLayerManager/openspec/changes/viewport-display-usd-data/tasks.md

4.0 KiB

1. ViewportCamera

  • 1.1 Create src/core/ViewportCamera.h with 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: LookAt view 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.h with class declaration: stage ref, OpenGL buffer handles, methods for SetStage(), Rebuild(), Render(), Cleanup()
  • 2.2 Implement src/core/UsdSceneRenderer.cpp — stage traversal: iterate prims, filter UsdGeomMesh, extract points, 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 UsdShadeMaterial binding diffuse color, fall back to primvars: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() and Rebuild(): delete old OpenGL buffers, re-traverse stage, re-upload geometry

3. ViewportPanel (FBO + ImGui Integration)

  • 3.1 Create src/ui/ViewportPanel.h with class declaration: FBO/color/depth texture handles, ViewportCamera, UsdSceneRenderer, dimensions; methods for SetStage(), 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, call UsdSceneRenderer::Render() with camera matrices, unbind FBO, display color texture via ImGui::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 to ViewportCamera

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 glClear in 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 ViewportPanel member to Application, initialize in Application::Initialize(), wire to UsdStageManager via SetStage()
  • 5.2 Replace the placeholder Viewport ImGui::Begin/End block in Application::RenderUI() with ViewportPanel::Render()
  • 5.3 Call ViewportCamera::FrameBoundingBox() in RefreshManagers() 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 default and cmake --build to 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