<script src="https://cdn.babylonjs.com/v7.34.1/babylon.js"></script>Building up a basic demo with Babylon.js / notebook
Building up a basic demo with Babylon.js
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
<!doctype html>
<html lang="en-GB">
<head>
<meta charset="utf-8" />
<title>MDN Games: Babylon.js demo</title>
<style>
html,
body,
canvas {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
font-size: 0;
}
</style>
</head>
<body>
<!-- The local copy of Babylon.js -->
<script src="babylon.js"></script>
<!-- or loaded via CDN: -->
<!-- <script src="https://cdn.babylonjs.com/v7.34.1/babylon.js"></script> -->
<canvas id="render-canvas"></canvas>
<script>
const canvas = document.getElementById("render-canvas");
/* All of our JavaScript code goes here */
</script>
</body>
</html>const engine = new BABYLON.Engine(canvas);const scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color3(0.8, 0.8, 0.8);function renderLoop() {
scene.render();
}
engine.runRenderLoop(renderLoop);const camera = new BABYLON.FreeCamera(
"camera",
new BABYLON.Vector3(0, 0, -10),
scene,
);const light = new BABYLON.PointLight(
"light",
new BABYLON.Vector3(10, 10, 0),
scene,
);const box = BABYLON.Mesh.CreateBox("box", 2, scene);box.rotation.x = -0.2;
box.rotation.y = -0.4;const boxMaterial = new BABYLON.StandardMaterial("material", scene);
boxMaterial.emissiveColor = new BABYLON.Color3(0, 0.58, 0.86);
box.material = boxMaterial;