Viewer
The 3D Viewer at the heart of the xeokit SDK.
- A Viewer wraps a single Scene
- Add Plugins to a Viewer to extend its functionality.
- Viewer#metaScene holds metadata about models in the Viewer's MetaScene.
- Use Viewer#cameraFlight to fly or jump the Scene's Camera to target positions, boundaries or Entitys.
Constructor Summary
Public Constructor | ||
public |
constructor(cfg: Object) |
Member Summary
Public Members | ||
public |
The Viewer's Camera. This is also found on Scene#camera. |
|
public |
The Viewer's CameraControl, which controls the Scene's Camera with mouse, touch and keyboard input. |
|
public |
The Viewer's CameraFlightAnimation, which is used to fly the Scene's Camera to given targets. |
|
public |
The Viewer's ID. |
|
public |
this member was deprecated.
The Viewer's current language setting. |
|
public |
The viewer's locale service. This is configured via the Viewer's constructor. |
since 2.0 |
public |
Metadata about the Scene and the models and objects within it. |
|
public |
The Viewer's Scene. |
Method Summary
Public Methods | ||
public |
Enter snapshot mode. |
|
public |
destroy() Destroys this Viewer. |
|
public |
Exits snapshot mode. |
|
public |
Logs an error message to the JavaScript developer console, prefixed with the ID of this Viewer. |
|
public |
Fires an event at this Viewer. |
|
public |
getSnapshot(params: *): String Gets a snapshot of this Viewer's Scene as a Base64-encoded image. Usage:
|
|
public |
Logs a message to the JavaScript developer console, prefixed with the ID of this Viewer. |
|
public |
off(event: *) Unsubscribes from an event fired at this Viewer. |
|
public |
Subscribes to an event fired at this Viewer. |
Public Constructors
public constructor(cfg: Object) source
Params:
Name | Type | Attribute | Description |
cfg | Object | Viewer configuration. |
|
cfg.id | String |
|
Optional ID for this Viewer, defaults to the ID of Viewer#scene, which xeokit automatically generates. |
cfg.canvasId | String |
|
ID of an existing HTML canvas for the Viewer#scene - either this or canvasElement is mandatory. When both values are given, the element reference is always preferred to the ID. |
cfg.canvasElement | HTMLCanvasElement |
|
Reference of an existing HTML canvas for the Viewer#scene - either this or canvasId is mandatory. When both values are given, the element reference is always preferred to the ID. |
cfg.keyboardEventsElement | HTMLElement |
|
Optional reference to HTML element on which key events should be handled. Defaults to the HTML Document. |
cfg.spinnerElementId | String |
|
ID of existing HTML element to show the Spinner - internally creates a default element automatically if this is omitted. |
cfg.passes | Number |
|
The number of times the Viewer#scene renders per frame. |
cfg.clearEachPass | Boolean |
|
When doing multiple passes per frame, specifies if to clear the canvas before each pass (true) or just before the first pass (false). |
cfg.preserveDrawingBuffer | Boolean |
|
Whether or not to preserve the WebGL drawing buffer. This needs to be |
cfg.transparent | Boolean |
|
Whether or not the canvas is transparent. |
cfg.premultipliedAlpha | Boolean |
|
Whether or not you want alpha composition with premultiplied alpha. Highlighting and selection works best when this is |
cfg.gammaInput | Boolean |
|
When true, expects that all textures and colors are premultiplied gamma. |
cfg.gammaOutput | Boolean |
|
Whether or not to render with pre-multiplied gama. |
cfg.gammaFactor | Number |
|
The gamma factor to use when rendering with pre-multiplied gamma. |
cfg.backgroundColor | Number[] |
|
Sets the canvas background color to use when |
cfg.backgroundColorFromAmbientLight | Boolean |
|
When |
cfg.units | String |
|
The measurement unit type. Accepted values are |
cfg.scale | Number |
|
The number of Real-space units in each World-space coordinate system unit. |
cfg.origin | Number[] |
|
The Real-space 3D origin, in current measurement units, at which the World-space coordinate origin |
cfg.saoEnabled | Boolean |
|
Whether to enable Scalable Ambient Obscurance (SAO) effect. See SAO for more info. |
cfg.antialias | Boolean |
|
Whether to enable anti-aliasing. |
cfg.alphaDepthMask | Boolean |
|
Whether writing into the depth buffer is enabled or disabled when rendering transparent objects. |
cfg.entityOffsetsEnabled | Boolean |
|
Whether to enable Entity#offset. For best performance, only set this |
cfg.pickSurfacePrecisionEnabled | Boolean |
|
Whether to enable full-precision accuracy when surface picking with Scene#pick. Note that when |
cfg.logarithmicDepthBufferEnabled | Boolean |
|
Whether to enable logarithmic depth buffer. When this is true, you can set huge values for Perspective#far and Ortho#far, to push the far clipping plane back so that it does not clip huge models. |
cfg.pbrEnabled | Boolean |
|
Whether to enable physically-based rendering. |
cfg.localeService | LocaleService |
|
Optional locale-based translation service. |
Throw:
Throws an exception when both canvasId or canvasElement are missing or they aren't pointing to a valid HTMLCanvasElement. |
Public Members
public camera: Camera source
The Viewer's Camera. This is also found on Scene#camera.
Properties:
Name | Type | Attribute | Description |
camera | * |
public cameraControl: CameraControl source
The Viewer's CameraControl, which controls the Scene's Camera with mouse, touch and keyboard input.
Properties:
Name | Type | Attribute | Description |
cameraControl | * |
public cameraFlight: CameraFlightAnimation source
The Viewer's CameraFlightAnimation, which is used to fly the Scene's Camera to given targets.
Properties:
Name | Type | Attribute | Description |
cameraFlight | * |
public language: String source
The Viewer's current language setting.
Properties:
Name | Type | Attribute | Description |
language | * |
public localeService: LocaleService since 2.0 source
The viewer's locale service.
This is configured via the Viewer's constructor.
By default, this service will be an instance of LocaleService, which will just return null translations for all given strings and phrases.
Properties:
Name | Type | Attribute | Description |
localeService | * |
Public Methods
public beginSnapshot() source
Enter snapshot mode.
Switches rendering to a hidden snapshot canvas.
Exit snapshot mode using Viewer#endSnapshot.
public error(msg: String) source
Logs an error message to the JavaScript developer console, prefixed with the ID of this Viewer.
Params:
Name | Type | Attribute | Description |
msg | String | The error message |
public getSnapshot(params: *): String source
Gets a snapshot of this Viewer's Scene as a Base64-encoded image.
Usage:
const imageData = viewer.getSnapshot({
width: 500,
height: 500,
format: "png"
});
Params:
Name | Type | Attribute | Description |
params | * |
|
Capture options. |
params.width | Number |
|
Desired width of result in pixels - defaults to width of canvas. |
params.height | Number |
|
Desired height of result in pixels - defaults to height of canvas. |
params.format | String |
|
Desired format; "jpeg", "png" or "bmp". |
params.includeGizmos | Boolean |
|
When true, will include gizmos like SectionPlane in the snapshot. |
public log(msg: String) source
Logs a message to the JavaScript developer console, prefixed with the ID of this Viewer.
Params:
Name | Type | Attribute | Description |
msg | String | The message |
public off(event: *) source
Unsubscribes from an event fired at this Viewer.
Params:
Name | Type | Attribute | Description |
event | * |