# Class TwinfinityViewer

Represents a TwinfinityViewer, which is responsible for rendering and interacting with a 3D scene. There can only be one TwinfinityViewer.

##### Index

### Properties

addOrUpdateProductOptions
canvas
grid
keyboard
onPointerObservable
performance
scene
statistics
visualSettings

### Accessors

adaptiveMinZ
axes
camera
engine
globalLight
ifcRootNode
isSkyboxEnabled
isTouch
lightingProperties
selectables

### Methods

addOrReplaceMesh
addOrUpdateEnvironment
buildingMeshes
clear
dispose
enableDepthRenderer
getAndUpdatePickCamera
getTransparencyMode
isDebugLayerEnabled
measureGpuBufferMemory
pick
removeMesh
setClipPlane
setDitheringDepthDiscardMode
setDitheringMode
setTransparencyMode
wakeRenderLoop
create

## Properties

### addOrUpdateProductOptions

addOrUpdateProductOptions: {
meshMerge: { deadline: number; sleepInMs: number };
} = ...

### `Readonly` canvas

canvas: HTMLCanvasElement

### `Readonly` grid

grid: GridOptions = ...

### `Readonly` keyboard

keyboard: Keyboard

### `Readonly` onPointerObservable

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

### `Beta` performance

performance: TwinfinityViewerPerformanceOptions

Performance options.

### `Readonly` scene

scene: Scene

### `Readonly` statistics

statistics: {
addOrUpdateProducts: {
meshAllocateMemoryTime: number;
meshCreationTime: number;
meshMergeTime: number;
totalTime: PerfCounter;
};
mesh: {
count: PerfCounter;
triangleCount: PerfCounter;
verticeCount: PerfCounter;
};
} = ...

### `Readonly` visualSettings

visualSettings: PictureSettings

Controls the visual settings of the viewer. See VisualSettings for more information.

#### Remarks

Visual settings are things like global lightning but also how transparency is handled for IFC objects etc.

## Accessors

### adaptiveMinZ

- get adaptiveMinZ(): boolean

  Controls wheter to automatically adapt the near plane of the camera to preserve precision when viewing far away IFC objects when there are no close IFC objects

  #### Returns boolean

- set adaptiveMinZ(enabled: boolean): void

  #### Parameters

  - enabled: boolean

  #### Returns void

### axes

- get axes(): boolean

  #### Returns boolean

- set axes(isEnabled: boolean): void

  #### Parameters

  - isEnabled: boolean

  #### Returns void

### camera

- get camera(): ViewerCamera

  #### Returns ViewerCamera

### engine

- get engine(): Engine

  #### Returns Engine

### globalLight

- get globalLight(): HemisphericLight

  #### Returns HemisphericLight

  #### Deprecated

  Should not be used, there should exist a API method for changing lighting Should this be removed? Is it used by Jaxel? Otherwise normal constructor injection should be used

### ifcRootNode

- get ifcRootNode(): TransformNode

  #### Returns TransformNode

### isSkyboxEnabled

- get isSkyboxEnabled(): boolean

  #### Returns boolean

- set isSkyboxEnabled(enabled: boolean): void

  #### Parameters

  - enabled: boolean

  #### Returns void

### isTouch

- get isTouch(): boolean

  #### Returns boolean

### lightingProperties

- get lightingProperties(): IFCLightingEnvironment

  Gets the current lighting settings, allowing you to change them on the fly.

  #### Returns IFCLightingEnvironment

### selectables

- get selectables(): Selectables

  #### Returns Selectables

## Methods

### addOrReplaceMesh

- addOrReplaceMesh(geometry3D: Geometry3d): Mesh

  Adds a mesh to the scene based on the provided geometry. If a mesh with the same ID already exists, it will be removed and replaced with the new one.

  #### Parameters

  - geometry3D: Geometry3d

    Mesh to add or replace

  #### Returns Mesh

  Babylon mesh that was added

### addOrUpdateEnvironment

- addOrUpdateEnvironment(boundingInfo: BoundingInfo): void

  Adds or updates the environment settings for the viewer.

  #### Parameters

  - boundingInfo: BoundingInfo

    AABB. This method calculates the starting position for the camera based on the provided `boundingInfo`. It ensures that the entire `boundingInfo` is visible and sets the maximum z-coordinate of the camera to a value that allows everything to be visible. Additionally, it creates a skybox and sets its position and scaling based on the `boundingInfo`. The skybox is only visible if the isSkyboxEnabled property is set to `true`.

  #### Returns void

- addOrUpdateEnvironment(options: AddOrUpdateEnvironmentOptions): void

  Adds or updates the environment settings for the viewer.

  #### Parameters

  - options: AddOrUpdateEnvironmentOptions

    The options for the environment settings. This method calculates the starting position for the camera based on the provided `boundingInfo`. It ensures that the entire `boundingInfo` is visible and sets the maximum z-coordinate of the camera to a value that allows everything to be visible. Additionally, it creates a skybox and sets its position and scaling based on the `boundingInfo`. The skybox is only visible if the isSkyboxEnabled property is set to `true`.

  #### Returns void

### buildingMeshes

- buildingMeshes(): IterableIterator<Mesh>

  #### Returns IterableIterator<Mesh>

### clear

- clear(): void

  #### Returns void

### dispose

- dispose(): void
  `Internal`

  #### Returns void

