Skip to main content

Class: CoreEditorApp

Viewer-Editor-Templates.CoreEditorApp

ViewerApp with editor UI and plugins

example

const editor = new CoreEditorApp({canvas: document.getElementById('mcanvas')})

// add default editor plugins
await addEditorPlugins(editor, {caching: true, ground: true, bloom: true, depthTonemap: true, enableDrop: false, importPopup: false, debug: false})

// custom plugins(optional)
editor.addPlugin(CustomPlugin)
editor.addPlugin(CustomPlugin2)
const uiPlugin = editor.getPlugin(TweakpaneUiPlugin)
uiPlugin.setupPluginUi(CustomPlugin)
uiPlugin.setupPluginUi(CustomPlugin2)

// setup ui
await editor.setupUi({
'Picking': [CustomPlugin],
'Custom Tab': [CustomPlugin2],
})

Hierarchy

Properties

VERSION

Static Readonly VERSION: "0.9.22"

Inherited from

ViewerApp.VERSION

Defined in

webgi/src/viewer/ViewerApp.ts:127


defaultModes

defaultModes: { title: string ; plugins: Class<AViewerPlugin<any, ViewerApp>>[] ; div?: HTMLDivElement }[]

Defined in

webgi/src/extras/viewer/CoreEditorApp.ts:137


console

console: Console = console

Inherited from

ViewerApp.console

Defined in

webgi/src/viewer/ViewerApp.ts:129


scene

Readonly scene: RootScene<CameraController>

The Scene attached to the viewer, this cannot be changed.

Inherited from

ViewerApp.scene

Defined in

webgi/src/viewer/ViewerApp.ts:142


plugins

Readonly plugins: Record<string, IViewerPlugin<IViewerApp, boolean>> = {}

Inherited from

ViewerApp.plugins

Defined in

webgi/src/viewer/ViewerApp.ts:159


renderFilter

Readonly renderFilter: IFilter<RenderPass2, "render">

The IFilter wrapper for the main render pass for the effect composer.

Inherited from

ViewerApp.renderFilter

Defined in

webgi/src/viewer/ViewerApp.ts:167


resizeObserver

Readonly resizeObserver: undefined | ResizeObserver

The ResizeObserver observing the canvas element. Add more elements to this observer to resize viewer on their size change.

Inherited from

ViewerApp.resizeObserver

Defined in

webgi/src/viewer/ViewerApp.ts:193


enabled

enabled: boolean = true

If the viewer is enabled. Set this false to disable RAF loop.

Inherited from

ViewerApp.enabled

Defined in

webgi/src/viewer/ViewerApp.ts:418


renderEnabled

renderEnabled: boolean = true

Enable or disable all rendering, Animation loop including any frame/render events won't be fired when this is false.

Inherited from

ViewerApp.renderEnabled

Defined in

webgi/src/viewer/ViewerApp.ts:424


maxFramePerLoop

maxFramePerLoop: number = 1

Specifies how many frames to render in a single request animation frame. Keep to 1 for realtime rendering. Note: should be max (screen refresh rate / animation frame rate) like 60Hz / 30fps

Inherited from

ViewerApp.maxFramePerLoop

Defined in

webgi/src/viewer/ViewerApp.ts:437


rendersPerFrame

rendersPerFrame: number = 1

Number of times to run composer render. Used in WebVR plugin.

Inherited from

ViewerApp.rendersPerFrame

Defined in

webgi/src/viewer/ViewerApp.ts:443


serializePluginsIgnored

serializePluginsIgnored: string[] = []

Inherited from

ViewerApp.serializePluginsIgnored

Defined in

webgi/src/viewer/ViewerApp.ts:965

Accessors

editorInitialized

get editorInitialized(): boolean

Returns

boolean

Defined in

webgi/src/extras/viewer/CoreEditorApp.ts:127


useRgbm

get useRgbm(): boolean

Use RGBM HDR Pipeline for rendering, which makes it faster on smaller devices but disables some features like transparency.

Returns

boolean

Inherited from

ViewerApp.useRgbm

Defined in

webgi/src/viewer/ViewerApp.ts:148


screenShader

get screenShader(): TViewerScreenShader

Screen shader used for final rendering on screen, this can be used by other plugins to render on screen like TonemapPlugin. so it's readonly.

Returns

TViewerScreenShader

Inherited from

ViewerApp.screenShader

Defined in

webgi/src/viewer/ViewerApp.ts:155


useGBufferDepth

get useGBufferDepth(): boolean

Whether to use the rendered gbuffer as depth-prepass. Requires GBufferPlugin This gives performance improvements but sometimes creates issues with z-fighting

