# Class IfcGeometryBuilder

Represents a builder for creating geometries from IFC product meshes.

##### Index

### Properties

geometryBuildId
loaderElements
options

### Accessors

geometryCount
ifcProductMeshCount
indiceCount

### Methods

build
create

## Properties

### `Readonly` geometryBuildId

geometryBuildId: number

The ID of the geometry build.

### `Readonly` loaderElements

loaderElements: IBimIfcLoaderElement[]

The loader elements to build geometries from.

### `Static` `Readonly` options

options: IfcGeometryBuilderOptions = ...

Options to control for how long the geometry builder behavior.

## Accessors

### geometryCount

- get geometryCount(): number

  The number of geometries that will be built when build is called.

  #### Returns number

  The number of geometries.

### ifcProductMeshCount

- get ifcProductMeshCount(): number

  The number of IFC product meshes this builder will build geometries for.

  #### Returns number

  The number of meshes.

### indiceCount

- get indiceCount(): number

  Gets the number of indices in the geometry. The number of triangles in the geometry is this number divided by 3.

  #### Returns number

  The total number of indices.

## Methods

### build

- build(
  action: (eventData: GeometryBuilderBuildEventData) => void,
  ): Promise<Geometry3dHandle[]>

  Builds Geometry3d instance from all BimProduct instances that was included during the call to create. This is a very CPU intensive operation.

  #### Parameters

  - action: (eventData: GeometryBuilderBuildEventData) => void

    The action to be invoked for each built Geometry3d instance. Call TwinfinityViewer.addOrReplaceMesh to add the geometry to the viewer. The `eventData` parameter contains both the current Geometry3d instance that was built and information such as the current progress of the build operation. See GeometryBuilderBuildEventData for more information.

  #### Returns Promise<Geometry3dHandle[]>

  A promise that resolves to an array of Geometry3dHandle objects. These can be used to unload the geometries from TwinfinityViewer by calling TwinfinityViewer.removeMesh.

  #### Remarks

  Only access the Geometry3d instance inside the action callback. The Geometry3d instance, and all data accessable trhoug it, will be invalid after the action callback has been invoked. Each Geometry3d instance will contain the geometry from all BimProductMesh instances that share the same `mergeId`.

### `Static` create

- create(o: IfcGeometryBuilderCreateOptions): Promise<IfcGeometryBuilder>

  Creates an instance of IfcGeometryBuilder.

  #### Parameters

  - o: IfcGeometryBuilderCreateOptions

    The options for creating the geometry builder.

  #### Returns Promise<IfcGeometryBuilder>

  A promise that resolves to an instance of `IfcGeometryBuilder`.

  #### Remarks

  The create method will traverse all BimProduct instances provided by `o.loaderElements.entries()`. Each BimProduct that has geometry, not all products do, has N BimProductMesh instances. The create method will visit each such instance and assign a `mergeId` to each of them. This `mergeId` will be identical for BimProductMesh instances that shall be merged into the same Geometry3d instance when build is called. BimProductMesh instances that alredy have a `mergeId` will be ignored as it is assumed that has already been processed by another IfcGeometryBuilder instance. It is also possible to ignore certain BimProduct instances by providing a predicate function in `o.predicate`. This will allow the caller to filter out products that should not be included in the geometry creation. For example, one might want to only include IFC products that are of a certain type or have a certain property set. Specifying a predicate function allows for this.

  When a IfcGeometryBuilder instance has been created, the caller can call build to start the geometry creation process. This is a very CPU intensive process.

  One should always attempt to use as few IfcGeometryBuilder instances, to create Geometry3d instances, as possible. The more Geometry3d instances that we add to TwinfinityViewer, by calling TwinfinityViewer.addOrReplaceMesh, the worse rendering performance we will get. This is because the more geometries we have the more draw calls we will have. The more draw calls we have the worse performance we will get. There is no fixed number of geometries that is the limit. It depends on the hardware and the complexity of the geometries.