Babylon.js

Babylon.js is a powerful, beautiful, simple, and open game and rendering en...

README

Babylon.js

Getting started? Play directly with the Babylon.js API using our playground. It also contains a lot of samples to learn how to use it.
npm version Build Status Average time to resolve an issue Percentage of issues still open
Build size Twitter
Discourse users
Any questions? Here is our official forum.

CDN

- -
For the preview release, use the following URLs:
- -
A list of additional references can be found here.

npm

BabylonJS and its modules are published on npm with full typing support. To install, use:
  1. ```text
  2. npm install babylonjs --save
  3. ```
This will allow you to import BabylonJS entirely using:
  1. ```javascript
  2. import * as BABYLON from 'babylonjs';
  3. ```
or individual classes using:
  1. ```javascript
  2. import { Scene, Engine } from 'babylonjs';
  3. ```
If using TypeScript, don't forget to add 'babylonjs' to 'types' in tsconfig.json:
  1. ```json
  2.     ...
  3.     "types": [
  4.         "babylonjs",
  5.         "anotherAwesomeDependency"
  6.     ],
  7.     ...
  8. ```
To add a module, install the respective package. A list of extra packages and their installation instructions can be found on the babylonjs user on npm.

Usage

  1. ```javascript
  2. // Get the canvas DOM element
  3. var canvas = document.getElementById('renderCanvas');
  4. // Load the 3D engine
  5. var engine = new BABYLON.Engine(canvas, true, {preserveDrawingBuffer: true, stencil: true});
  6. // CreateScene function that creates and return the scene
  7. var createScene = function(){
  8.     // Create a basic BJS Scene object
  9.     var scene = new BABYLON.Scene(engine);
  10.     // Create a FreeCamera, and set its position to {x: 0, y: 5, z: -10}
  11.     var camera = new BABYLON.FreeCamera('camera1', new BABYLON.Vector3(0, 5, -10), scene);
  12.     // Target the camera to scene origin
  13.     camera.setTarget(BABYLON.Vector3.Zero());
  14.     // Attach the camera to the canvas
  15.     camera.attachControl(canvas, false);
  16.     // Create a basic light, aiming 0, 1, 0 - meaning, to the sky
  17.     var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0, 1, 0), scene);
  18.     // Create a built-in "sphere" shape using the SphereBuilder
  19.     var sphere = BABYLON.MeshBuilder.CreateSphere('sphere1', {segments: 16, diameter: 2, sideOrientation: BABYLON.Mesh.FRONTSIDE}, scene);
  20.     // Move the sphere upward 1/2 of its height
  21.     sphere.position.y = 1;
  22.     // Create a built-in "ground" shape;
  23.     var ground = BABYLON.MeshBuilder.CreateGround("ground1", { width: 6, height: 6, subdivisions: 2, updatable: false }, scene);
  24.     // Return the created scene
  25.     return scene;
  26. }
  27. // call the createScene function
  28. var scene = createScene();
  29. // run the render loop
  30. engine.runRenderLoop(function(){
  31.     scene.render();
  32. });
  33. // the canvas/window resize event handler
  34. window.addEventListener('resize', function(){
  35.     engine.resize();
  36. });
  37. ```

Contributing

If you want to contribute, please read our contribution guidelines first.

Documentation

Contributing

Please see the Contributing Guidelines.

Useful links

- Official web site: www.babylonjs.com
- Online playground to learn by experimentating
- Online sandbox where you can test your .babylon and glTF scenes with a simple drag'n'drop
- Online shader creation tool where you can learn how to create GLSL shaders
- 3DS Max exporter can be used to generate a .babylon file from 3DS Max
- Maya exporter can be used to generate a .babylon file from Maya
- Blender exporter can be used to generate a .babylon file from Blender 3d
- Unity 5 (deprecated) exporter can be used to export your geometries from Unity 5 scene editor(animations are supported)
- glTF Tools by KhronosGroup

Features

To get a complete list of supported features, please visit our website.