API Reference

Class List

pc.Scene

Extends: pc.EventHandler

A scene is graphical representation of an environment. It manages the scene hierarchy, all graphical objects, lights, and scene-wide properties.

Summary

Properties

ambientLight

The color of the scene's ambient light.

defaultMaterial

The default material used in case no other material is available.

exposure

The exposure value tweaks the overall brightness of the scene.

fog

The type of fog used by the scene.

fogColor

The color of the fog (if enabled).

fogDensity

The density of the fog (if enabled).

fogEnd

The distance from the viewpoint where linear fog reaches its maximum.

fogStart

The distance from the viewpoint where linear fog begins.

gammaCorrection

The gamma correction to apply when rendering the scene.

layers

A pc.LayerComposition that defines rendering order of this scene.

lightmapMaxResolution

The maximum lightmap resolution.

lightmapMode

The lightmap baking mode.

lightmapSizeMultiplier

The lightmap resolution multiplier.

root

The root entity of the scene, which is usually the only child to the Application root entity.

skybox

The base cubemap texture used as the scene's skybox, if mip level is 0.

skyboxIntensity

Multiplier for skybox intensity.

skyboxMip

The mip level of the skybox to be displayed.

skyboxPrefiltered128

The prefiltered cubemap texture (size 128x128) used as the scene's skybox, if mip level 1.

skyboxPrefiltered16

The prefiltered cubemap texture (size 16x16) used as the scene's skybox, if mip level 4.

skyboxPrefiltered32

The prefiltered cubemap texture (size 32x32) used as the scene's skybox, if mip level 3.

skyboxPrefiltered4

The prefiltered cubemap texture (size 4x4) used as the scene's skybox, if mip level 6.

skyboxPrefiltered64

The prefiltered cubemap texture (size 64x64) used as the scene's skybox, if mip level 2.

skyboxPrefiltered8

The prefiltered cubemap texture (size 8x8) used as the scene's skybox, if mip level 5.

skyboxRotation

The rotation of the skybox to be displayed.

toneMapping

The tonemapping transform to apply when writing fragments to the frame buffer.

Methods

setSkybox

Sets the cubemap for the scene skybox.

Events

set:layers

Fired when the layer composition is set.

set:skybox

Fired when the skybox is set.

Inherited

Methods

fire

Fire an event, all additional arguments are passed on to the event listener.

hasEvent

Test if there are any handlers bound to an event name.

off

Detach an event handler from an event.

on

Attach an event handler to an event.

once

Attach an event handler to an event.

Details

Constructor

Scene()

Creates a new Scene.

Properties

pc.ColorambientLight

The color of the scene's ambient light. Defaults to black (0, 0, 0).

pc.StandardMaterialdefaultMaterial

The default material used in case no other material is available.

numberexposure

The exposure value tweaks the overall brightness of the scene. Defaults to 1.

stringfog

The type of fog used by the scene. Can be:

Defaults to pc.FOG_NONE.

pc.ColorfogColor

The color of the fog (if enabled). Defaults to black (0, 0, 0).

numberfogDensity

The density of the fog (if enabled). This property is only valid if the fog property is set to pc.FOG_EXP or pc.FOG_EXP2. Defaults to 0.

numberfogEnd

The distance from the viewpoint where linear fog reaches its maximum. This property is only valid if the fog property is set to pc.FOG_LINEAR. Defaults to 1000.

numberfogStart

The distance from the viewpoint where linear fog begins. This property is only valid if the fog property is set to pc.FOG_LINEAR. Defaults to 1.

numbergammaCorrection

The gamma correction to apply when rendering the scene. Can be:

Defaults to pc.GAMMA_NONE.

pc.LayerCompositionlayers

A pc.LayerComposition that defines rendering order of this scene.

numberlightmapMaxResolution

The maximum lightmap resolution. Defaults to 2048.

numberlightmapMode

The lightmap baking mode. Can be:

  • pc.BAKE_COLOR: single color lightmap
  • pc.BAKE_COLORDIR: single color lightmap + dominant light direction (used for bump/specular). Only lights with bakeDir=true will be used for generating the dominant light direction.

Defaults to pc.BAKE_COLORDIR.

numberlightmapSizeMultiplier

The lightmap resolution multiplier. Defaults to 1.

pc.Entityroot

The root entity of the scene, which is usually the only child to the Application root entity.

pc.Textureskybox

The base cubemap texture used as the scene's skybox, if mip level is 0. Defaults to null.

numberskyboxIntensity

Multiplier for skybox intensity. Defaults to 1.

numberskyboxMip

The mip level of the skybox to be displayed. Only valid for prefiltered cubemap skyboxes. Defaults to 0 (base level).

pc.TextureskyboxPrefiltered128

The prefiltered cubemap texture (size 128x128) used as the scene's skybox, if mip level 1. Defaults to null.

pc.TextureskyboxPrefiltered16

