mattdesl / canvas-sketch

[beta] A framework for making generative artwork in JavaScript and the browser.
MIT License
5.01k stars 393 forks source link

Blank Frames in animation export #111

Closed forrestbaer closed 3 years ago

forrestbaer commented 3 years ago

Hey there,

I'm actually working through your frontend masters course and noticing something when I'm exporting frames for an animation every now and then a render will happen that looks like it was rendered super close-up or renders empty, so I the animation isn't seamless. It's almost like something hasn't finished rendering or the camera is not ready/in the right place for that frame.

Have you run into this at all?

return {
    // Handle resize events here
    resize({ pixelRatio, viewportWidth, viewportHeight }) {
      renderer.setPixelRatio(pixelRatio);
      renderer.setSize(viewportWidth, viewportHeight, false);
      const aspect = viewportWidth / viewportHeight;

      // Ortho zoom
      const zoom = 2;

      // Bounds
      camera.left = -zoom * aspect;
      camera.right = zoom * aspect;
      camera.top = zoom;
      camera.bottom = -zoom;

      // Near/Far
      camera.near = -100;
      camera.far = 100;

      // Set position & look at world center
      camera.position.set(zoom, zoom, zoom);
      camera.lookAt(new THREE.Vector3());

      // Update the camera
      camera.updateProjectionMatrix();
    },
    // Update & render your scene here
    render({ playhead }) {
      const t = Math.sin(playhead * Math.PI); 
      scene.rotation.y = eases.expoInOut(t);
      renderer.render(scene, camera);
    },
    // Dispose of events & renderer for cleaner hot-reloading
    unload() {
      renderer.dispose();
    }
  };

blockanim

forrestbaer commented 3 years ago

That often comes with this error, which might not be related but I'm not sure: (Unchecked runtime.lastError: The message port closed before a response was received.)

mattdesl commented 3 years ago

Hmm, I haven't seen this but it could be related to that error. I would try a couple things:

Also what OS and Node/npm version are you running? That info might help me debug this a bit better.

forrestbaer commented 3 years ago

My apologies I should have tried a few more things before asking, it seems like restarting the server helped that time, but didn't the first time I had tried it.. I'm using Chrome, latest macOS w/ npm 6.14..

I'll keep an eye on it, if it happens again perhaps I'll be able to get useful information.

Anyway, good to go, thanks!