# Class Materials

Manages materials and textures used by Twinfinity for rendering of IFC products and other objects.

##### Index

### Constructors

constructor

### Properties

globalRenderState
reservedGpuPickClearColor

### Accessors

availableObjectCount
isBackfaceCullingEnabled
maxObjectCount
objectCount
state

### Methods

add
clear
copyColorTo
createGpuTextureObject
deleteGpuTextureObject
dispose
get
getBabylonMeshCustomDepthMaterial
getBimProductAndMeshById
getColorComponent
getGpuPickingMaterial
getIFCMeshCustomDepthMaterial
getOutlineMaterial
gpuPickRgbToInt32
intToGpuPickRgbaInPlace
renderPropertiesFor
setColor
updateDitherTexture

## Constructors

### constructor

- new Materials(_isBackfaceCullingEnabled?: boolean): Materials

  Materials constructor.

  #### Parameters

  - _isBackfaceCullingEnabled: boolean = true

  #### Returns Materials

## Properties

### `Readonly` globalRenderState

globalRenderState: GlobalState = ...

### `Readonly` reservedGpuPickClearColor

reservedGpuPickClearColor: Color4 = ...

Color used to as scene.clearColor when doing gpu picking.

## Accessors

### availableObjectCount

- get availableObjectCount(): number

  Number of objects (IFC products or TextureObject) that can still be added to this instance

  #### Returns number

### isBackfaceCullingEnabled

- get isBackfaceCullingEnabled(): boolean

  Gets a value indicating whether backface culling is enabled. Backface culling is a rendering technique used to improve performance by not drawing polygons facing away from the camera.

  #### Returns boolean

  `true` if backface culling is enabled; otherwise, `false`.

- set isBackfaceCullingEnabled(value: boolean): void

  Sets the backface culling state for the material.

  #### Parameters

  - value: boolean

    A boolean indicating whether backface culling is enabled. If true, backface culling is enabled; otherwise, it is disabled.

  #### Returns void

### maxObjectCount

- get maxObjectCount(): number

  Maximum number of Ifc products and TextureObject instances material can hold.

  #### Returns number

### objectCount

- get objectCount(): number

  Number of objects (IFC products or TextureObject) this instance currently holds. Cannot be higher than maxObjectCount.

  #### Returns number

### state

- get state(): Record<string, never>

  Changed whenever colors or properties on objects, managed by this Materials instance, change. Useful when performing checks (for exemple during rendering) to determine if something has changed between one frame and another. Let your code keep a reference to state. Whenever you need to check whether something has changed just compare your local reference with state. If they differ then colors or properties of objects have changed since the last frame. Dont forget to update the local reference afterwards.

  #### Returns Record<string, never>

## Methods

### add

- add(ifcFiles: IBimIfcLoaderElement[]): void

  #### Parameters

  - ifcFiles: IBimIfcLoaderElement[]

  #### Returns void

### clear

- clear(): void

  #### Returns void

### copyColorTo

- copyColorTo(
  mesh: BimProductMesh,
  dst: Writeable<ArrayLike<number>>,
  dstOffset?: number,
  ): void

  #### Parameters

  - mesh: BimProductMesh
  - dst: Writeable<ArrayLike<number>>
  - dstOffset: number = 0

  #### Returns void

### createGpuTextureObject

- createGpuTextureObject(): undefined | TextureObject

  Create a TextureObject.

  #### Returns undefined | TextureObject

  A valid TextureObject or undefined if the maximum number of gpu texture objects have been reached.

### deleteGpuTextureObject

- deleteGpuTextureObject(textureObject: number | TextureObject): boolean

  Deletes a TextureObject.

  #### Parameters

  - textureObject: number | TextureObject

    Object to delete.

  #### Returns boolean

  True if deleted, otherwise false.

### dispose

- dispose(): void

  #### Returns void

### get

- get(isTransparent: boolean, scene: Scene): Material

  #### Parameters

  - isTransparent: boolean
  - scene: Scene

  #### Returns Material

### getBabylonMeshCustomDepthMaterial

- getBabylonMeshCustomDepthMaterial(
  scene: Scene,
  storeNonLinearDepth: boolean,
  ): BabylonMeshDepthMaterial

  Creates a custom depth material that is used for Babylon meshes for two reasons:

  1. It correctly excludes the invisible fragments from the IFC meshes
  2. It uses a camera with a nearplane that is further away, to increase precision and thereforce reduce z fighting for effects that use depth textures written to with this material

  #### Parameters

  - scene: Scene

    The scene for which the depth material should be created

  - storeNonLinearDepth: boolean

    Whether the custom depth material should write the depth linearly or logarithmically

  #### Returns BabylonMeshDepthMaterial

  The custom depth material, which was created for the scene

