Babylon.js 是一个功能强大、美观、简单且开放的游戏和渲染引擎,它被封装在一个友好的 JavaScript 框架中。
准备入门?使用我们的 playground 直接体验 Babylon.js API。它还包含大量示例,帮助您学习如何使用它。
⚠️ 警告:请勿在生产环境中使用 CDN。我们的 CDN 旨在为正在学习如何使用 Babylon 平台或进行小型实验的用户提供软件包。一旦您构建好应用程序并准备将其分享给更多用户,您应该使用自己的 CDN 提供所有软件包。
预览版请使用以下 URL:
更多参考资料请参见此处。
BabylonJS 及其模块已发布在 npm 上,并提供完整的类型支持。要安装,请使用:
npm install babylonjs --save
或者,您现在可以依赖我们的 ES6 包。使用 ES6 版本可以实现 tree shaking 以及其他打包优势。
这将允许您使用以下方式导入 BabylonJS:
import * as BABYLON from 'babylonjs';
或者使用以下方式导入单个类:
import { Scene, Engine } from 'babylonjs';
如果使用 TypeScript,请不要忘记在 tsconfig.json 文件中将 'babylonjs' 添加到 'types' 中:
...
"types": [
"babylonjs",
"anotherAwesomeDependency"
],
...
要添加模块,请安装相应的包。您可以在 babylonjs 用户在 npm 上的页面 上找到额外的包列表及其安装说明。
请参阅入门指南:
// 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();
});
官方网站:www.babylonjs.com
在线实验区,可用于通过实验学习
在线沙盒,可通过简单的拖放操作测试您的 .babylon 和 glTF 场景
在线着色器创建工具,可用于学习如何创建 GLSL 着色器
3DS Max 导出器,可用于从 .babylon 文件生成 .babylon 文件3DS Max
Maya 导出器 可用于从 Maya 生成 .babylon 文件
Blender 导出器 可用于从 Blender 3D 生成 .babylon 文件
Unity 5 (已弃用)导出器 可用于从 Unity 5 场景编辑器导出几何体(支持动画)
KhronosGroup 的 glTF 工具
要获取支持功能的完整列表,请访问我们的网站。