Permalink
Fetching contributors…
Cannot retrieve contributors at this time
88 lines (72 sloc) 2.9 KB
<!DOCTYPE html>
<html>
<head>
<title>
CubicVR.js: Basic Texured Cube /w Scene
</title>
<script src="../../CubicVR.js" type="text/javascript">
</script>
<script type='text/javascript'>
function webGLStart(gl,canvas) {
// Create a material for the mesh
var boxMaterial1 = new CubicVR.Material({
textures: { color: "../images/6583-diffuse.jpg" }
});
var boxMaterial2 = new CubicVR.Material({
textures: { color: "../images/1422-diffuse.jpg" }
});
var boxMaterial3 = new CubicVR.Material({
textures: { color: "../images/2282-diffuse.jpg" }
});
var boxMaterial4 = new CubicVR.Material({
textures: { color: "../images/2576-diffuse.jpg" }
});
var boxMaterial5 = new CubicVR.Material({
textures: { color: "../images/4734-diffuse.jpg" }
});
var boxMaterial6 = new CubicVR.Material({
textures: { color: "../images/grass.jpg" }
});
// Add a box to mesh, size 1.0, apply base material and UV mapper
var boxMesh = new CubicVR.Mesh({
primitive: {
type: "box",
size: 1.0,
material: boxMaterial1,
uvmapper: {
projectionMode: "cubic",
scale: [1, 1, 1]
}
}
});
// before it's triangulated, the box is composed of 6 quads, we can assign a material to each
boxMesh.setFaceMaterial(boxMaterial1,0);
boxMesh.setFaceMaterial(boxMaterial2,1);
boxMesh.setFaceMaterial(boxMaterial3,2);
boxMesh.setFaceMaterial(boxMaterial4,3);
boxMesh.setFaceMaterial(boxMaterial5,4);
boxMesh.setFaceMaterial(boxMaterial6,5);
// triangulate and buffer object to GPU, remove unused data
boxMesh.prepare();
// 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.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.render();
});
// initialize a mouse view controller
mvc = new CubicVR.MouseViewController(canvas, scene.camera);
}
</script>
</head>
<body onLoad="CubicVR.start('auto',webGLStart);"></body>
</html>