[name]

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.

Example

// loaded GLTF 2.0 asset var url = 'template.gltf'; // construct a new application with simple rotating preloader var app = new v3d.App('container', null, new v3d.SimplePreloader({ container: 'container' })); // load main scene app.loadScene(url, function() { app.enableControls(); app.run(); runCode(); }); function runCode() { // place your own code here }

Constructor

[name](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 instance of application's [page:Preloader Preloader] class.

This constructor does the following:

  1. Creates a new container element (if necessary).
  2. Checks whether WebGL technology is supported, if not displays an error dialog.
  3. Initializes an application clock.
  4. Creates a new 3D canvas with WebGL 1.0 or WebGL 2.0 context and adds it to the container element.
  5. Initializes a GLTF loader.
  6. Adds an app instance to v3d.apps list (in case of non-modularized engine).

Properties

[property:Array actions]

Array of [page:AnimationAction animation actions] used to schedule app animations. Instead of accessing this list directly you can also use the [page:SceneUtils.getAnimationActionByName getAnimationActionByName] method to search for an action by its clip name.

[property:Boolean clearBkgOnLoad]

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

[property:HTMLElement container]

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

[property:Scene scene]

Application main scene.

[property:Camera camera]

Application main camera.

[property:Clock clock]

Application clock object.

[property:null controls]

Application main camera controls object.

[property:Number frame]

Current rendering frame of the application.

[property:Number frameRateDivider]

Application FPS divider. Use [page:.setFrameRateDivider setFrameDivider] to set this value.

[property:AnimationMixer mixer]

Mixer used to play animations loaded from glTF data.

[property:HTMLElement preloader]

App preloader element (exists only during scene loading)

[property:WebGLRenderer renderer]

Application WebGL renderer.

[property:Array renderCallbacks]

Array of functions which will be called every time when rendering begins.

[property:GLTFLoader loader]

Application glTF loader.

[property:Number worldCubemapRes]

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

[property:Material worldMaterial]

Material used to generate world environment.

[property:Array xrControllers]

Array of controller objects for the active WebXR session.

[property:XRSession xrSession]

Active WebXR session.

Methods

[method:null animate]()

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

[method:null appendScene](url, loadCb, progressCb, errorCb, loadCameras, loadLights)

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.

Such parameters as *loadCameras* and *loadLights* are used to specify if cameras and lights will be appended from the loaded scene. Both parameters are *true* by default.

[method:null cleanup]()

Deprecated. Use [page:.dispose dispose] or [page:.unload unload] instead.

[method:null disablePostprocessing](keepOutline)

Disable all post-processing effects (except outline when keepOutline=true).

[method:null disableRendering](after)

Disable graphics updates in the animation loop after the given amount of frames (specify 0 to disable immediately). The controls and the animation mixer will keep being updated and the render callbacks will keep being called.

[method:null disableSSAA]()

Disable supersample anti-aliasing.

[method:null dispose]()

Unloads the scene and cleans up the application data.

[method:null enableControls]()

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.

[method:null enablePostprocessing](effects)

Enable the given post-processing effects.

[method:null enableRendering]()

Enable graphics updates in the animation loop.

[method:null enableSSAA](sampleLevel, iterative)

Enable supersample anti-aliasing. The number of samples is calculated as 2^sampleLevel (e.g specify 4 to enable 16x SSAA).

[method:Camera getCamera]()

Returns main app camera.

[method:number getHeight]()

Return calculated container element height.

[method:number getWidth]()

Return calculated container element width.

[method:null initPostprocessing]()

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

[method:null load](url, loadOkCb, loadErrorCb, autoStart)

Deprecated. Use [page:.loadScene 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 [page:.load load] method), then use [page:.unload unload] first to avoid conflicts between the existed scene and the loaded one.

[method:null loadScene](url, loadCb, progressCb, errorCb)

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 [page:.loadScene loadScene] method), then use [page:.unload unload] first to avoid conflicts between the existed scene and the loaded one.

[method:null onResize]()

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

[method:null printPerformanceInfo](delta)

Estimate and print out rendering performance profile. delta is an optional period of estimation (default 1).

[method:null render]()

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

[method:null run]()

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

[method:null setFrameRateDivider]([param:Integer divider])

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.

[method:null unload]([page:Object3D rootObj])

[page:Object3D 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.

[method:null updateEnvironment]([page:Material wMat])

Update world environment from the specified material.

[sourceHint]