WebGL plants game in Oculus Rift with one line of code

It's not every day that you see an internet-based 3D engine pushing a game to virtual reality with one line of code. That's what's been demoed this week as HTML5 loomed over the crowd at Microsoft's BUILD 2014 developers convention. It's just one line of code with the Babylon.js 3D engine and a game is converted from 2D to fully Oculus Rift-ready.

Babylon.js is a 3D engine for all manner of digital creations. This 3D engine is based on webgl and javascript, and it supports a massive amount of features in animation, particle systems, textures, special FX, cameras, meshes, per pixel material, and optimizations galore.

In the demonstration of a basic 3D environment this week, Microsoft literally copied a single line of a code from this Github site and pasted it. The game was then able to launch in Oculus Rift, playing back in an Internet Explorer web browser window.

var originCamera = scene.activeCamera;

BABYLON.OculusOrientedCamera.BuildOculusStereoCamera(scene, "Oculus", canvas, originCamera.minZ,

originCamera.maxZ, originCamera.position, { yaw: 3, pitch: 0, roll: 0 }, false, true, true);

Above you'll see that single code. The function this code creates is BABYLON.OculusOrientedCamera.BuildOculusStereoCamera, which takes the following parameters.

• Scene

• Name

• Near clip distance

• Far clip distance

• Position

• Neutral orientation: It defines the rest orientation)

• Boolean to define if you want to add a FXAA post-process

• Boolean to disable the gravity for this camera

• Boolean to disable collisions for this camera

• Initial Oculus Rift settings. If undefined, Babylon.js will use

• default values: BABYLON.OculusController.CameraSettings_OculusRiftDevKit2013_Metric

So the scene went from this single frame layout that you're seeing above to the dual-lens setup you see below. This is only a flattened view of what the Oculus Rift device works with – inside the device it's much more of a 3D experience, of course. Virtual Reality and all that.

With implementation this simple, it's difficult to imaging Oculus Rift and the Virtual Reality experience getting much easier to implement for developers. We're clearly on the doorstep of a much more vast digital experience!