The prefiltered cubemap texture (size 16x16) used as the scene's skybox, if mip level 4. Defaults to null.

pc.TextureskyboxPrefiltered32

The prefiltered cubemap texture (size 32x32) used as the scene's skybox, if mip level 3. Defaults to null.

pc.TextureskyboxPrefiltered4

The prefiltered cubemap texture (size 4x4) used as the scene's skybox, if mip level 6. Defaults to null.

pc.TextureskyboxPrefiltered64

The prefiltered cubemap texture (size 64x64) used as the scene's skybox, if mip level 2. Defaults to null.

pc.TextureskyboxPrefiltered8

The prefiltered cubemap texture (size 8x8) used as the scene's skybox, if mip level 5. Defaults to null.

pc.QuatskyboxRotation

The rotation of the skybox to be displayed. Defaults to pc.Quat.IDENTITY.

numbertoneMapping

The tonemapping transform to apply when writing fragments to the frame buffer. Can be:

Defaults to pc.TONEMAP_LINEAR.

Methods

setSkybox([cubemaps])

Sets the cubemap for the scene skybox.

Parameters

cubemapspc.Texture[]

An array of cubemaps corresponding to the skybox at different mip levels. If undefined, scene will remove skybox. Cubemap array should be of size 7, with the first element (index 0) corresponding to the base cubemap (mip level 0) with original resolution. Each remaining element (index 1-6) corresponds to a fixed prefiltered resolution (128x128, 64x64, 32x32, 16x16, 8x8, 4x4).

Events

set:layers

Fired when the layer composition is set. Use this event to add callbacks or advanced properties to your layers.

this.app.scene.on('set:layers', function (oldComp, newComp) {
    var list = newComp.layerList;
    var layer;
    for (var i = 0; i < list.length; i++) {
        layer = list[i];
        switch (layer.name) {
            case 'MyLayer':
                layer.onEnable = myOnEnableFunction;
                layer.onDisable = myOnDisableFunction;
                break;
            case 'MyOtherLayer':
                layer.shaderPass = myShaderPass;
                break;
        }
    }
});

Parameters

oldComppc.LayerComposition

Previously used pc.LayerComposition.

newComppc.LayerComposition

Newly set pc.LayerComposition.

set:skybox

Fired when the skybox is set.

Parameters

usedTexpc.Texture

Previously used cubemap texture. New is in the pc.Scene#skybox.

Inherited

Methods

fire(name, [arg1], [arg2], [arg3], [arg4], [arg5], [arg6], [arg7], [arg8])

Fire an event, all additional arguments are passed on to the event listener.

obj.fire('test', 'This is the message');

Parameters

nameobject

Name of event to fire.

arg1*

First argument that is passed to the event handler.

arg2*

Second argument that is passed to the event handler.

arg3*

Third argument that is passed to the event handler.

arg4*

Fourth argument that is passed to the event handler.

arg5*

Fifth argument that is passed to the event handler.

arg6*

Sixth argument that is passed to the event handler.

arg7*

Seventh argument that is passed to the event handler.

arg8*

Eighth argument that is passed to the event handler.

Returns

pc.EventHandler

Self for chaining.

hasEvent(name)

Test if there are any handlers bound to an event name.

obj.on('test', function () { }); // bind an event to 'test'
obj.hasEvent('test'); // returns true
obj.hasEvent('hello'); // returns false

Parameters

namestring

The name of the event to test.

Returns

boolean

True if the object has handlers bound to the specified event name.

off([name], [callback], [scope])

Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.

var handler = function () {
};
obj.on('test', handler);

obj.off(); // Removes all events
obj.off('test'); // Removes all events called 'test'
obj.off('test', handler); // Removes all handler functions, called 'test'
obj.off('test', handler, this); // Removes all hander functions, called 'test' with scope this

Parameters

namestring

Name of the event to unbind.

callbackpc.callbacks.HandleEvent

Function to be unbound.

scopeobject

Scope that was used as the this when the event is fired.

Returns

pc.EventHandler

Self for chaining.

on(name, callback, [scope])

Attach an event handler to an event.

obj.on('test', function (a, b) {
    console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console

Parameters

namestring

Name of the event to bind the callback to.

callbackpc.callbacks.HandleEvent

Function that is called when event is fired. Note the callback is limited to 8 arguments.

scopeobject

Object to use as 'this' when the event is fired, defaults to current this.

Returns

pc.EventHandler

Self for chaining.

once(name, callback, [scope])

Attach an event handler to an event. This handler will be removed after being fired once.

obj.once('test', function (a, b) {
    console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
obj.fire('test', 1, 2); // not going to get handled

Parameters

namestring

Name of the event to bind the callback to.

callbackpc.callbacks.HandleEvent

Function that is called when event is fired. Note the callback is limited to 8 arguments.

scopeobject

Object to use as 'this' when the event is fired, defaults to current this.

Returns

pc.EventHandler

Self for chaining.