Viewer

This class is used to set up the configuration and canvas for RenderEngine. It also contains instance of grid-like ground, background and Coordinate System.

Core Interface

This class is used to set up the configuration and canvas for RenderEngine. It also contains instance of grid-like ground, background and Coordinate System.

interface Viewer {
name: string;
get canvasContainer(): HTMLElement;
getScene(): Scene3D;
setScene(scene: Scene3D): void;
get isDestroyed(): boolean;
get enableInstance(): boolean;
set enableInstance(v: boolean): void;
get enableAutoInstanceKey(): boolean;
set enableAutoInstanceKey(v: boolean): void;
get enableMultiMeshMerge(): boolean;
set enableMultiMeshMerge(v: boolean): void;
get enableMeshMerge(): boolean;
set enableMeshMerge(v: boolean): void;
get rendererBackend(): RendererBackend;
get renderInfo(): RenderInfo;
get snapshotRendererV2(): SnapshotRenderer;
get requestRenderHandler(): RequestRenderHandler | undefined;
set requestRenderHandler(v: RequestRenderHandler | undefined): void;
requestRender: () => void;
createViewport(name: string, bound?: Vector4): Viewport;
removeViewport(viewport: Viewport): void;
clearViewport(): void;
waitForRenderOver: (v?: number) => Promise<void>;
getSize(): Size;
resize(size?: Size): void;
pause(): void;
resume(): void;
render(): void;
readRenderResult(resultData: Uint8Array, range: IRange): void;
readRenderResultAsync(
resultData: Uint8Array,
range: IRange,
): Promise<void> | undefined;
readRenderResultDataUrl(type?: string, ...args: any[]): string;
destroy(): void;
getRenderStatistics(): Readonly<RenderStatistics>;
getMemoryInfo(whenGrowFailed?: boolean): Readonly<MemoryInfo>;
downloadSceneData(name?: string): void;
createPicker(): Picker;
freeGPU(): void;
get snapshotRenderer(): SnapshotRenderer;
get config(): ViewerConfig;
get currentBackground(): BackgroundMode;
set currentBackground(v: BackgroundMode): void;
get ground(): Ground;
set ground(v: Ground): void;
coordSysHelper: CoordinateSystemHelper;
get currentRenderMode(): RenderMode;
get basicBackground(): BasicBackground;
set basicBackground(background: BasicBackground): void;
get solidBackground(): SolidColorBackground;
set solidBackground(background: SolidColorBackground): void;
get skyBackground(): SkyBackground;
set skyBackground(background: SkyBackground): void;
get envBackground(): EnvMapBackground;
set envBackground(background: EnvMapBackground): void;
get gradientBackground(): GradientBackground;
set gradientBackground(background: GradientBackground): void;
getContainerElement(): Readonly<HTMLElement>;
updateBackGroundParameter(parameter: BackgroundParameter): void;
setBackGroundMode(type: BackgroundMode): void;
setCamera(camera: Camera3D | ArrayCamera): void;
getCamera(): Camera3D;
setHighlightObjects(objects: HighLightItem[]): void;
setHighlightGroups(groups: HighlightGroup[]): void;
_uuid: string | null;
get uuid(): string;
set uuid(uuid: string): void;
_listeners: Map<Symbol, Listener<never>[]>;
on<T>(type: EventType<T>, listener: Listener<T>): void;
once<T>(type: EventType<T>, listener: Listener<T>): void;
has<T>(type: EventType<T>, listener: Listener<T>): boolean;
off<T>(type: EventType<T>, listener: Listener<T>): void;
emit(type: EventType<never>): void;
emit<T>(type: EventType<T>, payload: T): void;
clearAllListeners(): void;
}

Hierarchy

  • EventDispatcher
    • Viewer

Properties

name: string

The name of viewer, which could be empty.

requestRender: () => void

Request to invoke RenderHandler function if it is not null;

waitForRenderOver: (v?: number) => Promise<void>

Give an asynchronous function to user to block program until passed a period from last render.

coordSysHelper: CoordinateSystemHelper

An instance of CoordinateSystemHelper which could be turned on by the config.

_uuid: string | null
_listeners: Map<Symbol, Listener<never>[]>

