Reference Source
public class | source

BIMViewer

Extends:

src/Controller.js~Controller → BIMViewer

A BIM viewer based on the xeokit SDK.

Constructor Summary

Public Constructor
public

constructor(server: Server, cfg: *)

Constructs a BIMViewer.

Member Summary

Public Members
public get

localeService: LocaleService: *

Returns the LocaleService that was configured on this Viewer.

public
public
public

viewer: Viewer

The xeokit Viewer at the core of this BIMViewer.

Method Summary

Public Methods
public

Adds a model.

public

Clears sections.

public

deleteModel(modelId: String)

Deletes a model.

public

Destroys the viewer, freeing all resources.

public

Disables all sections.

public

editModel(modelId: String)

Edits a model.

public

Enables all sections.

public

Inverts the direction of sections.

public

flyToObject(objectId: String, done: Function)

Flies the camera to fit the given object in view.

public

Gets whether the viewer is in 3D or 2D viewing mode.

public

getConfig(name: String): *

Gets the value of a viewer configuration.

public

Gets whether keyboard camera control is enabled.

public

Returns the IDs of the currently loaded models, if any.

public

Returns the ID of the currently loaded project, if any.

public

Returns the IDs of the models in the currently loaded project.

public

Returns the number of sections that currently exist.

public
this method was deprecated.

Gets where the colors for model objects will be loaded from.

public

getObjectInfo(projectId: String, modelId: String, objectId: String, done: Function, error: Function)

Gets information on the given object, belonging to the given model, within the given project.

public

Returns the ID of the currently open viewer tab.

public

Gets whether the viewer is in orthographic viewing mode.

public

getProjectInfo(projectId: String, done: Function, error: Function)

Gets information on the given project.

public

Gets information on all available projects.

public

Gets whether the viewer allows IFCSpace types to be shown.

public

Hides the section edition control, if currently shown.

public

Gets if the given model is loaded.

public

jumpToObject(objectId: String)

Jumps the camera to fit the given object in view.

public

Load all models in the currently loaded project.

public

loadBCFViewpoint(bcfViewpoint: *, options: *)

Sets viewer state to the given BCF viewpoint.

public

loadModel(modelId: String, done: Function, error: Function)

Loads a model into the viewer.

public

loadProject(projectId: String, done: Function, error: Function)

Loads a project into the viewer.

public

openTab(tabId: String)

Opens the specified viewer tab.

public

Resets the view.

public

saveBCFViewpoint(options: *): *

Saves viewer state to a BCF viewpoint.

public

selectStorey(storeyObjectId: String, done: Function)

Transitions the viewer into an isolated view of the given building storey.

public

set3DEnabled(enabled: Boolean, done: Function)

Switches the viewer between 2D and 3D viewing modes.

public

Sets whether or not all objects are selected.

public

Sets the visibility of all objects.

public

Sets whether or not all objects are X-rayed.

public

setBackgroundColor(rgbColor: Number[])

Sets the viewer's background color.

public

Sets the camera to the given position.

public

setConfig(name: String, value: *)

Sets a viewer configuration.

public

setConfigs(viewerConfigs: *)

Sets a batch of viewer configurations.

public

Enables or disables the various buttons and controls throughout the viewer.

public

Sets whether or not keyboard camera control is enabled.

public
this method was deprecated.

Sets where the colors for model objects will be loaded from.

public

setObjectsSelected(objectIds: String[], selected: Boolean)

Sets whether or not the given objects are selected.

public

setObjectsVisible(objectIds: String[], visible: Boolean)

Sets whether or not the given objects are visible.

public

setObjectsXRayed(objectIds: String[], xrayed: Boolean)

Sets whether or not the given objects are X-rayed.

public

setOrthoEnabled(enabled: Boolean, done: Function)

Sets whether the viewer is in orthographic viewing mode.

public

Sets whether IFCSpace types are ever shown.

public

setViewerState(viewerState: Object, done: Function)

Updates viewer UI state according to the properties in the given object.

public

Highlights the given object in the tree views within the Objects, Classes and Storeys tabs.

public

Shows the properties of the given object in the Properties tab.

public

