Skip to content

Commit

Permalink
updated CubicVR.js to latest, re-compiled super.html
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcliffe committed May 22, 2011
1 parent f2c75ab commit 2da6784
Show file tree
Hide file tree
Showing 3 changed files with 408 additions and 84 deletions.
227 changes: 191 additions & 36 deletions lib/cubicvr/CubicVR.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,44 @@

/*globals alert: false */

/** Global Constants **/
var M_PI = 3.1415926535897932384626433832795028841968;
var M_TWO_PI = 2.0 * M_PI;
var M_HALF_PI = M_PI / 2.0;
(function(window, document, Math, undef) {

var SCRIPT_LOCATION = "";
/** Global Constants **/
var M_PI = Math.PI;
var M_TWO_PI = 2.0 * Math.PI;
var M_HALF_PI = Math.PI / 2.0;

try {
Array.forEach(document.querySelectorAll("script"), function (a) {
var SCRIPT_LOCATION = "";

try {
Array.forEach(document.querySelectorAll("script"), function (a) {
var pos = a.src.lastIndexOf('/CubicVR.js');
if (pos > -1) {
SCRIPT_LOCATION = a.src.substr(0, pos) + "/";
} //if
});
}
catch(e) {
// likely that 'document' is not defined (doesn't really matter)
} //try

(function(undef) {

var CubicVR = this.CubicVR = {};
});
}
catch(e) {
// likely that 'document' is not defined (doesn't really matter)
} //try

var GLCore = {};
var CubicVR = window['CubicVR'] = {};

var GLCore = {
canvas: null,
width: null,
height: null,
fixed_aspect: 0.0,
fixed_size: null,
depth_alpha: false,
default_filter: 1, // LINEAR_MIP
mainloop: null,
shadow_near: 0.1,
shadow_far: 100,
soft_shadow: false,
resize_active: false,
resizeList: []
};
var Materials = [];
var Material_ref = [];
var Textures = [];
Expand Down Expand Up @@ -858,11 +872,45 @@ catch(e) {
GLCore.init = function(gl_in, vs_in, fs_in) {
var gl;

if (vs_in === undef && fs_in === undef) { // default shader handler if no custom override specified
if (window.CubicVR.CubicVRCoreVS && window.CubicVR.CubicVRCoreFS) {
vs_in = window.CubicVR.CubicVRCoreVS;
fs_in = window.CubicVR.CubicVRCoreFS;
} else {
vs_in = SCRIPT_LOCATION + "CubicVR_Core.vs";
fs_in = SCRIPT_LOCATION + "CubicVR_Core.fs";
}
}


if (gl_in === undef) { // no canvas? no problem!
gl_in = document.createElement("canvas");
if (!gl) gl = gl_in.getContext("experimental-webgl");
GLCore.gl = gl;

if (GLCore.fixed_size !== null) {
GLCore.width = GLCore.fixed_size[0];
GLCore.height = GLCore.fixed_size[1];
GLCore.resizeElement(gl_in,GLCore.width,GLCore.height);
} else {
gl_in.style.position = "absolute";
// document.body.style.margin = "0px";
// document.body.style.padding = "0px";
GLCore.addResizeable(gl_in);
GLCore.resizeElement(gl_in,window.innerWidth,window.innerHeight);
}

document.body.appendChild(gl_in);
}

if (gl_in.getContext!==undef&&gl_in.width!==undef&&gl_in.height!==undef)
{
try {
gl = gl_in.getContext("experimental-webgl");
if (!gl) gl = gl_in.getContext("experimental-webgl");
gl.viewport(0, 0, gl_in.width, gl_in.height);
GLCore.canvas = gl_in;
GLCore.width = gl_in.width;
GLCore.height = gl_in.height;

// set these default, can always be easily over-ridden
gl.clearColor(0.0, 0.0, 0.0, 1.0);
Expand All @@ -881,22 +929,14 @@ catch(e) {
gl = gl_in;
}


GLCore.gl = gl;
GLCore.CoreShader_vs = util.getScriptContents(vs_in);
GLCore.CoreShader_fs = util.getScriptContents(fs_in);
GLCore.depth_alpha = false;
GLCore.default_filter = enums.texture.filter.LINEAR_MIP;
GLCore.mainloop = null;
GLCore.shadow_near = 0.1;
GLCore.shadow_far = 100;
GLCore.soft_shadow = false;

gl.enable(gl.CULL_FACE);
gl.cullFace(gl.BACK);
gl.frontFace(gl.CCW);


for (var i = enums.light.type.NULL; i < enums.light.type.MAX; i++) {
ShaderPool[i] = [];
}
Expand Down Expand Up @@ -933,9 +973,88 @@ catch(e) {
ShaderPool[i] = [];
}

if (GLCore.resizeList.length) {
window.addEventListener('resize', function() { CubicVR.GLCore.onResize(); }, false);
GLCore.resize_active = true;
}

return gl;
};

GLCore.addResizeable = function(e) {
CubicVR.GLCore.resizeList.push(e);
}

GLCore.onResize = function() {
var w = window.innerWidth;
var h = window.innerHeight;

if (GLCore.fixed_size !== null) {
w = CubicVR.GLCore.fixed_size[0];
h = CubicVR.GLCore.fixed_size[1];
}

for (var i = 0, iMax = CubicVR.GLCore.resizeList.length; i < iMax; i++) {
GLCore.resizeElement(CubicVR.GLCore.resizeList[i],w,h);
}
}

GLCore.setFixedAspect = function(fa_in) {
CubicVR.GLCore.fixed_aspect = fa_in;
}

GLCore.setFixedSize = function(fs_width, fs_height) {
CubicVR.GLCore.fixed_size = [fs_width,fs_height];
}

GLCore.getCanvas = function() {
return CubicVR.GLCore.canvas;
}

GLCore.resizeElement = function(e,width,height) {
var gl = GLCore.gl;

if (GLCore.fixed_aspect !== 0.0) {
var aspect_height = width*(1.0/CubicVR.GLCore.fixed_aspect);
if (aspect_height > height) {
aspect_height = height;
width = height*CubicVR.GLCore.fixed_aspect;
}
height = aspect_height;
}

if (e.getContext !== undef) {
e.width = width;
e.height = height;

if (!CubicVR.GLCore.fixed_size) {
e.style.left = parseInt(window.innerWidth/2.0-width/2.0)+"px";
e.style.top = parseInt(window.innerHeight/2.0-height/2.0)+"px";
}

gl.viewport(0, 0, width, height);
} else {
e.resize(width,height);
}

/*
canvas.style.position="absolute";
aspect = 1280/720;
canvas_w = window.innerWidth;
canvas_h = canvas_w*(1.0/aspect);
if (canvas_h>window.innerHeight) canvas_h = window.innerHeight;
var toppx = (window.innerHeight/2)-(canvas_h/2);
canvas.width = canvas_w;
canvas.height = canvas_h;
canvas.style.top = toppx+"px";
canvas.style.left = "0px";
*/
}

GLCore.setDepthAlpha = function(da, near, far) {
GLCore.depth_alpha = da;
Expand Down Expand Up @@ -1035,7 +1154,7 @@ catch(e) {
that.worker.postMessage({
message: "function",
data: fn,
options: options,
options: options
});
};
this.start = function(options) {
Expand Down Expand Up @@ -1316,6 +1435,11 @@ catch(e) {
this.doclear = (doclear!==undef)?doclear:true;
CubicVR.GLCore.mainloop = this;

if (GLCore.resizeList.length && !CubicVR.GLCore.resize_active) {
window.addEventListener('resize', function() { CubicVR.GLCore.onResize(); }, false);
CubicVR.GLCore.resize_active = true;
}

var loopFunc = function() { return function() {
var gl = CubicVR.GLCore.gl;
timer.update();
Expand Down Expand Up @@ -1844,6 +1968,11 @@ catch(e) {
return this.currentFace;
};

Mesh.prototype.flipFaces = function() {
for (var i = 0, iMax = this.faces.length; i < iMax; i++) {
this.faces[i].flip();
}
}

Mesh.prototype.triangulateQuads = function() {
for (var i = 0, iMax = this.faces.length; i < iMax; i++) {
Expand Down Expand Up @@ -2048,6 +2177,18 @@ catch(e) {
return this;
};

Mesh.prototype.prepare = function(doClean) {
if (doClean === undef) {
doClean = true;
}

this.triangulateQuads().compile();
if (doClean) {
this.clean();
}

return this;
}

Mesh.prototype.clean = function() {
var i,iMax;
Expand Down Expand Up @@ -2935,7 +3076,7 @@ Light.prototype.setupShader = function(lShader,lNum) {
Light.prototype.setShadow = function(map_res_in) // cone_tex
{
this.map_res = map_res_in;
this.shadowMapTex = new RenderBuffer(this.map_res, this.map_res, false);
this.shadowMapTex = new RenderBuffer(this.map_res, this.map_res, true);
this.shadowMapTex.texture.setFilter(enums.texture.filter.NEAREST);

this.dummyCam = new Camera(this.map_res,this.map_res,0.1,this.distance);
Expand Down Expand Up @@ -3846,7 +3987,6 @@ function CanvasTexture(options) {
if ( options.nodeName === 'IMG' ) {
this.update();
} //if

}; //CanvasTexture

CanvasTexture.prototype.update = function() {
Expand Down Expand Up @@ -4978,7 +5118,7 @@ SceneObject.prototype.adjust_octree = function() {
} //if
} //if
}; //SceneObject::adjust_octree
SceneObject.prototype.bindChild = function(childSceneObj, pickable) {
SceneObject.prototype.bindChild = function(childSceneObj) {
if (this.children === null) {
this.children = [];
}
Expand Down Expand Up @@ -6955,6 +7095,10 @@ Camera.prototype.setDimensions = function(width, height) {
this.calcProjection();
};

Camera.prototype.resize = function(width,height) {
this.setDimensions(width,height);
}


Camera.prototype.setFOV = function(fov) {
this.fov = fov;
Expand Down Expand Up @@ -7356,7 +7500,7 @@ Scene.prototype.renderSceneObjectChildren = function(sceneObj, camera, lights) {
if (sceneObj.children[i].visible === false) {
continue;
} //if

try {
sceneObj.children[i].doTransform(sceneObj.tMatrix);
}catch(e){break;}
Expand Down Expand Up @@ -7482,6 +7626,12 @@ Scene.prototype.updateCamera = function() {
GLCore.depth_alpha_far = this.camera.farclip;
}

Scene.prototype.resize = function(w_in, h_in) {
if (this.camera) {
this.camera.setDimensions(w_in,h_in);
}
}

Scene.prototype.render = function() {
++this.frames;

Expand Down Expand Up @@ -9531,7 +9681,7 @@ function cubicvr_parseCollada(meshUrl, prefix, deferred_bin) {
scenes: [],
lights: [],
cameras: [],
animations: [],
animations: []
};


Expand Down Expand Up @@ -9666,12 +9816,12 @@ function cubicvr_parseCollada(meshUrl, prefix, deferred_bin) {

var getFloatNode = (function () {
return function (n) {
var el = n.float;
var el = n['float'];
if (!el) {
return false;
}

var cn = n.float;
var cn = n['float'];
cn = cn ? parseFloat(cn.$) : 0;

return cn;
Expand Down Expand Up @@ -11933,15 +12083,19 @@ var fsQuad = {

// Extend CubicVR module by adding public methods and classes
var extend = {
GLCore: GLCore,
init: GLCore.init,
addResizeable: GLCore.addResizeable,
setFixedAspect: GLCore.setFixedAspect,
setFixedSize: GLCore.setFixedSize,
getCanvas: GLCore.getCanvas,
enums: enums,
vec2: vec2,
vec3: vec3,
mat4: mat4,
util: util,
fsQuad: fsQuad,
IdentityMatrix: cubicvr_identity,
GLCore: GLCore,
Timer: Timer,
MainLoop: MainLoop,
MouseViewController: MouseViewController,
Expand Down Expand Up @@ -12013,5 +12167,6 @@ for (var ext in extend) {
}

Materials.push(new Material("(null)"));
}());

}(window, window.document, Math));

Loading

0 comments on commit 2da6784

Please sign in to comment.