Overview
The scene graph consists of two primary structures defined insrc/scenegraph.rs:
- OGScene - A named collection of geometric entities
- OGSceneManager - Manages multiple scenes and provides WASM-exposed API
OGScene
A scene is a container for geometric entities:SceneEntity
Each entity in a scene wraps a BREP body:kind field identifies the primitive or shape type that generated the BREP, enabling type-aware operations.
Creating Scenes
Basic Scene Creation
Adding Entities
Entities are added using theupsert_entity method:
- If entity ID exists → replaces existing entity
- If entity ID is new → appends to entity list
Removing Entities
true if entity was found and removed, false otherwise.
OGSceneManager
The scene manager provides a stateful API for working with multiple scenes:Creating Scenes
Managing Active Scene
Removing Scenes
Adding Entities to Scenes
The scene manager provides convenience methods for adding primitives:From BREP
From Primitives
add_line_to_scene_internaladd_polyline_to_scene_internaladd_arc_to_scene_internaladd_rectangle_to_scene_internaladd_polygon_to_scene_internaladd_cuboid_to_scene_internaladd_cylinder_to_scene_internaladd_sphere_to_scene_internaladd_wedge_to_scene_internal
- Extracts the BREP from the primitive
- Creates a SceneEntity with appropriate
kind - Adds to the specified scene
Scene to BREP Relationship
Every entity in a scene contains a complete BREP representation:- Each entity is self-contained
- No shared vertex/edge pools between entities
- Easy to add/remove entities without topology updates
- Straightforward serialization
2D Projection
Scenes can be projected to 2D with hidden line removal:Via Scene Manager
WASM API
TheOGSceneManager is exposed to JavaScript via wasm-bindgen:
WASM Methods
Scene Management:createScene(name: string): stringremoveScene(sceneId: string): booleansetCurrentScene(sceneId: string)getCurrentSceneId(): string | undefinedlistScenes(): string(JSON array)
addBrepEntityToScene(sceneId, entityId, kind, brepJson)addLineToScene(sceneId, entityId, line)addCuboidToScene(sceneId, entityId, cuboid)- … (one method per primitive type)
removeEntityFromScene(sceneId, entityId): boolean
projectTo2DCamera(sceneId, cameraJson, hlrJson): stringprojectTo2DLines(sceneId, cameraJson, hlrJson): string
Current Scene Shortcuts
Many methods have variants that operate on the current scene:Scene Serialization
Scenes and entities are fully serializable:- Scene ID and name
- All entities with their IDs, kinds, and complete BREP data
Example: Building a Multi-Entity Scene
Performance Considerations
- Entity lookup: O(n) search by ID (consider HashMap for large scenes)
- BREP cloning: Each add operation clones the BREP
- Projection: All entities processed together, efficient for batch operations
- Serialization: Full scene serialization can be expensive for large models
Next Steps
BREP Structure
Learn about the entity data structure
Projection
Understand 2D projection and hidden line removal