Accessors

  • get canvasContainer(): HTMLElement

    Returns HTMLElement

  • get isDestroyed(): boolean

    Returns boolean

  • get enableInstance(): boolean

    Returns boolean

  • set enableInstance(v: boolean): void

    Parameters

    • v: boolean

    Returns void

  • get enableAutoInstanceKey(): boolean

    Returns boolean

  • set enableAutoInstanceKey(v: boolean): void

    Parameters

    • v: boolean

    Returns void

  • get enableMultiMeshMerge(): boolean

    Returns boolean

  • set enableMultiMeshMerge(v: boolean): void

    Parameters

    • v: boolean

    Returns void

  • get enableMeshMerge(): boolean

    Returns boolean

  • set enableMeshMerge(v: boolean): void

    Parameters

    • v: boolean

    Returns void

  • get rendererBackend(): RendererBackend

    Returns RendererBackend

  • get renderInfo(): RenderInfo

    This method provides some information of the engine for users. The instance of RenderInfo can get the number of refreshed times in the Shader program, materials and lights. The frameInfo includes Fps, usage of CPU and so on. The objectInfo includes the number of geometries, textures, drawcall, vertices, faces and so on.

    Returns RenderInfo

  • get snapshotRendererV2(): SnapshotRenderer

    Returns SnapshotRenderer

  • get requestRenderHandler(): RequestRenderHandler | undefined

    Returns RequestRenderHandler | undefined

  • set requestRenderHandler(v: RequestRenderHandler | undefined): void

    Parameters

    • v: RequestRenderHandler | undefined

    Returns void

  • get snapshotRenderer(): SnapshotRenderer

    An instance of SnapshotRenderer used to take snapshot of selected object.

    Returns SnapshotRenderer

    use snapshotRendererV2

    It is initialized in the constructor of the RenderEngine.

    See SnapshotRenderer| SnapshotRenderer for more details.

  • get config(): ViewerConfig

    An instance of EngineConfig used to manipulate configuration of the engine.

    Returns ViewerConfig

    The instance is initialized in constructor function of Viewer.

    See EngineConfig| EngineConfig for more details.

  • get ground(): Ground

    Returns Ground

  • set ground(v: Ground): void

    Parameters

    • v: Ground

    Returns void

  • get currentRenderMode(): RenderMode

    The mode of render which is applied in current scene.

    Returns RenderMode

  • get basicBackground(): BasicBackground

    An instance of BasicBackground, which only works when the render mode of background is set to BasicBackground.

    Returns BasicBackground

    use config.background.basic instead basicBackground is move to postPipeline

  • set basicBackground(background: BasicBackground): void

    Parameters

    • background: BasicBackground

    Returns void

    set is not allow to use, use config.background.basic to update parameters instead. basicBackground is move to postPipeline

  • get solidBackground(): SolidColorBackground

    An instance of SolidColorBackground, which only works when the render mode of background is set to SolidColorBackground.

    Returns SolidColorBackground

    use config.background.solid instead solidBackground is move to postPipeline

  • set solidBackground(background: SolidColorBackground): void

    Parameters

    • background: SolidColorBackground

    Returns void

    set is not allow to use, use config.background.solid to update parameters instead. solidBackground is move to postPipeline

  • get skyBackground(): SkyBackground

    An instance of SkyBackground, which only works when the render mode of background is set to SkyBackground.

    Returns SkyBackground

    use config.background.sky instead skyBackground is move to postPipeline

  • set skyBackground(background: SkyBackground): void

    Parameters

    • background: SkyBackground

    Returns void

    set is not allow to use, use config.background.sky to update parameters instead. skyBackground is move to postPipeline

  • get envBackground(): EnvMapBackground

    An instance of EnvMapBackground, which only works when the render mode of background is set to EnvMapBackground.

    Returns EnvMapBackground

    use config.background.envmap instead envBackground is move to postPipeline

  • set envBackground(background: EnvMapBackground): void

    Parameters

    • background: EnvMapBackground

    Returns void

    set is not allow to use, use config.background.envmap to update parameters instead. envBackground is move to postPipeline

  • get gradientBackground(): GradientBackground

    An instance of GradientBackground, which only works when the render mode of background is set to GradientBackground.

    Returns GradientBackground

    use config.background.gradient instead gradientBackground is move to postPipeline

  • set gradientBackground(background: GradientBackground): void

    Parameters

    • background: GradientBackground

    Returns void

    set is not allow to use, use config.background.gradient to update parameters instead. gradientBackground is move to postPipeline

  • get uuid(): string

    Returns string

  • set uuid(uuid: string): void

    Parameters

    • uuid: string

    Returns void

