Camera Class
A Camera defines a viewpoint within a Viewer.
Overview
- You can have an unlimited number of Cameras in a Viewer.
- At any instant, the Camera we're looking through is the one whose active property is true.
- Cameras can be controlled with controls such as CameraControl, KeyboardAxisCamera, KeyboardOrbitCamera, KeyboardPanCamera, KeyboardZoomCamera, MouseOrbitCamera, MousePanCamera and MouseZoomCamera.
Example
In this example we define multiple Cameras looking at a TeapotObject, then periodically switch between the Cameras.
// Create a Viewer
var viewer = new BIMSURFER.Viewer({ element: "myDiv" });
// Create an object
var box = new BIMSURFER.TeapotObject(viewer);
// Create some Cameras
var cameras = [
new BIMSURFER.Camera(viewer, {
eye: [5, 5, 5],
active: false
}),
new BIMSURFER.Camera(viewer, {
eye: [-5, 5, 5],
active: false
}),
new BIMSURFER.Camera(viewer, {
eye: [5, -5, 5],
active: false
}),
new BIMSURFER.Camera(viewer, {
eye: [5, 5, -5],
active: false
}),
new BIMSURFER.Camera(viewer, {
eye: [-5, -5, 5],
active: false
})
];
// Periodically switch between the Cameras
var i = -1;
var last = -1;
setInterval(function () {
if (last > -1) {
cameras[last].active = false
}
i = (i + 1) % (cameras.length - 1);
cameras[i].active = true;
last = i;
}, 1000);
Constructor
Camera
-
[viewer]
-
[cfg]
Parameters:
-
[viewer]
Viewer optionalParent Viewer.
-
[cfg]
optionalConfigs
-
[id]
String optionalOptional ID, unique among all components in the parent viewer, generated automatically when omitted.
-
[meta]
String:Object optionalOptional map of user-defined metadata to attach to this Camera.
-
[eye=[0,0,-10]]
Array of Number optionalEye position.
-
[look=[0,0,0]]
Array of Number optionalThe position of the point-of-interest we're looking at.
-
[up=[0,1,0]]
Array of Number optionalThe "up" vector.
-
[fovy=60.0]
Number optionalField-of-view angle, in degrees, on Y-axis.
-
[aspect=1.0]
Number optionalAspect ratio.
-
[near=0.1]
Number optionalPosition of the near plane on the View-space Z-axis.
-
[far=10000]
Number optionalPosition of the far plane on the View-space Z-axis.
-
Item Index
Properties
Methods
destroy
()
error
-
message
Logs an error for this component to the JavaScript console.
The console message will have this format: [ERROR] <component id>: <message>
Parameters:
-
message
StringThe message to log
fire
-
event
-
value
-
[forget=false]
Fires an event on this component.
Notifies existing subscribers to the event, retains the event to give to any subsequent notifications on that location as they are made.
Parameters:
-
event
StringThe event type name
-
value
ObjectThe event
-
[forget=false]
Boolean optionalWhen true, does not retain for subsequent subscribers
log
-
message
Logs a console debugging message for this component.
The console message will have this format: [LOG] <component id>: <message>
Parameters:
-
message
StringThe message to log
off
-
handle
Parameters:
-
handle
StringSubscription handle
on
-
event
-
callback
-
[scope=this]
Subscribes to an event on this component.
The callback is be called with this component as scope.
Parameters:
-
event
StringPublication event
-
callback
FunctionCalled when fresh data is available at the event
-
[scope=this]
Object optionalScope for the callback
Returns:
Handle to the subscription, which may be used to unsubscribe with {@link #off}.
once
-
event
-
callback
-
[scope=this]
Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is handled.
Parameters:
-
event
StringData event to listen to
-
callback
Function(data)Called when fresh data is available at the event
-
[scope=this]
Object optionalScope for the callback
warn
-
message
Logs a warning for this component to the JavaScript console.
The console message will have this format: [WARN] <component id>: <message>
Parameters:
-
message
StringThe message to log
Properties
active
Boolean
Flag which indicates whether this Camera is active or not.
Fires an active event on change.
className
String
final
JavaScript class name for this Component.
destroyed
Boolean
True as soon as this Component has been destroyed
exclusive
Boolean
final
Indicates that only one instance of a Camera may be active within its Viewer at a time. When a Camera is activated, that has a true value for this flag, then any other active Camera will be deactivated first.
eye
Array(Number)
Position of the eye. Fires an Camera/eye:event event on change.
Default: [0,0,-10]
far
Number
Distance to far clip plane in normalized device coordinates [0..1]. Fires an far event on change.
Default: 10000
Items in this map
Unknown
look
Array(Number)
Position of the point-of-interest. Fires a Camera/look:event event on change.
Default: [0,0,0]
metadata
Object
Metadata on this component.
near
Number
Distance to near clip plane in normalized device coordinates [0..1]. Fires an near event on change.
Default: 0.1
up
Array(Number)
Direction of the "up" vector. Fires an Camera/up:event event on change.
Default: [0,1,0]
Events
active
Fired whenever this Camera's active property changes.
Event Payload:
-
value
ObjectThe property's new value
destroyed
Fired when this Component is destroyed.
far
Fired whenever this Camera's far property changes.
Event Payload:
-
value
ObjectThe property's new value
fovy
Fired whenever this Camera's Camera/fovy:property property changes.
Event Payload:
-
value
ObjectThe property's new value
near
Fired whenever this Camera's near property changes.
Event Payload:
-
value
ObjectThe property's new value