Skip to content

Latest commit

 

History

History
118 lines (81 loc) · 5.56 KB

readme-es6.md

File metadata and controls

118 lines (81 loc) · 5.56 KB

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

Any questions? Here is our official forum.

CDN

To look into our CDN bundled distribution, you can refer to the package babylonjs

npm

BabylonJS and its modules are published on npm as esNext modules with full typing support. To install, use:

npm install @babylonjs/core --save

This will allow you to import BabylonJS entirely using:

import * as BABYLON from "@babylonjs/core/Legacy/legacy";

or individual classes to benefit from enhanced tree shaking using :

import { Scene } from "@babylonjs/core/scene";
import { Engine } from "@babylonjs/core/Engines/engine";

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 scoped on @babylonjs.

Usage

See our ES6 dedicated documentation:

import { Engine } from "@babylonjs/core/Engines/engine";
import { Scene } from "@babylonjs/core/scene";
import { Vector3 } from "@babylonjs/core/Maths/math";
import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera";
import { HemisphericLight } from "@babylonjs/core/Lights/hemisphericLight";

// Side-effects only imports allowing the standard material to be used as default.
import "@babylonjs/core/Materials/standardMaterial";
// import the individual builders or use MeshBuilder to have them all
import { CreateSphere } from "@babylonjs/core/Meshes/Builders/sphereBuilder";
import { CreateGround } from "@babylonjs/core/Meshes/Builders/groundBuilder";

const canvas = document.getElementById("renderCanvas") as HTMLCanvasElement;
const engine = new Engine(canvas);
var scene = new Scene(engine);

// This creates and positions a free camera (non-mesh)
var camera = new FreeCamera("camera1", new Vector3(0, 5, -10), scene);

// This targets the camera to scene origin
camera.setTarget(Vector3.Zero());

// This attaches the camera to the canvas
camera.attachControl(canvas, true);

// This creates a light, aiming 0,1,0 - to the sky (non-mesh)
var light = new HemisphericLight("light1", new Vector3(0, 1, 0), scene);

// Default intensity is 1. Let's dim the light a small amount
light.intensity = 0.7;

// Our built-in 'sphere' shape. Params: name, options, scene
var sphere = CreateSphere("sphere1", { segments: 16, diameter: 2 }, scene);

// Move the sphere upward 1/2 its height
sphere.position.y = 2;

// Our built-in 'ground' shape. Params: name, options, scene
CreateGround("ground1", { width: 6, height: 6, subdivisions: 2 }, this._scene);

engine.runRenderLoop(() => {
    scene.render();
});

Documentation

Contributing

Please see the contribution 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 3DS Max
  • 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.

Build

Babylon.js is automatically built using Gulp. For further instructions see the readme at /Tools/Gulp.