Babylon.js是一个功能强大且开放的游戏和渲染引擎

Babylon.js


Babylon.js 是一个功能强大、美观、简单且开放的游戏和渲染引擎,它被封装在一个友好的 JavaScript 框架中。

准备入门?使用我们的 playground 直接体验 Babylon.js API。它还包含大量示例,帮助您学习如何使用它。

CDN

⚠️ 警告:请勿在生产环境中使用 CDN。我们的 CDN 旨在为正在学习如何使用 Babylon 平台或进行小型实验的用户提供软件包。一旦您构建好应用程序并准备将其分享给更多用户,您应该使用自己的 CDN 提供所有软件包。

预览版请使用以下 URL:

更多参考资料请参见此处

npm

BabylonJS 及其模块已发布在 npm 上,并提供完整的类型支持。要安装,请使用:

text 复制代码
npm install babylonjs --save

或者,您现在可以依赖我们的 ES6 包。使用 ES6 版本可以实现 tree shaking 以及其他打包优势。

这将允许您使用以下方式导入 BabylonJS:

javascript 复制代码
import * as BABYLON from 'babylonjs';

或者使用以下方式导入单个类:

javascript 复制代码
import { Scene, Engine } from 'babylonjs';

如果使用 TypeScript,请不要忘记在 tsconfig.json 文件中将 'babylonjs' 添加到 'types' 中:

json 复制代码
...

"types": [

"babylonjs",

"anotherAwesomeDependency"

],

...

要添加模块,请安装相应的包。您可以在 babylonjs 用户在 npm 上的页面 上找到额外的包列表及其安装说明。

使用方法

请参阅入门指南:

javascript 复制代码
// Get the canvas DOM element
var canvas = document.getElementById('renderCanvas');
// Load the 3D engine
var engine = new BABYLON.Engine(canvas, true, {preserveDrawingBuffer: true, stencil: true});
// CreateScene function that creates and return the scene
var createScene = function(){
    // Create a basic BJS Scene object
    var scene = new BABYLON.Scene(engine);
    // Create a FreeCamera, and set its position to {x: 0, y: 5, z: -10}
    var camera = new BABYLON.FreeCamera('camera1', new BABYLON.Vector3(0, 5, -10), scene);
    // Target the camera to scene origin
    camera.setTarget(BABYLON.Vector3.Zero());
    // Attach the camera to the canvas
    camera.attachControl(canvas, false);
    // Create a basic light, aiming 0, 1, 0 - meaning, to the sky
    var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0, 1, 0), scene);
    // Create a built-in "sphere" shape using the SphereBuilder
    var sphere = BABYLON.MeshBuilder.CreateSphere('sphere1', {segments: 16, diameter: 2, sideOrientation: BABYLON.Mesh.FRONTSIDE}, scene);
    // Move the sphere upward 1/2 of its height
    sphere.position.y = 1;
    // Create a built-in "ground" shape;
    var ground = BABYLON.MeshBuilder.CreateGround("ground1", { width: 6, height: 6, subdivisions: 2, updatable: false }, scene);
    // Return the created scene
    return scene;
}
// call the createScene function
var scene = createScene();
// run the render loop
engine.runRenderLoop(function(){
    scene.render();
});
// the canvas/window resize event handler
window.addEventListener('resize', function(){
    engine.resize();
});

文档

实用链接

功能

要获取支持功能的完整列表,请访问我们的网站

关于项目

Babylon.js 是一个功能强大、美观、简单且开放的游戏和渲染引擎,它被封装在一个友好的 JavaScript 框架中。
Apache-2.0
Typescript
24,794
3581
525
2013-06-28
2025-11-27

增长趋势 - stars