-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
112 lines (97 loc) · 3.7 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!doctype html>
<html lang="en">
<head>
<title>now with animation</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() {
// var d = document.getElementById('post-body-1464980370977528245');
var d = document.body;
var container = document.createElement( 'div' );
d.appendChild( container );
var color;
renderer = new THREE.WebGLRenderer( {clearColor: 0x000000, clearAlpha: 1, antialias: true } );
renderer.setSize( 640, 320 );
renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;
container.appendChild( renderer.domElement );
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 40, 640 / 320, 1, 10000 );
camera.position.set(100, 100, -100);
controls = new THREE.TrackballControls( camera, renderer.domElement );
light = new THREE.AmbientLight( 0xffffff );
scene.add( light );
light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 100, 100, 100 ).normalize();
scene.add( light );
light = new THREE.PointLight( 0xff0040, 20, 100 );
light.position.set( -50, 50, -50);
scene.add( light );
light = new THREE.SpotLight( 0xffffff, 1.5 );
light.position.set( -50, 50, -50 );
light.castShadow = true;
light.shadowCameraNear = 1;
light.shadowCameraFar = camera.far;
light.shadowCameraFov = 50;
scene.add( light );
color = Math.random() * 0xffffff;
material = new THREE.MeshBasicMaterial( {color: color, ambient: color, side: THREE.DoubleSide } );
geometry = new THREE.PlaneGeometry( 100, 100, 10, 10 );
mesh = new THREE.Mesh( geometry, material );
mesh.position.set(0, 0, 0);
mesh.rotation.x = -1.5708;
// mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add( mesh );
for ( var i = 0; i < 20; i++) {
geometry = new THREE.CubeGeometry( 5, 5, 5 );
color = Math.random() * 0xffffff;
material = new THREE.MeshPhongMaterial( {color: color, ambient: color, shading: THREE.SmoothShading } );
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 );
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add( mesh );
}
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
stats.domElement.style.zIndex = 100;
container.appendChild( stats.domElement );
renderers.push( {renderer: renderer, scene: scene, camera: camera, controls: controls, stats: stats} );
}
</script>
</body>
</html>