2010-10-09

3D environments

For the purpose of making a 3D visualisation of the interpreter, I tried several different ways of getting 3D.

OpenGL

OpenGL is a low-level graphics library used on several platforms and with several programming languages. For a more serious 3D application, this might have been the library of choice. However, this implementation is not about efficiency on that level, so neither OpenGL nor C seems optimal. I did not need any complex 3D models, just the most basic functionality, so it seemed at first that maybe going down to this basic level would be a good idea. But there are simple and complex schemes on both high and low level, and it soon became apparent that this was not the best option.

Java3D

Java3D is an API for Java, which can implement OpenGL. It seemed like an easier way into OpenGL, rather than using it directly through C. It seemed like a good idea to make the semantic model in Java, so it would be rather convenient to be able to connect it to the graphical interface within Java. But altho somewhat more high-level, Java3D is not the simple solution I was looking for.

Alice

Alice is a program designed to teach object-oriented programming to young students. It does this using 3D scenes, and has a collection of animated 3D models available. It was based on Java and Python. This seemed like a good way to get the needed functionality without the complexity of a full-blown Java API; there were already models, and there were simple functions for doing the basic things that needed doind, such as moving the models around or resizing them. But how to get the functions out of the rather limited Alice environment and get them to connect to the interpreter?

Writing the visualisation in Alice itself didn't seem like a viable idea; it was far too limited. Earlier versions of Alice had supported scripting with Jython, and it turned out to be possible to enable that functionality in version 2.2 as well. Unfortionaltely the scripting left a lot to be desired. It was unstable, undocumented, and generally unreliable. It seemed at the time like a lost cause for this purpose.

SketchUp

SketchUp is Google's easy-to-use CAD program, partly made for use with Google Earth. It's not made for animation or interaction, but it does have scripting capabilities, using Ruby. One advantage of this solution is there are a large number of models available. As a CAD program it is indeed fairly straightforward, and, I considered writing the whole project in Ruby. But on further exploration, the scripting turned out to be rather slow and cumbersome.

Finally

I realised that there was a new version of Alice, still in beta but with a very important improvement: The projects could now be exported, to create a set of Java files. This made everything a great deal easier. I could now do all the real work on the visualisation in Java, as well as the semantic model. I was essentially only using the 3D engine and models from Alice, as I had hoped to do all along.

No comments:

Post a Comment