-
Notifications
You must be signed in to change notification settings - Fork 4
/
index-b01.html
351 lines (286 loc) · 9.98 KB
/
index-b01.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<!doctype html>
<html lang="en">
<head>
<title>brain of richard</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<body>
<script src='http://mrdoob.github.com/three.js/build/three.min.js'></script>
<script src="http://mrdoob.github.com/three.js/examples/js/controls/OrbitControls.js"></script>
<script src='http://mrdoob.github.com/three.js/examples/js/libs/stats.min.js'></script>
<script src="http://mrdoob.github.com/three.js/examples/js/Detector.js"></script>
<script src="http://mrdoob.github.com/three.js/examples/js/libs/dat.gui.min.js"></script>
<!--
<script src='../../three.js/build/three.min.js'></script>
<script src='../../three.js/examples/js/Detector.js'></script>
<script src='../../three.js/examples/js/Stats.js'></script>
<script src='../../examples/js/DAT.GUI.min.js'></script>
-->
<script src="dat.gui.config.js"></script>
<script>
if ( ! Detector.webgl ) { Detector.addGetWebGLMessage(); }
document.body.style.font = '12pt monospace';
document.body.style.margin = '0';
document.body.style.overflow = 'hidden';
document.body.style.textAlign = 'center';
var info = document.createElement( 'div' );
document.body.appendChild( info );
info.style.top = '15px';
info.style.color = '#000';y
info.style.position = 'absolute';
info.style.width = '100%';
info.innerHTML = '<b>brain of richard ~ 2012-01-18<\/b>';
var splash = document.createElement( 'div' );
document.body.appendChild( splash );
splash.style.backgroundColor = '#ddd';
splash.style.borderRadius = '10px';
splash.style.boxShadow = '10px 10px 5px #888888';
splash.style.color = '#000';
splash.style.display = 'block';
splash.style.left = '80px';
splash.style.opacity = '0.85';
splash.style.padding = '0 15px 15px 15px';
splash.style.position = 'absolute';
splash.style.top = '48px';
splash.style.width = '300px';
var splashText = '<h2 style="text-align:right;"><a href="#" title="Click to close" onClick="toggleSplash()" style="color:#888;text-decoration:none;">[X]<\/a><\/h2>' +
'<h1><a href="../../index.html" style=text-decoration:none; >jaanga</a> »<br>The Brain of Richard App<\/h1>' +
'<p>3D compilations of hundreds of 2D scanned MRI images<\/p>' +
'<p>Built by Richard (1960-2013)<br>and Theo' +
'<br\/><b>~<\/b><\/p>' +
'<p>If mouse: click and drag in screen to update view' +
'<br\/>If no mouse: Click zoom, rotate & pan in side menu<br>~' +
'<br>Cursor keys: highlight individual scans' +
'<br>~<\/p>' +
'Veggie scans courtesy of <a href="http://insideinsides.blogspot.com/" target="_blank">Inside Insides<\/a>' +
'<br><b>~<\/b><br>' +
'<a href="#" onclick="guiConfig.cameraMoving = false;">stop camera</a></p>' +
'<p>Launch the 90 second demo...<\/p>';
splash.innerHTML = splashText;
// See brainDemo.js for the demo code.
var audioElement = document.createElement('audio');
splash.appendChild( audioElement );
if (!!(audioElement.canPlayType && audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/, ''))) {
audioElement.src = 'brain-of-richard.ogg';
} else {
audioElement.setAttribute('src', 'brain-of-richard.mp3');
}
audioElement.style.width = '300px';
audioElement.controls = 'true';
var demo, playingDemo = false;
var whichDemoApp = function(){ return; };
//audioElement.addEventListener("click", function() {
// if ( playingDemo ) {playingDemo = false;}
//}, false);
audioElement.addEventListener("playing", function() {
if (!demo) {
loadScript('brainDemo.js');
} else {
demo.style.display = 'block';
}
// playingDemo = true;
}, false);
function loadScript(fname) {
var js = document.createElement('script');
js.setAttribute('type', 'text/javascript');
js.setAttribute('src', fname);
document.body.appendChild(js);
}
var scene, camera, controls, light, stats, renderer;
var geometry, map, material, mesh;
var clock = new THREE.Clock();
var projector;
var intersected;
var mouseMove;
var raycaster;
var scans, plane, boundary, axis, box;
// pardon the jumble below, a combination of an alpha app and insufficient JavaScript object experience
var hack = {};
function brainHack(count) {
if (count === 1) {
hack = {
count: 26,
dir: 'hack01/',
angle: 1.5708,
startY: -50,
startZ: 0,
deltaY: 5,
deltaZ: 0,
opacityDefault: 0.2,
meshY: -50
};
}
if (count === 2) {
hack = {
count: 91,
dir: 'hack02/',
angle: 0,
startY: 0,
startZ: 0,
deltaY: 0,
deltaZ: -1,
opacityDefault: 0.02,
meshY: -100
};
}
if (count === 3) {
hack = {
count: 123,
dir: 'hack03/',
angle: 0,
startY: 0,
startZ: 0,
deltaY: 0,
deltaZ: -1,
opacityDefault: 0.02,
meshY: -100
};
}
if (count === 4 ) {
hack = {
count: 194,
dir: 'plants/artichoke/png/',
angle: 0,
startY: 0,
startZ: 0,
deltaY: 0,
deltaZ: -1,
opacityDefault: 0.2,
meshY: -100
};
}
if (count === 5 ) {
hack = {
count: 53,
dir: 'plants/cactus/png/',
angle: 0,
startY: 0,
startZ: 0,
deltaY: 0,
deltaZ: -2,
opacityDefault: 0.1,
meshY: -100
};
}
if ( count > 1 ) {
guiConfig.cameraMoving = false;
guiConfig.highlighting = false;
}
guiConfig.opacityDefault = hack.opacityDefault;
guiConfig.scansFinish = hack.count;
brainApp.buildBrain();
buildGui();
}
var brainApp = brainApp || {};
brainApp.buildBrain = function() {
if ( scans ) { scene.remove( scans ); }
geometry = new THREE.PlaneBufferGeometry( 200, 200, 1, 1 );
scans = new THREE.Object3D();
scans.current = 0;
for ( var i = 0; i < hack.count; i++ ) {
map = THREE.ImageUtils.loadTexture( hack.dir + ( i + 1 ) + '.png' );
map.minFilter = map.magFilter = THREE.NearestFilter;
// map.needsUpdate = true;
material = new THREE.MeshBasicMaterial( { color: 0xffffff, map: map, opacity: hack.opacityDefault, side: THREE.DoubleSide, transparent: true, wireframe: false} );
mesh = new THREE.Mesh( geometry, material );
mesh.rotation.x = hack.angle;
mesh.position.set(0, hack.startY + i * hack.deltaY, hack.startZ + i * hack.deltaZ);
scans.add( mesh );
}
scene.add( scans );
};
init();
animate();
function init() {
renderer = new THREE.WebGLRenderer( {alpha: 1, antialias: true, clearColor: 0xffffff } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 10, 10000 );
camera.position.set( 200, 100, 250 );
scene.add( camera );
controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.maxDistance = 800;
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
stats.domElement.style.zIndex = 100;
document.body.appendChild( stats.domElement );
// projector = new THREE.Projector();
raycaster = new THREE.Raycaster();
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
document.addEventListener( 'keydown', onKeyDown, false );
brainHack( 1 );
}
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
controls.update( clock.getDelta() );
renderer.render( scene, camera );
var tim = clock.elapsedTime;
// if (!mouseMove && !playingDemo && guiConfig.cameraMoving) {
if ( !mouseMove && guiConfig.cameraMoving === true) {
camera.position.x += -1 * Math.cos( tim * 0.15);
camera.position.z += -1 * Math.sin( tim * 0.15);
} else if ( playingDemo ) {
if (typeof whichDemoApp === 'function') {
whichDemoApp();
} else {
whichDemoApp; // slow speed
}
}
mouseMove = false;
}
function onDocumentMouseMove( event ) { // needs work
var mouse = { x: -1, y: -1 };
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( scene.children );
/*
var projector = new THREE.Projector();
var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
projector.unprojectVector( vector, camera );
var raycaster = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );
var intersects = raycaster.intersectObjects( scans.children );
var vector = new THREE.Vector3( ( event.clientX / window.innerWidth ) * 2 - 1, - ( event.clientY / window.innerHeight ) * 2 + 1, 0.5 );
projector.unprojectVector( vector, camera );
var ray = new THREE.Ray( camera.position, vector.sub( camera.position ).normalize() ),
intersects = ray.intersectObjects( scans.children );
*/
if ( intersects.length > 0 ) {
if ( guiConfig.highlighting && intersected !== intersects[ 0 ].object ) {
if ( intersected ) { intersected.material.opacity = guiConfig.opacityDefault; }
intersected = intersects[ 0 ].object;
scans.current = scans.children.indexOf(intersected);
brainApp.scanHighlight(scans.current);
}
} else {
if (intersected) { intersected.material.opacity = guiConfig.opacityDefault; }
intersected = null;
}
mouseMove = true;
}
function onKeyDown ( event ) {
// http://www.webonweboff.com/tips/js/event_key_codes.aspx
event.preventDefault();
switch( event.keyCode ) {
case 37: /*<*/ scans.current--; if (scans.current < 0) {scans.current = hack.count;} brainApp.scanHighlight(scans.current); break;
case 39: /*>*/ scans.current++; if (scans.current > hack.count) {scans.current = 0;} brainApp.scanHighlight(scans.current); break;
case 38: /*^*/ scans.current = 0; brainApp.scanHighlight(0); break;
case 40: /*v*/ scans.current = hack.count; brainApp.scanHighlight(hack.count - 1); break;
}
}
brainApp.scanHighlight = function(count) {
for (var i = guiConfig.scansStart - 1, l = hack.count; i < l; i++) {
scans.children[i].material.opacity = guiConfig.opacityDefault;
if (i === count) { scans.children[i].material.opacity = guiConfig.opacityHighlight; }
}
};
</script>
</body>
</html>