Reference Source
import {ViewerUI} from '@xeokit/xeokit-viewer/src/ViewerUI.js'
public class | source

ViewerUI

Extends:

src/Controller.js~Controller → ViewerUI

UI controller for a xeokit Viewer toolbar.

Constructor Summary

Public Constructor
public

constructor(server: Server, cfg: *)

Constructs a ViewerUI.

Method Summary

Public Methods
public

De-selects all objects currently in the viewer.

public

Destroys the viewer, freeing all resources.

public

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

public

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

public

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

Gets information on a project.

public

Gets information on all available projects.

public

Hides all objects currently in the viewer.

public

Hides all objects currently in the viewer, except for those with the given IDs.

public

hideObject(objectId: String)

Hides the object with the given ID.

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

Selects all objects currently in the viewer.

public

Selects all objects currently in the viewer, except for those with the given IDs.

public

selectObject(objectId: String)

Selects the objects with the given ID.

public

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

public

Shows all objects currently in the viewer.

public

Shows all objects currently in the viewer, except for those with the given IDs.

public

showObject(objectId: String)

Shows the object with the given ID.

public

showObjectInClassesTab(objectId: *)

public

showObjectInObjectsTab(objectId: *)

public

showObjectInStoreysTab(objectId: *)

public

unloadModel(modelId: *)

Unloads a model from the viewer.

public

Unloads all currently loaded models.

public

X-rays all objects currently in the viewer.

public

X-rays all objects currently in the viewer, except for those with the given IDs.

public

Un-x-rays all objects currently in the viewer.

public

xrayObject(objectId: String)

X-ray the object with the given ID.

Public Constructors

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

Constructs a ViewerUI.

Params:

NameTypeAttributeDescription
server Server

Data access strategy.

cfg *

Configuration.

Public Methods

public deselectAllObjects() source

De-selects all objects currently in the viewer.

public destroy() source

Destroys the viewer, freeing all resources.

public getLoadedModelIds(): String[] source

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

Return:

String[]

The IDs of the currently loaded models, else 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, else null if no project is currently loaded.

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

Gets information on a project.

Use ViewerUI#getProjects to get information on all available projects.

Example

myViewer.getProjectInfo(("Duplex") => {
     console.log(JSON.stringify(projectInfo, null, "\t"));
});

Returns JSON similar to:

{
     "id": "Duplex",
     "name": "Duplex"
}

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 ViewerUI#getProjects.

done Function

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

error Function

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

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

Gets information on all available projects.

Example

myViewer.getProjectsInfo((projectsInfo) => {
     console.log(JSON.stringify(projectsInfo, null, "\t"));
});

Returns JSON similar to:

{
     "projects": [
         {
             "id": "Duplex",
             "name": "Duplex"
         },
         {
             "id": "Schependomlaan",
             "name": "Schependomlaan"
         },
         {
             "id": "WestRiversideHospital",
             "name": "West Riverside Hospital"
         }
    ]
}

Params:

NameTypeAttributeDescription
done Function

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

error Function

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

public hideAllObjects() source

Hides all objects currently in the viewer.

public hideAllObjectsExceptFor(objectIds: String[]) source

Hides all objects currently in the viewer, except for those with the given IDs.

Params:

NameTypeAttributeDescription
objectIds String[]

IDs of objects to not hide.

public hideObject(objectId: String) source

Hides the object with the given ID.

Params:

NameTypeAttributeDescription
objectId String

ID of object to hide.

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

When true (default), immediately set camera position.

options.duration Boolean
  • optional

Flight duration in seconds. Overrides CameraFlightAnimation#duration.

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

Loads a model into the viewer.

Assumes that the project that contains 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 fired on success.

error Function

Callback fired 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 project and contained models that are already loaded.

Params:

NameTypeAttributeDescription
projectId String

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

done Function

Callback fired on success.

error Function

Callback fired 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, and
  • "storeys" - the Storeys tab, which contains a tree view for each loaded model, with nodes grouped within IfcBuildingStoreys, sub-grouped by their IFC types.

Params:

NameTypeAttributeDescription
tabId String

ID of the tab to open - see method description.

public resetView() source

Resets the view.

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.

Return:

*

BCF JSON viewpoint object

Example:


const viewpoint = viewerUI.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 selectAllObjects() source

Selects all objects currently in the viewer.

public selectAllObjectsExceptFor(objectIds: String[]) source

Selects all objects currently in the viewer, except for those with the given IDs.

Params:

NameTypeAttributeDescription
objectIds String[]

IDs of objects to not select.

public selectObject(objectId: String) source

Selects the objects with the given ID.

Params:

NameTypeAttributeDescription
objectId String

ID of object to select.

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 showAllObjects() source

Shows all objects currently in the viewer.

public showAllObjectsExceptFor(objectIds: String[]) source

Shows all objects currently in the viewer, except for those with the given IDs.

Params:

NameTypeAttributeDescription
objectIds String[]

IDs of objects to not show.

public showObject(objectId: String) source

Shows the object with the given ID.

Params:

NameTypeAttributeDescription
objectId String

ID of object to show.

public showObjectInClassesTab(objectId: *) source

Params:

NameTypeAttributeDescription
objectId *

public showObjectInObjectsTab(objectId: *) source

Params:

NameTypeAttributeDescription
objectId *

public showObjectInStoreysTab(objectId: *) source

Params:

NameTypeAttributeDescription
objectId *

public unloadModel(modelId: *) source

Unloads a model from the viewer.

Does nothing if the model is not currently loaded.

Params:

NameTypeAttributeDescription
modelId *

public unloadAllModels() source

Unloads all currently loaded models.

public xrayAllObjects() source

X-rays all objects currently in the viewer.

public xrayAllObjectsExceptFor(objectIds: String[]) source

X-rays all objects currently in the viewer, except for those with the given IDs.

Params:

NameTypeAttributeDescription
objectIds String[]

IDs of objects to not x-ray.

public xrayNoObjects() source

Un-x-rays all objects currently in the viewer.

public xrayObject(objectId: String) source

X-ray the object with the given ID.

Params:

NameTypeAttributeDescription
objectId String

ID of object to x-ray.