Skip to content

Instantly share code, notes, and snippets.

@feiss
Created March 15, 2017 17:20
Show Gist options
  • Save feiss/ffb78e1059436ad6529bac34194dd74c to your computer and use it in GitHub Desktop.
Save feiss/ffb78e1059436ad6529bac34194dd74c to your computer and use it in GitHub Desktop.
ccapture in aframe
AFRAME.registerComponent('gifcapture', {
schema: {
width: {default: 200},
height:{default: 200},
fps: {default: 15},
duration: {default: 3 },
delay: {default: 0},
jsPath: {default: './vendor/'},
},
init: function () {
this.capturing = false;
this.capturer = new CCapture({
format: 'png',
framerate: this.data.fps,
workersPath: this.data.jsPath,
verbose: true,
name: 'mydance',
timeLimit: this.data.duration
});
window.setTimeout(this.startCapture.bind(this), this.data.delay*1000);
},
startCapture: function () {
this.capturing = true;
this.startTime = null;
this.el.sceneEl.renderer.setSize(this.data.width, this.data.height);
this.el.emit('start');
this.capturer.start();
},
tick: function (time, delta) {
if (!this.capturing) return;
if (!this.starttime) {
this.startTime = time;
}
if (time - this.startTime > this.data.duration){
this.capturer.stop();
this.capturer.save();
this.el.emit('done');
this.capturing = false;
}
else {
this.capturer.capture(this.el.sceneEl.canvas);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment