Skip to content

Instantly share code, notes, and snippets.

@cedricpinson
Last active May 28, 2019 06:51
Show Gist options
  • Save cedricpinson/5303099 to your computer and use it in GitHub Desktop.
Save cedricpinson/5303099 to your computer and use it in GitHub Desktop.
camera animation
var sketchfabModule = window['sketchfab-iframe'];
var moduleVersion = sketchfabModule.version;
var Sketchfab = sketchfabModule.Sketchfab;
var Q = sketchfabModule.Q;
var urlid = "z9Psf5XIvSeuJYiMnuBgeRjLwql";
var iframeWindow = $('#myIframeCamera')[0];
var options = {
"nocamera": 1,
"autostart": 1,
"transparent": 1,
"controls": 0,
"watermark":0,
"desc_button":0,
"stop_button":0
};
var api = new Sketchfab(iframeWindow);
$("#example-camera-start").click(function() {
Q.when(api.load(urlid, options)).then(function(data) {
api.start();
$("#example-camera-status").text("scene loaded");
}).fail( function(error) {
$("#example-camera-status").text("error can't load scene");
});
});
var duration = 4.0;
var targety = 5.0;
var target = [0.0,0.0, targety];
var cameraList = [
{ eye: [0,-10, targety],
target: target,
text: "front view"
},
{ eye: [10, 0, targety],
target: target,
text: "right view"
},
{ eye: [0,10, targety],
target: target,
text: "back view"
},
{ eye: [-10,0, targety],
target: target,
text: "left view"
}
];
var currentCamera = 1;
var cam = cameraList[currentCamera];
$("#example-camera-next").text(cam.text);
$("#example-camera-next").click(function() {
var cam = cameraList[currentCamera];
currentCamera = (currentCamera + 1 ) % cameraList.length;
var nextCamText = cameraList[currentCamera].text;
$("#example-camera-next")[0].innerHTML = cam.text;
Q.when(api.lookat(cam.eye, cam.target, duration), function() {
$("#example-camera-status").text("animation " + cam.text + " finished");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment