SkyBox

cjcliffe edited this page Oct 15, 2011 · 3 revisions

CubicVR.SkyBox

SkyBox is a convenience class that accomplishes the effect of a consistent surrounding environment in a scene: http://en.wikipedia.org/wiki/Skybox_(video_games). This implementation of a SkyBox is by far the simplest in that it is a large cube (just smaller than the frustum) that follows the camera.

Constructor:

SkyBox( input )

Parameters:

input - Object constructor

Object Constructor:

  • input
    • texture: May be either a string or a [[Texture]]. If texture is a string, it is treated as a URL and will try to be loaded as a new image.
    • mapping: ( optional ) While a default UV mapping is implemented, one may be supplied in the form of an array comprised of 6 arrays, one for each face of the SkyBox cube, with the ordering top, bottom, left, right, front, back. Currently, this is the default mapping:
mapping = [ [ 1/3, 0.5, 2/3-tw, 1 ],//top
           [0, 0.5, 1/3, 1],        //bottom
           [0, 0, 1/3-tw, 0.5],  //left
           [2/3, 0, 1, 0.5],        //right
           [2/3+tw, 0.5, 1, 1],  //front
           [1/3, 0, 2/3, 0.5]];     //back

...where tw is texel width, and th is texel height. Currently, texel width and height are only available after onready is called, so automatic texel adjustment is not supported. i.e. any supplied mapping would have to consist of exact values, or use some method of inserting variables later.

Methods:

onready( )

This event handler is called automatically after texture is loaded to grab correct texel values.

Example usage:

From tests/skybox/skybox.html:

// ...
scene.setSkyBox(new CubicVR.SkyBox({
   texture: "../images/space_skybox.jpg"
}));
// ...