Methods

  • Get the instance of 3D scene in current viewer.

    Returns Scene3D

  • If some users hopes to replace or update the 3d scene, they need to use the function, which has been invoked in constructor to initialize the root.

    Parameters

    • scene: Scene3D

      A Scene3D object of current scene.

    Returns void

    If change the scene, ground, coordinate system and background will be reset.

  • Parameters

    Returns void

  • Returns void

  • Get real size of drawing area from engine's width and height. The size normally is same as canvas.

    Returns Size

  • Change the size of rendering area, if the size is not given then it will automatically adapt to the canvas.

    Parameters

    • size: Size

      Optional parameter.

    Returns void

  • Returns void

  • Returns void

  • Render one frame with the configuration and objects in the scene. All setting of config, scene or camera need to be finished before this.

    Returns void

    If user draw a 2D scene, the attribute render2D should be set to true in advance.

  • Get render result to a TypedArray from the Framebuffer. The result is a rectangular area from left-bottom beginning to right-top ending pixel.

    Parameters

    • resultData: Uint8Array

      All color will be store in this array, which color' format is RGBA within 0-255,

    • range: IRange

    Returns void

    use readRenderResultAsync instead

  • Get render result to a TypedArray from the Framebuffer. The result is a rectangular area from left-bottom beginning to right-top ending pixel.

    Parameters

    • resultData: Uint8Array

      All color will be store in this array, which color' format is RGBA within 0-255,

    • range: IRange

    Returns Promise<void> | undefined

  • Get render result to a Data Url from the canvas api.

    Parameters

    • type: string

      A DOMString indicating the image format. The default type is image/png;

    • ...args: any[]

    Returns string

    unstable read back, depend on browser's implement, use readRenderResultAsync instead.

  • stop the listening events, reset scene graph and camera, release the resource of engine and remove bounded canvas.

    Returns void

  • Statistics data not only include the content of RenderInfo, also provide the size of geometryBuffer, textureByte and Framebuffer and so on.

    Returns Readonly<RenderStatistics>

    See renderInfo for more details.

  • Parameters

    • whenGrowFailed: boolean

    Returns Readonly<MemoryInfo>

  • Download a file which store the data of current scene from browser.

    Parameters

    • name: string

      The name of downloaded file. Default name is debug.

    Returns void

  • If user needs picking feature, this method will offer a Picker's instance with two APIS: pick and pickFirst.

    Returns Picker

  • free gpu memory by context lost, restore gpu memory when next draw

    Returns void

  • Returns Readonly<HTMLElement>

    use canvasContainer Get instance of HTMLElement that will attach canvas which is set in the constructor function.

  • Change the parameters of background such as mode and corresponding parameters.

    Parameters

    • parameter: BackgroundParameter

      An object of BackgroundParameter.

    Returns void

    use config.background instead.

  • Change the mode of background, and the parameters of the background will be set to default values;

    Parameters

    Returns void

    use config.background.active instead.

  • Apply user's camera to renderer. This only works for 3D scene. ArrayCamera is not supported in this function, use Viewport instead.

    Parameters

    • camera: Camera3D | ArrayCamera

      An instance belongs or extents form Camera.

    Returns void

    If the user changes the camera's parameter or uses a new camera, the better way is through this function to avoid errors;

  • Get the camera instance of current viewer. This only works for 3D scene.

    Returns Camera3D

  • This method will add highlight effect to all objects in the array.

    Parameters

    • objects: HighLightItem[]

      HighLightItem is an interface which requires a Drawable object and an optional group index of geometry.

    Returns void

  • Parameters

    • groups: HighlightGroup[]

    Returns void

  • Adds a listener to an event type.

    Type Parameters

    • T

    Parameters

    • type: EventType<T>

      The type of event to listen to.

    • listener: Listener<T>

      The function that gets called when the event is fired.

    Returns void

  • Only active the listener one times and then off it| it.

    Type Parameters

    • T

    Parameters

    • type: EventType<T>
    • listener: Listener<T>

    Returns void

  • Checks if listener is added to an event type.

    Type Parameters

    • T

    Parameters

    • type: EventType<T>
    • listener: Listener<T>

    Returns boolean

  • Removes a listener from listening list.

    Type Parameters

    • T

    Parameters

    • type: EventType<T>
    • listener: Listener<T>

    Returns void

  • Active the event and call the registered listener.

    Parameters

    • type: EventType<never>

    Returns void

  • Active the event and call the registered listener.

    Type Parameters

    • T

    Parameters

    • type: EventType<T>
    • payload: T

    Returns void

  • Removes all listeners from listening list.

    Returns void