Skip to content

feat: add scene graph with spatial indexing and object placement#96

Merged
ViTeXFTW merged 3 commits intofeat/terrain-renderingfrom
claude/phase-5-scene-graph-BUg31
Feb 23, 2026
Merged

feat: add scene graph with spatial indexing and object placement#96
ViTeXFTW merged 3 commits intofeat/terrain-renderingfrom
claude/phase-5-scene-graph-BUg31

Conversation

@ViTeXFTW
Copy link
Copy Markdown
Owner

Summary

This PR introduces a complete scene graph system with spatial indexing capabilities, along with utilities for object placement and resolution. The implementation provides efficient spatial queries for rendering and includes comprehensive test coverage.

Key Changes

Scene Graph Infrastructure

  • SceneNode: Base class for all scene objects with transform (position, rotation, scale), visibility, and bounding box support
  • SceneGraph: Container managing scene nodes with quadtree-based spatial indexing for efficient frustum and region queries
  • Quadtree: Spatial partitioning data structure supporting:
    • Recursive subdivision with configurable depth and node capacity
    • Rectangular region queries
    • Frustum-based visibility queries
    • Automatic node placement based on world bounds

Object Placement & Resolution

  • ObjectResolver: Caches and resolves W3D model files from template names using asset registry and archive manager
  • ObjectNode: Scene node subclass wrapping HLodModel with skeleton pose support for animated objects
  • ObjectPlacementUtils: Static utility functions for:
    • Template name to W3D filename conversion
    • Map coordinate to Vulkan coordinate transformation
    • Road/bridge point and render flag detection

Testing

  • Comprehensive unit tests for SceneNode (transforms, bounds, visibility)
  • Quadtree tests covering insertion, queries, and spatial operations
  • SceneGraph tests for node management and visibility filtering
  • ObjectPlacementUtils tests for coordinate conversion and flag detection

Implementation Details

  • Quadtree uses center-point containment check first, then fallback to intersection for entries spanning multiple quadrants
  • World bounds calculation transforms all 8 corners of local bounding box through world matrix
  • Scene nodes without explicit bounds use 1-unit fallback bounds centered at position
  • Frustum queries convert 2D rectangles to 3D bounding boxes with infinite Y range for intersection testing
  • Model cache in ObjectResolver uses template name as key for efficient lookup

https://claude.ai/code/session_01JKxTAtdKkNECTCaiVV5Ywz

claude and others added 2 commits February 23, 2026 11:50
Adds SceneNode/Quadtree/SceneGraph spatial indexing infrastructure and
ObjectNode/ObjectResolver/ObjectPlacementUtils for placing W3D models
at map object positions with correct coordinate-system conversion.

- SceneNode: base class with position/rotationY/scale transforms, local
  and world bounding boxes, visibility flag, and worldTransform() matrix
- Quadtree: 2D spatial index in X/Z plane with frustum and rect queries;
  center-based single-child insertion avoids duplicate query results;
  subdivide() accesses nodes by index (not reference) to avoid UB from
  vector reallocation during push_back
- SceneGraph: owns SceneNodes, maintains Quadtree, provides queryVisible()
  for frustum-culled queries and queryAll() for full iteration
- ObjectNode: SceneNode subclass wrapping HLodModel* with templated draw()
  composing worldTransform with per-bone transforms; fromMapObject() factory
- ObjectPlacementUtils: Vulkan-free static utilities (templateNameToW3DName,
  mapPositionToVulkan Z-up->Y-up, isRoadPoint, isBridgePoint, shouldRender)
- ObjectResolver: caches loaded HLodModels by template name; resolve() looks
  up W3D path via AssetRegistry, extracts from BIG archive, parses and caches
- 47 new tests (scene_tests + object_resolver_tests); 100% pass rate

https://claude.ai/code/session_01JKxTAtdKkNECTCaiVV5Ywz
@ViTeXFTW
Copy link
Copy Markdown
Owner Author

@greptileai

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Feb 23, 2026

Greptile Summary

Implemented scene graph system with spatial indexing for efficient object placement and rendering queries. The PR adds a quadtree-based SceneGraph with SceneNode base class, ObjectNode for W3D models, and ObjectResolver for template-to-model caching.

Major Changes:

  • SceneNode base class with position/rotation/scale transforms and world/local bounding boxes
  • Quadtree spatial partitioning for rectangular and frustum-based queries
  • SceneGraph container managing nodes with visibility filtering
  • ObjectNode wrapping HLodModel with skeleton pose support
  • ObjectResolver caching W3D models resolved from map template names
  • ObjectPlacementUtils for coordinate conversion and flag detection
  • Comprehensive test coverage for all scene graph components

Issues Found:

  • Critical bug in quadtree.cpp:94 where depth parameter is hardcoded to 1 during subdivision, breaking depth tracking for multi-level trees
  • Minor inconsistency between ObjectPlacementUtils::shouldRender() and MapObject::shouldRender() implementations

