BabylonJS: ScreenShot Cheat Sheet

Syntax to take screenshot of the screen:

BABYLON.Tools.CreateScreenshot(engine, camera, { width: 1024, height: 300 }, function (data) {
   var img = document.createElement("img");
   img.src = data;
   document.body.appendChild(img);	
});

Changes are made to the engine which is passed to the screenshot api.

var engine = new BABYLON.Engine(canvas, true, { 
   preserveDrawingBuffer: true, stencil: true 
});	

It requires options like preserveDrawingBuffer and stencil set to true.

Button is added:

ssButton = document.createElement("input");
document.body.appendChild (ssButton);

Leave a Reply

Your email address will not be published. Required fields are marked *