# Class BimApi

BimApi is the main API class. This a subclass of BimCoreApi that is extended with information only available from the Twinfinity API backend.

#### Hierarchy (View Summary)

- BimCoreApi
  - BimApi

##### Index

### Constructors

constructor

### Properties

camera
viewer
runRenderLoop

### Accessors

axes
backend
currentContainerInfo
grid
ifc
isSkyboxEnabled
onPointerObservable
selectables

### Methods

applyVisualChanges
clear
createCoordinateTracker
dispose
filter
foreach
getIntersections
info
initialize
loadPropertySets
on
products
setBackgroundColor
setContainer
setHighlightColor
withVisibleBimObjects
zoomToExtent
create
createApi

## Constructors

### constructor

- new BimApi(
  canvas: HTMLCanvasElement,
  _apiClient: TwinfinityApiClient,
  bimApiOptions?: BimApiOptions,
  ): BimApi

  Constructor.

  #### Parameters

  - canvas: HTMLCanvasElement

    Canvas element where 3D content will be rendered.

  - _apiClient: TwinfinityApiClient

    Methods for communicating with the backend.

  - `Optional` bimApiOptions: BimApiOptions

  #### Returns BimApi

  Overrides BimCoreApi.constructor

## Properties

### `Readonly` camera

camera: BimCamera

Camera is an instance of BimCamera and used for manipulating the 3D camera view of the BIM viewer.

Inherited from BimCoreApi.camera

### `Readonly` viewer

viewer: TwinfinityViewer

Exposes viewer internals. Use this to access BabylonJS API. Disclaimer! Accessing BabylonJS internals is considered advanced usage and you are effectively bypassing BimCoreApi (and subclasses). We cannot make guarantees that:

- BabylonJS APIs will remain backwards compatible. Therefore, your application may break when BabylonJS is updated to a new version.
- Babylonjs data that BimCoreApi creates, such as scene hierarchy, lights, camera etc., will remain backwards compatible between versions. Relying on this may break your application.
- Your modifications to BabylonJS data (such as scene hierarchy, lights, cameras etc.) will not be changed by code in this package.
- Other bugs will not occur as a result of direct usage of BabylonJS APIs. https://doc.babylonjs.com/api/classes/babylon.scene

#### Example

    api.viewer.scene.ambientColor = new Color3(1, 0, 0);

Inherited from BimCoreApi.viewer

### `Static` `Beta` runRenderLoop

runRenderLoop: RunRenderLoopHandler = ...

Extension point for applications that need to run the renderloop outside their own change handling (AngularJs is one such example). Assignment should be done before creation of a BimCoreApi instance.

#### Example: Example for Angular JS

     const bimApi: BimApi;
     BimCoreApi.runRenderLoop = this.ngZone.runOutSideAngular;

#### Param: renderLoop

Renderloop function will be provided by the viewer. Simply call it in your provided function

Inherited from BimCoreApi.runRenderLoop

## Accessors

### axes

- get axes(): boolean

  Gets or sets a value indicating whether to hide or show coordinate system axes.

  #### Returns boolean

  Inherited from BimCoreApi.axes

- set axes(isEnabled: boolean): void

  #### Parameters

  - isEnabled: boolean

  #### Returns void

  Inherited from BimCoreApi.axes

### backend

- get backend(): TwinfinityApiClient

  Direct access to the methods for communicating the backend.

  #### Returns TwinfinityApiClient

  Overrides BimCoreApi.backend

### currentContainerInfo

- get currentContainerInfo(): BimContainerInfo

  Gives information on currently selected container such as title, language and also details of the current user.

  #### Returns BimContainerInfo

### grid

- get grid(): GridOptions

  Gets or sets options for 3D help grid visualization.

  #### Returns GridOptions

  Inherited from BimCoreApi.grid

### ifc

- get ifc(): BimIfcLoader
  `Internal`

  Returns an IFC structure.

  #### Returns BimIfcLoader

  Inherited from BimCoreApi.ifc

### isSkyboxEnabled

- get isSkyboxEnabled(): boolean

  Gets or sets a value indicating whether to show or hide skybox.

  #### Returns boolean

  Inherited from BimCoreApi.isSkyboxEnabled

- set isSkyboxEnabled(enabled: boolean): void

  #### Parameters

  - enabled: boolean

  #### Returns void

  Inherited from BimCoreApi.isSkyboxEnabled

### onPointerObservable

- get onPointerObservable(): Observable<
  DeepImmutableObject<PointerInfoWithTimings>,
  >

  Subscribe to get access to pointer events (mouse, touchpad etc) and to determine what (if anything) a mouse click interacted with (what object was 'picked' in the 3D scene).

  #### Returns Observable<DeepImmutableObject<PointerInfoWithTimings>>

  Inherited from BimCoreApi.onPointerObservable

### selectables

