Sketchfab Viewer API: Camera Limits + Annotations (Full Viewer API)
by James Green
HTML
<script src="https://static.sketchfab.com/api/sketchfab-viewer-1.12.1.js"></script>
<!-- Learn about this code on sketchfab: https://sketchfab.com/developers/viewer -->
<div class="container">
<div class="iframe-container">
<iframe src="" id="api-frame"></iframe>
</div>
<div class="controls" id="controls">
<pre id="Info"></pre>
</div>
</div>
CSS
html,
body {
padding: 0;
margin: 0;
width: 100vw;
height: 100vh;
-webkit-font-smoothing: antialiased;
-moz-font-smoothing: grayscale;
font-family: Open Sans, sans-serif;
}
* {
box-sizing: border-box;
}
.container {
display: flex;
flex-direction: column;
height: 100%;
}
.iframe-container {
position: relative;
width: 100%;
flex: 1;
display: flex;
}
.iframe-container > iframe {
border: 0;
width: 100%;
flex: 1;
}
.controls {
display: flex;
align-items: center;
flex-wrap: wrap;
flex-shrink: 0;
min-height: 50px;
padding: 15px 0 0 15px;
background-color: #F2F2F2;
border-top: 1px solid #e7e7e7;
}
.controls > * {
margin-right: 15px;
margin-bottom: 15px;
}
button {
display: inline-flex;
justify-content: center;
align-items: center;
position: relative;
border: 2px solid transparent;
border-radius: 4px;
padding: 0 13px;
font-family: "Open Sans", sans-serif;
font-weight: 600;
text-align: center;
text-shadow: none;
text-transform: uppercase;
line-height: 1.2;
cursor: pointer;
outline: none;
transition: background 0.2s;
color: white;
background-color: #1caad9;
height: 25px;
font-size: 12px;
}
JavaScript
// Sketchfab Viewer API: Camera Limits + Annotations (Full Viewer API)
const version = '1.12.1';
const uid = 'ac615ea10a3c4175bcb7e338e14c9b03';
const iframe = document.getElementById('api-frame');
const client = new window.Sketchfab(version, iframe);
let api;
// Camera logs from model 8aaa8a43ba05482aaf6214ec80fb412b
const cameraData = {
"useCameraConstraints": true,
"usePanConstraints": true,
"useZoomConstraints": true,
"usePitchConstraints": true,
"useYawConstraints": false,
"zoomIn": 4.793854567970662,
"zoomOut": 8.913641525068408,
"left": -3.1415926536,
"right": 3.1415926536,
"up": 1.5707963267948966,
"down": -0.10471975511965978
};
// Annotation logs from model 842538cffe56494e98b6b2a71b32e1c1
const annotationData = [{
"ScenePosition": [
-1,
-0.9912384525901777,
-0.9782408156737455
],
"eye": [
-3.51173837748195,
-3.5561263768828995,
2.8879868388701135
],
"target": [
-0.0000019968,
-0.0000019968,
-0.0000019968
],
"title": "1",
"text": ""
},
{
"ScenePosition": [
0.982930109090494,
0.9999960064888,
-0.9890996490142058
],
"eye": [
3.2915101571471066,
-3.5913093101249967,
-3.096330798890831
],
"target": [
-0.0000019968,
-0.0000019968,
-0.0000019968
],
"title": "2",
"text": ""
},
{
"ScenePosition": [
0.9999960064888,
-0.9857409219136845,
0.9883227176066233
],
"eye": [
3.8353906578653802,
3.7326430661033645,
2.162384774317129
],
"target": [
-0.0000019968,
-0.0000019968,
-0.0000019968
],
"title": "3",
...