Thursday 3 September 2020

Second Life Mesh Physics 101

 

(Originally posted on the official Second Life forum)

Physics in a virtual world has two purposes, it defines where avatars (and objects set to be physical) can and can't move and it provides surfaces for "ray tracing" (a feature that defines which spots you can rez on and is also used for pathfinding and a few other things).

Physics engines work with two very different kinds of physical objects, surfaces and hulls. (There's a third one too, height fields but it's only used for the system ground so it isn't relevant here). HAVOK, the physics engine used by Second Life, operates with five different hulls and two different surfaces but only the two surfaces and one of the hulls are available for meshes.

When we analyze the physics, the uploader will try to convert the physics mesh we feed it into one or more hulls, if we don't analyze, it will use the input as it is and treat it as a surface. The physics engine, including the uploader's analyze function, is not LL's own, HAVOK is an Irish software copmany currently owned by Microsoft. This means there's not much LL can do about it, they have to use it as it is.

Both surface and hull physics have their pros and cons:


Hulls

A hull can be compared to ban lines in that they defines an "exclusion zone" you are not allowed to be inside.

The pros are:

  • They are always totally solid, if you are inside it, you will always be pushed out.
  • The physics weight is constant. If the hulls are all simple cubes, each of them will always add 0.360 to the physics weight. More complex hull shapes may add a bit more but it's still constant.

The cons:

  • The physics engine won't allow two hulls to touch each other, it will always leave a little bit of space between them. The uploader tries to compensate for this by shrinking the physics shape slightly but this is not a precise science so you will always hover a little bit above a mesh surface made with hulls.
  • There is no way to reduce the physics weight below the 0.360 per hull limit and the hull shapes are always farly simple. If an objects needs a complex physics shape, it'll have to be made from a lot of hulls.
  • Since a hull isn't defined by its surface and ray tracing is all based on surfaces, it can sometimes cause problems with rezzing and for pathfinding characters.

Surfaces

As I said, we have two different kinds of them:

Triangle

A single triangle has a constant physics weight of 0.200, making it the lightest of the shapes available for mesh (three of the special hulls we can't use are even lighter). It doesn't give us any useable physics of course but can still be handy for objects that can be phantom anyway.

Triangle list

Triangle list is just another name for a mesh, a surface made from several triangles streched between vertices. It is said to be heavier on the server than hull physics but that is a truth with modifcations. We often need multiple hulls or a very complex single hull to get a good physics model and in those cases triangle lists are usually considerably lighter.

One peculiar quirk HAVOK has, is that it doesn't handle triangle lists with small or very long and narrow triangles very well, the bigger the triangles are, the better. If the object size is smaller than 0.5 m on any axis, HAVOK simply gives up and handles it as a single convex hull and depending on other factros, you can get very high physics weight long before you reach that limit.

Pros:

  • Allows for very precise physics shapes
  • No ray tracing issues

Cons:

  • May cause inflated physics weight for very thin objects
  • Does not work at all with objects smaller than the 0.5 m limit
  • Is single sided so you may be able to penetrate it (with a little bit of difficulty) if you walk into it from the back side
  • If you move very fast, you may end up penetrating the surface before the physics engine has time to react. This is not a problem with normal avatar walking/running/flying speeds (unless there is a server glitch) but if you drop onto the surface from a high altitude or crash into it in a fast moving vehicle you can sometimes go right through it.

Four special points worth mentioning

For a physics model is made from a single 12 tri cube it doesn't seem to matter whether it's analyzed or not. The physics weight is always 0.360 and it doesn't seem to suffer from any of the quirks neither of the hull or surface physics. This may be because it corresponds exactly with the object's bounding box.

The bounding box is a cube surrounding the entire object. The physics engine can't keep track of the relations between every single object and avatar in a region of course so it uses the bounding boxes as a preliminary check to see if two objects are so enough to each other it'll have to do a more precise calculation.

For those who wonder, the "convex hull" option in the edit window uses HAVOK's analyzer to generate a single hull for the entire object. The physics weight depends on how complex that hull is but usually it's lower than the more detailed "prim physics".

Practically all parcels in Second Life are configured with no pushing. This means worn items are always phantom so there is no point in using elaborate physics models for clothes, hair, jewelry etc. Just upload with a single triangle as physics.

No comments:

Post a Comment