- get selectables(): Selectables

  Exposes methods related to selection operations. For example, what the user actually clicked on.

  #### Returns Selectables

  Inherited from BimCoreApi.selectables

## Methods

### applyVisualChanges

- applyVisualChanges(): Promise<void>

  Updates the viewer with the latest visual changes on BIM objects. See foreach for an example.

  #### Returns Promise<void>

  Inherited from BimCoreApi.applyVisualChanges

### clear

- clear(): void

  Clears api (any loaded IFC files etc are unloaded).

  #### Returns void

  Inherited from BimCoreApi.clear

### createCoordinateTracker

- createCoordinateTracker<Tracked3D extends Vertex3 = any>(): CoordinateTracker<
  Tracked3D,
  >

  Gets a CoordinateTracker instance.

  #### Type Parameters

  - Tracked3D extends Vertex3 = any

  #### Returns CoordinateTracker<Tracked3D>

  Inherited from BimCoreApi.createCoordinateTracker

### `Protected` dispose

- dispose(): void

  Disposes the API and releases all resources including WASM memory and Babylon.js resources. After calling this method, the API instance should not be used.

  #### Returns void

  Inherited from BimCoreApi.dispose

### filter

- filter(predicate: BimIfcObjectForEachPredicate): BimIfcObject[]

  Iterate the BimIfcObject instances and return those that match the specified predicate.

  #### Parameters

  - predicate: BimIfcObjectForEachPredicate

    Predicate. Items matching this will be returned in array format.

  #### Returns BimIfcObject[]

  Array with BimIfcObject instances matched by the specified predicate.

  Inherited from BimCoreApi.filter

### foreach

- foreach(action: BimIfcObjectForEachAction): void

  Use this function to iterate over all BIM objects.

  #### Parameters

  - action: BimIfcObjectForEachAction

    This is a lambda function to evaluate on each BimIfcObject.

  #### Returns void

  #### Example

      api.foreach((o, recursionOptions) => {
          if (o.hasGeometry && o.class.id !== "IfcFlowSegment") {
              console.log(o.gid);
              o.visible(true);
          } else {
              o.visible(false);
          }
      });

  Inherited from BimCoreApi.foreach

### getIntersections

- getIntersections(
  origin: Vector3,
  direction: Vector3,
  objects?: BimIfcObject[],
  ): undefined | Intersection[]

  Intersects all visible BIM objects using ray from origin towards direction

  #### Parameters

  - origin: Vector3

    Vector3

  - direction: Vector3

    Vector3

  - objects: BimIfcObject[] = []

    BimIfcObject[]

  #### Returns undefined | Intersection[]

  Intersection[] | undefined

  #### Example

      // GetIntersections makes a hit test on all visible BIM objects, from origin in direction and return first object intersection.
      const intersections = this.api.getIntersections([0, 0, 0], [1, 1, 1]);

  #### Example

      // GetIntersections makes a hit test on a subset of  BIM objects, from origin in direction and return first object intersection.
      const intersections = this.api.withSelection(myVisibleObjects, objects => this.api.getIntersections([0, 0, 0], [1, 1, 1]);

  #### Example

      // GetIntersections makes a hit test on a subset of visible BIM objects, from origin in direction and return first object intersection.
      const intersections = this.api.getIntersections([0, 0, 0], [1, 1, 1], myObjects);

  Inherited from BimCoreApi.getIntersections

### info

- info(): TwinfinityInfo

  General Twinfinity information such as customer portal name, Twinfinity API version etc.

  #### Returns TwinfinityInfo

### `Protected` initialize

- initialize(): Promise<void>

  Called from createApi. Subclasses can implement if they need to initialize more data during API creation in createApi

  #### Returns Promise<void>

  Overrides BimCoreApi.initialize

### loadPropertySets

- loadPropertySets(): Promise<void>

  Loads all BIM property sets for all loaded files.

  #### Returns Promise<void>

  #### Deprecated

  Call BimIfcLoader.loadPropertySets on ifc instead.

  Inherited from BimCoreApi.loadPropertySets

### on

- on(type: "click", clickEventHandler: ClickEventHandler): void

  Sets a handler to event of given type

  #### Parameters

  - type: "click"

    Type of event. For now only "click" is supported

  - clickEventHandler: ClickEventHandler

    Function that gets called when the event occurs

  #### Returns void

  #### Deprecated

  Use onPointerObservable instead.

  Inherited from BimCoreApi.on

### products

- products(): IterableIterator<BimIfcObject>

  Create a iterator that can be used to iterate over all BimIfcObject's. Same as foreach but with a iterator instead.

  #### Returns IterableIterator<BimIfcObject>

  Iterator that can be used to iterate over all BimIfcObject's.

  #### Example

      for(const o of api.products()) {
          if (o.hasGeometry && o.class.id !== "IfcFlowSegment") {
              console.log(o.gid);
              o.visible(true);
          } else {
              o.visible(false);
          }
      };

  Inherited from BimCoreApi.products

### setBackgroundColor

- setBackgroundColor(color: Color3 | Color): void

  Sets background color in viewer

  #### Parameters

  - color: Color3 | Color

    RGB in range 0-1

  #### Returns void

  #### Example

      api.setBackgroundColor([0.95, 0.95, 0.95]);

  Inherited from BimCoreApi.setBackgroundColor

### setContainer

- setContainer(
  containerOrUrl: BimContainer | URL,
  options?: BimApiLoadOptions,
  ): Promise<void>

  Sets the container of the current BimApi instance.

  #### Parameters

  - containerOrUrl: BimContainer | URL

    Container object or absolute URL Example: https://bim.foo.com/sites/portal/projects/{project name}

  - `Optional` options: BimApiLoadOptions

    Loading options

  #### Returns Promise<void>

  Overrides BimCoreApi.setContainer

### setHighlightColor

- setHighlightColor(color: Color3, highlightIndex: ColoredHighlightIndexes): void

  Sets highlight color in viewer

  #### Parameters

  - color: Color3

    RGB in range 0-1

  - highlightIndex: ColoredHighlightIndexes

    The highlight index tgo change, it's restricted to One, Two and Three because it makes no sense to change the color of the Empty index (since it's only there to denote that a productMesh has no highlight). The highlight index defaults to One

  #### Returns void

  #### Example

      api.setHighlightColor([1.0, 0.0, 0.0]); <-- Sets the color of the first highlight index to solid red
      api.setHighlightColor([0.0, 1.0, 0.0], HighlightIndex.Two); <-- Sets the color of the second highlight index to solid green

  Inherited from BimCoreApi.setHighlightColor