Returns

boolean

Inherited from

ViewerApp.useGBufferDepth

Defined in

webgi/src/viewer/ViewerApp.ts:173


isAntialiased

get isAntialiased(): boolean

Whether using Multisample render targets for rendering.

Returns

boolean

Inherited from

ViewerApp.isAntialiased

Defined in

webgi/src/viewer/ViewerApp.ts:183


renderer

get renderer(): BaseRenderer

The renderer for the viewer that's attached to the canvas. This is wrapper around WebGLRenderer and EffectComposer and manages post-processing passes and rendering logic

Returns

BaseRenderer

Inherited from

ViewerApp.renderer

Defined in

webgi/src/viewer/ViewerApp.ts:384


state

get state(): ViewerState

deprecated State of the viewer. Not implemented.

see ViewerApp.enabled.

Returns

ViewerState

Inherited from

ViewerApp.state

Defined in

webgi/src/viewer/ViewerApp.ts:539


container

get container(): HTMLElement

Get the HTML Element containing the canvas

Returns

HTMLElement

Inherited from

ViewerApp.container

Defined in

webgi/src/viewer/ViewerApp.ts:547


canvas

get canvas(): HTMLCanvasElement

Get the HTML Canvas Element where the viewer is rendering

Returns

HTMLCanvasElement

Inherited from

ViewerApp.canvas

Defined in

webgi/src/viewer/ViewerApp.ts:559


canvasTexture

get canvasTexture(): CanvasTexture

Returns

CanvasTexture

Inherited from

ViewerApp.canvasTexture

Defined in

webgi/src/viewer/ViewerApp.ts:565


renderManager

get renderManager(): BaseRenderer

Returns

BaseRenderer

Inherited from

ViewerApp.renderManager

Defined in

webgi/src/viewer/ViewerApp.ts:1088


assetManager

get assetManager(): undefined | AssetManagerPlugin

Returns

undefined | AssetManagerPlugin

Inherited from

ViewerApp.assetManager

Defined in

webgi/src/viewer/ViewerApp.ts:1092

Constructors

constructor

new CoreEditorApp(options)

Create a viewer instance for using the webgi viewer SDK.

Parameters

NameType
optionsIViewerAppOptions

Overrides

ViewerApp.constructor

Defined in

webgi/src/extras/viewer/CoreEditorApp.ts:132

Methods

setupUi

setupUi(plugins?, modes?): Promise<void>

Parameters

NameType
plugins?Record<string, Class<AViewerPlugin<any, ViewerApp>>[]>
modes?{ title: string ; plugins: Class<AViewerPlugin<any, ViewerApp>>[] ; div?: HTMLDivElement }[]

Returns

Promise<void>

Defined in

webgi/src/extras/viewer/CoreEditorApp.ts:184


resize

resize(): void

Mark that the canvas is resized. If the size is changed, the renderer and all render targets are resized. This happens before the render of the next frame.

Returns

void

Inherited from

ViewerApp.resize

Defined in

webgi/src/viewer/ViewerApp.ts:363


setDirty

setDirty(source?, event?): void

Set the viewer to dirty and trigger render of the next frame.

Parameters

NameTypeDescription
source?anyThe source of the dirty event. like plugin or 3d object
event?IEvent<any>The event that triggered the dirty event.

Returns

void

Inherited from

ViewerApp.setDirty

Defined in

webgi/src/viewer/ViewerApp.ts:374


dispose

dispose(): void

Disposes the viewer and frees up all resource and events. Do not use the viewer after calling dispose.

note - If you want to reuse the viewer, set viewer.enabled to false instead, then set it to true again when required. To dispose all the objects, materials in the scene use viewer.scene.disposeSceneModels() This function is not fully implemented yet. There might be some memory leaks.

Returns

void

Inherited from

ViewerApp.dispose

Defined in

webgi/src/viewer/ViewerApp.ts:393


getPlugin

getPlugin<T>(type): undefined | T

Get the Plugin by a type.

Type parameters

NameType
Textends IViewerPlugin<IViewerApp, boolean, T>

Parameters

NameTypeDescription
typestring | Class<T>The class of the plugin to get.

Returns

undefined | T

  • The plugin of the specified type.

Inherited from

ViewerApp.getPlugin

Defined in

webgi/src/viewer/ViewerApp.ts:580


getPluginByType

getPluginByType<T>(type): undefined | T

Get the Plugin by the string type. Use this function if the plugin is not a dependency and you don't want to bundle the plugin.

Type parameters

NameType
Textends IViewerPlugin<ViewerApp, boolean, T>

Parameters

NameTypeDescription
typestringThe string type of the plugin to get. This in the static PluginType property of the plugin

Returns

undefined | T

Inherited from

ViewerApp.getPluginByType

Defined in

webgi/src/viewer/ViewerApp.ts:590


getOrAddPlugin

getOrAddPlugin<T>(type, ...args): Promise<T>

Type parameters

NameType
Textends IViewerPlugin<IViewerApp, boolean, T>

Parameters

NameType
typeClass<T>
...argsany[]

Returns

Promise<T>

Inherited from

ViewerApp.getOrAddPlugin

Defined in

webgi/src/viewer/ViewerApp.ts:594


getOrAddPluginSync

getOrAddPluginSync<T>(type, ...args): T

Type parameters

NameType
Textends IViewerPluginSync<IViewerApp, T>

Parameters

NameType
typeClass<T>
...argsany[]

Returns

T

Inherited from

ViewerApp.getOrAddPluginSync

Defined in

webgi/src/viewer/ViewerApp.ts:599


addPlugin

addPlugin<T>(plugin, ...args): Promise<T>

Add a plugin to the viewer.

Type parameters

NameType
Textends IViewerPlugin<IViewerApp, boolean, T>

Parameters

NameTypeDescription
pluginT | Class<T>The instance of the plugin to add or the class of the plugin to add.
...argsany[]Arguments for the constructor of the plugin, in case a class is passed.

Returns

Promise<T>

  • The plugin added.

Inherited from

ViewerApp.addPlugin

Defined in

webgi/src/viewer/ViewerApp.ts:611


addPluginSync

addPluginSync<T>(plugin, ...args): T

Add a plugin to the viewer(sync).

Type parameters

NameType
Textends IViewerPluginSync<IViewerApp, T>

Parameters

NameType
pluginT | Class<T>
...argsany[]

Returns

T

Inherited from

ViewerApp.addPluginSync

Defined in

webgi/src/viewer/ViewerApp.ts:649


addPlugins

addPlugins(plugins): Promise<void>

Parameters

NameType
plugins(IViewerPlugin<IViewerApp, boolean> | Class<IViewerPlugin<IViewerApp, boolean>>)[]

Returns

Promise<void>

Inherited from

ViewerApp.addPlugins

Defined in

webgi/src/viewer/ViewerApp.ts:683


addPluginsSync

addPluginsSync(plugins): Promise<void>

Parameters

NameType
plugins(IViewerPluginSync<IViewerApp> | Class<IViewerPluginSync<IViewerApp>>)[]

Returns

Promise<void>

Inherited from

ViewerApp.addPluginsSync

Defined in

webgi/src/viewer/ViewerApp.ts:688


removePlugin

removePlugin(p, dispose?): Promise<void>

Remove a plugin instance or a plugin class. Works similar to {@see ViewerApp.addPlugin}

Parameters

NameTypeDefault value
pIViewerPlugin<IViewerApp, boolean>undefined
disposebooleantrue

Returns

Promise<void>

Inherited from

ViewerApp.removePlugin

Defined in

webgi/src/viewer/ViewerApp.ts:698


removePluginSync

removePluginSync(p, dispose?): void

Parameters

NameTypeDefault value
pIViewerPluginSync<IViewerApp>undefined
disposebooleantrue

Returns

void

Inherited from

ViewerApp.removePluginSync

Defined in

webgi/src/viewer/ViewerApp.ts:708


createCamera

createCamera(camera): CameraController

Converts a three.js Camera instance to be used in the viewer.

Parameters

NameTypeDescription
cameraOrthographicCamera | PerspectiveCameraThe three.js OrthographicCamera or PerspectiveCamera instance

Returns

CameraController

  • A wrapper around the camera with some useful methods and properties.

Inherited from

ViewerApp.createCamera

Defined in

webgi/src/viewer/ViewerApp.ts:723


setSize

setSize(size?): void

Set size of the canvas and update the renderer. If no width/height is passed, canvas is set to 100% of the container.

Parameters

NameType
size?Object
size.width?number
size.height?number

Returns

void

Inherited from

ViewerApp.setSize

Defined in

webgi/src/viewer/ViewerApp.ts:742


doOnce

doOnce<TRet>(event, func?): Promise<undefined | TRet>

Type parameters

Name
TRet

Parameters

NameType
event"preRender" | "postRender" | "preFrame" | "postFrame" | "renderEnabled" | "renderDisabled"
func?(...args: any[]) => TRet

Returns

Promise<undefined | TRet>

Inherited from

ViewerApp.doOnce

Defined in

webgi/src/viewer/ViewerApp.ts:797


setBackgroundColor

setBackgroundColor(color): void

Set the background color.

deprecated use {@see RootScene.setBackgroundColor} instead.

Parameters

NameTypeDescription
colorstring | number | Colorcolor in sRGB space.

Returns

void

Inherited from

ViewerApp.setBackgroundColor

Defined in

webgi/src/viewer/ViewerApp.ts:827


setBackground

setBackground(asset): void

Set the background color or texture, toggle it to show the environment as the background. This function is async because the background can be processed by some plugins after setting. This assumes the color to be in the Linear RGB color space, to use with sRGB use function {@see setBackgroundColor}.

deprecated use {@see RootScene.setBackground} instead.

Parameters

NameTypeDescription
assetnull | string | number | ITexture<any> | Colora Texture object, or a string/number/Color to set a solid color or {@see envMapBackground} for showing the scene environment map

Returns

void

  • returns after background is set.

Inherited from

ViewerApp.setBackground

Defined in

webgi/src/viewer/ViewerApp.ts:839


getBackground

getBackground(raw?): null | string | number | ITexture<any>

Get the background color or texture for the scene.

Parameters

NameTypeDefault valueDescription
rawbooleanfalseif true, returns the raw value that was passed to {@see setBackground}, otherwise returns the computed value. (eg. with RGBM, colors are converted to 1px textures, when raw is false, the texture is returned, else the raw color value that was set.)

Returns

null | string | number | ITexture<any>

Inherited from

ViewerApp.getBackground

Defined in

webgi/src/viewer/ViewerApp.ts:875


getManager

getManager(): undefined | AssetManagerPlugin

Gets the Asset management plugin, contains useful functions for managing, loading and inserting assets.

Returns

undefined | AssetManagerPlugin

Inherited from

ViewerApp.getManager

Defined in

webgi/src/viewer/ViewerApp.ts:890


resetCamera

resetCamera(__namedParameters?): void

Sets the camera pointing towards the object at a specific distance.

Parameters

NameType
__namedParametersAnyOptions

Returns

void

Inherited from

ViewerApp.resetCamera

Defined in

webgi/src/viewer/ViewerApp.ts:903


fitToView

fitToView(selected?, distanceMultiplier?, duration?, ease?): Promise<void>

Parameters

NameTypeDefault value
selected?Object3D<Event, string>undefined
distanceMultipliernumber1.5
duration?numberundefined
ease?Easing | "linear" | "easeIn" | "easeOut" | "easeInOut" | "circIn" | "circOut" | "circInOut" | "backIn" | "backOut" | "backInOut" | "anticipate" | "bounceOut" | "bounceIn" | "bounceInOut" | "easeInOutSine"undefined

Returns

Promise<void>

Inherited from

ViewerApp.fitToView

Defined in

webgi/src/viewer/ViewerApp.ts:926


createObject3D

createObject3D(object?, addToRoot?): Promise<undefined | Object3DModel>

Create a new empty object in the scene or add an existing three.js object to the scene.

Parameters

NameTypeDefault value
object?Object3D<Event, string>undefined
addToRootbooleanfalse

Returns

Promise<undefined | Object3DModel>

Inherited from

ViewerApp.createObject3D

Defined in

webgi/src/viewer/ViewerApp.ts:939


createPhysicalMaterial

createPhysicalMaterial(material?): undefined | MeshStandardMaterial2

Create a new physical material from a template or another material. It returns the same material if a material is passed created by the material manager.

Parameters

NameType
material?Material<Event, string> | MeshPhysicalMaterialParameters

Returns

undefined | MeshStandardMaterial2

Inherited from

ViewerApp.createPhysicalMaterial

Defined in

webgi/src/viewer/ViewerApp.ts:946


createMaterial

createMaterial<T>(template, material?): undefined | T

Create a new material from a template or another material. It returns the same material if a material is passed created by the material manager.

Type parameters

NameType
Textends IMaterial<any, T>

Parameters

NameTypeDescription
templatestringtemplate name registered in MaterialManager
material?anythree.js material object or material params to create a new material

Returns

undefined | T

Inherited from

ViewerApp.createMaterial

Defined in

webgi/src/viewer/ViewerApp.ts:954


serializePlugins

serializePlugins(meta?, filter?): any[]

Serialize all the plugins and their settings to save or create presets. Used in {@see toJSON}.

Parameters

NameTypeDescription
meta?anyThe meta object.
filter?string[]List of PluginType for the to include.

Returns

any[]

Inherited from

ViewerApp.serializePlugins

Defined in

webgi/src/viewer/ViewerApp.ts:973


deserializePlugins

deserializePlugins(plugins, meta?): CoreEditorApp

