-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
160 lines (150 loc) · 5.24 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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sketchfab Ortographic Viewer</title>
<!-- Insert this script -->
<script type="text/javascript" src="https://static.sketchfab.com/api/sketchfab-viewer-1.12.1.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 99.8%;
font-family: Arial, Helvetica, Sans-Serif;
text-decoration: none;
}
iframe {
border: none;
border-width: 0px;
}
#alertMsg, #resetLs {
margin-left: 10px;
padding: 4px 8px 4px 8px !important;
color: rgb(87, 155, 245);
font-weight: bold;
background-color: rgba(48, 48, 48, 0.568) !important;
}
#toolbar-top {
position: fixed;
z-index: 999;
right: 100px;
top: 1%;
padding: 4px;
backdrop-filter: blur(3px);
background-color: rgba(255,255,255,0.1);
font-size: 12px;
color: black;
text-align: center;
border-radius: 5px;
box-shadow: 0px 0px 6px 0px rgba(0,0,0,0.1);
}
#toolbar-top button, #toolbar-top input {
border-radius: 4px;
display: inline-block;
border: none;
padding: 4px;
backdrop-filter: blur(3px);
background-color: rgba(255,255,255,0.1);
box-shadow: 0px 0px 6px 0px rgba(0,0,0,0.1);
cursor: pointer;
}
#toolbar-top label {
margin-left: 5px;
}
</style>
</head>
<body>
<div id="toolbar-top">
<button onclick="setView('left')">Left</button>
<button onclick="setView('right')">Right</button>
<button onclick="setView('front')">Front</button>
<button onclick="setView('rear')">Rear</button>
<button onclick="setView('top')">Top</button>
<button onclick="setView('bottom')">Bottom</button>
<label>Zoom: <input type="number" value="150000" id="zoom-value" oninput="setView(null, parseFloat(this.value), parseFloat(document.querySelector('#fov-value').value))" onchange="setView(null, parseFloat(this.value), parseFloat(document.querySelector('#fov-value').value))"></label>
<label>FOV: <input type="number" value="0.01" min="0.01" style="width: 3.5em;" id="fov-value" oninput="setView(null, parseFloat(document.querySelector('#zoom-value').value), parseFloat(this.value))" onchange="setView(null, parseFloat(document.querySelector('#zoom-value').value), parseFloat(this.value))"></label>
<label>Model UID: <input type="text" value="7w7pAfrCfjovwykkEeRFLGw5SXS" id="model-uid"></label>
<button onclick="init()">Reload</button>
<button onclick="alert(alertMsg)" id="alertMsg"> ? </button>
<button onclick="resetLs()" id="resetLs">Reset</button>
</div>
<iframe src="" width="100%" height="100%" id="api-frame" allow="autoplay; fullscreen; xr-spatial-tracking" xr-spatial-tracking execution-while-out-of-viewport execution-while-not-rendered web-share allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>
<script type="text/javascript">
//var uid = localStorage.getItem('last-uid') ?? '96c6bb14737f4c7b9862496d9e3eaa4b'; // model uid, default: '7w7pAfrCfjovwykkEeRFLGw5SXS'
document.querySelector('#model-uid').value = localStorage.getItem('last-uid') ?? '7w7pAfrCfjovwykkEeRFLGw5SXS';
let storedLZ = parseFloat(localStorage.getItem('last-zoom'));
const alertMsg = `Fixes: Keep the model inspector ( i / bottom right button ) open and change something to unlock the zoom limit. Use a negative zoom value if the views are inverted. If the FOV was set to 0, and it broke the viewer, refresh the page.`;
var iframe = document.getElementById( 'api-frame' );
var client = new Sketchfab( iframe );
let api;
let lastSide = 'left';
let lastZoom = storedLZ!=NaN && storedLZ ? storedLZ : 16000;
document.querySelector('#zoom-value').value = lastZoom;
function setView(side, zoom, fov) {
lastSide = side ?? lastSide;
lastZoom = zoom ?? lastZoom;
const sideViews = {
'left': [lastZoom,0,0],
'right': [-lastZoom,0,0],
'front': [0,-lastZoom,0],
'rear': [0,lastZoom,0],
'top': [0,0,lastZoom],
'bottom': [0,0,-lastZoom],
}
localStorage.setItem('last-zoom',lastZoom);
if(api) {
api.setFov(fov ?? 0.01, function(err, angle) {
if (!err) {
window.console.log('FOV set to', angle);
}
});
api.setCameraLookAt(sideViews[lastSide], [0, 0, 0], 1, function(err) {
if (!err) {
window.console.log('Camera moved to '+sideViews[lastSide]);
}
});
}
}
function getView() {
if(api) {
api.getCameraLookAt(function(err, camera) {
window.console.log(`${camera.position}\n${camera.target}`);
});
}
}
function resetLs() {
localStorage.clear();
document.querySelector('#model-uid').value = '7w7pAfrCfjovwykkEeRFLGw5SXS';
document.querySelector('#zoom-value').value = 16000;
lastSide = 'left';
lastZoom = 16000;
init();
}
function init() {
const uid = document.querySelector('#model-uid').value;
localStorage.setItem('last-uid',uid);
client.init(uid, {
success: function onSuccess(_api) {
api = _api;
api.start();
api.addEventListener('viewerready', function() {
console.log('Viewer API is ready');
api.getFov(function(err, fov) {
if (!err) {
window.console.log('FOV was', fov);
}
});
setView();
});
},
error: function onError() {
console.log('Viewer API error');
}
});
}
init();
</script>
</body>
</html>