### withVisibleBimObjects

- withVisibleBimObjects<T>(
  visibleBimObjects: BimIfcObject[],
  action: (objects: BimIfcObject[]) => T,
  ): T

  Makes it possible to perform API operations, that operate on the set of visible BIM objects, on a smaller set of (still visible) BIM objects

  #### Type Parameters

  - T

  #### Parameters

  - visibleBimObjects: BimIfcObject[]

    Visible objects to run operation on

  - action: (objects: BimIfcObject[]) => T

    Operation

  #### Returns T

  #### Example

      // GetIntersections makes a hit test on a subset of visible BIM objects, from origin in direction and return first object intersection.
      const intersections = this.api.withVisibleBimObjects(myVisibleBimObjects, objects => api.getIntersections([0, 0, 0], [1, 1, 1]));

  Inherited from BimCoreApi.withVisibleBimObjects

### zoomToExtent

- zoomToExtent(products: BimIfcObject[]): void

  This function zooms the camera to contain BIM objects in view frustum.

  #### Parameters

  - products: BimIfcObject[]

    Array of BIM objects.

  #### Returns void

  Inherited from BimCoreApi.zoomToExtent

### `Static` create

- create(
  _htmlElementOrId: string | HTMLElement,
  absoluteContainerUrlOrApiClient: string | URL | TwinfinityApiClient,
  options?: BimApiOptions,
  ): Promise<BimApi>

  Creates a new instance of BimApi.

  #### Parameters

  - _htmlElementOrId: string | HTMLElement

    ID of the HTML element where the viewer should be created.

  - absoluteContainerUrlOrApiClient: string | URL | TwinfinityApiClient

    Absolute URL to the container.

  - `Optional` options: BimApiOptions

    Creation options.

  #### Returns Promise<BimApi>

  #### Example

      // Create an API instance.
      const api = await BimApi.create('viewer', 'project-url'); // Open project directly.
      const api = await BimApi.create('viewer', new BimTwinfinityApiClient(url)); // Create API. If a valid container url is given, the API automatically switches to it, otherwise calls api.setContainer() afterwards.

### `Static` createApi

- createApi<TBimApi extends BimCoreApi>(
  _htmlElementOrId: string | HTMLElement,
  apiFactory: (canvas: HTMLCanvasElement) => TBimApi,
  ): Promise<TBimApi>

  Creates a new instance of BimCoreApi or subclass of BimCoreApi.

  #### Type Parameters

  - TBimApi extends BimCoreApi

  #### Parameters

  - _htmlElementOrId: string | HTMLElement

    ID of the HTML element where the viewer should be created.

  - apiFactory: (canvas: HTMLCanvasElement) => TBimApi

    Factory function to create the API instance.

  #### Returns Promise<TBimApi>

  #### Example

      // Create an API instance.
      const bimCoreApi = await BimCoreApi.create('viewer', canvas => new BimCoreApi(canvas, new BimApiClientTwinfinity()));
      const bimApi = await BimCoreApi.create('viewer', canvas => new BimApi(canvas, new BimApiClientTwinfinity()));

  Inherited from BimCoreApi.createApi