Overview
ThePlanCamera class manages camera positioning, controls, and viewport interactions in OpenPlans. It provides a top-down view optimized for architectural and engineering drawings with built-in orbit controls, zoom functionality, and view fitting capabilities.
Camera System
PlanCamera uses thecamera-controls library to provide smooth, intuitive camera interactions. The camera is automatically configured for plan view (top-down) rendering.
Initialization
The camera is automatically created when you instantiate OpenPlans:Properties
The camera controls instance providing orbit, pan, and zoom functionality. Based on the
camera-controls library.Key features:- Orbit rotation (disabled for touch with one finger)
- Pan with mouse drag
- Zoom with mouse wheel
- Dolly to cursor position
Internal clock used for smooth camera animations and transitions.
Configuration
The camera is pre-configured with the following settings:Methods
fitToElement()
Automatically adjusts the camera to frame one or more meshes in the viewport.Array of Three.js meshes to fit in the viewport. The camera will adjust position and zoom to show all provided meshes with a small margin.
- Calculates a bounding box containing all meshes
- Expands the box by 2 units for padding
- Fits the camera to the bounding sphere
- Animates the transition smoothly
update()
Updates the camera controls. This is called automatically in the render loop.- Calculates delta time since last update
- Updates camera controls with smooth interpolation
- Handles ongoing camera animations
setupCamera()
Internal method for additional camera configuration. This method is called during initialization to set up camera-controls integration.Camera presets and view modes can be implemented by manually configuring the camera-controls instance through the OpenPlans API.
Usage with OpenPlans Methods
OpenPlans provides high-level methods that utilize the PlanCamera internally:fit()
Fit the camera to all entities of a specific type:The
ogType of elements to fit (e.g., ‘LinePrimitive’, ‘RectanglePrimitive’, ‘space’).Complete Example
Advanced Camera Controls
Access the underlyingcamera-controls instance for advanced functionality:
2D Views
OpenPlans supports creating additional 2D orthographic views:The container element for the 2D view.
The height at which to create a horizontal section plane for the 2D view.
Camera Events
Listen to camera events for custom interactions:Best Practices
- Use
fitToElement()orfit()to frame content after adding elements - Listen to camera events to update UI or trigger actions
- Set appropriate
minDistancefor your scale - Use camera transitions for smooth user experience
- Consider creating 2D views for section cuts and detail views
Notes
- The camera starts at position (0, 20, 0) looking down at the origin
- One-finger touch rotation is disabled to prevent accidental rotations on mobile
- Zoom dollies toward the cursor position for intuitive interaction
- The minimum zoom distance is set to 1.5 units
- Camera updates are synchronized with the render loop automatically