The scene, lights and camera
Background
babylon.scene paints what is behind the model: one colour (backgroundColour), a straight or round gradient between two or many colours, an image, or any CSS background. A skybox (enableSkybox, enableSkyboxCustomTexture) surrounds the scene with a picture of an environment and lights the model with it, which is what makes metal look like metal; hideSkybox keeps the light and hides the picture.
Light and shadow
drawDirectionalLight adds a sun: light from one direction everywhere, the usual choice for a model, with shadows when enableShadows is on. drawPointLight adds a bulb at a point. Shadows are drawn from a map of the scene seen from the light; in a large or a millimetre-scale scene, raise shadowGeneratorMapSize for sharper shadows and set shadowNormalBias in the scene's own units if the surfaces show stripes. fog fades distant geometry into a colour.
Camera
The scene starts with an orbiting camera aimed at the origin. adjustActiveArcRotateCamera moves it and sets its limits: how close and how far it may go, how far it may turn, and how fast it pans and zooms. babylon.camera builds other cameras: arcRotate to orbit a target, free to fly, target to look from a fixed spot; activateCamera switches to one.
Physics and the engine
enablePhysics turns on the physics engine with a gravity vector; in the editors that is Havok. babylon.engine hands you the engine and its canvas, for the renderer's own settings.
Every function
Scene
| Function | What it does |
|---|---|
activateCamera | Makes a camera the one the scene renders through, detaching the controls of the camera that was active before. |
adjustActiveArcRotateCamera | Repositions the default orbiting camera, the one named Camera, and sets its limits and sensitivities. |
backgroundColour | Fills the background of the scene with one plain color and removes any canvas background image or gradient set before. |
canvasBackgroundImage | Shows an image behind the scene with the CSS background options for how it repeats, scales, sits and scrolls; the scene's clear color becomes transparent so the image shows through. |
canvasCSSBackgroundImage | Paints any CSS background-image value behind the scene, a gradient or an image, by making the scene's clear color transparent and styling the canvas. |
clearAllDrawn | Removes everything drawn from the scene: meshes, materials, textures, lights other than the default hemispheric one, transform nodes, shadow generators, fog and the environment texture, and restores the default camera when another was active. |
drawDirectionalLight | Adds a light that shines the same way everywhere, like the sun, along direction. |
drawDirectionalLightNoReturn | Adds a directional light to the scene, as drawDirectionalLight does, without giving it back; for scripts that only need the light to exist. |
drawPointLight | Adds a light that shines in every direction from a point, like a bulb, with an optional small glowing sphere at its position. |
drawPointLightNoReturn | Adds a point light to the scene, as drawPointLight does, without giving it back; for scripts that only need the light to exist. |
enablePhysics | Turns on the physics engine for the scene with the given gravity, so bodies given physics fall and collide; the physics plugin must be set up on the context. |
enableSkybox | Surrounds the scene with one of the built-in skyboxes and uses it as the environment lighting that reflective materials pick up. |
enableSkyboxCustomTexture | Surrounds the scene with a skybox loaded from your own texture and uses it as the environment lighting. |
enableSkyboxFromTexture | Surrounds the scene with a skybox built from a cube texture you loaded yourself and uses it as the environment lighting. |
fog | Fades distant geometry into a color, the way haze does. |
getActiveCamera | Gives the camera the scene currently renders through. |
getScene | Gives the scene every draw call goes into, for direct use of the BabylonJS API on it. |
getShadowGenerators | Lists the shadow generators of the lights created through this library, one per light with shadows enabled; drawn meshes are registered with them as casters. |
multiColorLinearGradientBackground | Paints a straight gradient through several colors behind the scene, each at its own stop percentage; colors and stops must be the same length, or an error object comes back instead. |
multiColorRadialGradientBackground | Paints a round gradient through several colors behind the scene, each at its own stop percentage; colors and stops must be the same length, or an error object comes back instead. |
onPointerDown | Sets the function that runs when a pointer button is pressed on the canvas, replacing any function set before. |
onPointerMove | Sets the function that runs whenever the pointer moves over the canvas, replacing any function set before; it runs often, so keep it light. |
onPointerUp | Sets the function that runs when a pointer button is released on the canvas, replacing any function set before. |
setAndAttachScene | Makes the given scene the one this library draws into, adding the shadow bookkeeping and root node it expects; for applications that create the scene themselves. |
twoColorLinearGradientBackground | Paints a straight gradient between two colors behind the scene, in the given direction, with the stops as percentages along it. |
twoColorRadialGradientBackground | Paints a round gradient between two colors behind the scene, spreading out from position in the given shape, with the stops as percentages from the center. |
useRightHandedSystem | Switches the scene between the left-handed coordinate system BabylonJS uses by default and a right-handed one, the convention of most CAD tools and of glTF; the active camera is refreshed to match. |
Lights
| Function | What it does |
|---|---|
shadowLight.setDirectionToTarget | Aims a shadow-casting light at a point in the scene, turning its direction to point from its position toward target. |
shadowLight.setPosition | Moves a shadow-casting light to a point in the scene; for a directional light the position sets where its shadows are computed from. |
Camera
| Function | What it does |
|---|---|
arcRotate.create | Creates a camera that orbits target at distance radius, controlled by the pointer on the canvas, and adds it to the scene without activating it. |
free.create | Creates a camera at position looking at target that the keyboard and pointer fly around, and adds it to the scene without activating it. |
freezeProjectionMatrix | Stops a camera from recomputing its projection every frame, saving work when its field of view and clipping distances no longer change. |
getPosition | Reads where a camera is in the scene, as a point. |
getSpeed | Reads how fast a camera moves in response to its controls. |
getTarget | Reads the point a camera is looking at. |
makeCameraOrthographic | Switches a camera to orthographic projection, where objects keep their size whatever their distance, as in technical drawings. |
makeCameraPerspective | Switches a camera back to perspective projection, where distant objects look smaller, the default for cameras. |
setMaxZ | Sets the far clipping distance of a camera: anything farther than maxZ scene units is not drawn. |
setMinZ | Sets the near clipping distance of a camera: anything closer than minZ scene units is not drawn. |
setPosition | Moves a camera to a point in the scene; a target camera keeps looking at its target from there. |
setSpeed | Sets how fast a camera moves in response to its keyboard and pointer controls; 1 is the default pace. |
setTarget | Turns a camera to look at a point in the scene. |
target.create | Creates a camera at position looking at target with no navigation controls of its own, and adds it to the scene without activating it. |
unfreezeProjectionMatrix | Lets a frozen camera recompute its projection again, needed after changing its field of view or clipping distances. |
Engine
| Function | What it does |
|---|---|
getEngine | Gets the engine for the current context |
getRenderingCanvas | Gets the rendering canvas on which scene cameras can be attached |