Back to Demos

This demo shows how you can clear scenes.


var api = claraplayer('player');
var ids = ['8896e431-9e54-4e9d-b22d-5b3d4eb071bb', '045c3a62-f2d8-47fa-93dd-4d1de80c06c0', 'cb6a5e12-483c-4175-8c3f-abbfdacfd621', ''];
var initialState = 0;
var content = document.getElementById('content');

api.sceneIO.fetchAndUse(ids[initialState]).then(function() {
  ids.map(function(id, i) {
    var button = document.createElement('button');
    button.innerText = (i !== ids.length - 1) ? 'Scene ' + (i + 1) : 'Clear Scene';
    button.onclick = function(ev) {
      api.sceneIO.clearScene();
      if (i >= 0 && ids[i] !== '')
        api.sceneIO.fetchAndUse(ids[i]);
    }
    content.appendChild(button);
  });
  addResourcesList();
});

function addResourcesList(){
  var text = document.createElement("u");  
  text.innerText = "Clara.io demo resources:";
  var subTitle = document.createElement('p');
  subTitle.appendChild(text);
  document.getElementById('content').appendChild(subTitle);
  var resourcesList = document.createElement('ul');
  content.appendChild(resourcesList);
  var list;
  var link;
  for(var i = 0;i < ids.length - 1;++i){
    list = document.createElement('li');
    link = document.createElement('a');
    link.innerText = 'Visit Scene '+(i+1);
    link.setAttribute('href','https://clara.io/view/'+ids[i]);
    link.setAttribute('target','_blank');
    list.appendChild(link);
    resourcesList.appendChild(list);
  };
};