API

Class Viewer

Provides an experience for viewing a single 3D model.

The Viewer is not tied to a specific UI framework and can be used with Babylon.js in a browser or with Babylon Native.

Hierarchy

  • ViewerBase
    • Viewer

Implements

  • unknown
  • IViewer
Index
onAfterRenderObservable: any = ...

Fired after each frame is rendered.

onAnimationProgressChanged: any = ...

Fired when the current point on the selected animation timeline changes.

onAnimationSpeedChanged: any = ...

Fired when the animation speed changes.

onCameraAutoOrbitChanged: any = ...

Fired when the camera auto orbit state changes.

onCamerasAsHotSpotsChanged: any = ...

Fired when the cameras as hot spots property changes.

onClearColorChanged: any = ...

Fired when the clear color changes.

onEnvironmentChanged: any = ...

Fired when the environment has changed.

onEnvironmentConfigurationChanged: any = ...

Fired when the environment configuration has changed.

onEnvironmentError: any = ...

Fired when an error occurs while loading the environment.

onHotSpotsChanged: any = ...

Fired when the hot spots object changes to a complete new object instance.

onIsAnimationPlayingChanged: any = ...

Fired when the selected animation is playing or paused.

onLoadingProgressChanged: any = ...

Fired when progress changes on loading activity.

onModelChanged: any = ...

Fired when a model is loaded into the viewer (or unloaded from the viewer).

The event argument is the source that was loaded, or null if no model is loaded.

onModelError: any = ...

Fired when an error occurs while loading a model.

onPostProcessingChanged: any = ...

Fired when the post processing state changes.

onSelectedAnimationChanged: any = ...

Fired when the selected animation changes.

onSelectedMaterialVariantChanged: any = ...

Fired when the selected material variant changes.

onShadowsConfigurationChanged: any = ...

Fired when the shadows configuration changes.

showDebugLogs: boolean = false

When enabled, the Viewer will emit additional diagnostic logs to the console.

  • get animationProgress(): number

    The current point on the selected animation timeline, normalized between 0 and 1.

    Returns number

  • set animationProgress(value: number): void

    Gets or sets the current point on the selected animation timeline, normalized between 0 and 1.

    Parameters

    • value: number

    Returns void

  • get camerasAsHotSpots(): boolean

    True if scene cameras should be used as hotspots.

    Returns boolean

  • set camerasAsHotSpots(value: boolean): void

    Gets or sets whether cameras embedded in the model should be exposed as hot spots.

    Parameters

    • value: boolean

    Returns void

  • get environmentConfig(): Readonly<EnvironmentParams>

    Returns Readonly<EnvironmentParams>

  • set environmentConfig(value: Partial<Readonly<EnvironmentParams>>): void

    Parameters

    • value: Partial<Readonly<EnvironmentParams>>

    Returns void

  • get loadingProgress(): number | boolean

    The current loading progress. False when no load is in flight, true when at least one load is in flight with indeterminate progress, or a number between 0 and 1 representing the average of all in-flight loads' progress.

    Returns number | boolean

  • get materialVariants(): readonly string[]

    The list of material variant names for the currently loaded model.

    Returns readonly string[]

  • get selectedMaterialVariant(): Nullable<string>

    The currently selected material variant.

    Returns Nullable<string>

  • get shadowConfig(): Readonly<ShadowParams>

    Gets the current shadow configuration.

    Returns Readonly<ShadowParams>

  • Updates the camera to focus on a named hotspot.

    Parameters

    • name: string

      The name of the hotspot to focus on.

    Returns boolean

    true if the hotspot was found and the camera was updated, false otherwise.

  • Return world and canvas coordinates of an hot spot.

    Parameters

    • query: any

      mesh index and surface information to query the hot spot positions.

    • result: ViewerHotSpotResult

      Query a Hot Spot and does the conversion for Babylon Hot spot to a more generic HotSpotPositions, without Vector types.

    Returns boolean

    true if hotspot found.

  • Loads an environment from the specified URL. The lighting and skybox sides have independent locks and abort controllers so concurrent requests for one side don't cancel an in-flight load for the other.

    Parameters

    • url: string

      The URL of the environment to load.

    • Optionaloptions: LoadEnvironmentOptions

      Selects which sides to update (defaults to both) and forwards engine-specific extras.

    • OptionalabortSignal: AbortSignal

      Optional signal that can be used to abort the load externally.

    Returns Promise<void>

    A promise that resolves when the environment has finished loading.

  • Loads a 3D model from the specified source.

    Parameters

    • source: string | File | ArrayBufferView<ArrayBufferLike>

      The source of the model to load.

    • Optionaloptions: any

      Options for loading the model. See LoadModelOptions.

    • OptionalabortSignal: AbortSignal

      Optional signal that can be used to abort the load externally.

    Returns Promise<void>

    A promise that resolves when the model has finished loading.

  • Resets the viewer to its initial state based on the options passed in to the constructor.

    Parameters

    • ...flags: ResetFlag[]

      The flags that specify which parts of the viewer to reset. If no flags are provided, all parts will be reset.

      • "source": Reset the loaded model.
      • "environment": Reset environment related state.
      • "shadow": Reset shadow related state.
      • "animation": Reset animation related state.
      • "camera": Reset camera related state.
      • "post-processing": Reset post-processing related state.
      • "material-variant": Reset material variant related state.

    Returns void

  • Resets the camera to its initial pose.

    Parameters

    • Optionalreframe: boolean

      If true, the camera will be reframed to fit the model bounds. If false, it will use the default camera pose passed in with the options to the constructor (if present). If undefined, default to false if other viewer state matches the default state (such as the selected animation), otherwise true.

    Returns void

  • Resets the environment to its default state.

    Parameters

    • Optionaloptions: Partial<Readonly<{ lighting: boolean; skybox: boolean }>>

      The options to use when resetting the environment.

    • OptionalabortSignal: AbortSignal

      An optional signal that can be used to abort the reset.

    Returns Promise<void>

  • Unloads the current 3D model if one is loaded.

    Parameters

    • OptionalabortSignal: AbortSignal

      Optional signal that can be used to abort the reset.

    Returns Promise<void>

    A promise that resolves when the current model has been unloaded.

  • Updates the camera pose.

    Parameters

    • pose: {
          alpha?: number;
          beta?: number;
          radius?: number;
          targetX?: number;
          targetY?: number;
          targetZ?: number;
      }

      The new pose of the camera.

    Returns void

    Any unspecified values are left unchanged.

  • Updates the shadow configuration.

    Parameters

    • value: Partial<Readonly<ShadowParams>>

      The new shadow configuration.

    • OptionalabortSignal: AbortSignal

      Optional signal that can be used to abort the update externally.

    Returns Promise<void>

    A promise that resolves when the shadow update completes.