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.
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.
Extends
EventDispatcher
Properties
name
name:
string
The name of viewer, which could be empty.
requestRender
requestRender: () =>
void
Request to invoke RenderHandler function if it is not null;
Returns
void
waitForRenderOver
waitForRenderOver: (
v?) =>Promise<void>
Give an asynchronous function to user to block program until passed a period from last render.
Parameters
v?
number
Returns
Promise<void>
coordSysHelper
coordSysHelper:
CoordinateSystemHelper
An instance of CoordinateSystemHelper which could be turned on by the config.
_uuid
_uuid:
string|null
Inherited from
_listeners
_listeners:
Map<Symbol,Listener<never>[]>
Inherited from
EventDispatcher._listeners
Accessors
canvasContainer
Get Signature
get canvasContainer():
HTMLElement
Returns
HTMLElement
isDestroyed
Get Signature
get isDestroyed():
boolean
Returns
boolean
enableInstance
Get Signature
get enableInstance():
boolean
Returns
boolean
Set Signature
set enableInstance(
v):void
Parameters
v
boolean
Returns
void
enableAutoInstanceKey
Get Signature
get enableAutoInstanceKey():
boolean
Returns
boolean
Set Signature
set enableAutoInstanceKey(
v):void
Parameters
v
boolean
Returns
void
enableMultiMeshMerge
Get Signature
get enableMultiMeshMerge():
boolean
Returns
boolean
Set Signature
set enableMultiMeshMerge(
v):void
Parameters
v
boolean
Returns
void
enableMeshMerge
Get Signature
get enableMeshMerge():
boolean
Returns
boolean
Set Signature
set enableMeshMerge(
v):void
Parameters
v
boolean
Returns
void
rendererBackend
Get Signature
get rendererBackend():
RendererBackend
Returns
RendererBackend
renderInfo
Get Signature
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
snapshotRendererV2
Get Signature
get snapshotRendererV2():
SnapshotRenderer
Returns
SnapshotRenderer
requestRenderHandler
Get Signature
get requestRenderHandler():
RequestRenderHandler|undefined
Returns
RequestRenderHandler | undefined
Set Signature
set requestRenderHandler(
v):void
Parameters
v
RequestRenderHandler | undefined
Returns
void
snapshotRenderer
Get Signature
get snapshotRenderer():
SnapshotRenderer
An instance of SnapshotRenderer used to take snapshot of selected object.
Deprecated
use snapshotRendererV2
Initialize
It is initialized in the constructor of the RenderEngine.
Remarks
See SnapshotRenderer| SnapshotRenderer for more details.
Returns
SnapshotRenderer
config
Get Signature
get config():
ViewerConfig
An instance of EngineConfig used to manipulate configuration of the engine.
Initialize
The instance is initialized in constructor function of Viewer.
Remarks
See EngineConfig| EngineConfig for more details.
Returns
ViewerConfig
currentBackground
Get Signature
get currentBackground():
BackgroundMode
The background mode which is shown in current canvas.
Default Value
BackgroundMode.SkyBackground
Deprecated
currentBackground is move to postPipeline
Returns
Set Signature
set currentBackground(
v):void
Parameters
v
Returns
void
ground
Get Signature
get ground():
Ground
Returns
Ground
Set Signature
set ground(
v):void
Parameters
v
Ground
Returns
void
currentRenderMode
Get Signature
get currentRenderMode():
RenderMode
The mode of render which is applied in current scene.
Default Value
RenderMode.SHADING
Deprecated
Returns
RenderMode
basicBackground
Get Signature
get basicBackground():
BasicBackground
An instance of BasicBackground, which only works when the render mode of background is set to BasicBackground.
Deprecated
use config.background.basic instead
basicBackground is move to postPipeline
Returns
BasicBackground
Set Signature
set basicBackground(
background):void
Deprecated
set is not allow to use, use config.background.basic to update parameters instead.
basicBackground is move to postPipeline
Parameters
background
BasicBackground
Returns
void
solidBackground
Get Signature
get solidBackground():
SolidColorBackground
An instance of SolidColorBackground, which only works when the render mode of background is set to SolidColorBackground.
Deprecated
use config.background.solid instead
solidBackground is move to postPipeline
Returns
SolidColorBackground
Set Signature
set solidBackground(
background):void
Deprecated
set is not allow to use, use config.background.solid to update parameters instead.
solidBackground is move to postPipeline
Parameters
background
SolidColorBackground
Returns
void
skyBackground
Get Signature
get skyBackground():
SkyBackground
An instance of SkyBackground, which only works when the render mode of background is set to SkyBackground.
Deprecated
use config.background.sky instead
skyBackground is move to postPipeline
Returns
SkyBackground
Set Signature
set skyBackground(
background):void
Deprecated
set is not allow to use, use config.background.sky to update parameters instead.
skyBackground is move to postPipeline
Parameters
background
SkyBackground
Returns
void
envBackground
Get Signature
get envBackground():
EnvMapBackground
An instance of EnvMapBackground, which only works when the render mode of background is set to EnvMapBackground.
Deprecated
use config.background.envmap instead
envBackground is move to postPipeline
Returns
EnvMapBackground
Set Signature
set envBackground(
background):void
Deprecated
set is not allow to use, use config.background.envmap to update parameters instead.
envBackground is move to postPipeline
Parameters
background
EnvMapBackground
Returns
void
gradientBackground
Get Signature
get gradientBackground():
GradientBackground
An instance of GradientBackground, which only works when the render mode of background is set to GradientBackground.
Deprecated
use config.background.gradient instead
gradientBackground is move to postPipeline
Returns
GradientBackground
Set Signature
set gradientBackground(
background):void
Deprecated
set is not allow to use, use config.background.gradient to update parameters instead.
gradientBackground is move to postPipeline
Parameters
background
GradientBackground
Returns
void
uuid
Get Signature
get uuid():
string
Returns
string
Set Signature
set uuid(
uuid):void
Parameters
uuid
string
Returns
void
Inherited from
EventDispatcher.uuid
Methods
getScene()
getScene():
Scene3D
Get the instance of 3D scene in current viewer.
Returns
setScene()
setScene(
scene):void
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
A Scene3D object of current scene.
Returns
void
Tips
If change the scene, ground, coordinate system and background will be reset.
createViewport()
createViewport(
name,bound?):Viewport
Parameters
name
string
bound?
Returns
removeViewport()
removeViewport(
viewport):void
Parameters
viewport
Returns
void
clearViewport()
clearViewport():
void
Returns
void
getSize()
getSize():
Size
Get real size of drawing area from engine’s width and height. The size normally is same as canvas.
Returns
Size
resize()
resize(
size?):void
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
pause()
pause():
void
Returns
void
resume()
resume():
void
Returns
void
render()
render():
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
Tip
If user draw a 2D scene, the attribute render2D should be set to true in advance.
readRenderResult()
readRenderResult(
resultData,range):void
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
Deprecated
use readRenderResultAsync instead
readRenderResultAsync()
readRenderResultAsync(
resultData,range):Promise<void> |undefined
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
readRenderResultDataUrl()
readRenderResultDataUrl(
type?, …args):string
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
Deprecated
unstable read back, depend on browser’s implement, use readRenderResultAsync instead.
destroy()
destroy():
void
stop the listening events, reset scene graph and camera, release the resource of engine and remove bounded canvas.
Returns
void
getRenderStatistics()
getRenderStatistics():
Readonly<RenderStatistics>
Statistics data not only include the content of RenderInfo, also provide the size of geometryBuffer, textureByte and Framebuffer and so on.
Returns
Readonly<RenderStatistics>
Remarks
See renderInfo for more details.
getMemoryInfo()
getMemoryInfo(
whenGrowFailed?):Readonly<MemoryInfo>
Parameters
whenGrowFailed?
boolean
Returns
Readonly<MemoryInfo>
downloadSceneData()
downloadSceneData(
name?):void
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
createPicker()
createPicker():
Picker
If user needs picking feature, this method will offer a Picker’s instance with two APIS: pick and pickFirst.
Returns
Picker
freeGPU()
freeGPU():
void
free gpu memory by context lost, restore gpu memory when next draw
Returns
void
getContainerElement()
getContainerElement():
Readonly<HTMLElement>
Returns
Readonly<HTMLElement>
Deprecated
use canvasContainer
Get instance of HTMLElement that will attach canvas which is set in the constructor function.
updateBackGroundParameter()
updateBackGroundParameter(
parameter):void
Change the parameters of background such as mode and corresponding parameters.
Parameters
parameter
BackgroundParameter
An object of BackgroundParameter.
Returns
void
Deprecated
use config.background instead.
setBackGroundMode()
setBackGroundMode(
type):void
Change the mode of background, and the parameters of the background will be set to default values;
Parameters
type
A constant of BackgroundMode.
Returns
void
Deprecated
use config.background.active instead.
setCamera()
setCamera(
camera):void
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
Tips
If the user changes the camera’s parameter or uses a new camera, the better way is through this function to avoid errors;
getCamera()
getCamera():
Camera3D
Get the camera instance of current viewer. This only works for 3D scene.
Returns
setHighlightObjects()
setHighlightObjects(
objects):void
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
setHighlightGroups()
setHighlightGroups(
groups):void
Parameters
groups
HighlightGroup[]
Returns
void
on()
on<
T>(type,listener):void
Adds a listener to an event type.
Type Parameters
T
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
Inherited from
EventDispatcher.on
once()
once<
T>(type,listener):void
Only active the listener one times and then off it| it.
Type Parameters
T
T
Parameters
type
EventType<T>
listener
Listener<T>
Returns
void
Inherited from
EventDispatcher.once
has()
has<
T>(type,listener):boolean
Checks if listener is added to an event type.
Type Parameters
T
T
Parameters
type
EventType<T>
listener
Listener<T>
Returns
boolean
Inherited from
EventDispatcher.has
off()
off<
T>(type,listener):void
Removes a listener from listening list.
Type Parameters
T
T
Parameters
type
EventType<T>
listener
Listener<T>
Returns
void
Inherited from
EventDispatcher.off
emit()
Call Signature
emit(
type):void
Active the event and call the registered listener.
Parameters
type
EventType<never>
Returns
void
Inherited from
EventDispatcher.emit
Call Signature
emit<
T>(type,payload):void
Active the event and call the registered listener.
Type Parameters
T
T
Parameters
type
EventType<T>
payload
T
Returns
void
Inherited from
EventDispatcher.emit
clearAllListeners()
clearAllListeners():
void
Removes all listeners from listening list.
Returns
void
Inherited from
EventDispatcher.clearAllListeners