De-highlights the object previously highlighted with BIMViewer#showObjectInExplorers.

public

Unloads all currently loaded models.

public

unloadModel(modelId: String)

Unloads a model from the viewer.

public

Unloads whatever project is currently loaded.

public

Flies the camera to fit all objects in view.

public

viewFitModels(modelIds: String[], done: Function)

Fits the given models in view.

public

viewFitObjects(objectIds: String[], done: Function)

Flies the camera to fit the given objects in view.

Public Constructors

public constructor(server: Server, cfg: *) source

Constructs a BIMViewer.

Params:

NameTypeAttributeDescription
server Server

Data access strategy.

cfg *

Configuration.

cfg.enableEditModels Boolean
  • optional
  • default: false

Set true to show "Add", "Edit" and "Delete" options in the Models tab's context menu.

cfg.keyboardEventsElement Boolean
  • optional

Optional reference to HTML element on which key events should be handled. Defaults to the HTML Document.

Public Members

public get localeService: LocaleService: * source

Returns the LocaleService that was configured on this Viewer.

Return:

LocaleService

The LocaleService.

public setFirstPersonModeActive: * source

public setThreeDModeActive: * source

public viewer: Viewer source

The xeokit Viewer at the core of this BIMViewer.

Public Methods

public addModel() source

Adds a model.

public clearSections() source

Clears sections.

Sections are the slicing planes, that we use to section models in order to see interior structures.

public deleteModel(modelId: String) source

Deletes a model.

Assumes that the project containing the model is currently loaded.

Params:

NameTypeAttributeDescription
modelId String

ID of the model to delete. Must be the ID of one of the models in the currently loaded project.

public destroy() source

Destroys the viewer, freeing all resources.

public disableSections() source

Disables all sections.

public editModel(modelId: String) source

Edits a model.

Assumes that the project containing the model is currently loaded.

Params:

NameTypeAttributeDescription
modelId String

ID of the model to edit. Must be the ID of one of the models in the currently loaded project.

public enableSections() source

Enables all sections.

public flipSections() source

Inverts the direction of sections.

public flyToObject(objectId: String, done: Function) source

Flies the camera to fit the given object in view.

Params:

NameTypeAttributeDescription
objectId String

ID of the object

done Function

Callback invoked on completion

public get3DEnabled(): boolean source

Gets whether the viewer is in 3D or 2D viewing mode.

Return:

boolean

True when in 3D mode, else false.

public getConfig(name: String): * source

Gets the value of a viewer configuration.

These are set with BIMViewer#setConfig and BIMViewer#setConfigs.

Params:

NameTypeAttributeDescription
name String

Configuration name.

Return:

*

public getKeyboardEnabled(): Boolean source

Gets whether keyboard camera control is enabled.

This is useful when we don't want key events over the canvas to clash with other UI elements outside the canvas.

Default value is true.

Return:

Boolean

Returns true if keyboard input is enabled.

public getLoadedModelIds(): String[] source

Returns the IDs of the currently loaded models, if any.

Return:

String[]

The IDs of the currently loaded models, otherwise an empty array if no models are currently loaded.

public getLoadedProjectId(): String source

Returns the ID of the currently loaded project, if any.

Return:

String

The ID of the currently loaded project, otherwise null if no project is currently loaded.

public getModelIds(): String[] source

Returns the IDs of the models in the currently loaded project.

Return:

String[]

The IDs of the models in the currently loaded project.

public getNumSections(): Number source

Returns the number of sections that currently exist.

sections are the sliceing planes, that we use to slice models in order to see interior structures.

Return:

Number

The number of sections.

public getObjectColorSource(): String source

this method was deprecated.

Gets where the colors for model objects will be loaded from.

This is "model" by default.

Return:

String

Where colors will be loaded from - "model" to get colors from the model, or "viewer" to get them from the viewer's built-in table of colors for IFC types.

public getObjectInfo(projectId: String, modelId: String, objectId: String, done: Function, error: Function) source

Gets information on the given object, belonging to the given model, within the given project.

See Getting Info on an Object for usage.

Params:

NameTypeAttributeDescription
projectId String

