Permalink
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (76 sloc) 2.41 KB
<!DOCTYPE html>
<html>
<head>
<title>
CubicVR.js: Basic Texured Cube with Motion
</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;
};
// Add a box to mesh, size 1.0, apply material and UV parameters
var boxMesh = new CubicVR.Mesh({
primitive: {
type: "box",
size: 1.0,
material: {
textures: {
color: "../images/6583-diffuse.jpg"
}
},
uv: {
projectionMode: "cubic",
scale: [1, 1, 1]
}
},
compile: true
});
// New scene with our canvas dimensions and default camera with FOV 80
var scene = new CubicVR.Scene(canvas.width, canvas.height, 80);
// SceneObject with motion constructor, xml/json/id/url compatible.
var boxObject = new CubicVR.SceneObject({
mesh:boxMesh,
motion: {
position: {
0.0: { x: 0, y: 1 },
1.0: { x: 1 },
2.0: { x: -1, y: 0 },
3.0: { x: -0.5 },
4.0: { x: 0, y: 1 },
},
rotation: {
0.0: { x: 0, z: 0 },
1.0: { x: 90, z: 45 },
envelope: {
behavior: "offset"
}
},
envelope: {
behavior: "repeat"
}
}
});
// Add SceneObject containing the mesh to the scene
scene.bind(boxObject);
// set initial camera position and target
scene.camera.position = [1, 1, 1];
scene.camera.target = [0, 0, 0];
// 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.evaluate(timer.getSeconds());
scene.render();
});
}
</script>
</head>
<body onLoad="webGLStart();"></body>
</html>