### enableDepthRenderer

- enableDepthRenderer(storeNonLinearDepth: boolean): ShortFrustumDepthRenderer

  Creates a renderer that that writes out the scenes depth to a render target texture which can be sampled for various uses like SSAO and line detection. Unlike Babylonjs standard depth renderer, this renderer applies a custom depth material to the IFC meshes to be able to dicard the depth writes for fragments that are invisible

  #### Parameters

  - storeNonLinearDepth: boolean

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

  #### Returns ShortFrustumDepthRenderer

  The depth renderer

### getAndUpdatePickCamera

- getAndUpdatePickCamera(
  rayOrScreenCoordinate?: Ray | CanvasPosition,
  ): TargetCamera

  #### Parameters

  - `Optional` rayOrScreenCoordinate: Ray | CanvasPosition

  #### Returns TargetCamera

  #### Deprecated

  Use ViewerCamera.pick instead.

### getTransparencyMode

- getTransparencyMode(): TransparencyMode

  Gets the currently active mode of transparency

  #### Returns TransparencyMode

### isDebugLayerEnabled

- isDebugLayerEnabled(isEnabled?: boolean): Promise<boolean>

  Enables or disables the debug layer. Will only be available if the module 'import "@twinfinity/core/internal/Debug' has also been added to the application. Adding it will generate extra .js files during bundling (which are quite large) and will increase build times. The extra files are loaded on demand though (when debug layer becomes enabled for the first time).

  #### Parameters

  - `Optional` isEnabled: boolean

    `true` to enable. Otherwise `false`. If Not specified then current state of debug layer is returned.

  #### Returns Promise<boolean>

  Promise which when resolved is `true` if layer is enabled. Otherwise `false`

### measureGpuBufferMemory

- measureGpuBufferMemory(): {
  bufferCount: number;
  meshCount: number;
  totalBytes: number;
  }

  Diagnostic method to measure actual GPU buffer memory usage. Call from browser console: viewer.measureGpuBufferMemory()

  #### Returns { bufferCount: number; meshCount: number; totalBytes: number }

### pick

- pick(
  pickingCamera: TargetCamera,
  textureSizePow2?: number,
  doIntersectionTestOnGeometry?: boolean,
  saveRenderedGpuPickingSceneTexture?: boolean,
  ): PickResult

  #### Parameters

  - pickingCamera: TargetCamera
  - textureSizePow2: number = 16
  - doIntersectionTestOnGeometry: boolean = false
  - saveRenderedGpuPickingSceneTexture: boolean = false

  #### Returns PickResult

  #### Deprecated

  Use ViewerCamera.pick instead.

### removeMesh

- removeMesh(geometry3D: Geometry3dHandle): undefined | Mesh

  #### Parameters

  - geometry3D: Geometry3dHandle

  #### Returns undefined | Mesh

### setClipPlane

- setClipPlane(clipPlaneOptions: ClipPlaneOptions): void

  Enables or disables a clip plane, indexed from 1 to 6. Enabling a clip plane means that all geometry inside the clip plane will not be rendered. Note that this is only clipping for the IFC models, regular Babylon meshes needs to have clipping applied through the clip planes in Babylons scene Like this: https://doc.babylonjs.com/features/featuresDeepDive/scene/clipPlanes, the docs says that only 4 planes are available, but there are 6

  #### Parameters

  - clipPlaneOptions: ClipPlaneOptions

    An object with the options for enabling or disabling clip planes.

  #### Returns void

### setDitheringDepthDiscardMode

- setDitheringDepthDiscardMode(ditherDiscardDepth: boolean): void

  Set the currently used dither mode for solid objects that are dithered, never for transparent objects, even if the transparency mode is dithering

  #### Parameters

  - ditherDiscardDepth: boolean

    Wheter or not to discard fragments in the depth shader that are dithered, this is needed for transparent objects to not write to the depth buffer

  #### Returns void

### setDitheringMode

- setDitheringMode(ditherMode: DitheringTextureMode, animatedFrames: number): void

  Set the dither mode and animated frames used for dithering

  #### Parameters

  - ditherMode: DitheringTextureMode

    What dithering mode to use, bayer uses a bayer matrix to determine which pixels to render opaque, blue noise uses a blue noise texture

  - animatedFrames: number

    How many frames to use for the dithering animation when moving the camera, if 1 then no animation is used. Works best with Blue Noise

  #### Returns void

### setTransparencyMode

- setTransparencyMode(transparencyMode: TransparencyMode): void

  Changes how transparency is handled for transparent IFC objects

  #### Parameters

  - transparencyMode: TransparencyMode

    The type of rendering that will be used for all transparent IFC objects, dithering means that pixels are rendered opaque but skipping every few pixels in a screen pattern depending on the opacity Seethrough is normal alpha blending

  #### Returns void

### wakeRenderLoop

- wakeRenderLoop(): void

  Forces render loop to temporarily wake up if it is sleeping

  #### Returns void

### `Static` create

- create(
  canvas: HTMLCanvasElement,
  materials: Materials,
  runRenderLoop: RunRenderLoopHandler,
  ): TwinfinityViewer

  #### Parameters

  - canvas: HTMLCanvasElement
  - materials: Materials
  - runRenderLoop: RunRenderLoopHandler

  #### Returns TwinfinityViewer