# Class BimCoreApi

BimCoreApi is a generic API class. It is completely unaware about the Twinfinity API backend and can therefore be used as a base for integration with a completely different backend. This must be used in conjunction with a specialized implementation of BimCoreApiClient. BimApi is an actual example of such an implementation.

#### Hierarchy (View Summary)

- BimCoreApi
  - BimApi

##### Index

### Constructors

constructor

### Properties

camera
viewer
runRenderLoop

### Accessors

axes
backend
grid
ifc
isSkyboxEnabled
onPointerObservable
selectables

### Methods

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

## Constructors

### constructor

- new BimCoreApi(
  htmlCanvasElement: HTMLCanvasElement,
  _bimBackendApi: BimCoreApiClient,
  options?: BimCoreApiOptions,
  ): BimCoreApi

  Constructor. Use createApi instead.

  #### Parameters

  - htmlCanvasElement: HTMLCanvasElement
  - _bimBackendApi: BimCoreApiClient
  - `Optional` options: BimCoreApiOptions

  #### Returns BimCoreApi

## Properties

### `Readonly` camera

camera: BimCamera

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

### `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);

### `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

## Accessors

### axes

- get axes(): boolean

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

  #### Returns boolean

- set axes(isEnabled: boolean): void

  #### Parameters

  - isEnabled: boolean

  #### Returns void

### backend

- get backend(): BimCoreApiClient

  Direct access to the methods for communicating with the backend.

  #### Returns BimCoreApiClient

### grid

- get grid(): GridOptions

  Gets or sets options for 3D help grid visualization.

  #### Returns GridOptions

### ifc

- get ifc(): BimIfcLoader
  `Internal`

  Returns an IFC structure.

  #### Returns BimIfcLoader

### isSkyboxEnabled

- get isSkyboxEnabled(): boolean

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

  #### Returns boolean

- set isSkyboxEnabled(enabled: boolean): void

  #### Parameters

  - enabled: boolean

  #### Returns void

### 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>>

### selectables

- get selectables(): Selectables

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

  #### Returns 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>

### clear

- clear(): void

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

  #### Returns void

### createCoordinateTracker

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

  Gets a CoordinateTracker instance.

  #### Type Parameters

  - Tracked3D extends Vertex3 = any

  #### Returns CoordinateTracker<Tracked3D>

### `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

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

### 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);
          }
      });

### 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);

### `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>

### loadPropertySets

- loadPropertySets(): Promise<void>

  Loads all BIM property sets for all loaded files.

  #### Returns Promise<void>

  #### Deprecated

  Call BimIfcLoader.loadPropertySets on ifc instead.

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

### 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);
          }
      };

### 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]);

### 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>

  #### Remarks

  This method previously returned a `BimQuery` instance. Use foreach, products, filter instead.

### 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

### 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]));

### 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

### `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()));