Viewer2d
Class in @bimworks/viewer2d.
API catalogue · @bimworks/viewer2d · Class
2D viewer based on WebGL.
Inheritance and interfaces#
Members#
| Member | Kind | Description |
|---|---|---|
| constructor | Method | Create a new Viewer2d |
| canvas | Property | The canvas the 2D viewer draws on (inside container) |
| container | Property | |
| modelManager | Property | |
| objectStateManager | Property | |
| addedToSelectionSet | Method | Objects were added to the selection implementationOf: ObjectStateListener.addedToSelectionSet |
| addedToVisibleSet | Method | Objects were made visible implementationOf: ObjectStateListener.addedToVisibleSet |
| addModels | Method | Models were loaded: their object data is in the ModelManager already implementationOf: ModelListener.addModels |
| cameraPoseToWorld | Method | A camera pose position (mm, frame of the 3D viewer) in 2D world coordinates; z is passed through |
| cameraPoseUpdated | Method | The pose (eye, pivot, target) of a camera has been updated (ObjectStateManager.setCameraPose) implementationOf: ObjectStateListener.cameraPoseUpdated |
| colorChanged | Method | |
| colorReset | Method | The colour of the given objects has been reset to their own implementationOf: ObjectStateListener.colorReset |
| destroy | Method | Destroys the viewer and any (heavy) resources associated with it. As long as there is a reference to the Viewer2d instance it won't be completely destroyed. |
| getActiveStorey | Method | The storey the plan shows: the current one while visible, else the first visible storey with a level; null for none. minZ is the storey's lowest point in mod… |
| getControl | Method | Get access to the Control object for programmatic viewer manipulation |
| getFontScale | Method | The size of the text labels in pixels (15 by default) |
| getHeight | Method | Get the height of the viewer in pixels |
| getModelManager | Method | |
| getWidth | Method | Get the width of the viewer in pixels |
| hasModels | Method | Whether any model is loaded in the plan |
| hoverOff | Method | Called when the given object is not being hovered on anymore implementationOf: ObjectStateListener.hoverOff |
| hoverOn | Method | Called when the given object is being hovered on implementationOf: ObjectStateListener.hoverOn |
| init | Method | This method must be called before loading any of the models. Keep in mind that this method is async, and models can only be loaded after the returned Promise… |
| isDoorOpeningRendering | Method | |
| isFaceRendering | Method | |
| isFullScreen | Method | |
| isIfcLineRendering | Method | |
| isTextShown | Method | Whether the text labels are shown (toggleShowText); false before init |
| isWireframeRendering | Method | |
| removedFromSelectionSet | Method | Objects were removed from the selection implementationOf: ObjectStateListener.removedFromSelectionSet |
| removedFromVisibleSet | Method | Objects were hidden. Any of them that were selected have been deselected first implementationOf: ObjectStateListener.removedFromVisibleSet |
| removeModels | Method | Models were unloaded implementationOf: ModelListener.removeModels |
| resize | Method | |
| screenshot | Method | Will take a screenshot of the contents of the Viewer2d. |
| setBuildingStoreysVisibleExclusive | Method | Show only the objects of these building storeys, without their openings when hideOpenings implementationOf: ObjectStateListener.setBuildingStoreysVisibleExcl… |
| setBuildingStoreyVisibleExclusive | Method | Show only the objects of one building storey (ObjectStateManager.setBuildingStoreyVisibleExclusive with one storey) implementationOf: ObjectStateListener.set… |
| setCameraConeDepth | Method | Set the depth of the camera cone, default is 250px |
| setCameraConeVisible | Method | Toggle whether the cone indicating where the 3D camera is (in a Viewer3d) should be visible, default is visible |
| setCameraPoseViewer | Method | The viewer whose camera poses this viewer shows as the camera cone. Only needed when that viewer is not registered on this viewer's ObjectStateManager; the 2… |
| setCameraTrackingMode | Method | Switch how the synced 3D camera indicator behaves inside the 2D viewer. "MAP" keeps the map fixed and lets the cone move through it. "FOLLOW" keeps the cone … |
| setDirty | Method | To be called whenever the rendering state has changed and updates need to become visible |
| setFontScale | Method | |
| setToSelectionSet | Method | The selection was replaced (also by a click in single-select mode) implementationOf: ObjectStateListener.setToSelectionSet |
| setVisibleSet | Method | The set of visible objects was replaced implementationOf: ObjectStateListener.setVisibleSet |
| start | Method | Starts the viewer. The viewer will only redraw when needed. |
| stop | Method | Stops the viewer. When the viewer is stopped, the view is not updated anymore. Any changes to the viewer will be accumulated and become visible as soon as th… |
| toggleDoorOpeningRendering | Method | Toggle whether (generated) door openings are rendered. This only works for models that have been processed when the repository setting `features.generate_doo… |
| toggleFaceRendering | Method | Toggle whether faces are rendered. |
| toggleFullScreen | Method | Toggles full screen (the container fills the window); returns whether it is now full screen |
| toggleIfcLineRendering | Method | Toggle whether ifc lines are rendered. IFC Lines are all lines that have been defined in the original IFC file, such as Axis and FootPrint representations. |
| toggleShowText | Method | Toggles whether the text labels are shown |
| toggleUserPanning | Method | Toggle whether user panning (by mouse or touch device) is enabled or disabled. It is enabled by default |
| toggleUserRotate | Method | Toggle whether user rotate (by mouse or touch device) is enabled or disabled. It is enabled by default |
| toggleUserSelection | Method | Toggle whether user selection (by mouse or touch device) is enabled or disabled. It is enabled by default |
| toggleUserZoom | Method | Toggle whether user zooming (by mouse wheel or touch device) is enabled or disabled. It is enabled by default. Changing this settings also enabled/disabled z… |
| toggleWireframeRendering | Method | Toggle whether wireframes are rendered. Wireframes are usually drawn to emphesize the edges and generally make the model look better |
| viewFit | Method | Fits the given objects into view: the viewport is updated so that it shows the bounding box of all of them, and the building storey most of them are on is ma… |
| viewFitModels | Method | Fits the given models into view as a whole, using the bounds of each model as loaded. Models not loaded in this viewer are skipped. Rotation as for viewFit; … |
| worldToCameraPose | Method | The inverse of cameraPoseToWorld for a 2D world position: [x, y] in mm in the frame of the 3D viewer |
constructor#
constructor(objectStateManager: ObjectStateManager, settings?: Viewer2dSettings)Create a new Viewer2d
Parameters#
| Name | Type | Description |
|---|---|---|
objectStateManager |
ObjectStateManager | The ObjectStateManager manages all object related state such as visibility, color and selection |
settings |
Viewer2dSettings | Optional settings, will use default settings when not provided |
canvas#
readonly canvas: HTMLCanvasElementThe canvas the 2D viewer draws on (inside container)
container#
readonly container: HTMLElementmodelManager#
readonly modelManager: ModelManagerobjectStateManager#
readonly objectStateManager: ObjectStateManageraddedToSelectionSet#
Objects were added to the selection
implementationOf: ObjectStateListener.addedToSelectionSet
Parameters#
| Name | Type | Description |
|---|---|---|
qids |
Iterable<Qid> |
The objects added |
addedToVisibleSet#
Objects were made visible
implementationOf: ObjectStateListener.addedToVisibleSet
Parameters#
| Name | Type | Description |
|---|---|---|
qids |
Iterable<Qid> |
addModels#
public addModels(newVersions: Iterable<Version>, allVersions: Iterable<Version>): Promise<void>Models were loaded: their object data is in the ModelManager already
implementationOf: ModelListener.addModels
Parameters#
| Name | Type | Description |
|---|---|---|
newVersions |
Iterable<Version> |
The versions that were added |
allVersions |
Iterable<Version> |
Every loaded version, the new ones included |
cameraPoseToWorld#
public cameraPoseToWorld(position: ArrayLike<number>): Float32ArrayA camera pose position (mm, frame of the 3D viewer) in 2D world coordinates; z is passed through
Parameters#
| Name | Type | Description |
|---|---|---|
position |
ArrayLike<number> |
cameraPoseUpdated#
The pose (eye, pivot, target) of a camera has been updated (ObjectStateManager.setCameraPose)
implementationOf: ObjectStateListener.cameraPoseUpdated
Parameters#
| Name | Type | Description |
|---|---|---|
sourceViewer |
unknown |
The tag the pose was set with, to recognise one's own updates: "viewer3d" from the Viewer3d, null from the application; compare it, do not use it as an object |
pose |
Pose | The new camera pose, in the 3D viewer's render frame |
colorChanged#
Parameters#
| Name | Type | Description |
|---|---|---|
qids |
Iterable<Qid> |
|
color |
TinyColor |
colorReset#
The colour of the given objects has been reset to their own
implementationOf: ObjectStateListener.colorReset
Parameters#
| Name | Type | Description |
|---|---|---|
qids |
Iterable<Qid> |
The objects whose colour was reset |
destroy#
public destroy(): voidDestroys the viewer and any (heavy) resources associated with it. As long as there is a reference to the Viewer2d instance it won't be completely destroyed.
getActiveStorey#
public getActiveStorey(): { minZ: number; qid: string } | nullThe storey the plan shows: the current one while visible, else the first visible storey with a level; null for none. minZ is the storey's lowest point in model mm
getControl#
Get access to the Control object for programmatic viewer manipulation
getFontScale#
public getFontScale(): numberThe size of the text labels in pixels (15 by default)
getHeight#
public getHeight(): numberGet the height of the viewer in pixels
getModelManager#
public getModelManager(): ModelManagerReturns#
The ModelManager connected to this viewer
getWidth#
public getWidth(): numberGet the width of the viewer in pixels
hasModels#
public hasModels(): booleanWhether any model is loaded in the plan
hoverOff#
Called when the given object is not being hovered on anymore
implementationOf: ObjectStateListener.hoverOff
Parameters#
| Name | Type | Description |
|---|---|---|
qid |
Qid | The Qid of the object that is not being hovered over anymore |
hoverOn#
Called when the given object is being hovered on
implementationOf: ObjectStateListener.hoverOn
Parameters#
| Name | Type | Description |
|---|---|---|
qid |
Qid | The Qid of the object being hovered over |
previousQid |
Qid | The object hovered before, null or undefined for none |
screenspaceLocation |
vec2 | The screenspace location of the hover event, when the caller gave one. This can be useful to for example place a popup/tooltip at that location. Screenspace location is x, y coordinate between 0, 0 and canvas width,height |
init#
public init(): Promise<void>This method must be called before loading any of the models. Keep in mind that this method is async, and models can only be loaded after the returned Promise has resolved.
isDoorOpeningRendering#
public isDoorOpeningRendering(): booleanReturns#
Whether rendering of generated door opening directions is currently enabled
isFaceRendering#
public isFaceRendering(): booleanReturns#
Whether face rendering is currently enabled
isFullScreen#
public isFullScreen(): booleanisIfcLineRendering#
public isIfcLineRendering(): booleanReturns#
Whether IFC line rendering is currently enabled
isTextShown#
public isTextShown(): booleanWhether the text labels are shown (toggleShowText); false before init
isWireframeRendering#
public isWireframeRendering(): booleanReturns#
Whether wireframe rendering is currently enabled
removedFromSelectionSet#
Objects were removed from the selection
implementationOf: ObjectStateListener.removedFromSelectionSet
Parameters#
| Name | Type | Description |
|---|---|---|
qids |
Iterable<Qid> |
The objects that are no longer selected |
removedFromVisibleSet#
Objects were hidden. Any of them that were selected have been deselected first
implementationOf: ObjectStateListener.removedFromVisibleSet
Parameters#
| Name | Type | Description |
|---|---|---|
qids |
Iterable<Qid> |
removeModels#
Models were unloaded
implementationOf: ModelListener.removeModels
Parameters#
| Name | Type | Description |
|---|---|---|
versions |
Iterable<Version> |
The versions that were removed |
resize#
public resize(width: number, height: number): voidParameters#
| Name | Type | Description |
|---|---|---|
width |
number |
|
height |
number |
screenshot#
public screenshot(options?: ScreenshotOptions): Promise<Blob>Will take a screenshot of the contents of the Viewer2d.
Parameters#
| Name | Type | Description |
|---|---|---|
options |
ScreenshotOptions |
Optional options object |
Returns#
A Blob
Example#
The returned Blob can for example be downloaded by the user, using the following example
const width = viewer2d.width;
const height = viewer2d.height;
const filename = `screencapture-${width}x${height}.png`;
Utils.downloadBlob(blob, filename);setBuildingStoreysVisibleExclusive#
Show only the objects of these building storeys, without their openings when hideOpenings
implementationOf: ObjectStateListener.setBuildingStoreysVisibleExclusive
Parameters#
| Name | Type | Description |
|---|---|---|
buildingStoreyQids |
Iterable<Qid> |
setBuildingStoreyVisibleExclusive#
public setBuildingStoreyVisibleExclusive(buildingStoreyQid: unknown): voidShow only the objects of one building storey (ObjectStateManager.setBuildingStoreyVisibleExclusive with one storey)
implementationOf: ObjectStateListener.setBuildingStoreyVisibleExclusive
Parameters#
| Name | Type | Description |
|---|---|---|
buildingStoreyQid |
unknown |
setCameraConeDepth#
public setCameraConeDepth(depth: number): voidSet the depth of the camera cone, default is 250px
Parameters#
| Name | Type | Description |
|---|---|---|
depth |
number |
The depth in pixels |
setCameraConeVisible#
public setCameraConeVisible(visible: boolean): voidToggle whether the cone indicating where the 3D camera is (in a Viewer3d) should be visible, default is visible
Parameters#
| Name | Type | Description |
|---|---|---|
visible |
boolean |
Whether it should be visible |
setCameraPoseViewer#
public setCameraPoseViewer(viewer: any): voidThe viewer whose camera poses this viewer shows as the camera cone. Only needed when that viewer is not registered on this viewer's ObjectStateManager; the 2D viewer uses its global base translation to bring poses into its own world frame
Parameters#
| Name | Type | Description |
|---|---|---|
viewer |
any |
setCameraTrackingMode#
public setCameraTrackingMode(mode: CameraTrackingMode): voidSwitch how the synced 3D camera indicator behaves inside the 2D viewer. "MAP" keeps the map fixed and lets the cone move through it. "FOLLOW" keeps the cone centered while moving the map, clamping manual interaction so the cone stays inside the viewport.
Parameters#
| Name | Type | Description |
|---|---|---|
mode |
CameraTrackingMode | The camera tracking mode |
setDirty#
public setDirty(): voidTo be called whenever the rendering state has changed and updates need to become visible
setFontScale#
public setFontScale(scale: number): voidParameters#
| Name | Type | Description |
|---|---|---|
scale |
number |
setToSelectionSet#
public setToSelectionSet(qids: Iterable<Qid>, qidsToUnselect: Iterable<Qid>): void | Promise<void>The selection was replaced (also by a click in single-select mode)
implementationOf: ObjectStateListener.setToSelectionSet
Parameters#
| Name | Type | Description |
|---|---|---|
qids |
Iterable<Qid> |
The objects selected now |
qidsToUnselect |
Iterable<Qid> |
The objects no longer selected |
setVisibleSet#
public setVisibleSet(qids: Iterable<Qid>, qidsToHide: Iterable<Qid>): void | Promise<unknown>The set of visible objects was replaced
implementationOf: ObjectStateListener.setVisibleSet
Parameters#
| Name | Type | Description |
|---|---|---|
qids |
Iterable<Qid> |
The objects that have been made visible |
qidsToHide |
Iterable<Qid> |
The objects that have been made invisible |
start#
public start(): voidStarts the viewer. The viewer will only redraw when needed.
stop#
public stop(): voidStops the viewer. When the viewer is stopped, the view is not updated anymore. Any changes to the viewer will be accumulated and become visible as soon as the viewer is started again The main reason for stopping the viewer would be for performance, for example when the viewer is currently hidden
toggleDoorOpeningRendering#
public toggleDoorOpeningRendering(enabled: boolean): voidToggle whether (generated) door openings are rendered. This only works for models that have been processed when the repository setting features.generate_door_openings had been enabled.
Some models contains door opening direction geometry as IFC lines, in those cases it's best to disabled rendering generated door openings.
Parameters#
| Name | Type | Description |
|---|---|---|
enabled |
boolean |
True when enabled |
toggleFaceRendering#
public toggleFaceRendering(enabled: boolean): voidToggle whether faces are rendered.
Parameters#
| Name | Type | Description |
|---|---|---|
enabled |
boolean |
True when enabled |
toggleFullScreen#
public toggleFullScreen(enable?: boolean): booleanToggles full screen (the container fills the window); returns whether it is now full screen
Parameters#
| Name | Type | Description |
|---|---|---|
enable |
boolean |
toggleIfcLineRendering#
public toggleIfcLineRendering(enabled: boolean): voidToggle whether ifc lines are rendered. IFC Lines are all lines that have been defined in the original IFC file, such as Axis and FootPrint representations.
Parameters#
| Name | Type | Description |
|---|---|---|
enabled |
boolean |
True when enabled |
toggleShowText#
public toggleShowText(): voidToggles whether the text labels are shown
toggleUserPanning#
public toggleUserPanning(enabled: boolean): voidToggle whether user panning (by mouse or touch device) is enabled or disabled. It is enabled by default
Parameters#
| Name | Type | Description |
|---|---|---|
enabled |
boolean |
Whether it should be enabled |
toggleUserRotate#
public toggleUserRotate(enabled: boolean): voidToggle whether user rotate (by mouse or touch device) is enabled or disabled. It is enabled by default
Parameters#
| Name | Type | Description |
|---|---|---|
enabled |
boolean |
Whether it should be enabled |
toggleUserSelection#
public toggleUserSelection(enabled: boolean): voidToggle whether user selection (by mouse or touch device) is enabled or disabled. It is enabled by default
Parameters#
| Name | Type | Description |
|---|---|---|
enabled |
boolean |
Whether it should be enabled |
toggleUserZoom#
public toggleUserZoom(enabled: boolean): voidToggle whether user zooming (by mouse wheel or touch device) is enabled or disabled. It is enabled by default. Changing this settings also enabled/disabled zoom on double-click
Parameters#
| Name | Type | Description |
|---|---|---|
enabled |
boolean |
Whether it should be enabled |
toggleWireframeRendering#
public toggleWireframeRendering(enabled: boolean): voidToggle whether wireframes are rendered. Wireframes are usually drawn to emphesize the edges and generally make the model look better
Parameters#
| Name | Type | Description |
|---|---|---|
enabled |
boolean |
True when enabled |
viewFit#
public viewFit(qids: Iterable<Qid>, options?: ViewFitOptions): void | Promise<void>Fits the given objects into view: the viewport is updated so that it shows the bounding box of all of them, and the building
storey most of them are on is made visible. The plan's rotation is set by options.rotation (ViewFitRotation, default
"KEEP"); with "OBJECT_AXIS" the object of options.rotationObject (or the one fitted object) orients the plan.
implementationOf: ObjectStateListener.viewFit
Parameters#
| Name | Type | Description |
|---|---|---|
qids |
Iterable<Qid> |
The Qids of the objects to fit |
options |
ViewFitOptions | Margin, animation and rotation, see ViewFitOptions |
Returns#
Resolves once the fit has been applied; the "OBJECT_AXIS" rotation first queries the object's oriented bounding box
viewFitModels#
public viewFitModels(versionUuids: Iterable<string>, options?: ViewFitOptions): void | Promise<void>Fits the given models into view as a whole, using the bounds of each model as loaded. Models not loaded in this viewer are
skipped. Rotation as for viewFit; "MODEL_AXIS" uses the oriented bounding boxes of exactly these models.
implementationOf: ObjectStateListener.viewFitModels
Parameters#
| Name | Type | Description |
|---|---|---|
versionUuids |
Iterable<string> |
The models to fit |
options |
ViewFitOptions | Margin, animation and rotation, see ViewFitOptions |
worldToCameraPose#
public worldToCameraPose(worldCoordinates: ArrayLike<number>): (number)[]The inverse of cameraPoseToWorld for a 2D world position: [x, y] in mm in the frame of the 3D viewer
Parameters#
| Name | Type | Description |
|---|---|---|
worldCoordinates |
ArrayLike<number> |