Skip to main content

Constructors

constructor

Parameters Returns: Viewer

Accessors

Utils

Returns: Utils

World

Returns: World

Methods

cancelLoad

Cancels any ongoing loading operations, with the option of unloading an current progress Parameters
  • url: string
  • (optional) unload: boolean
Returns: A promise which resolves when the operation completes

createExtension

Creates and registers the extension of the specified type constructor Parameters Returns: The extension instance

dispose

Disposes the viewer instance Returns: void

getContainer

Gets HTML container used at viewer initialisation Returns: HTMLElement

getExtension

Gets the extension of type T registered with the viewer. Returns: Extension subclass, undefined if it does not exist

getObjectProperties

Goes through all objects and builds PropertyInfo objects asynchronously.
When executing for a very large number of objects, this method can take long to finish
Parameters
  • resourceURL: The id of the node where to start building properties.
  • (optional) bypassCache: Enabled the use of the property cache. Default false
Returns: PropertyInfo[]

getRenderer

Gets the SpeckleRenderer instance associated with the viewer. Returns: SpeckleRenderer

getViews

Gets all the current SpeckleView instances. Returns: SpeckleView[]

getWorldTree

Gets the WorldTree instance associated with the viewer. Returns: WorldTree[]

hasExtension

Returns true if specified extension type exists, false otherwise Returns: boolean

init

Initializes the viewer asynchronously and loads required assets. Returns: Promise< void >

loadObject

Loads an object using the specified loader. Parameters
  • loader: SpeckleLoader
  • (optional) autoFit: boolean - Whether to automatically fit the view to the loaded object
Returns: Promise< void >

on

Subscribes handlers to ViewerEvents. Parameters
  • eventType: The ViewerEvent the handler needs to register to
  • handler: The event handler
Returns: void

query

General purpose mechanism for getting spatial information from the viewer. Parameters
  • query: The Query to run
Returns: QueryResult

requestRender

Requests the viewer to render one or more frames. Parameters
  • (optional) flags: UpdateFlags. If no flags are provided it defaults to UpdateFlags.RENDER.
Returns: void

resize

Resize the viewer manually. The dimensions will be inherited from the container. Returns: void

screenshot

Takes a snapshot of the current viewer camera view and returns it as a base64 encoded string. Returns: A promise which resolves to a base64 encoded image.

setLightConfiguration

Applies the provided LightConfiguration. Returns: void

unloadAll

Unloads and disposes everything that’s currently loaded. Returns: _Promise< void > _

unloadObject

Unloads and disposes the specified resource associated with the provided url. Parameters
  • url: The resource id to unload.
Returns: _Promise< void > _

Typedefs

LightConfiguration

  • enabled: Enables direct lighting (sun).
  • castShadow: Enables shadows.
  • intensity: Direct light(sun) intensity.
  • color: Direct light(sun) color.
  • indirectLightIntensity: Indirect IBL intensity.
  • shadowcatcher: Enables The Shadowcatcher. 🛸

ObjectLayers

All the layers the viewer uses for rendering objects and props. Rendering order generally follows the order of layers values. The same layers are also used for raycasting, where they are all enabled by default except STREAM_CONTENT_POINT which is disabled

PropertyInfo

  • key: Property identifier, flattened.
  • objectCount: Total number of objects that have this property.
  • type: If the property is numeric or string based.

SelectionEvent

Payload for ViewerEvent.ObjectClicked and ViewerEvent.ObjectDoubleClicked.
  • multiple: Whether this is a multiple selection or not.
  • event: The browser PointerEvent piggybacked.
  • hits: The array of hits sorted by distance, where closest is first. node is the intersected TreeNode and point is it’s point of intersection.

SpeckleView

  • origin: The origin (location) of the view
  • target: The point where the view is “looking at”.
  • (optional) name: Human readable name
  • (optional) upDirection: The view’s basis up
  • (optional) name: The view’s basis forward

SunLightConfiguration

  • elevation: Sun elevation in polar coordinates.
  • azimuth: Sun azimuth in polar coordinates.
  • radius: Sun distance from World center.

UpdateFlags

Specifies which rendering aspects need to be updated. UpdateFlags work by bit masking. So if you want multiple flags, you need to OR them.

UtilsInterface

Two utilities that help you move values form NDC to Screen space and back.

ViewerEvent

All the events the viewer can emit.

ViewerEventPayload

Mapping of viewer events to event handler argument types

ViewerParams

  • showStats: Displays a stats panel.
  • environmentSrc: The URL of the image used for indirect IBL.
  • verbose: Enables viewer logs.

Asset

  • id: Mandatory id of the asset.
  • src: The URL of the asset. Supports inline base64 encoded assets
  • type: AssetType
For correct asset caching use need to use unique asset ids!

WorldClass

Utility class for keeping track of the total dimensions of loaded objects. It’s mostly used for informative purposes