sketchfab viewer api sample

by velo_ninja

HTML

<script src="https://static.sketchfab.com/api/sketchfab-viewer-1.11.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.3/dat.gui.min.js"></script>
<!-- Learn about this code on sketchfab: https://sketchfab.com/developers/viewer -->


<div class="container">
    <div class="iframe-container">
        <iframe title="Sketchfab Viewer" 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;
    height: 80px;
    padding: 15px 0 0 15px;
    background-color: #F2F2F2;
    border-top: 1px solid #e7e7e7;
    overflow: scroll;
}

.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 .2s;
    color: white;
    background-color: #1caad9;
    height: 25px;
    font-size: 12px;
}

button.disabled {
    cursor: default;
    pointer-events: none;
    color: #ccc;
    background-color: #e7e7e7;
    transition: background-color .25s ease;
}

.description {
    box-sizing: border-box;
    position: absolute;
    padding: 30px;
    top: 30px;
    right: 30px;
    width: 240px;
    background: rgba(0, 0, 0, 0.6);
    color: #ffffff;
    border-radius: 3px;
    z-index: 2;

    opacity: 0;
    pointer-events: none;
}

.description.--active {
    opacity: 1;
    pointer-events: all;
}

.description iframe,
.description img {
    max-width: 100%;
    height: auto;
}

JavaScript

// Sketchfab Viewer API: customize annotation appearance
var version = '1.11.0';
var uid = '12dd524ace5242f5a33e0255bcb4eeaa';
var iframe = document.getElementById('api-frame');

if (!iframe) {
  console.log('no target');
}

if (!window.Sketchfab) {
  console.log('no Sketchfab library');
}

var client = new window.Sketchfab(version, iframe);
var imgBLogo; // Code to create textureimage for pastille from svg

function computePastilles(wCanvas, hCanvas, bgColor, bgBorderColor, fgColor, fgBorderColor, text, numHotspot, wPastille, hPastille) {
  var wSize = wPastille / 10.0;
  var col = wCanvas / wSize;
  var row = hCanvas / wSize;
  var padding = 2;
  var w = wSize - padding;
  var cx;
  var cy = w * 0.5; //var cy = 24;

  var ty = cy + 8;
  var pastille = '';
  var num = 0;

  for (var i = 0; i < row; i++) {
    cx = wSize * 0.5;

    for (var k = 0; k < col; k++) {
      num++;
      var letters = text === 0 ? num : text[num];
      var circle = "<circle cx=\"".concat(cx, "\"\n            cy=\"").concat(cy, "\"\n            r=\"20\"\n            fill=\"").concat(bgColor, "\"\n            stroke=\"").concat(bgBorderColor, "\"\n            stroke-width=\"2\"/>");
      var textVG = "<text font-size=\"26\"\n          stroke=\"".concat(fgBorderColor, "\"\n          fill=\"").concat(fgColor, "\"\n          font-family=\"sans-serif\"\n          text-anchor=\"middle\"\n          alignment-baseline=\"baseline\"\n          x=\"").concat(cx, "\"\n          y=\"").concat(ty, "\">").concat(letters, "</text>");
      pastille += circle + textVG;
      cx += wSize;
    }

    cy += wSize;
    ty += wSize;
  }

  var s = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  s.setAttribute('version', '1.1');
  s.setAttribute('baseProfile', 'full');
  s.setAttribute('width', wPastille);
  s.setAttribute('height', hPastille);
  s.setAttribute('viewBox', "0 0 ".concat(wPastille, " ").concat(hPastille));
  s.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
 ...