ID of the project to get information on. Must be the ID of one of the projects in the information obtained by BIMViewer#getProjects.

modelId String

ID of a model within the project. Must be the ID of one of the models in the information obtained by BIMViewer#getProjectInfo.

objectId String

ID of an object in the model.

done Function

Callback invoked on success, into which the object information JSON is passed.

error Function

Callback invoked on failure, into which the error message string is passed.

public getOpenTab(): string source

Returns the ID of the currently open viewer tab.

The available tabs are:

  • "models" - the Models tab, which lists the models available within the currently loaded project,
  • "objects" - the Objects tab, which contains a tree view for each loaded model, organized to indicate the containment hierarchy of their objects,
  • "classes" - the Classes tab, which contains a tree view for each loaded model, with nodes grouped by IFC types of their objects,
  • "storeys" - the Storeys tab, which contains a tree view for each loaded model, with nodes grouped within IfcBuildingStoreys, sub-grouped by their IFC types,
  • "properties" - the Properties tab, which shows property sets for a given object, and
  • "none" - no tab is open; this is unlikely, since one of the above tabs should be open at a any time, but here for robustness.

Return:

string

public getOrthoEnabled(): boolean source

Gets whether the viewer is in orthographic viewing mode.

The viewer is either in orthographic mode or perspective mode. The viewer is in perspective mode by default.

Return:

boolean

True when in ortho mode, else false when in perspective mode.

public getProjectInfo(projectId: String, done: Function, error: Function) source

Gets information on the given project.

See Getting Info on a Project for usage.

Params:

NameTypeAttributeDescription
projectId String

ID of the project to get information on. Must be the ID of one of the projects in the information obtained by BIMViewer#getProjects.

done Function

Callback invoked on success, into which the project information JSON is passed.

error Function

Callback invoked on failure, into which the error message string is passed.

public getProjectsInfo(done: Function, error: Function) source

Gets information on all available projects. Gets information on all available projects.

See Getting Info on Available Projects for usage.

Params:

NameTypeAttributeDescription
done Function

Callback invoked on success, into which the projects information JSON is passed.

error Function

Callback invoked on failure, into which the error message string is passed.

public getSpacesShown(): boolean source

Gets whether the viewer allows IFCSpace types to be shown.

Return:

boolean

True to allow IFCSpaces to be shown, else false to always keep them hidden.

public hideSectionEditControl() source

Hides the section edition control, if currently shown.

public isModelLoaded(modelId: String): Boolean source

Gets if the given model is loaded.

Params:

NameTypeAttributeDescription
modelId String

ID of the model to check. Must be the ID of one of the models in the currently loaded project.

Return:

Boolean

True if the given model is loaded.

public jumpToObject(objectId: String) source

Jumps the camera to fit the given object in view.

Params:

NameTypeAttributeDescription
objectId String

ID of the object

public loadAllModels(done: Function) source

Load all models in the currently loaded project.

Doesn't reload any models that are currently loaded.

Params:

NameTypeAttributeDescription
done Function

Callback invoked on successful loading of the models.

public loadBCFViewpoint(bcfViewpoint: *, options: *) source

Sets viewer state to the given BCF viewpoint.

This assumes that the viewer currently contains the same project and model(s) that were loaded at the time that the viewpoint was originally saved (the BCF viewpoint specification does not contain that information).

Note that xeokit's Camera#look is the point-of-interest, whereas the BCF camera_direction is a direction vector. Therefore, when loading a BCF viewpoint, we set Camera#look to the absolute position obtained by offsetting the BCF camera_view_point along camera_direction.

When loading a viewpoint, we also have the option to find Camera#look as the closest point of intersection (on the surface of any visible and pickable Entity) with a 3D ray fired from camera_view_point in the direction of camera_direction.

Params:

NameTypeAttributeDescription
bcfViewpoint *

BCF JSON viewpoint object or "reset" / "RESET" to reset the viewer, which clears SectionPlanes, shows default visible entities and restores camera to initial default position.

options *
  • optional

Options for setting the viewpoint.

options.rayCast Boolean
  • optional
  • default: true