### getBimProductAndMeshById

- getBimProductAndMeshById(id: number): undefined | BimProductMesh

  Retrieves a BimProductMesh object by its ID.

  #### Parameters

  - id: number

    The ID of the BimProductMesh. The alpha component is masked away as it is not part of the ID. The ID is converted to an unsigned value to handle values above 2^31 correctly.

  #### Returns undefined | BimProductMesh

  The BimProductMesh object associated with the given ID, or undefined if not found.

### getColorComponent

- getColorComponent(mesh: BimProductMesh, colorComponent: RgbaComponent): number

  #### Parameters

  - mesh: BimProductMesh
  - colorComponent: RgbaComponent

  #### Returns number

### getGpuPickingMaterial

- getGpuPickingMaterial(sceneOrMesh: Scene | AbstractMesh): Material

  #### Parameters

  - sceneOrMesh: Scene | AbstractMesh

  #### Returns Material

### getIFCMeshCustomDepthMaterial

- getIFCMeshCustomDepthMaterial(
  scene: Scene,
  storeNonLinearDepth: boolean,
  ): IfcMeshDepthMaterial

  Creates a custom depth material that is used for IFC meshes instead of Babylons normal depth material for two reasons:

  1. It correctly excludes the invisible fragments from the IFC meshes
  2. It uses a camera with a nearplane that is further away, to increase precision and thereforce reduce z fighting for effects that use depth textures written to with this material

  #### Parameters

  - scene: Scene

    The scene for which the depth material should be created

  - storeNonLinearDepth: boolean

    Wheter the custom depth material should write the depth linearly or logarithmic

  #### Returns IfcMeshDepthMaterial

  The custom depth material, which was created for the scene

### getOutlineMaterial

- getOutlineMaterial(sceneOrMesh: Scene | AbstractMesh): Material

  #### Parameters

  - sceneOrMesh: Scene | AbstractMesh

  #### Returns Material

### gpuPickRgbToInt32

- gpuPickRgbToInt32(pixels: ArrayLike<number>, offset: number): number

  Converts RGB components of a pixel array to a 32-bit unsigned integer.

  #### Parameters

  - pixels: ArrayLike<number>

    An array-like object containing pixel data.

  - offset: number

    The offset within the pixel array to start reading RGB components.

  #### Returns number

  The 32-bit integer representation of the RGB components.

### intToGpuPickRgbaInPlace

- intToGpuPickRgbaInPlace<T extends Writeable<ArrayLike<number>>>(
  pixelValue: number,
  alpha: number,
  dst: T,
  ): T

  Converts an integer pixel value to an RGBA array and sets the alpha value in place.

  #### Type Parameters

  - T extends Writeable<ArrayLike<number>>

    A writable array-like type that will hold the RGBA values.

  #### Parameters

  - pixelValue: number

    The integer pixel value to be converted.

  - alpha: number

    The alpha value to be set in the resulting RGBA array.

  - dst: T

    The destination array where the RGBA values will be stored.

  #### Returns T

  The destination array with the RGBA values and the specified alpha value.

### renderPropertiesFor

- renderPropertiesFor(mesh: BimProductMesh): Uint32Bits

  Sets various on/off properties pertaining to rendering of a BimProductMesh instance. A mask representing the bits that you want to flip, Legend: idw: Depth write, single bit, represents a bool, wheter the object is written into the postprocess depth buffer or not v: Visibility, 1 bit wheter the object is visible or not o: Outline, 1 bit wheter the object is outlined or not h: Highlight, 2 bits for a total of 3 different highlight colors, or no highlight if all bits are turned off cpi: Clip plane ignore s: Shininess, 4 bits, represents a number 0: unused bit [0|0|0|0 0|0|0|0] [0|0|0|0 0|0|0|0] [0|0|0|0 s|s|s|s] [0|0|cpi|o h|h|v|idw]

  #### Parameters

  - mesh: BimProductMesh

    Mesh to read/write properties for.

  #### Returns Uint32Bits

  A Uint32Bits instance. Use to manipulate the bits in the property mask for the BimProductAndMesh instance.

### setColor

- setColor(mesh: BimProductMesh, color: ArrayLike<number>): boolean

  #### Parameters

  - mesh: BimProductMesh
  - color: ArrayLike<number>

  #### Returns boolean

### updateDitherTexture

- updateDitherTexture(ditherOptions: DitheringOptions): void

  #### Parameters

  - ditherOptions: DitheringOptions

  #### Returns void