-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
95 lines (84 loc) · 3.41 KB
/
index.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>we have callbacks</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="Theo Armour">
</head>
<body>
<img border="0" height="320" src="http://1.bp.blogspot.com/-N3gWY-XID30/UH3Br0HJ_zI/AAAAAAAAFe8/lWDdDiaQHRY/s320/cynthia-draw-lightning.jpg" width="320" />
<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() {
var meshes,
// d = document.getElementById('post-body-7520199647430558687');
d = document.body;
d.style.textAlign = 'center';
d.style.width = '640px';
renderer = new THREE.WebGLRenderer( { alpha: 1, antialias: true, clearColor: 0xffffff } );
renderer.setSize( 640, 320 );
renderer.domElement.style.backgroundColor = 'transparent';
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://1.bp.blogspot.com/-N3gWY-XID30/UH3Br0HJ_zI/AAAAAAAAFe8/lWDdDiaQHRY/s1600/cynthia-draw-lightning.jpg');
material = new THREE.MeshBasicMaterial({map: map});
meshes = new THREE.Object3D();
for ( var i = 0; i < 20; i++) {
geometry = new THREE.BoxGeometry( 5, 5, 5 );
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 );
meshes.add( mesh );
}
scene.add( meshes );
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;
meshes.position.x = 50 * Math.cos( tim );
meshes.position.y = 50 * Math.cos( tim );
meshes.position.z = 50 * Math.sin( tim );
meshes.rotation.x += 0.02;
};
renderers.push( {renderer: renderer, scene: scene, camera: camera, controls: controls, stats: stats, callback: callback} );
}
</script>
</body>
</html>