Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (54 sloc) 2.79 KB
<!DOCTYPE html>
<html>
<head>
<title>
CubicVR.js: CubicVR XML Mesh loader test
</title>
<script src="../../CubicVR.js" type="text/javascript">
</script>
<script type='text/javascript'>
function webGLStart() {
// by default generate a full screen canvas with automatic resize
var gl = CubicVR.init();
var canvas = CubicVR.getCanvas();
if (!gl) {
alert("Sorry, no WebGL support.");
return;
};
// load procedural mesh models
var boxMesh = new CubicVR.loadMesh("procedural/box.xml","../images/");
var sphereMesh = new CubicVR.loadMesh("procedural/sphere.xml","../images/");
var coneMesh = new CubicVR.loadMesh("procedural/cone.xml","../images/");
var planeMesh = new CubicVR.loadMesh("procedural/plane.xml","../images/");
var torusMesh = new CubicVR.loadMesh("procedural/torus.xml","../images/");
var cylinderMesh = new CubicVR.loadMesh("procedural/cylinder.xml","../images/");
var latheMesh = new CubicVR.loadMesh("procedural/lathe.xml","../images/");
var polygon1Mesh = new CubicVR.loadMesh("procedural/polygon1.xml","../images/");
// New scene with our canvas dimensions and default camera with FOV 80
var scene = new CubicVR.Scene(canvas.width, canvas.height, 80);
// Add a simple directional light
scene.bind(new CubicVR.Light({type:"directional",specular:[1,1,1],direction:[0.5,-1,0.5]}));
scene.bind(new CubicVR.SceneObject({mesh: boxMesh, position:[-1.5,0,-1]}));
scene.bind(new CubicVR.SceneObject({mesh: sphereMesh, position:[0,0,-1]}));
scene.bind(new CubicVR.SceneObject({mesh: coneMesh, position:[1.5,0,-1]}));
scene.bind(new CubicVR.SceneObject({mesh: planeMesh, position:[-1.5,0,1]}));
scene.bind(new CubicVR.SceneObject({mesh: torusMesh, position:[0,0,1]}));
scene.bind(new CubicVR.SceneObject({mesh: cylinderMesh, position:[1.5,0,1]}));
scene.bind(new CubicVR.SceneObject({mesh: latheMesh, position:[0,0,-2.5]}));
scene.bind(new CubicVR.SceneObject({mesh: polygon1Mesh, position:[0,0,2.5]}));
// set initial camera position and target
scene.camera.position = [2, 2, 1];
scene.camera.target = [0, 0, 0];
// initialize a mouse view controller
mvc = new CubicVR.MouseViewController(canvas, scene.camera);
// Add our scene to the window resize list
CubicVR.addResizeable(scene);
// Start our main drawing loop, it provides a timer and the gl context as parameters
CubicVR.MainLoop(function(timer, gl) {
scene.render();
});
}
</script>
</head>
<body onLoad="webGLStart();"></body>
</html>