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 |
cameraControl: CameraControl |
|
public |
The Viewer's CameraFlightAnimation, which is used to fly the Scene's Camera to given targets. |
|
public get |
capabilities: {astcSupported: boolean, etc1Supported: boolean, pvrtcSupported: boolean, etc2Supported: boolean, dxtSupported: boolean, bptcSupported: boolean}: * Returns the capabilities of this Viewer. |
|
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 |
async getSnapshotWithPlugins(params: *): Promise Gets a snapshot of this Viewer's Scene as a Base64-encoded image which includes the HTML elements created by various plugins. The snapshot image is composed of an image of the viewer canvas, overlaid with an image of the HTML container element belonging to each installed Viewer plugin. Each container element is only rendered once, so it's OK for plugins to share the same container. |
|
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.readableGeometryEnabled | 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.colorTextureEnabled | Boolean |
|
Whether to enable base color texture rendering. |
cfg.pbrEnabled | Boolean |
|
Whether to enable physically-based rendering. |
cfg.localeService | LocaleService |
|
Optional locale-based translation service. |
cfg.dtxEnabled | Boolean |
|
Whether to enable data texture-based (DTX) scene representation within the Viewer. When this is true, the Viewer will use data textures to store geometry on the GPU for triangle meshes that don't have textures. This gives a much lower memory footprint for these types of model element. This mode may not perform well on low-end GPUs that are optimized to use textures to hold geometry data. Works great on most medium/high-end GPUs found in desktop computers, including the nVIDIA and Intel HD chipsets. Set this false to use the default vertex buffer object (VBO) mode for storing geometry, which is the standard technique used in most graphics engines, and will work adequately on most low-end GPUs. |
cfg.markerZOffset | Number |
|
The Z value of offset for Marker's OcclusionTester. The closest the value is to 0.000 the more precise OcclusionTester will be, but at the same time the less precise it will behave for Markers that are located exactly on the Surface. |
cfg.numCachedSectionPlanes | number |
|
Enhances the efficiency of SectionPlane creation by proactively allocating Viewer resources for a specified quantity of SectionPlanes. Introducing this parameter streamlines the initial creation speed of SectionPlanes, particularly up to the designated quantity. This parameter internally configures renderer logic for the specified number of SectionPlanes, eliminating the need for setting up logic with each SectionPlane creation and thereby enhancing responsiveness. It is important to consider that each SectionPlane impacts rendering performance, so it is recommended to set this value to a quantity that aligns with your expected usage. |
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
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 get capabilities: {astcSupported: boolean, etc1Supported: boolean, pvrtcSupported: boolean, etc2Supported: boolean, dxtSupported: boolean, bptcSupported: boolean}: * source
Returns the capabilities of this Viewer.
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 async getSnapshotWithPlugins(params: *): Promise source
Gets a snapshot of this Viewer's Scene as a Base64-encoded image which includes the HTML elements created by various plugins.
The snapshot image is composed of an image of the viewer canvas, overlaid with an image of the HTML container element belonging to each installed Viewer plugin. Each container element is only rendered once, so it's OK for plugins to share the same container.
Usage:
viewer.getSnapshotWithPlugins({
width: 500,
height: 500,
format: "png"
}).then((imageData)=>{
});
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 | * |