Confidence Score: 3/5

  • Contains a depth tracking bug in quadtree subdivision that could cause incorrect spatial indexing behavior
  • The quadtree subdivision bug at line 94 is a logical error that will cause incorrect depth tracking when nodes subdivide beyond depth 1. This could lead to excessive subdivision or failure to subdivide when expected, potentially affecting rendering performance and correctness. The rest of the implementation is solid with good test coverage.
  • src/lib/scene/quadtree.cpp requires fixing the depth parameter bug in the subdivide function

Important Files Changed

Filename Overview
src/lib/scene/scene_node.cpp Added base SceneNode class with position, rotation, scale transforms and bounding box calculations - clean implementation
src/lib/scene/quadtree.cpp Quadtree spatial indexing with potential depth tracking bug in subdivide function
src/lib/scene/scene_graph.cpp SceneGraph container managing nodes with quadtree-based visibility queries - straightforward implementation
src/render/object_placement_utils.cpp Utility functions for template name parsing and coordinate conversion - has inconsistency with MapObject::shouldRender
src/render/object_resolver.cpp Model caching and W3D file resolution from template names - correct implementation

Last reviewed commit: d741f30

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

17 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment thread src/lib/scene/quadtree.cpp Outdated
Comment thread src/render/object_placement_utils.cpp
…Render inconsistency

- Fix critical bug in Quadtree::subdivide() where depth was hardcoded to 1
  when re-inserting entries after subdivision, causing incorrect depth
  tracking for multi-level trees. Pass depth through to subdivide() and
  use it when calling insertInto() to preserve correct tree depth.

- Fix MapObject::shouldRender() to exclude road/bridge points, aligning it
  with ObjectPlacementUtils::shouldRender(). Road/bridge points are
  placement markers, not renderable models, so both call sites now agree.

- Add regression test SubdivisionDepthIsTrackedCorrectly to verify that
  multi-level subdivision respects maxDepth limits.

https://claude.ai/code/session_01JKxTAtdKkNECTCaiVV5Ywz
@ViTeXFTW
Copy link
Copy Markdown
Owner Author

@greptileai

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Feb 23, 2026

Greptile Summary

This PR implements a complete scene graph system with spatial indexing for efficient object management in the map viewer. The implementation addresses previous review feedback and maintains consistency across the codebase.

  • Scene Graph Core: SceneNode base class provides transforms (position, Y-rotation, scale), bounding boxes, and visibility. SceneGraph manages nodes with quadtree-based spatial indexing for efficient frustum culling.
  • Quadtree Spatial Indexing: Recursive subdivision with configurable depth/capacity, supporting both rectangular region and frustum-based queries. Previous depth tracking bug has been fixed.
  • Object Placement: ObjectResolver caches W3D models by template name, loading from BIG archives. ObjectNode wraps HLodModel with skeleton pose support. ObjectPlacementUtils handles template name parsing and coordinate conversion (map Y/Z swap to Vulkan Y/Z).
  • Render Filtering: shouldRender() logic now consistent between MapObject::shouldRender() and ObjectPlacementUtils::shouldRender() - both exclude FLAG_DONT_RENDER, road points, and bridge points.
  • Test Coverage: Comprehensive unit tests cover scene nodes, quadtree operations (including depth tracking regression test), scene graph queries, and object placement utilities.

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • All previous review feedback has been addressed, implementation follows project patterns, comprehensive test coverage validates correctness, and no bugs or inconsistencies were found
  • No files require special attention

Important Files Changed

Filename Overview
src/lib/scene/scene_node.cpp Transform and bounding box computation - correctly transforms all 8 corners
src/lib/scene/quadtree.cpp Quadtree implementation with correct depth tracking after addressing previous feedback
src/lib/scene/scene_graph.cpp Scene graph implementation with visibility filtering for queries
src/render/object_placement_utils.cpp Template name parsing, coordinate conversion, and render flag filtering - consistent with types.hpp
src/render/object_resolver.cpp W3D model loading from BIG archives with template-based caching
src/lib/formats/map/types.hpp Updated MapObject::shouldRender to exclude road/bridge points, now consistent with ObjectPlacementUtils

Last reviewed commit: f20af65

@ViTeXFTW ViTeXFTW marked this pull request as ready for review February 23, 2026 15:48
@ViTeXFTW ViTeXFTW changed the base branch from claude/implement-water-rendering-hYFD0 to feat/terrain-rendering February 23, 2026 15:52
@ViTeXFTW ViTeXFTW changed the title Add scene graph with spatial indexing and object placement feat: add scene graph with spatial indexing and object placement Feb 23, 2026
@ViTeXFTW ViTeXFTW merged commit 4390c87 into feat/terrain-rendering Feb 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants