Babylon.js is a complete JavaScript framework for building 3D games with HTML 5 and WebGL. BabylonJS was chosen because it is the most efficient, most feature-rich, and most modern WebGL graphics library available.
The goal with BabylonCpp is to fully implement the relevant portions of the excellent Babylon.js 3D framework/engine in C++17, facilitating the creation of lightweight, cross-platform 3D games and applications with native performance.
This repository contains submodules for some of the external dependencies, so when doing a fresh clone you need to clone recursively:
git clone --recursive https://github.com/samdauwe/BabylonCpp.git
Existing repositories can be updated manually:
git submodule init
git submodule update
A build script named cmake_build.py
is provided for compiling all sources from command line on Linux and Windows:
Release build:
python cmake_build.py all --mode=release
Debug build:
python cmake_build.py all --mode=debug
Use the provided CMakeLists.txt with CMake to generate a build configuration for your favorite IDE or compiler.
A Visual Studio solution file can be generated by using the provided cmake_build.py
script:
python cmake_build.py configure
If you're using a different IDE or compiler you can use the provided CMakeLists.txt for use with CMake to generate a build configuration for your toolchain.
The following code initializes a basic scene by creating a camera, a light, and two basic meshes (a sphere and a ground plane).
void initializeScene(ICanvas* canvas, Scene* scene)
{
// Create a FreeCamera, and set its position to (x:0, y:5, z:-10)
auto camera = FreeCamera::New("camera1", Vector3(0, 5, -10), scene);
// Target the camera to the scene origin
camera->setTarget(Vector3::Zero());
// Attach the camera to the canvas
camera->attachControl(canvas, true);
// Create a basic light, aiming 0,1,0 - meaning, to the sky
auto light = HemisphericLight::New("light1", Vector3(0, 1, 0), scene);
// Default intensity is 1. Let's dim the light a small amount
light->intensity = 0.7f;
// Create a built-in "sphere" shape; its constructor takes 5 params: name,
// subdivs, size, scene
auto sphere = Mesh::CreateSphere("sphere1", 32, 2.f, scene);
// Move the sphere upward 1/2 of its height
sphere->position().y = 1.f;
// Create a built-in "ground" shape.
// Params: name, width, depth, subdivs, scene
Mesh::CreateGround("ground1", 6, 6, 2, scene);
}
This code results in the following scene:
Example scenes can be found on the samples page.
- Earcut: A C++ port of earcut.js, a fast, header-only polygon triangulation library.
- Google Test: Google's framework for writing C++ tests on a variety of platforms, used for the unit tests (Optional).
- GLFW: Framework for OpenGL application development, used for the examples (Optional).
- GLXW: OpenGL loader, used for the examples (Optional).
- GCC >= 7.0.0
- Clang >= 4.0
- MSVC >= 2017
- Linux
- Windows >= 7
Open-source under Apache 2.0 license.