API

Getting Started - Chapter 5 - Skies Above

We can simulate the appearance of a sky by applying six suitable images to the insides of a large skybox cube. (Images are a lot easier and faster to render than 3D objects, and just as good for far-distant scenery.)

Skybox images are usually loaded with CubeTexture. CubeTexture's constructor takes a base URL and (by default) appends "_px.jpg", "_nx.jpg", "_py.jpg", "_ny.jpg", "_pz.jpg", and "_nz.jpg" to load the +x, -x, +y, -y, +z, and -z facing sides of the cube.

some cloudsmore cloudsthe sun overheadsolid graymore cloudsmore clouds
skybox_px.jpg
skybox_nx.jpg
skybox_py.jpg
skybox_ny.jpg
skybox_pz.jpg
skybox_nz.jpg

Cube textures must be applied using reflectionTexture even though the skybox is not a reflection map. Setting coordinatesMode to SKYBOX_MODE paints the texture directly on the cube rather than simulating reflections.

import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial";
import { CubeTexture } from "@babylonjs/core/Materials/Textures/cubeTexture";
import { Texture } from "@babylonjs/core/Materials/Textures/texture";
import { Color3 } from "@babylonjs/core/Maths/math.color";
import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder";
const skybox = MeshBuilder.CreateBox("skyBox", { size: 150 }, scene);
const skyboxMaterial = new StandardMaterial("skyBox", scene);
skyboxMaterial.backFaceCulling = false;
skyboxMaterial.reflectionTexture = new CubeTexture("textures/skybox", scene);
skyboxMaterial.reflectionTexture.coordinatesMode = Texture.SKYBOX_MODE;
skyboxMaterial.diffuseColor = new Color3(0, 0, 0);
skyboxMaterial.specularColor = new Color3(0, 0, 0);
skybox.material = skyboxMaterial;

We also restrict the camera so that it cannot move below ground level.

camera.upperBetaLimit = Math.PI / 2.2;
Adding a Skybox

After making a sky, the next environmental improvement is to grow some trees.

Further reading

Skyboxes
Learn how to add a skybox to your Babylon.js scene.
Skyboxes