Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

113 lines (98 sloc) 3.649 kb
<!DOCTYPE html>
<html>
<head>
<title>
CubicVR.js: Fast dynamic updating of VBO points and normals every frame with JS
</title>
<script src="../../CubicVR.js" type="text/javascript">
</script>
<script type='text/javascript'>
// build Cube from arrays, apply color to points
function buildMesh() {
var half_box = 1;
var face_uv = [[0,1],[1,1],[1,0],[0,0]];
var face_color = [[1,0,0],[0,1,0],[0,0,1],[1,1,1]];
var mesh = new CubicVR.Mesh({
material:{
specular: [1,1,1],
textures: {
color: "../images/1422-diffuse.jpg",
envsphere: "../images/fract_reflections.jpg"
},
env_amount: 0.2,
colorMap: true
},
points:[
[half_box, -half_box, half_box],
[half_box, half_box, half_box],
[-half_box, half_box, half_box],
[-half_box, -half_box, half_box],
[half_box, -half_box, -half_box],
[half_box, half_box, -half_box],
[-half_box, half_box, -half_box],
[-half_box, -half_box, -half_box]
],
faces:[
[0, 1, 2, 3],
[7, 6, 5, 4],
[4, 5, 1, 0],
[5, 6, 2, 1],
[6, 7, 3, 2],
[7, 4, 0, 3]
],
uv:[
face_uv,face_uv,face_uv,
face_uv,face_uv,face_uv
],
color: [
face_color,face_color,face_color,
face_color,face_color,face_color
],
dynamic: true
});
// apply regular subdivision, 2 levels
mesh.subdivide(2,false);
// apply catmull-clark subdivision, 3 levels
mesh.subdivide(2);
// prep for rendering and clean data
mesh.prepare();
return mesh;
}
function webGLStart(gl,canvas) {
// New scene with our canvas dimensions and default camera with FOV 80
var scene = new CubicVR.Scene({
camera: {
width: canvas.width,
height: canvas.height,
fov: 80,
position: [-1.3, 1, -1.5],
target: [0, 0, 0]
},
light: {
type:"directional",
direction:[0.5,-0.5,0.5],
specular:[0.9,0.9,1.0]
},
sceneObject: { name: "cube", mesh: buildMesh }
});
// Add our scene to the window resize list
CubicVR.addResizeable(scene);
// initialize a mouse view controller
var mvc = new CubicVR.MouseViewController(canvas, scene.camera);
var mesh = scene.getSceneObject("cube").getMesh();
// Start our main drawing loop, it provides a timer and the gl context as parameters
CubicVR.MainLoop(function(timer, gl) {
scene.render();
var val = timer.getSeconds();
for (var i = 0, iMax = mesh.points.length; i < iMax; i++) {
mesh.points[i][0] = mesh.sourcePoints[i][0]+Math.sin(val*2.0+mesh.sourcePoints[i][1]*mesh.sourcePoints[i][2]*5.0)*0.1;
mesh.points[i][1] = mesh.sourcePoints[i][1]+Math.cos(val*2.2+mesh.sourcePoints[i][0]*mesh.sourcePoints[i][1]*5.0)*0.1;
mesh.points[i][2] = mesh.sourcePoints[i][2]-Math.cos(val*2.4+mesh.sourcePoints[i][1]*mesh.sourcePoints[i][0]*5.0)*0.1;
}
mesh.update();
});
}
</script>
</head>
<body onLoad="CubicVR.start('auto',webGLStart);"></body>
</html>
Jump to Line
Something went wrong with that request. Please try again.