const { Vector3, MeshBuilder, StandardMaterial, FreeCamera, HemisphericLight } = BABYLON;

1 min read
Nice! That line:
const { Vector3, MeshBuilder, StandardMaterial, FreeCamera, HemisphericLight } = BABYLON;
is using object destructuring to pull out specific classes from the BABYLON namespace, which makes your code shorter and cleaner.
✅ What this does:
Instead of writing this every time:
const camera = new BABYLON.FreeCamera(...);
const light = new BABYLON.HemisphericLight(...);
const box = BABYLON.MeshBuilder.CreateBox(...);
You can now just do:
const camera = new FreeCamera(...);
const light = new HemisphericLight(...);
const box = MeshBuilder.CreateBox(...);
🔍 Breakdown of What You’re Importing:
Class | What it does |
Vector3 | Represents a 3D coordinate (x, y, z) |
MeshBuilder | Used to create shapes like boxes, spheres, etc. |
StandardMaterial | A basic material used for coloring and texturing objects |
FreeCamera | A camera you can move freely (good for first-person/fly mode) |
HemisphericLight | A basic light source that lights all sides (like sunlight from the sky) |
📌 Example usage:
const camera = new FreeCamera("camera1", new Vector3(0, 5, -10), scene);
camera.attachControl(canvas, true);
const light = new HemisphericLight("light1", new Vector3(1, 1, 0), scene);
const box = MeshBuilder.CreateBox("box", {}, scene);
const material = new StandardMaterial("boxMat", scene);
material.diffuseColor = new BABYLON.Color3(1, 0, 0); // red
box.material = material;
0
Subscribe to my newsletter
Read articles from Godson Prakasia directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
