-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebgl-on-chromebook.html
95 lines (83 loc) · 3.43 KB
/
webgl-on-chromebook.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!doctype html>
<html lang="en">
<head>
<title>webgl-on-chromebook</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="Theo Armour">
</head>
<body>
<script src='http://mrdoob.github.io/three.js/build/three.min.js'></script>
<script src='http://mrdoob.github.io/three.js/examples/js/controls/TrackballControls.js'></script>
<script src='http://mrdoob.github.io/three.js/examples/js/libs/stats.min.js'></script>
<script>
// the above scripts and these vars are in the Blogger template
var renderer, scene, camera, controls, stats,
light, geometry, material, mesh, clock = new THREE.Clock(), renderers = [];
// the animate source ccode, as below, is in the Blogger Creative Commons widget - for easy acces
function animate() {
requestAnimationFrame( animate );
var tim = clock.getElapsedTime() * 0.15;
for ( var i = 0, l = renderers.length; i < l; i++ ) {
var r = renderers[i];
r.renderer.render( r.scene, r.camera );
if (r.stats) { r.stats.update(); }
if (r.callback) {
r.callback();
} else {
r.camera.position.x = 20 * Math.cos( tim );
r.camera.position.y = 20 * Math.cos( tim );
r.camera.position.z = 20 * Math.sin( tim );
}
r.controls.update();
}
}
animate();
</script>
<script type='text/javascript'>
init();
function init() {
// d = document.getElementById('post-body-7520199647430558687');
var d = document.body;
d.style.margin = '0 auto';
d.style.textAlign = 'center';
d.style.width = '640px';
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( 640, 320 );
renderer.domElement.style.backgroundColor = 'transparent';
renderer.domElement.style.background = '#ffffff url(http://3.bp.blogspot.com/-fob6Re7cR1w/UIihpJfWZ2I/AAAAAAAAFjs/5bM0ZWrh3C0/s320/webgl-chromebook.jpg) no-repeat center top';
renderer.domElement.style.border = '5px solid black';
//renderer.domElement.style.position = 'absolute';
//renderer.domElement.style.left = '0px';
d.appendChild( renderer.domElement );
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 40, 640 / 320, 1, 10000 );
camera.position.set( 50, 50, 50);
controls = new THREE.TrackballControls( camera, renderer.domElement );
THREE.ImageUtils.crossOrigin = 'anonymous';
var map = THREE.ImageUtils.loadTexture('http://3.bp.blogspot.com/-fob6Re7cR1w/UIihpJfWZ2I/AAAAAAAAFjs/5bM0ZWrh3C0/s320/webgl-chromebook.jpg');
material = new THREE.MeshBasicMaterial({ map: map });
material.opacity = 0.3;
material.transparent = true;
geometry = new THREE.CubeGeometry( 50, 50, 50 );
mesh = new THREE.Mesh( geometry, material );
mesh.position.set( Math.random() * 40 - 20, Math.random() * 40, Math.random() * 40 - 20 );
mesh.rotation.set( Math.random() * 1.5807, Math.random() * 1.5807, Math.random() * 1.5807 );
scene.add( mesh );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
stats.domElement.style.zIndex = 100;
d.appendChild( stats.domElement );
var callback = function() {
var tim = clock.getElapsedTime() * 0.15;
mesh.position.x = 20 * Math.cos( tim );
mesh.position.y = 20 * Math.cos( tim );
mesh.position.z = 20 * Math.sin( tim );
material.opacity = Math.abs(Math.sin( tim ));
mesh.rotation.x += 0.02;
};
renderers.push( {renderer: renderer, scene: scene, camera: camera, controls: controls, stats: stats, callback: callback} );
}
</script>
</body>
</html>