sketchfab viewer api sample: multiple clint.int / success
by sketchfab
HTML
<script src="https://static.sketchfab.com/api/sketchfab-viewer-1.8.0.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 idhttps://jsfiddle.net/sketchfab/29nqskpe/#="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: calc(100% - 31px);
}
.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: StartAR, "Total White Label", Load Model Progress info
const version = '1.8.0';
const uid = 'cc89c1e265514cbab1234eba999683e1';
const iframe = document.getElementById('api-frame');
const client = new window.Sketchfab(version, iframe);
let api;
var error = function() {
console.error('Sketchfab API error');
};
var success = function(apiClient) {
api = apiClient;
api.start(function() {
console.log('started');
});
api.addEventListener('viewerready', function() {
console.log('viewer ready');
});
api.addEventListener('modelLoadProgress', function(eventData) {
console.log("model-LoadProgress", Math.floor(eventData.progress * 100));
});
api.addEventListener('textureLoadProgress', function(eventData) {
console.log("texture-LoadProgress", Math.floor(eventData.progress * 100));
});
document.getElementById('init').addEventListener('click', function() {
api.startAR();
});
};
//////////////////////////////////
// GUI Code
//////////////////////////////////
const initGui = () => {
const controls = document.getElementById('controls');
let buttonsText = '';
buttonsText += '<button id="init">start AR</button>';
controls.innerHTML = buttonsText;
};
initGui();
//////////////////////////////////
// GUI Code end
//////////////////////////////////
client.init(uid, {
annotation: 0, // Usage: Setting to [1 – 100] will automatically load that annotation when the viewer starts.
annotations_visible: 1, // Usage: Setting to 0 will hide annotations by default.
autospin: 0, // Usage: Setting to any other number will cause the model to automatically spin around the z-axis after loading.
autostart: 1, // Usage: Setting to 1 will make the model load immediately once the page is ready, rather than waiting for a user to click the Play button.
cardboard: 0, // Usage: Start the viewer in stereoscopic VR Mode built for Google Cardboard and similar devices.
camera: 0, // Usage: Setting to 0 will skip...