Canvatorium Lab 041
Taking screenshots with Babylon JS.
Babylon JS has a built-in tool for this.
const createLabContent = async (scene) => {
const engine = scene.getEngine();
const camera = scene.activeCamera;
MeshBuilder.CreateBox("box", { size: 1 }, scene).position.y = 0.5;
// Take a screenshot of the scene when I press the 's' key
window.addEventListener("keydown", (event) => {
if (event.key === "s") {
const screenshot = Tools.CreateScreenshot(engine, camera, 1024);
console.log(screenshot);
}
});
};
I also added a screenshot button to the global lab overlay. Here is a quick demo
This lab is part of a project called Canvatorium, an experimental design lab for spatial computing. Learn more.