Physics in OpenSim

[2011-10-04 There is now a new version of Bullet physics that works but remains under testing: see notes below.]

Recently, my private grid (running OpenSim has been having some major problems with the standard physics engine ODE (the Open Dynamics Engine) throwing exceptions due to segment faults when running on Mono 2.6.7. This happened after Mono was upgraded when I incautiously decided to upgrade Ubuntu 10.04 to 10.10 without first checking whether the bundled new Mono version would interfere with OpenSim. It’s not easy to downgrade since various bundled parts of Ubuntu 10.10 rely on this version of Mono. Currently, I’m not quite sure if I have managed to solve it and, if so, how, but the problems are currently levelling off have now inexplicably disappeared again. It largely happens with hollow or cut-path prims, usually large ones over 10m, and is was entirely reproducible. I tried using ulimit -s 262144 but I’m wondering if this was set in the same child shell as the GNU Screen session in which OpenSim runs, as it seemed to have little effect until I did it manually. The crashes have temporarily abated, but I am no closer to finding out whether it is anything to do with ulimit and the stack size.

It did focus my mind on the ODE physics engine, however. Readers may know that Second Life ™ uses the free binary distribution of Havok 4, noting that the proprietary source code however is not freely available as open source. It can’t be distributed for commercial purposes (likely to be a problem for some commercial grids based on OpenSim) and the OpenSim developers can’t modify it for use with OpenSim without access to the source code. There are several other physics engines packaged with OpenSim. These are: Basic Physics, BulletDotNET BulletX, ODE, Modifed BulletX, POS, RealPhysX. [2011-10-04] only ODE and BulletSPlugin are now functional. Since at one point I could barely keep an avatar moving near my build for a few seconds at a time without crashing the region server, I decided to try these out. The initial results were not at all encouraging:

Basic Physics – this works fine but, as it sounds, is basic: in fact, so much so that it does not support collisions. Flight is jerky and all prims are phantom, so buildings or any prim structures are basically pointless. It may have some use for debugging, although the jerky flight made it awkward to use for building.

BulletDotNET – as my grid runs Linux, it wasn’t possible to test this, as it only runs on Windows and .NET rather than Linux and Mono. [defunct]

BulletX – it has long been recommended that Modified BulletX is used to replace this under OpenSim, so I did not test it directly and don’t know if it is still directly supported as a separate option. [defunct]

ODE – largely fine, minus proper vehicle physics and one or two minor glitches. But if my experience and that of several others is typical, use caution for the time being if you intend to upgrade to Mono 2.6.7 in the near future, which appears to the most likely source of the recent spate of crashes. [2011-10-04] Note that Mono 2.6.x and 2.10.x but NOT 2.8.x work with the OpenSim 0.7.2 Release Candidate according to the release notes, but I suggest that you do not use above 2.4.3 with OpenSim 0.7.1.x versions. According to this Mantis issue, the crash problems should have been sorted out, so please comment here or re-open the issue there if you experience problems similar to those I described.

Modifed BulletX – disappointing, this is no longer functional in OpenSim. Although it is possible to start a simulator using this physics engine, it appears to process every prim in every region before it is possible to connect, which takes a long time. At the end of this process, the avatar is unable to move from around 100m in flight without being bounced slowly back into that position, and other movement is likewise impossible. It’s thus difficult for the average user to test whether physics works for other objects and collisions. [defunct]

POS – billed as Basic Physics with collisions, at least it is possible to start a simulator and connect to it, although avatar movement does not work at all, unlike in Basic Physics. It appears to be obsolete. It was not possible to test it any further; in any case, it never supported much functionality in the first place. [defunct]

RealPhysX – while this may be a useful physics engine too, it is no longer functional with OpenSim, which simply crashes on start up. [defunct]

[2011-10-04] BulletSPlugin was added in June by Robert Adams, as noted at the top of this post.

So, whether or not the more advanced physics engines listed above (e.g. BulletDotNET, BulletX, Modified BulletX, RealPhysX) are better or worse than ODE is currently impossible to tell inside OpenSim running on Linux, and I’ll leave it to others running Windows to discuss BulletDotNET.

However, I did discover that there are various other physics engines available for gaming applications, of which ODE is only one. The problem is that it would require a new physics API to be written for OpenSim in C#, since none of these are currently supported. Although OpenSim is technically modular enough to allow this, it has never yet been done. There are a number of other physics engines available, as I gleaned from this discussion, from which this is the relevant excerpt:

Box2D <>
>> (experimental)
>> – Bullet <>
>> – Dynamechs<>
>> (deprecated)
>> – Havok <>
>> (experimental)
>> – IBDS <>
>> (experimental)
>> – JigLib <>
>> – Meqon <>
>> (deprecated)
>> – Newton <>
>> – ODE <>
>> – OpenTissue <>
>> – PhysX (a.k.a Novodex, Ageia PhysX, nVidia PhysX)<>
>> – Simple Physics Engine<>
>> – Tokamak <>
>> – TrueAxis <>

I’m not entirely sure for how many of these the source code is available as fully open source software, or whether there are commercial restrictions on some of them, so I’ll leave it to the reader to follow up on this point. There are instructions for using Newton physics with OpenSim dating from 2008, and these may still work although I have not tested them. This is an open source N-body gravity physics engine for astrophysics that is not aimed primarily at gaming physics and collisions and is apparently NOT the same as Newton Game Dynamics, a freely available proprietary, closed source physics engine for gaming. Obviously, OpenSim and SL employ gaming physics.

The really interesting possibility for physics is the Physics Abstraction Layer (PAL), which OpenSim developers such as Adam Frisby and Teravus Ovares have been keeping an eye on for some years. If suitable developers could be found and the logistical issues overcome, it would enable more or less any advanced physics engine to be used with OpenSim. I wonder if any developer types with more knowledge than me would like to comment on the feasibility of this? It does seem that ODE physics development for OpenSim hasn’t moved on much lately, so perhaps it is not a current priority?

The new Aurora distribution of OpenSim is working on a modified version of ODE that apparently includes vehicle and underwater physics. I did notice that, when testing this (in early alpha, to be fair), once or twice I ended up propelled upwards and left standing on a vertical block of air about 20 feet tall. But no doubt such glitches will be ironed out: it is impressive that they are taking on the fearsome work of improving the physics engine, which I doubt is work for the faint-hearted. [2011-10-04] It seems from their web site that many improvements have been made to Aurora, including ODE fixes and enabling HyperGrid.

Since physics is so basic to the experience of 3D worlds, surely it should be more of a priority in order to improve the user experience? At the same time, I know it is a difficult area of technical development. I hope to see advances in this area, given occasional glitches, and my recent bad experiences with ODE crashes. To some users, though not me in particular, vehicle physics in particular is an important missing area of functionality. At present, it seems that we have little alternative to continuing to use ODE with OpenSim for the foreseeable future. [2011-10-04] Although in testing, BulletSPlugin apparently now works, and is said to outperform ODE in some respects. I have not tried it out myself, however.