Beauty of Unity3D
Previously I touched a bit on adding 3D content to a page using the, as yet, unfinalized WebGL standard. The page I made was simple and displayed a non-shaded bspline. But what if you aren’t savvy or maybe you lack the time to wrangle the oddities of OpenGL? The best option that I’ve found so far is Unity3D, a free(for the Indie version) game engine.
One of my most popular posts covers merging Ogre3D w/ Havok physics. That project actually continued long after the page I posted was up (sadly the code couldn’t be updated as it became an official project) and I was having a blast. The problem was I never had enough time. As the only developer on the project I had to handle every piece of the engine. I could pull from many open source options but integration was never fast and easy, like a Yeti. On top of that there wasn’t any sort of scripting framework, all changes had to be written in raw C++ and recompiled. Scripting was always planned but kept taking a back seat to graphics, networking, and physics.

Why am I blathering (BLATHERING BLATHERSKITE!…. Anyone? DuckTales?) on about time and 3D engines? Unity3D pretty much does everything you need and then some w/o the hassle of coding an entire engine. The beauty of their engine isn’t necessarily the tech., it’s the editor. Simple to understand, easy to use, and extremely friendly on novice users. Indeed, everything is tied to an impressive C#/Java scripting framework that makes accessing existing core functionality a snap. Coupled w/ an active community and some decent examples Unity3D is very easy to pick up.
Scripts are compiled on the fly in to a sort of pseudo bytecode(also known as jit compiled, or just in time compiled).
It is around 20 times faster than traditional javascript and around 50% slower than native C++ code.
The only real downside is the lack of control over the core at the C++ level. Adding in features is definitely possible but if you are someone that needs complete control over every aspect of his/her engine you’ll be disappointed. All this means is you have to be clever with the tools you are given in order to create a unique game. Additionally if you are looking to make something other than a generic RTS or FPS you’ll need the pro version which offers full shader support and RTT.
To see an example, click below to download the Unity plugin. After which the 3D image of a toy gun should appear. This is a VERY simple model viewer I threw together in maybe 10 minutes? It took me longer to write this post.
Left/Right Arrow Keys – Rotate around Y-Axis (Spin)
Up/Down Arrow Keys – Rotate around X-Axis (Tilt)
And this is the only script in that scene:
var rotateSpeed : float = 1.0; var center : Vector3 = Vector3.zero; var prefab : Transform; private var windowRect : Rect = new Rect(0,0,150,50); function Awake(){ ///calculate model center; var mesh : Mesh = GetComponent(MeshFilter).mesh; var bounds = mesh.bounds; ///Be sure to apply all transformations current present in the model. center = mesh.bounds.center; center = transform.rotation * center; center = center * transform.localScale.x; center += transform.position; ///Draw a dummy object to the scene, not necessary but helps to debug odd centers. print("Center: " + center.x + "," + center.y + "," + center.z); Instantiate(prefab,center, Quaternion.identity); } function OnGUI () { windowRect = GUI.Window (0, windowRect, SpeedGUI, "Speed Control"); } function SpeedGUI(id : int){ rotateSpeed = GUI.HorizontalSlider (Rect (25, 25, 100, 30), rotateSpeed, 1.0, 25.0); } function Update () { //Key left/right & up/down key movements var rotZ = Input.GetAxis("Vertical"); var rotY = Input.GetAxis("Horizontal"); //Rotate model around it's center. transform.RotateAround(center, Vector3.up,-rotY * rotateSpeed); transform.RotateAround(center, Vector3.right,rotZ * rotateSpeed); }
