Skip to content
cjcliffe edited this page Nov 28, 2011 · 9 revisions

CubicVR.Scene

Scene( obj_init )

Note that Scene( width, height, fov, nearclip, farclip, octree ) may be deprecated

The Scene class is used to represent a collection of SceneObject objects that compose a scene. Scene handles transforming, rendering, motion application and more.

var myScene = new CubicVR.Scene({
    camera: {           // Specify a camera, a default one is provided otherwise.
        width: 512,     
        height: 512,
        fov: 60,
        nearclip: 0.1,
        farclip: 400,
     },
     sceneObjects: null, // An array of [[SceneObject]] objects to bind to the scene.
     lights: null,       // An array of [[Light]] objects to bind to the scene.
     octree: null,       // An octree to bind to the scene for visibility use.
     skybox: null,       // A skybox image/texture to use.
     wireframe: null     // Set true to enable wireframe rendering by default (for meshes with edges built)
});

Methods:

attachOctree( octree )

Attach an Octree octree to the Scene. The Octree provides automatic visibility/culling for the Scene.Camera

Parameters:

octree - An initialized Octree object, ensuring sufficient dimensions for the Scene.

Returns:

none

setSkyBox( skybox )

Attach a SkyBox to the Scene, a skybox provides a simple way to provide a background viewable from all angles.

Parameters:

skybox - A SkyBox object.

Returns:

none

bindSceneObject( sceneObj, pickable, use_octree )

Attach a SceneObject and it's child objects to the scene.

Parameters:

  • sceneObj : A valid SceneObject
  • pickable : true if you wish this object to be pickable via bbRayTest(), false if not, default: false
  • use_octree : Whether or not to include this SceneObject in octree visibility calculations, default: true

Returns:

none

getSceneObject( name )

Retrieve a bound SceneObject with the given name of name.

Parameters:

name - The name of the SceneObject to retrieve.

Returns:

SceneObject if successful, null if not found.

removeSceneObject( sceneObj )

Remove a SceneObject and it's child objects from the scene.

Parameters:

Returns:

none

bindLight( lightObj, use_octree )

Attach a Light to the scene.

Parameters:

  • lightObj : A valid Light.
  • use_octree : Whether or not to include this Light in octree visibility calculations, default: true

Returns:

none

removeLight( lightObj )

Remove a Light from the scene.

Parameters:

  • lightObj : A valid Light.

Returns:

none

bindCamera( cameraObj )

Attach a Camera to the scene. Replaces the Scene.camera binding with cameraObj.

Parameters:

cameraObj - A valid Camera

Returns:

none

setCamera( cameraObj )

Replaces the Scene.camera binding with cameraObj.

Parameters:

cameraObj - A valid Camera

Returns:

none

getCamera( cameraName )

Return the Camera with the given name cameraName.

Parameters:

cameraName - The name of the Camera

Returns:

A Camera object if found, null if not.

removeCamera( cameraObj )

Remove a Camera from the scene.

Parameters:

cameraObj - A valid Camera

Returns:

none

evaluate( time_index )

Evaluate any motion controllers to the given time_index in seconds and apply relevant transformations.

Parameters:

time_index - Time to evaluate in Seconds.

Returns:

none

render( options )

Render the scene from the current Scene.camera point of view.

Parameters:

  • options : Optional rendering parameters such as supplying a post-process chain.
    var options = {
        postProcess: myPostProcessChain,    // Supply a PostProcessChain to render directly to it.
        postBuffer: false                   // 'false' to clear the PostProcess before render, 'true' to keep it
    };

Returns:

none

bbRayTest( position, ray, axisMatch )

Cast a ray and test for any pickable objects that intersect that ray.

Parameters:

  • position : Source position for ray, typically Camera.position if picking.
  • ray : Ray vector from position, typicaly Camera.getRayTo( view_x, view_y ).
  • axisMatch : How many axes must have a solid picking match to be considered picked; (< 3 = fuzzy match) values 1-3, default: 2.

Returns:

An array of SceneObjects indexed by distance. The first element will be the best ray match.

Example usage:

From samples/basic/cube_scene.html:

// ...

// New scene with our canvas dimensions and default camera with FOV 80
var scene = new CubicVR.Scene(canvas.width, canvas.height, 80);

// SceneObject container for the mesh
var boxObject = new CubicVR.SceneObject(boxMesh);

// Add SceneObject containing the mesh to the scene
scene.bindSceneObject(boxObject);

// set initial camera position and target
scene.camera.position = [1, 1, 1];
scene.camera.target = [0, 0, 0];

// Start our main drawing loop, it provides a timer and the gl context as parameters
CubicVR.MainLoop(function(timer, gl) {
   scene.render();
});
Clone this wiki locally