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

Godson PrakasiaGodson Prakasia
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:

ClassWhat it does
Vector3Represents a 3D coordinate (x, y, z)
MeshBuilderUsed to create shapes like boxes, spheres, etc.
StandardMaterialA basic material used for coloring and texturing objects
FreeCameraA camera you can move freely (good for first-person/fly mode)
HemisphericLightA 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

Godson Prakasia
Godson Prakasia