Class Viewer
Hierarchy
- ViewerBase
- Viewer
Implements
- unknown
- IViewer
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
-
Parameters
- _engine: AbstractEngine
Optional_options: Readonly<ViewerOptions>
Returns Viewer
Properties
Readonlyon After Render Observable
Fired after each frame is rendered.
Readonlyon Animation Progress Changed
Fired when the current point on the selected animation timeline changes.
Readonlyon Animation Speed Changed
Fired when the animation speed changes.
Readonlyon Camera Auto Orbit Changed
Fired when the camera auto orbit state changes.
Readonlyon Cameras As Hot Spots Changed
Fired when the cameras as hot spots property changes.
Readonlyon Clear Color Changed
Fired when the clear color changes.
Readonlyon Environment Changed
Fired when the environment has changed.
Readonlyon Environment Configuration Changed
Fired when the environment configuration has changed.
Readonlyon Environment Error
Fired when an error occurs while loading the environment.
Readonlyon Hot Spots Changed
Fired when the hot spots object changes to a complete new object instance.
Readonlyon Is Animation Playing Changed
Fired when the selected animation is playing or paused.
Readonlyon Loading Progress Changed
Fired when progress changes on loading activity.
Readonlyon Model Changed
Fired when a model is loaded into the viewer (or unloaded from the viewer).
Readonlyon Model Error
Fired when an error occurs while loading a model.
Readonlyon Post Processing Changed
Fired when the post processing state changes.
Readonlyon Selected Animation Changed
Fired when the selected animation changes.
Readonlyon Selected Material Variant Changed
Fired when the selected material variant changes.
Readonlyon Shadows Configuration Changed
Fired when the shadows configuration changes.
show Debug Logs
When enabled, the Viewer will emit additional diagnostic logs to the console.
Accessors
animation Progress
-
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
animations
-
get animations(): readonly string[]
The list of animation names for the currently loaded model.
Returns readonly string[]
animation Speed
-
get animationSpeed(): number
The speed scale at which animations are played.
Returns number
-
set animationSpeed(value: number): void
Gets or sets the speed scale at which animations are played.
Parameters
- value: number
Returns void
camera Auto Orbit
-
Returns Readonly<CameraAutoOrbit>
-
Parameters
- value: Partial<Readonly<CameraAutoOrbit>>
Returns void
cameras As Hot Spots
-
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
clear Color
-
get clearColor(): IColor4Like
The viewer clear color (e.g. background).
Returns IColor4Like
-
set clearColor(value: IColor4Like): void
Parameters
- value: IColor4Like
Returns void
environment Config
-
get environmentConfig(): Readonly<EnvironmentParams>
Returns Readonly<EnvironmentParams>
-
set environmentConfig(value: Partial<Readonly<EnvironmentParams>>): void
Parameters
- value: Partial<Readonly<EnvironmentParams>>
Returns void
hot Spots
is Animation Playing
-
get isAnimationPlaying(): boolean
True if an animation is currently playing.
Returns boolean
is Model Loaded
-
get isModelLoaded(): boolean
True if a model is currently loaded.
Returns boolean
loading Progress
-
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
material Variants
-
get materialVariants(): readonly string[]
The list of material variant names for the currently loaded model.
Returns readonly string[]
post Processing
-
The post processing configuration.
Returns PostProcessing
-
Gets the post-processing configuration.
Parameters
- value: Partial<Readonly<PostProcessing>>
Returns void
selected Animation
-
get selectedAnimation(): number
The currently selected animation index.
Returns number
-
set selectedAnimation(value: number): void
Gets or sets the index of the selected animation.
Parameters
- value: number
Returns void
selected Material Variant
-
get selectedMaterialVariant(): Nullable<string>
The currently selected material variant.
Returns Nullable<string>
shadow Config
-
get shadowConfig(): Readonly<ShadowParams>
Gets the current shadow configuration.
Returns Readonly<ShadowParams>
Methods
dispose
-
Disposes of the resources held by the Viewer.
Returns void
focus Hot Spot
-
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.
- name: string
get Hot Spot To Ref
-
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.
- query: any
load Environment
-
loadEnvironment(
url: string,
options?: LoadEnvironmentOptions,
abortSignal?: AbortSignal,
): Promise<void>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: LoadEnvironmentOptionsSelects which sides to update (defaults to both) and forwards engine-specific extras.
OptionalabortSignal: AbortSignalOptional signal that can be used to abort the load externally.
Returns Promise<void>
A promise that resolves when the environment has finished loading.
- url: string
load Model
-
loadModel(
source: string | File | ArrayBufferView<ArrayBufferLike>,
options?: any,
abortSignal?: AbortSignal,
): Promise<void>Loads a 3D model from the specified source.
Parameters
- source: string | File | ArrayBufferView<ArrayBufferLike>
The source of the model to load.
Optionaloptions: anyOptions for loading the model. See LoadModelOptions.
OptionalabortSignal: AbortSignalOptional signal that can be used to abort the load externally.
Returns Promise<void>
A promise that resolves when the model has finished loading.
- source: string | File | ArrayBufferView<ArrayBufferLike>
pause Animation
-
Pauses the selected animation if there is one.
Returns Promise<void>
play Animation
-
Plays the selected animation if there is one.
Returns void
query Hot Spot
-
Get hotspot world and screen values from a named hotspot.
Parameters
- name: string
slot of the hot spot.
- result: ViewerHotSpotResult
resulting world and screen positions.
Returns boolean
world position, world normal and screen space coordinates.
- name: string
reset
-
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
- ...flags: ResetFlag[]
reset Camera
-
Resets the camera to its initial pose.
Parameters
Optionalreframe: booleanIf 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
reset Environment
-
resetEnvironment(
options?: Partial<Readonly<{ lighting: boolean; skybox: boolean }>>,
abortSignal?: AbortSignal,
): Promise<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: AbortSignalAn optional signal that can be used to abort the reset.
Returns Promise<void>
reset Model
-
Unloads the current 3D model if one is loaded.
Parameters
OptionalabortSignal: AbortSignalOptional signal that can be used to abort the reset.
Returns Promise<void>
A promise that resolves when the current model has been unloaded.
toggle Animation
-
Toggles the play/pause animation state if there is a selected animation.
Returns void
update Camera
update Shadows
-
Updates the shadow configuration.
Parameters
- value: Partial<Readonly<ShadowParams>>
The new shadow configuration.
OptionalabortSignal: AbortSignalOptional signal that can be used to abort the update externally.
Returns Promise<void>
A promise that resolves when the shadow update completes.
- value: Partial<Readonly<ShadowParams>>
Provides an experience for viewing a single 3D model.
Remarks
The Viewer is not tied to a specific UI framework and can be used with Babylon.js in a browser or with Babylon Native.