forked from ahb108/MicroPasts-3Dview
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
602 lines (520 loc) · 18.9 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
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
<!DOCTYPE html>
<html>
<!-- First created by Andrew Bevan, 21-Apr-2014 -->
<!-- micropasts.org -->
<!-- Based mainly on three.js and jquery, and
with further assistance from Marek Maciusowicz,
Daniel Pett, Johannes Raida, Markus Schütz and Manuel Wieser -->
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
<title>MicroPasts 3D Viewer</title>
<meta name="description" content="A 3D viewer for rendering of models from the MicroPasts project" />
<meta name="author" content="The MicroPasts team - Andrew Bevan" />
<meta property="og:title" content="MicroPasts 3D Viewer" />
<meta property="og:url" content="http://micropasts.org/3D" />
<meta property="og:image" content="http://crowdsourced.micropasts.org/static/img/MP_SQUARE_notype.png" />
<meta property="og:site_name" content="MicroPasts: 3D viewer" />
<meta property="og:type" content="website" />
<meta property="og:locale" content="en_GB" />
<meta property="og:description" content="Crowd and community fuelled archaeological research" />
<meta property="fb:admins" content="688811070" />
<meta property="fb:app_id" content="1376278705957324" />
<!-- Twitter card tags -->
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@micropasts" />
<meta name="twitter:title" content="MicroPasts 3D viewer" />
<meta name="twitter:description" content="Crowd and community fuelled archaeological research" />
<meta name="twitter:creator" content="@micropasts" />
<meta name="twitter:image:src" content="http://micropasts.org/3D/examples/P1991_3-3_5_snap.png">
<!-- Main Styles -->
<link rel=stylesheet href="css/mpview.css" />
<!-- jQuery UI style v1.10.4 -->
<link rel=stylesheet href="css/jquery-ui.css" />
</head>
<body>
<!-- Main container -->
<div id="my3dcontent">
<!-- Three Line Menu -->
<div id="toolbox-launcher">
<a href="#"><img src="images/threeline.svg" alt="Menu"></a>
</div>
<div id="toolbox">
<ul class="nav">
<li class="info">
<a href='#' onclick='infooverlay()'>Model Information</a>
</li>
<li class="measure">
<a href='#' onclick='measuring()'>Measurement</a>
</li>
<li class="skin">
<a href='#' onclick='skinswitch()'>Switch Skin</a>
</li>
<li class="reset">
<a href='#' onclick='viewreset()'>Reset View</a>
</li>
<li class="home">
<a href="http://www.micropasts.org/data-centre/">Data Centre</a>
</li>
<li class="help">
<a href='#' onclick='helpoverlay()'>Help</a>
</li>
</ul>
</div>
<!-- Measurement Buttons and Distance Label -->
<div id="mbuttonF">
<input type="button" onclick="placeStart()", class="mbuttonF">
</div>
<div id="mbuttonT">
<input type="button" onclick="placeEnd()", class="mbuttonT">
</div>
<div id="lblDistance">
abc
</div>
<!-- Logo Overlay -->
<div id="mylogo">
<a href="http://micropasts.org"><img width="100" src="images/mp-webgl.png"></a>
</div>
<!-- Replacement Page -->
<div id="backup">
<div id="backup-text-wrapper">
<p>
Sorry, it looks as if your device does not currently support a WebGL viewer.
Please consider updating your browser and/or checking your WebGL settings.
</p>
</div>
</div>
</div>
<!-- Moved scripts here to render faster -->
<script src="js/three.min.js"></script>
<script src="js/TrackballControls.js"></script>
<script src="js/OBJLoader.js"></script>
<script src="js/Detector.js"></script>
<script src="js/jquery-2.1.0.min.js"></script>
<script src="js/Markdown.Converter.js"></script>
<!-- Conditional behaviour of menu-->
<script>
$('#toolbox-launcher').on('click', function(e) {
if ($('#toolbox').css('display') == 'none') {
$('#toolbox').fadeIn();
} else {
$('#toolbox').fadeOut();
}
});
</script>
<!-- Dynamically add a border around my3dcontent, so calc() doesn't have to be used -->
<script type="text/javascript">
if (Detector.webgl) {
$('#my3dcontent').css('min-height', window.innerHeight - 6);
$('#my3dcontent').css('border', 'solid 3px');
window.addEventListener('resize', function() {
$('#my3dcontent').css('min-height', window.innerHeight - 6);
}, false);
} else {
$('#my3dcontent').css('min-height', $('#my3dcontent').height() - 6);
$('#my3dcontent').css('border', 'solid 3px');
window.addEventListener('resize', function() {
$('#my3dcontent').css('min-height', $(window).height() - 6);
}, false);
}
</script>
<!-- Conditional display depending on browser's WebGL capabiltites -->
<script>
$(document).ready(function() {
if (Detector.webgl) {
document.getElementById('backup').style.display = 'none';
} else {
$('#backup').css('display', 'block');
};
});
</script>
<!-- Measure button appearance on-click -->
<script>
$('.mbuttonF').on('click', function(e) {
e.stopPropagation();
$('.mbuttonT').css('border', 'solid 1px transparent');
$(this).css('border', 'solid 1px white');
});
$('.mbuttonT').on('click', function(e) {
e.stopPropagation();
$('.mbuttonF').css('border', 'solid 1px transparent');
$(this).css('border', 'solid 1px white');
});
$(document).on('click', function(e) {
$('.mbuttonF').css('border', 'solid 1px transparent');
$('.mbuttonT').css('border', 'solid 1px transparent');
});
</script>
<!-- WebGL Main Script -->
<script>
var container;
var camera, scene, renderer;
var mouseX = 0, mouseY = 0;
var myTextures = Array();
var texturetype = 0;
var globalObject;
var t1exists
var mouse = {
x : 0.1,
y : 0.1
};
var projector, raycaster;
var spStart, spEnd, sConnection;
var placeStartMode = false;
var placeEndMode = false;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
if (Detector.webgl) {
init();
animate();
}
/*** Initialize ***/
function init() {
var wrapper = document.createElement('div');
wrapper.style.position = 'absolute';
wrapper.style.overflow = 'hidden';
wrapper.style.top = 0;
wrapper.style.width = window.innerWidth + 'px';
wrapper.style.height = window.innerHeight + 'px';
window.addEventListener('resize', function() {
wrapper.style.width = window.innerWidth + 'px';
wrapper.style.height = window.innerHeight + 'px';
}, false);
document.body.appendChild(wrapper);
var container = document.createElement('div');
wrapper.appendChild(container);
// Adjust cameras distance and set the FOV. Last two values set the clippling plane.
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.01, 10);
camera.position.z = 0.4;
projector = new THREE.Projector();
raycaster = new THREE.Raycaster();
// Set camera behaviour and sensitivity
controls = new THREE.TrackballControls(camera);
controls.rotateSpeed = 4;
controls.zoomSpeed = 4;
controls.panSpeed = 2;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
// Add scene
scene = new THREE.Scene();
// White light with no shading effects
var ambient = new THREE.AmbientLight(0xffffff);
scene.add(ambient);
/*** Texture Loading ***/
if (Detector.webgl) {
var manager = new THREE.LoadingManager();
manager.onProgress = function(item, loaded, total) {
console.log(item, loaded, total);
};
var loader = new THREE.ImageLoader(manager);
// Get and set model texture(s) and info from same directory as obj
$.urlParam = function(name) {
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results == null) {
return null;
} else {
return results[1] || 0;
}
}
var modelurl = decodeURIComponent($.urlParam('mesh'));
if (modelurl == 'null') {
var modelurl = 'examples/P1991_3-3_5_LoRes.obj'
var t0 = 'examples/P1991_3-3_5_LoRes.jpg'
var t1 = 'examples/Texture1.jpg'
var mdf = 'examples/readme.md'
} else {
var urlbits = modelurl.split("/");
var modelname = urlbits[urlbits.length - 1];
var modurl = modelurl.substring(0, modelurl.length - 4)
var mydir = modelurl.substring(0, modelurl.length - modelname.length);
var t0 = modurl.concat('.jpg')
var t1 = mydir.concat('Texture1.jpg')
var mdf = mydir.concat('readme.md')
}
// Check for extra texture file
var xhr = new XMLHttpRequest();
xhr.open('HEAD', t1, false);
xhr.send();
t1exists = xhr.status != 404;
// Markdown converter
jQuery(document).ready(function jQueryReady($) {
var converter = new Markdown.Converter(), markdownToHtml = converter.makeHtml;
$.get(mdf).success(function(data) {
$("#readme").html(markdownToHtml(data));
});
});
// Load texture(s) into array
myTextures[0] = new THREE.Texture();
loader.load(t0, function(image) {
myTextures[0].image = image;
myTextures[0].needsUpdate = true;
});
if (t1exists) {
myTextures[1] = new THREE.Texture();
loader.load(t1, function(image) {
myTextures[1].image = image;
myTextures[1].needsUpdate = true;
});
// ele = document.getElementById("skin1");
// ele.style.color = (ele.style.color == "white") ? "silver" : "white";
}
// Load mesh and apply texture
var loader = new THREE.OBJLoader(manager);
loader.load(modelurl, function(mymodel) {
// Store global reference to .obj
globalObject = mymodel;
mymodel.traverse(function(child) {
if ( child instanceof THREE.Mesh) {
child.material.map = myTextures[texturetype];
child.material.needsUpdate = true;
THREE.GeometryUtils.center(child.geometry);
}
});
// Rescale if necessary
mymodel.scale = new THREE.Vector3(1, 1, 1);
// Re-position if necessary
mymodel.position.y += 0.0;
scene.add(mymodel);
});
}
// Measurement (prepared here but to be added via menu)
var sphereGeometry = new THREE.SphereGeometry(0.001, 32, 32);
var sphereMaterialS = new THREE.MeshBasicMaterial({
color : 0xc2852b,
shading : THREE.FlatShading
});
var sphereMaterialE = new THREE.MeshBasicMaterial({
color : 0xf0e8dd,
shading : THREE.FlatShading
});
spStart = new THREE.Mesh(sphereGeometry, sphereMaterialS);
spEnd = new THREE.Mesh(sphereGeometry, sphereMaterialE);
spStart.position.set(-0.1, 0, 0);
spEnd.position.set(0.13, 0, 0);
var lc = new THREE.Color(0xf0e8dd);
var lineGeometry = new THREE.Geometry();
lineGeometry.vertices.push(spStart.position.clone(), spEnd.position.clone());
lineGeometry.colors.push(lc, lc, lc);
var lineMaterial = new THREE.LineBasicMaterial({
vertexColors : THREE.VertexColors
});
sConnection = new THREE.Line(lineGeometry, lineMaterial);
// Check for WebGL (enable slower canvas render otherwise)
if (Detector.webgl) {
renderer = new THREE.WebGLRenderer({
alpha : true
});
} else {
renderer = new THREE.CanvasRenderer({
alpha : true
});
}
renderer.setSize(window.innerWidth, window.innerHeight);
container.appendChild(renderer.domElement);
container.addEventListener('resize', onWindowResize, false);
document.addEventListener("keydown", onDocumentKeyDown, false);
document.addEventListener('mousemove', onDocumentMouseMove, false);
document.addEventListener('touchmove', onDocumentTouchMove, false);
renderer.domElement.addEventListener('click', onClick, false);
}
// Handle keystroke events and related menu functions
function onDocumentKeyDown(event) {
var keyCode = event.which;
// Alternate between multiple textures via "s" keystroke
if (keyCode == 83) {
if (texturetype == 0 & t1exists) {
texturetype = 1;
globalObject.traverse(function(child) {
if ( child instanceof THREE.Mesh) {
child.material.map = myTextures[texturetype];
child.material.needsUpdate = true;
}
});
} else {
texturetype = 0;
globalObject.traverse(function(child) {
if ( child instanceof THREE.Mesh) {
child.material.map = myTextures[texturetype];
child.material.needsUpdate = true;
}
});
}
// Reset camera position via "r" keystroke
} else if (keyCode == 82) {
controls.reset();
}
}
// Alternate between multiple textures via menu
function skinswitch() {
if (texturetype == 0 & t1exists) {
texturetype = 1;
globalObject.traverse(function(child) {
if ( child instanceof THREE.Mesh) {
child.material.map = myTextures[texturetype];
child.material.needsUpdate = true;
}
});
} else {
texturetype = 0;
globalObject.traverse(function(child) {
if ( child instanceof THREE.Mesh) {
child.material.map = myTextures[texturetype];
child.material.needsUpdate = true;
}
});
}
}
// Re-set view
function viewreset() {
controls.reset();
}
// Enable measuring
function measuring() {
if ($('#lblDistance').css('display') == 'none') {
$('#lblDistance').fadeIn();
$('.mbuttonF').fadeIn();
$('.mbuttonT').fadeIn();
scene.add(spStart);
scene.add(spEnd);
scene.add(sConnection);
} else {
$('#lblDistance').fadeOut();
$('.mbuttonF').fadeOut();
$('.mbuttonT').fadeOut();
scene.remove(spStart);
scene.remove(spEnd);
scene.remove(sConnection);
}
}
// Handle window resizing
function onWindowResize(event) {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.onresize = onWindowResize;
// Moving mouse for distance measurement
function onDocumentMouseMove(event) {
event.preventDefault();
mouse.x = (event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight ) * 2 + 1;
}
function onDocumentTouchMove(event) {
event.preventDefault();
mouse.x = (event.touches[0].pageX / window.innerWidth ) * 2 - 1;
mouse.y = -(event.touches[0].pageY / window.innerHeight ) * 2 + 1;
}
// Render handler
function render() {
camera.updateMatrixWorld(true);
vector = new THREE.Vector3(mouse.x, mouse.y, 0.5);
projector.unprojectVector(vector, camera);
raycaster.ray.set(camera.position, vector.sub(camera.position).normalize());
if (placeStartMode || placeEndMode) {
var intersects = raycaster.intersectObject(globalObject, true);
if (intersects.length > 0) {
var I = intersects[0];
if (placeStartMode) {
spStart.position = I.point;
} else if (placeEndMode) {
spEnd.position = I.point;
}
sConnection.geometry.vertices[0].copy(spStart.position);
sConnection.geometry.vertices[1].copy(spEnd.position);
sConnection.geometry.verticesNeedUpdate = true;
sConnection.geometry.computeBoundingSphere();
}
}
// Calculation for distance label
var distance = spStart.position.distanceTo(spEnd.position);
var lblDistance = document.getElementById("lblDistance");
lblDistance.innerHTML = "Length: " + distance.toFixed(4) + " m";
renderer.render(scene, camera);
}
// Loop for new camera on each frame
function animate() {
requestAnimationFrame(animate);
controls.update();
render()
}
function placeStart() {
placeStartMode = true;
placeEndMode = false;
}
function placeEnd() {
placeStartMode = false;
placeEndMode = true;
}
function onClick() {
placeStartMode = false;
placeEndMode = false;
}
</script>
<!-- Google Analytics or similar solutions -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-298202-17']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
<!-- Info and Help and Overlays -->
<script>
function infooverlay() {
el = document.getElementById("infooverlay");
el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}
function helpoverlay() {
el = document.getElementById("helpoverlay");
el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}
</script>
<div id="infooverlay">
<div id="infooverlay-box" class="box">
<a href='#' class='icon-cancel' onclick='infooverlay()'></a>
<div id="readme"></div>
</div>
</div>
<div id="helpoverlay">
<div id="helpoverlay-box" class="box">
<a href='#' class='icon-cancel' onclick='helpoverlay()'></a>
<h3>3D Viewer Help</h3>
<p>
This is a 3D viewer designed by MicroPasts for viewing its models. You can use mouse or touchpad
controls to zoom in and out, pan or rotate the model.
There is a three-bar menu icon top-left which gives access to further options.
</p>
<ul>
<li>
Model Information -- Provides a brief summary of what we know about this model (where avaialble).
</li>
<li>
Measurement -- a distance measuring tool. Click on the brown button to move the brown landmark,
and then click on the white button to move the white landmark. The measured distance will be shown top-right.
</li>
<li>
Switch Skin -- Allows you to cycle through different mesh textures (if more than one is available).
</li>
<li>
Reset View -- Re-centres the model in the viewer at default zoom and position.
</li>
<li>
Data Centre -- Access to our Data Centre page where there are further 3D models and direct downloads available.
</li>
<li>
Help -- Some basic help. For any further queries, please post on our <a href="http://community.micropasts.org/">forum</a>
or consult the source code for this viewer on our <a href="https://github.com/MicroPasts/MicroPasts-3Dview">GitHub repsoitory</a>.
</li>
</ul>
</div>
</div>
</body>
</html>