Hi. I have a small code that rotates a textured sphere. My goal is to record this sketch. I tried the saveGif() function but it did not give a smooth result; so, I am trying the CCapture.js library because it’s said to be recording much faster. When I run this sketch, the sphere rotates correctly, but when I hit the spacebar to start recording, the sphere stops rotating and I get in the console:
Step is set to 33.333333333333336ms
Capturer start
Full Frame! 1
Capturing frame…
Frame: 1 0
I suspect I am not referencing the canvas id correctly.
Any suggestion?
Code:
let angleX = 0;
let angleY = 0;
let counter = 0;
let img;
let capturer;
let capturing = false;
function preload() {
img = loadImage('park in paris.png');
}
function setup() {
canvas = createCanvas(1280, 720, WEBGL);
canvas.GL.getExtension("OES_standard_derivatives");
//createCanvas(1280, 720, WEBGL);
capturer = new CCapture({
format: 'webm',
framerate: 30,
verbose: true
});
noStroke();
}
function draw() {
background(0);
camera(0, 0, 0, 0, 0, 1);
rotateX(angleX);
rotateY(angleY);
texture(img);
sphere(5000);
angleY += 0.001;
if (capturing) {
//capturer.capture(canvas);
capturer.capture(document.getElementById('defaultCanvas0'));
counter += 0.001;
console.log('Capturing frame...');
}
if (counter >= HALF_PI) {
capturer.stop();
console.log('stopped');
capturer.save();
capturing = false;
console.log('recording saved');
//noLoop();
}
}
function keyPressed() {
if (key === ' ') {
if (!capturing) {
capturer.start();
capturing = true;
//console.log('Recording started');
}
}
}