Make sure that you’ve rendered the scene before calling toDataURL()
. Here is an example I wrote a while ago using toBlob() instead of toDataURL(), but either one should work…
renderer.render( scene, camera );
const imgData = canvas.toBlob( ( blob ) => {
const imgEl = document.createElement( 'img' );
imgEl.src = URL.createObjectURL( blob );
document.body.appendChild( imgEl );
});