When true (default), will attempt to set Camera#look to the closest point of surface intersection with a ray fired from the BCF camera_view_point in the direction of camera_direction.

options.immediate Boolean
  • optional
  • default: true

When true (default), immediately set camera position.

options.duration Boolean
  • optional

Flight duration in seconds. Overrides CameraFlightAnimation#duration.

options.reset Boolean
  • optional
  • default: true

When true (default), set Entity#xrayed and Entity#highlighted false on all scene objects.

options.reverseClippingPlanes Boolean
  • optional
  • default: false

When true, clipping planes are reversed (https://github.com/buildingSMART/BCF-XML/issues/193)

options.updateCompositeObjects Boolean
  • optional
  • default: false

When true, then when visibility and selection updates refer to composite objects (eg. an IfcBuildingStorey), then this method will apply the updates to objects within those composites.

public loadModel(modelId: String, done: Function, error: Function) source

Loads a model into the viewer.

Assumes that the project containing the model is currently loaded.

Params:

NameTypeAttributeDescription
modelId String

ID of the model to load. Must be the ID of one of the models in the currently loaded project.

done Function

Callback invoked on success.

error Function

Callback invoked on failure, into which the error message string is passed.

public loadProject(projectId: String, done: Function, error: Function) source

Loads a project into the viewer.

Unloads any currently loaded project and its models first. If the given project is already loaded, will unload that project first.

Params:

NameTypeAttributeDescription
projectId String

ID of the project to load. Must be the ID of one of the projects in the information obtained by BIMViewer#getProjects.

done Function

Callback invoked on success.

error Function

Callback invoked on failure, into which the error message string is passed.

public openTab(tabId: String) source

Opens the specified viewer tab.

The available tabs are:

  • "models" - the Models tab, which lists the models available within the currently loaded project,
  • "objects" - the Objects tab, which contains a tree view for each loaded model, organized to indicate the containment hierarchy of their objects,
  • "classes" - the Classes tab, which contains a tree view for each loaded model, with nodes grouped by IFC types of their objects,
  • "storeys" - the Storeys tab, which contains a tree view for each loaded model, with nodes grouped within IfcBuildingStoreys, sub-grouped by their IFC types, and
  • "properties" - the Properties tab, which shows property sets for a given object.

Params:

NameTypeAttributeDescription
tabId String

ID of the tab to open - see method description.

public resetView() source

Resets the view.

This resets object appearances (visibility, selection, highlight and X-ray), sets camera to default position, and removes section planes.

public saveBCFViewpoint(options: *): * source

Saves viewer state to a BCF viewpoint.

This does not save information about the project and model(s) that are currently loaded. When loading the viewpoint, the viewer will assume that the same project and models will be currently loaded (the BCF viewpoint specification does not contain that information).

Note that xeokit's Camera#look is the point-of-interest, whereas the BCF camera_direction is a direction vector. Therefore, we save camera_direction as the vector from Camera#eye to Camera#look.

Params:

NameTypeAttributeDescription
options *
  • optional

Options for getting the viewpoint.

options.spacesVisible Boolean
  • optional
  • default: false

Indicates whether IfcSpace types should be forced visible in the viewpoint.

options.openingsVisible Boolean
  • optional
  • default: false

Indicates whether IfcOpening types should be forced visible in the viewpoint.

options.spaceBoundariesVisible Boolean
  • optional
  • default: false

Indicates whether the boundaries of IfcSpace types should be visible in the viewpoint.

options.reverseClippingPlanes Boolean
  • optional
  • default: false

When true, clipping planes are reversed (https://github.com/buildingSMART/BCF-XML/issues/193)

options.defaultInvisible Boolean
  • optional
  • default: false

When true, will save the default visibility of all objects as false. This means that when we load the viewpoint again, and there are additional models loaded that were not saved in the viewpoint, those models will be hidden when we load the viewpoint, and that only the objects in the viewpoint will be visible.

Return:

*

BCF JSON viewpoint object

Example:


const viewpoint = bimViewer.saveBCFViewpoint({
    spacesVisible: false,          // Default
    spaceBoundariesVisible: false, // Default
    openingsVisible: false         // Default
});

// viewpoint will resemble the following:

{
    perspective_camera: {
        camera_view_point: {
            x: 0.0,
            y: 0.0,
            z: 0.0
        },
        camera_direction: {
            x: 1.0,
            y: 1.0,
            z: 2.0
        },
        camera_up_vector: {
            x: 0.0,
            y: 0.0,
            z: 1.0
        },
        field_of_view: 90.0
    },
    lines: [],
    clipping_planes: [{
        location: {
            x: 0.5,
            y: 0.5,
            z: 0.5
        },
        direction: {
            x: 1.0,
            y: 0.0,
            z: 0.0
        }
    }],
    bitmaps: [],
    snapshot: {
        snapshot_type: png,
        snapshot_data: "data:image/png;base64,......"
    },
    components: {
        visibility: {
            default_visibility: false,
            exceptions: [{
                ifc_guid: 4$cshxZO9AJBebsni$z9Yk,
                originating_system: xeokit.io,
                authoring_tool_id: xeokit/v1.0
            }]
       },
        selection: [{
           ifc_guid: "4$cshxZO9AJBebsni$z9Yk",
        }]
    }
}

public selectStorey(storeyObjectId: String, done: Function) source

Transitions the viewer into an isolated view of the given building storey.

Does nothing and logs an error if no object of the given ID is in the viewer, or if the object is not an IfcBuildingStorey.

Params:

NameTypeAttributeDescription
storeyObjectId String

ID of an IfcBuildingStorey object.

done Function
  • optional

Optional callback to invoke on completion. When provided, the transition will be animated, with the camera flying into position. Otherwise, the transition will be instant, with the camera jumping into position.

public set3DEnabled(enabled: Boolean, done: Function) source

Switches the viewer between 2D and 3D viewing modes.

Params:

NameTypeAttributeDescription
enabled Boolean

Set true to switch into 3D mode, else false to switch into 2D mode.

done Function

Callback to invoke when switch complete. Supplying this callback causes an animated transition. Otherwise, the transition will be instant.

public setAllObjectsSelected(selected: Boolean) source

Sets whether or not all objects are selected.

Params:

NameTypeAttributeDescription
selected Boolean

Whether or not to set all objects selected.

public setAllObjectsVisible(visible: Boolean) source

Sets the visibility of all objects.

Params:

NameTypeAttributeDescription
visible Boolean

True to set objects visible, false to set them invisible.

public setAllObjectsXRayed(xrayed: Boolean) source

Sets whether or not all objects are X-rayed.

Params:

NameTypeAttributeDescription
xrayed Boolean

Whether or not to set all objects X-rayed.

public setBackgroundColor(rgbColor: Number[]) source

Sets the viewer's background color.

Params:

NameTypeAttributeDescription
rgbColor Number[]

Three-element array of RGB values, each in range [0..1].

public setCamera() source

Sets the camera to the given position.

Params:

NameTypeAttributeDescription
params.eye Number[]
  • optional

Eye position.

params.look Number[]
  • optional

Point of interest.

params.up Number[]
  • optional

Direction of "up".

public setConfig(name: String, value: *) source

Sets a viewer configuration.

See Viewer Configurations for the list of available configurations.

Params:

NameTypeAttributeDescription
name String

Configuration name.

value *

Configuration value.

public setConfigs(viewerConfigs: *) source

Sets a batch of viewer configurations.

Note that this method is not to be confused with BIMViewer#setViewerState, which batch-updates various states of the viewer's UI and 3D view.

See Viewer Configurations for the list of available configurations.

Params:

NameTypeAttributeDescription
viewerConfigs *

Map of key-value configuration pairs.

public setControlsEnabled(enabled: Boolean) source

Enables or disables the various buttons and controls throughout the viewer.

This also makes various buttons appear disabled.

Params:

NameTypeAttributeDescription
enabled Boolean

Whether or not to disable the controls.

public setKeyboardEnabled(enabled: Boolean) source

Sets whether or not keyboard camera control is enabled.

This is useful when we don't want key events over the canvas to clash with other UI elements outside the canvas.

Default value is true.

Params:

NameTypeAttributeDescription
enabled Boolean

Set true to enable keyboard input.

public setObjectColorSource(source: String) source

this method was deprecated.

Sets where the colors for model objects will be loaded from.

Options are:

  • "model" - (default) load colors from models, and
  • "viewer" - load colors from the viewer's inbuilt table of colors for IFC types.

This is "model" by default.

Params:

NameTypeAttributeDescription
source String

Where colors will be loaded from - "model" or "viewer".

public setObjectsSelected(objectIds: String[], selected: Boolean) source

Sets whether or not the given objects are selected.

Params:

NameTypeAttributeDescription
objectIds String[]

IDs of objects.

selected Boolean

Whether or not to set the objects selected.

public setObjectsVisible(objectIds: String[], visible: Boolean) source

Sets whether or not the given objects are visible.

Params:

NameTypeAttributeDescription
objectIds String[]

IDs of objects.

visible Boolean

True to set objects visible, false to set them invisible.

public setObjectsXRayed(objectIds: String[], xrayed: Boolean) source

Sets whether or not the given objects are X-rayed.

Params:

NameTypeAttributeDescription
objectIds String[]

IDs of objects.

xrayed Boolean

Whether or not to X-ray the objects.

public setOrthoEnabled(enabled: Boolean, done: Function) source

Sets whether the viewer is in orthographic viewing mode.

The viewer is either in orthographic mode or perspective mode. The viewer is in perspective mode by default.

Params:

NameTypeAttributeDescription
enabled Boolean

Set true to switch into ortho mode, else false to switch into perspective mode.

done Function

Callback to invoke when switch complete. Supplying this callback causes an animated transition. Otherwise, the transition will be instant.

public setSpacesShown(shown: Boolean) source

Sets whether IFCSpace types are ever shown.

Params:

NameTypeAttributeDescription
shown Boolean

Set true to allow IFCSpaces to be shown, else false to always keep them hidden.

public setViewerState(viewerState: Object, done: Function) source

Updates viewer UI state according to the properties in the given object.

Note that, since some updates could be animated (e.g. flying the camera to fit objects to view) this method optionally takes a callback, which it invokes after updating the UI.

Also, this method is not to be confused with BIMViewer#setConfigs, which is used to batch-update various configurations and user preferences on the viewer.

See Viewer States for the list of states that may be batch-updated with this method.

Params:

NameTypeAttributeDescription
viewerState Object

Specifies the viewer UI state updates.

done Function

Callback invoked on successful update of the viewer states.

public showObjectInExplorers(objectId: String) source

Highlights the given object in the tree views within the Objects, Classes and Storeys tabs.

Also scrolls the object's node into view within each tree, then highlights it.

De-highlights whatever node is currently highlighted in each of those trees.

Params:

NameTypeAttributeDescription
objectId String

ID of the object

public showObjectProperties(objectId: String) source

Shows the properties of the given object in the Properties tab.

Params:

NameTypeAttributeDescription
objectId String

ID of the object

public unShowObjectInExplorers() source

De-highlights the object previously highlighted with BIMViewer#showObjectInExplorers.

This only de-highlights the node. If the node is currently scrolled into view, then the node will remain in view.

For each tab, does nothing if a node is currently highlighted.

public unloadAllModels() source

Unloads all currently loaded models.

public unloadModel(modelId: String) source

Unloads a model from the viewer.

Does nothing if the model is not currently loaded.

Params:

NameTypeAttributeDescription
modelId String

ID of the model to unload.

public unloadProject() source

Unloads whatever project is currently loaded.

public viewFitAll(done: Function) source

Flies the camera to fit all objects in view.

Params:

NameTypeAttributeDescription
done Function

Callback invoked on completion

public viewFitModels(modelIds: String[], done: Function) source

Fits the given models in view.

Params:

NameTypeAttributeDescription
modelIds String[]

ID of the models.

done Function
  • optional

Callback invoked on completion. Will be animated if this is given, otherwise will be instantaneous.

public viewFitObjects(objectIds: String[], done: Function) source

Flies the camera to fit the given objects in view.

Params:

NameTypeAttributeDescription
objectIds String[]

IDs of the objects

done Function

Callback invoked on completion