@thatopen/ui’s grid-based layout system to create a responsive viewport with dynamic panel integration. The viewport manages 3D rendering, UI overlays, and adaptive layouts.
Viewport Architecture
The viewport system consists of three layers:- Main Application Grid - Top-level layout with left panel and viewport
- Viewport Component - 3D rendering container with floating grid
- Viewport Grid - Dynamic toolbar and panel layouts
Viewport Component
Source: main.ts:33-39Creation
<bim-viewport>- 3D rendering canvas container<bim-grid floating>- Overlay grid for UI elements
Renderer Integration
- Ambient Occlusion (AO): Adds depth perception with shadows
- Gamma Correction: Color space adjustment for accurate display
- Custom Effects: Edge rendering for model clarity
- Line Color: Dark gray (
0x17191c) for subtle outlines
Resize Handling
Main Application Layout
Source: main.ts:176-190Grid Structure
Layout Breakdown
CSS Grid Template:- Left Panel: Fixed width of 29rem (464px)
- Viewport: Fills remaining horizontal space (
1fr) - Height: Both fill container height (
1fr)
leftPanel- Tabbed panel with Project, Settings, and Help tabsviewport- 3D rendering viewport with floating grid
Viewport Grid Layouts
Source: main.ts:192-214 The floating grid inside the viewport has two dynamic layouts:Main Layout (Default)
- Empty Area: Full viewport for 3D rendering
- Toolbar: Bottom-aligned, auto-height toolbar
- Width: Fills viewport width (
1fr)
Second Layout (Selection Active)
- Empty Area: 3D viewport (reduced width)
- Element Data Panel: Fixed 24rem (384px) width, spans full height
- Toolbar: Bottom-left, auto-height
Layout Switching
Layouts switch automatically based on element selection: Selection Panel (src/components/Panels/Selection.ts):Toolbar Integration
Source: main.ts:131-158Tabbed Toolbar
floating- Overlays viewport instead of displacing contentjustify-self: center- Horizontally centers in grid areaborder-radius: 0.5rem- Rounded corners (8px)
- Import - IFC, Fragments, Tiles loading
- Selection - Camera controls, visibility, isolation, focus
- Measurement - Edge, Face, Volume, Length, Area tools
- Load to - Custom IFC loading UI
Grid Management
AppManager Grid Registry
AppManager maintains a registry of named grids for global access:
Dynamic Layout Changes
Layouts can be changed programmatically:World Grid Configuration
Source: main.ts:46-49Ground Plane Grid
- Color: Dark gray (
0x424242) for subtle reference - Size1: Primary grid spacing (2 units)
- Size2: Secondary grid spacing (8 units)
Scene Setup
Source: main.ts:19-31World Creation
- Scene:
SimpleScenewith basic lighting setup - Camera:
OrthoPerspectiveCamerafor orthographic/perspective switching - Renderer:
PostproductionRendererwith effects pipeline
Camera Configuration
Source: main.ts:90-95Camera Controls
- Threshold: 0.25 seconds of inactivity
- On Rest: Cancels ongoing tile loading, triggers culler update
- Purpose: Optimizes streaming by loading tiles only when camera is stable
Fragment Loading Integration
Source: main.ts:97-126On Fragments Loaded
- Index Properties: Process IFC relations if available
- Classify: Group by entity type
- Add to World: Register meshes (non-streamed only)
- Add to Scene: Add model group to Three.js scene
- Fit Camera: Frame all geometry with 80% padding (50ms delay)
On Fragments Disposed
- Removes disposed fragments from world mesh registry
- Ensures proper memory management
Streaming Configuration
Source: main.ts:77-95IFC Streamer Setup
- Threshold: 10 units - distance-based culling sensitivity
- Max Hidden Time: 1000ms - keep hidden tiles in memory for 1 second
- Max Lost Time: 40000ms - dispose unseen tiles after 40 seconds
- Loading only visible tiles
- Caching recently viewed tiles
- Disposing distant tiles to free memory
Highlighter Configuration
Source: main.ts:83-85- World Assignment: Links highlighter to main 3D world
- Zoom to Selection: Automatically frames selected elements
- Event System: Triggers layout changes via
onHighlight/onClearevents
Layout Best Practices
Grid Template Syntax
- Quoted strings: Grid area names
- After areas: Row heights
- After
/: Column widths - Units:
1fr(fraction),auto(content),24rem(fixed)
Responsive Considerations
- Fixed Panel Widths: Use
remunits for consistent sizing - Flexible Viewport: Use
1frto fill available space - Auto Toolbar Height: Use
autofor content-based height - Floating Grids: Overlay UI without affecting viewport size
Performance Tips
- Lazy Panel Loading: Only render element data panel when needed
- Layout Caching: Pre-define layouts, switch via property assignment
- Event Cleanup: Remove listeners when layouts change
- Culler Integration: Sync layout changes with mesh culling updates
Common Layout Patterns
Two-Column with Fixed Left
Toolbar at Bottom
Three-Column with Panels
Header and Content
Example: Custom Layout
Creating a custom viewport layout with split views:Viewport Event Handling
Resize Events
Camera Rest Events
Selection Events
See Also
- Panel Components - UI panel implementation
- Toolbar Components - Toolbar sections and tools
- AppManager - Global application state and grid management
- IFC Viewer - 3D visualization and camera controls