Thursday, August 7, 2008

Working with Second Life

As part of one of our other courses I tried to create a robot in Second Life. My own goals were to:

  • Get a feel for SL and how it compared to my other 3D programming experience
  • See how hard the SL scripting language was to learn
  • Try to make some sort of animated mechanical robot with an articulated arm

The process that I followed is documented in my journal files here: http://www.nadtec.to/doc/prog/slprog.htm where you can also find a zip file that contains the scripts I wrote in various stages of their evolution.




The work took me quite a long time and I found a great deal of it quite frustrating because the SL engine and its scripting language did not conform to my view of the 3D world. My previous experience was with more traditional 3D environments in which you are required to build a list of vertices and faces that describe an object and then render that object with shading, texture maps and so on according to a lighting scheme and a few other rules. You can read more about my earlier experience here: http://www.nadtec.to/books/graphics/default.htm.

The results of my work are not that impressive. The robot looks like a trashcan with one candy stick arm and a block of wood for the other. The movement of the robot and its arms and the way that the robot interacts with the avatars it encounters in SL is hardly realistic. Limitations in the SL primitive model and enforced delays in instructions in the scripting language resulted in animation that is fascinating to watch but obviously not what was intended. As the robot's left arm moves it becomes disconnected and the two parts of he arm move independently. They end up in the right place but the movement is awful.

So is SL a bad environment to develop 3D objects? No, not at all. SL has many very advanced features to offer such as gravitational mechanics, the concepts of buoyancy and flotation and, my personal favorite, the ability to make objects that sway with the wind. In fact it turns out that with a little practice you can make trees that bend with the wind, hair that flows as you move, boats that sail and much more.

So why could I not build a simple robot arm? Too stupid? Didn’t read the right blogs (there was little official documentation)? Not enough caffeine? No, the problem was simply that SL offers a rich set of capabilities packaged up in a way that makes those 'tricks' easy to do but does not expose the normal set of 3D primitives used to make them work. So we can make wavy hair in a few minutes but we can't make a linked set of kinematic objects.

It might be unfair to call them 'tricks'. In reality it probably took a great deal of effort to make the physics work - and it works very well indeed. The real problem is that my goals didn’t align with the set of users expected to be programming in SL and that's a problem we are starting to see a lot. Even with something like word processing we are starting to see that cool stuff like flowing text around an image in columns is trivial but detailed control of heading styles and numbering schemes is not. Professional writers struggle with Microsoft's Word 2007 because it makes it hard to get at the low level primitives but easy to do the hard stuff - and its showing off the hard stuff that attracts people to the products.

If you get an expert in SL to demo object creation to you, you'll be hooked in about 15 minutes. It's totally amazing to watch objects stretch, twist and evolve into lamps, chairs, tables, working doors, bunny rabbits and more. With a bit more effort you can apply fantastic texture maps and most fabulous of all bump maps. This isn't the place to describe bump maps but let me just say that by applying an 'image' as a bump map to a cube, you can turn it into a sofa. The 'pixels' in the bump map don’t describe colors but rather spatial displacements to apply to the object on which the bump map is overlaid.

SL is not an environment in which to model complex behavior. It's environment with which you can interact and which is visually rich which helps to make the experience deeper and more compelling. This is to say nothing of the fact that this is also a massively scalable, distributed system which supports millions of users. If we look into the architecture a bit more, we can start to understand why the cool stuff is easy and the small stuff is hard to expose.

To make SL work, it requires that the client computers do a great deal of the work. The servers used to implement the islands are more or less just databases that describe what objects are present, what the attributes of each object are and where they are located. Given that information you desktop PC can create an image of that 'world' from where your avatar is standing and let you see it. As you move about, the set of objects that are in your filed of view changes and the server needs to send you mode information but this information is quite small and does not need a lot of network bandwidth.

If I make myself some wavy hair, that's just one object with a set of properties. The server only needs to tell my PC where the hair is and how it behaves; the PC renders it and implements all the physics. My robot and its arm are just a collection of objects to the server which dutifully sends the details to the PC, but there is no real way for the server to send the details of the behavior I would like to my PC because the scripts need to run on the server so that all the connected clients see the same changes in position and orientation - and send that information our for rendering. The reason that scripts include forced timing delays between object movement commands is so that one script cannot saturate the system by requiring tens of thousands of update commands to be pushed to all the connected clients watching the scene.

So now I have figured out why I can’t make a cool robot. If I want to make it work better I need to either get a job with Linden Labs and build the kinematics into the client or perhaps work for one of the open-source teams currently developing alternative environments that work the same way.

So if you are a programmer, don’t expect too much from SL. Try to put on your artistic hat instead of your engineering hat and enjoy the environment for what it can do and try not to whine about the features that aren't there yet.

No comments: