App

App class allows you to set up your 3D application more easily. It includes code to init WebGL renderer, load glTF scenes, auto-start animations as well as logic for basic camera controls.

Constructor

App(container, ctxSettings, preloader)

container - the id of an HTML-element or the HTML-element itself to contain the canvas.
ctxSettings - the WebGL context attributes to be passed in the 'canvas.getContext()' method.
preloader - the application's Preloader.

Properties

.clearBkgOnLoad : Boolean

Set the scene background to null after loading a gltf scene. Default is false.

.container : HTMLElement

A container element. This is a parent element for 3D Canvas used for rendering operations.

.scene : Scene

Application main scene.

.camera : Camera

Application main camera.

.clock : Clock

Application clock object.

.controls : null

Application main camera controls object.

.mixer : AnimationMixer

Mixer used to play animations loaded from glTF data.

.preloader : HTMLElement

App preloader element (exists only during scene loading)

.renderer : WebGLRenderer

Application WebGL renderer.

.loader : GLTFLoader

Application glTF loader.

.worldCubemapRes : Number

Resolution of the cubemap texture represeinting the world material. Default is 1024.

Methods

.animate () : null

Handler for scene updates: rendering, animations and camera controls. Do not change unless you know what you are doing.

.appendScene (url, loadCb, progressCb, errorCb) : null

Append the scene from the specified glTF file to the current scene. The loadCb callback will receive the loaded scene as a parameter after the loading is finished.

If there is no active scene in the application, then nothing will be appended.

.cleanup () : null

Deprecated. Use dispose or unload instead.

.disableRendering () : null

Disable graphics updates in the animation loop. The controls and the animation mixer will keep being updated and the render callbacks will keep being called.

.dispose () : null

Unloads the scene and cleans up the application data.

.enableControls () : null

Enable controls for the main app camera. Depending on the control type specified for the camera this method will give you 'ORBIT', 'FLYING' or static camera.

.enableRendering () : null

Enable graphics updates in the animation loop.

.getCamera () : Camera

Returns main app camera.

.getHeight () : number

Return calculated container element height.

.getWidth () : number

Return calculated container element width.

.initPostprocessing () : null

Handler for app post-processing initialization. Do not change unless you know what you are doing.

.load (url, loadOkCb, loadErrorCb, autoStart) : null

Deprecated. Use loadScene instead.

Load the glTF scene. The loadOkCb callback will receive the loaded scene as a parameter after the loading is finished.

If there already is an active scene (e.g. loaded before via the load method), then use unload first to avoid conflicts between the existed scene and the loaded one.

.loadScene (url, loadCb, progressCb, errorCb) : null

Load the glTF scene. The loadCb callback will receive the loaded scene as a parameter after the loading is finished.

If there already is an active scene (e.g. loaded before via the loadScene method), then use unload first to avoid conflicts between the existed scene and the loaded one.

.onResize () : null

Handler for canvas resize event. Do not change unless you know what you are doing.

.render () : null

Handler for scene rendering. Do not change unless you know what you are doing.

.run () : null

Starts the application by removing the preloader and starting the rendering cycle.

.setFrameRateDivider (divider : Integer) : null

Lowers the maximum frame by dividing it by a specified integer number. By default the engine tries to render scenes at 60 frames per second. If the divider is set to 2, for example, the FPS will be topped out to 30.

.unload (rootObj) : null

rootObj -- (optional) an object to unload along with its children; if no object is given or the given object is the main application scene then the method performs full scene cleanup.

Unloads either a part or the whole scene depending on the parameters.

Source

For more info on how to obtain the source code of this module see this page.