Deserialize all the plugins and their settings from a preset. Used in {@see fromJSON}.

Parameters

NameTypeDescription
pluginsany[]The output of {@see serializePlugins}.
meta?Record<string, any>The meta object.

Returns

CoreEditorApp

Inherited from

ViewerApp.deserializePlugins

Defined in

webgi/src/viewer/ViewerApp.ts:988


traverseSceneObjects

traverseSceneObjects<T>(callback): void

Traverse all objects in scene model root.

Type parameters

NameType
Textends ISceneObject<any> = IModel<Object3D<Event, string>>

Parameters

NameType
callback(o: Object3D<Event, string> & T) => void

Returns

void

Inherited from

ViewerApp.traverseSceneObjects

Defined in

webgi/src/viewer/ViewerApp.ts:1009


toJSON

toJSON(meta?, pluginFilter?): any

Serialize all the viewer and plugin settings and versions.

Parameters

NameTypeDescription
meta?anyThe meta object.
pluginFilter?string[]List of PluginType to include.

Returns

any

  • Serializable JSON object.

Inherited from

ViewerApp.toJSON

Defined in

webgi/src/viewer/ViewerApp.ts:1019


fromJSON

fromJSON(data, meta?): CoreEditorApp

Deserialize all the viewer and plugin settings.

Parameters

NameTypeDescription
dataanyThe serialized JSON object returned from {@see toJSON}.
meta?Record<string, any>The meta object

Returns

CoreEditorApp

Inherited from

ViewerApp.fromJSON

Defined in

webgi/src/viewer/ViewerApp.ts:1044


load

load<T>(obj, options?): Promise<undefined | T>

Add an object/model/material/viewer-config/plugin-preset/... to the viewer scene from url or an IAsset object. Same as {@link AssetManager.addAssetSingle}

Type parameters

NameType
Tany

Parameters

NameType
objnull | string | IAsset
options?ImportAddOptions

Returns

Promise<undefined | T>

Inherited from

ViewerApp.load

Defined in

webgi/src/viewer/ViewerApp.ts:1102


setEnvironmentMap

setEnvironmentMap(map, __namedParameters?): Promise<null | ITexture<any> & Texture>

Set the environment map of the scene from url or an IAsset object.

Parameters

NameType
mapundefined | null | string | ITexture<any> | IAsset | Texture
__namedParameters{ forceImport?: boolean ; reimportDisposed?: boolean ; pathOverride?: string ; importedFile?: IFile } & { processImported?: boolean ; forceImporterReprocess?: boolean ; rootPath?: string ; generateMipmaps?: boolean ; _testDataTextureComplete?: boolean } & AddModelOptions & { pseudoCenter?: boolean ; autoCenter?: boolean ; license?: string } & AnyOptions & ImportFileOptions & { setBackground?: boolean }

Returns

Promise<null | ITexture<any> & Texture>

Inherited from

ViewerApp.setEnvironmentMap

Defined in

webgi/src/viewer/ViewerApp.ts:1112


setBackgroundMap

setBackgroundMap(map, __namedParameters?): Promise<null | ITexture<any> & Texture>

Set the background image of the scene from url or an IAsset object.

Parameters

NameType
mapundefined | null | string | ITexture<any> | IAsset | Texture
__namedParameters{ forceImport?: boolean ; reimportDisposed?: boolean ; pathOverride?: string ; importedFile?: IFile } & { processImported?: boolean ; forceImporterReprocess?: boolean ; rootPath?: string ; generateMipmaps?: boolean ; _testDataTextureComplete?: boolean } & AddModelOptions & { pseudoCenter?: boolean ; autoCenter?: boolean ; license?: string } & AnyOptions & ImportFileOptions & { setBackground?: boolean }

Returns

Promise<null | ITexture<any> & Texture>

Inherited from

ViewerApp.setBackgroundMap

Defined in

webgi/src/viewer/ViewerApp.ts:1124


alert

alert(message?): Promise<void>

Parameters

NameType
message?string

Returns

Promise<void>

Inherited from

ViewerApp.alert

Defined in

webgi/src/viewer/ViewerApp.ts:1141


confirm

confirm(message?): Promise<boolean>

Parameters

NameType
message?string

Returns

Promise<boolean>

Inherited from

ViewerApp.confirm

Defined in

webgi/src/viewer/ViewerApp.ts:1142


prompt

prompt(message?, _default?, cancel?): Promise<null | string>

Parameters

NameTypeDefault value
message?stringundefined
_default?stringundefined
cancelbooleantrue

Returns

Promise<null | string>

Inherited from

ViewerApp.prompt

Defined in

webgi/src/viewer/ViewerApp.ts:1143