forked from a-lew/360-tool-sketchfab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
265 lines (243 loc) · 11.5 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>360 tool | The Cleveland Museum of Art</title>
<script type="text/javascript" src="https://static.sketchfab.com/api/sketchfab-viewer-1.5.0.js"></script>
<link rel="stylesheet" href="style/fabview.css">
</head>
<body>
<div class="dashboard" id="sidebar">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<br />
<br />
<br />
<button id="activate">Start viewer</button>
<label>Accession ID</label>
<!-- UPDATE 1: add your artwork accession number and title HERE -->
<select id="accession-enum">
<option value="1915.338.2">1915.388.2 | Deity earring</option>
<option value="1916.1521">1916.1521 | Breastplate from hussar's cuirass</option>
<option value="1944.485">1944.485 | Wade Cup</option>
<option value="1955.166">1955.166 | Mother and Child</option>
<option value="1970.16">1970.16 | Neck Amphora</option>
<option value="1974.15">1974.15 | Microscope</option>
<option value="1974.16">1974.16 | Kottabos Element of a Dancing Satyr</option>
<option value="1978.43">1978.43 | Hand Mirror</option>
<option value="1980.16">1980.16 | Piggy Bank</option>
<option value="1983.28">1983.28 | Jar</option>
<option value="1990.180">1990.180 | Vessel with Ballplayer</option>
<option value="1991.165">1991.165 | Headdress (Ẹpa) called Atófòjọ́wò</option>
<option value="1991.45">1991.45 | Table</option>
<option value="2004.85">2004.85 | Staff of office</option>
<option value="2011.110">2011.110 | Indian Combat</option>
<option value="2017.15">2017.15 | Headrest with Three Lions</option>
<option value="2018.281">2018.281 | Peacock Table Lamp</option>
</select>
<button id="screenshot">Preview snapshot</button>
<button id="spin">Spin</button>
<button id="record">Capture</button>
<button id="sandbox">Sandbox</button>
<label>Resolution</label>
<select id="resolution-enum">
<option value="FHD">1920x1080</option>
<option value="4K">3840x2160</option>
</select>
<label>Filetype</label>
<select id="mimetype-enum">
<option value="image/png">PNG</option>
<option value="image/jpeg">JPG</option>
</select>
<button id="export">Export camera position</button>
<button id="import">Import camera position</button>
</div>
<div class="main" id="main">
<button class="hamburger" id="openbtn" onclick="openNav()">☰ Dashboard</button>
<div class="fab_frame">
<iframe src="" id="api-frame" allow="autoplay; fullscreen" allowfullscreen webkitallowfullscreen="true"></iframe>
</div>
</div>
<div class="stencil" id="tracer">
<div class="stencilgrab" id="tracerheader">Click here to drag</div>
<div class="stencilbar">
<label for="opacity-slider">Opacity</label>
<input id="opacity-slider" type="range" min="0" max="1" step="0.05" value="1">
<output id="opacity-indicator">1</output>
</div>
<img id="stencil-img" src="" />
</div>
<script type="text/javascript" src="js/sentinel.js"></script>
<script type="text/javascript" src="js/jszip.min.js"></script>
<script type="text/javascript" src="js/FileSaver.min.js"></script>
<script type="text/javascript" src="js/navbtn.js"></script>
<script type="text/javascript" src="js/dragelt.js"></script>
<script type="text/javascript" src="js/stencilOpacity.js"></script>
<script type="text/javascript">
var fabview = document.getElementById( 'api-frame' );
let acc_id = document.getElementById( 'accession-enum' );
let resolution = document.getElementById( 'resolution-enum' );
let uid = ''
var client = new Sketchfab( '1.5.0', fabview );
var onSuccess = function( api ) {
api.start();
document.getElementById( 'export' ).addEventListener( 'click', function() {
api.getCameraLookAt( function( err, camera) {
var win = window.open( '', 'camera-export' );
win.document.write( '<pre>' + JSON.stringify( camera, null, 4 ) + '</pre>');
});
});
document.getElementById( 'import' ).addEventListener( 'click', function() {
var camera;
try {
camera = JSON.parse( window.prompt());
} catch( e ) {
alert( 'Camera not valid' );
return;
}
if ( camera && camera.position && camera.target ) {
api.lookat( camera.position, camera.target, 0.0 );
}
});
document.getElementById( 'screenshot' ).addEventListener( 'click', function() {
let preview = screengrab( api, 'image/png', 3840, 2160 );
preview.then( function( image ) {
var thumbnail = document.createElement( 'img' );
thumbnail.src = URL.createObjectURL( image );
document.getElementById( 'dashboard' ).appendChild( thumbnail );
});
});
document.getElementById( 'spin' ).addEventListener( 'click', function() {
api.getCameraLookAt( function( err, initial_camera ) {
var total_frames = 400;
turntable( initial_camera, 0, 1 ).then( function( new_camera ) {
let offset = Math.atan2( initial_camera.position[ 1 ] - new_camera.target[ 1 ], initial_camera.position[ 0 ] - new_camera.target[ 0 ] );
return offset;
}).then( function( offset ) {
for ( let frame_index = 0; frame_index < total_frames; frame_index++ ) {
turntable( initial_camera, frame_index, total_frames, offset ).then( function( new_camera ) {
setTimeout( function() {
return api.lookat( new_camera.position, new_camera.target, 0 );
}, frame_index * 70 );
});
}
});
});
});
document.getElementById( 'record' ).addEventListener( 'click', function() {
// get screenshot parameters: resolution, frame count, total frames, mimetype
api.getCameraLookAt( function( err, initial_camera ) {
turntable( initial_camera, 0, 1 ).then( function( new_camera ) {
let offset = Math.atan2( initial_camera.position[ 1 ] - new_camera.target[ 1 ], initial_camera.position[ 0 ] - new_camera.target[ 0 ] );
return offset;
}).then( function( offset ) {
let mimetype_list = document.getElementById( 'mimetype-enum' );
let img_warehouse = new Array( 750 );
switch ( resolution.value ) {
case '4K': // 3480x2160
capture( api, acc_id.value, mimetype_list.value, initial_camera, 0, 1, 3840, 2160, offset );
break;
default:
capture( api, acc_id.value, mimetype_list.value, initial_camera, 0, 750, 1920, 1080, offset );
}
});
});
});
document.getElementById( 'sandbox' ).addEventListener( 'click', function() {
api.getCameraLookAt( function( err, initial_camera ) {
var total_frames = 1047;
turntable( initial_camera, 0, 1 ).then( function( new_camera ) {
let offset = Math.atan2( initial_camera.position[ 1 ] - new_camera.target[ 1 ], initial_camera.position[ 0 ] - new_camera.target[ 0 ] );
return offset;
}).then( function( offset ) {
turntable( initial_camera, 875, total_frames, offset ).then( function( new_camera) {
return api.lookat( new_camera.position, new_camera.target, 0 );
});
});
});
});
}
/*
* UPDATE 2: Add your accession number and Sketchfab ID
*/
document.getElementById( 'activate' ).addEventListener( 'click', function() {
console.log(acc_id.value);
switch ( acc_id.value ) {
case '1915.338.2': // deity earring
uid = '27834259e0c944af8647b9db1f1f851d';
break;
case '1916.1521': // breastplate from hussars cuirass
uid = '3056e857cf244a3fb651f9d07a66c5a9';
break;
case '1944.485': // Wade cup
uid = '4d4dfba6506d40b09b7eb34c642afab7';
break;
case '1955.166': // mother and child
uid = '5a452eaf4d5d44c1a7a23f7f53d81284';
break;
case '1970.16': // neck amphora
uid = '0bb2525bdd734bf69d5a7b2b051928ad';
break;
case '1974.15': // microscope
uid = 'dfb9849f5af049f6a945de6e7e0001d9';
break;
case '1974.16': // Kottabos
uid = '34d0cda5076c4c52a8ce2eecd2d192c6';
break;
case '1980.16': // piggy bank
uid = '14bfd106baf14d62aebf6eafbe25b3c3';
break;
case '1983.28': // jar
uid = '1f0a28465735411fb4292e63debf3ffa';
break;
case '1990.180': // vessel with Ballplayer
uid = 'c1ddf562b5bf4d5ba5304ddf2b567cd2';
break;
case '1991.165': // Headdress (Ẹpa) called Atófòjọ́wò
uid = 'f8645e86189e4b66b19639f09660af5a';
break;
case '1991.45': // Table
uid = '4ab2488154f74a589549010410800248';
break;
case '1978.43': // Hand mirror
uid = '8099a3de141b454894895fe744625e16';
break;
case '2004.85': // staff of office
uid = '54584c2569dd49798a49f1987fed4317';
break;
case '2011.110': // indian combat
uid = '7723feae34eb441fa9f74dd330b7b7d5';
break;
case '2017.15': // headrest with three lions
uid = '31a9a4ae69834c42a4869d0610f32515';
break;
case '2018.281': // Peacock Table Lamp
uid = 'f7ac44b4f4ec444bac694d64ac16ac43';
break;
default:
uid = '';
}
client.init( uid, {
success: onSuccess,
error: function onError() {
console.log( 'Viewer error' );
},
autostart: 1,
annotations_visible: 0,
camera: 0,
preload: 1,
double_click: 0,
ui_fullscreen: 0,
ui_stop: 0,
ui_help: 0,
ui_settings: 1, // settings for rendering, navigation & textures
ui_inspector: 0,
ui_vr: 0,
ui_annotations: 0,
ui_animations: 0,
ui_infos: 0,
transparent: 0 // set transparent background
});
});
</script>
</body>
</html>