InWorldz Blog

Where your Dreams are our Vision!News about the InWorldz Virtual World

Tech Blog

«

»

Nov
19

Vehicles and Physical Objects in PhysX

PhysX is here, presently in the beta grid and by the end of November it will be in the main grid, starting in the sandbox regions, oceans, straits, and a few selected private regions. The first phase roll-out makes it possible to make most objects physical. Physical objects fall; they collide with other objects, roll and bounce. Scripts will have access to the basic forces functions too (listed at the end of this article), and with those functions it is possible to make vehicle scripts.

But first let us focus primarily on the construction of physical objects, get a sense of the physics limits and then learn how to work through those limits.

Counting Physics Cost

We are used to making some extremely complex static objects in InWorldz. It is not unusual to see several hundred prim detailed constructs sitting on land or floating in the air. It is tempting to want to see these beautiful complex structures move but let us remember that there have always been limits to how complex physical objects can get.

Ye Olde Historie of Physiks

A long time ago in a grid far, far away, the limit for physical objects used to be 32 prims minus the number of seated avatars. This was a severe limit and yet physical vehicles managed to get built anyway. What often happened, though, is that complex vehicles ended up being powered using non-physics based movement scripts. The physical object prim limit was raised to 32 prims flat, and then later with the introduction of mesh some rather complex formulae were developed to try to determine the true physics costs of having physical objects (it is a bit mind numbing) but the number remained fixed at 32 prim equivalents.

In the New World

In InWorldz physics (using the PhysX engine), an object’s physics complexity is determined solely by the number of perfect spheres, boxes and convex hulls required to make up its physical representation — that number is used as the physics cost.

The current limit is 256. How this number relates to prims is a little complex but not unduly so.

All objects are represented by a mesh. Prims are just precompiled meshes which made it easy for people to build complex objects without having to deal with the intricacies of 3D modeling. A convex hull is a special mesh that has no concavities (no depressions or holes), and the primary reason convex hulls are important to physics is that they have mathematical properties that make it far easier to figure out if an object is colliding with another object (or land). The following diagrams help to explain what is going on.

The left diagram shows how an object with lots of concavities has to be represented with several convex hulls, six in this example. The diagram on the right shows how another object can be represented by a smaller set of convex hulls (three in this example) because the object has fewer concavities. This is one of several ways an object could be wrapped by convex hulls, and the point is to show that an object’s overall shape strongly influences how many convex hulls must be used to create a physical shape that comes close to mapping how the object looks to everyone.


Mapping an arbitrary object can be an arduous task. Here is an example of a bowl in mesh form. The mesh brings out the details for viewer rendering. To create a physics shape this mesh is remapped into convex hulls algorithmically. The diagram on the right shows how the physical representation of the bowl is approximated. Physics shapes need not be perfect fits. They tend to be imperfect fits because it can take a lot of time to compute the convex hulls. So, the fidelity is a trade off between time and resources needed to map the object.

Prims to Convex Hulls

When the basic prims are made physical, they are converted to convex hulls depending on their prim type and whether any transformations have been performed on them.

Boxes, prisms, cylinders and spheres are usually represented with 1 convex hull. However, when modified to have a hole, at least 4 convex hulls are needed to represent the prim (3 for prisms). A physical object made up of basic prims could well be made from at most 256 prims. However, add holes or path cuts to those prims and the maximum number of physical prims in an object drops to 64.

 

The basic torus requires 25 convex hulls to represent its physics shape. It has to be sliced up into many convex hulls to create a reasonable physical approximation. It gets worse when the torus is twisted, where the cost can rise to 79 convex hulls. Because a torus requires so many convex hulls, the number of torus prims becomes a major limiting factor for physical objects. A vehicle made from toruses is limited to 3 to 10 torus prims depending on whether they are twisted or not. Tubes and rings also have higher physics costs though not quite as high as torus prims. A basic tube requires 15 convex hulls and a ring requires 19 of them.

 

Sculpts To Convex Hulls

Physical sculpts are treated quite differently for now. All physical sculpts are wrapped with one convex hull no matter the number of holes or concavities. This poses some problems because a sculpt prim will behave quite differently when it is physical as compared to when it is static (non-physical). The following two photos illustrate the differences.

 

In the non-physics hull, the avatar can stand inside of it. This is the expected behavior of sculpts in InWorldz – they are surface accurate auto-generated meshes. Once made physical, the physics shape becomes a single convex hull and so it is not possible to stand inside of the sculpted cavity because the concavity is covered over by the convex hull. At some point in the development of physics, physical sculpts will have auto-generated convex hulls.

This can all get daunting trying to determine the maximums for a physical object, but fortunately, there is a way to find out the physics cost of prims by using the LSL function, llGetObjectDetails(), which fetches the physics cost of an object. I have provided a free physics explorer HUD that shows the physics cost of any object in front of the avatar’s camera. It is available in the main grid here: Ardhon en Ceredir – InMotion

Sometimes it is Too Much

Whenever an object is made physical (whether manually in the viewer or by a script), the simulator checks to see how many convex hulls are required to represent the object. If the number exceeds 256 convex hulls, an error pop-up message is sent to the viewer and then the object is made non-physical. In the example here, the object requires 406 convex hulls and so it reverts to nonphysical after the pop-up error is sent to the viewer

The builder faces several choices. He or she could simplify the object by eliminating some prims. Groups of prims could be replaced using sculpts, (eventually groups of prims can be replaced by mesh assemblies, although that has its own complexities), or selected prims could be made to have no physics shape at all.

Physics Shapes

When an object is made physical each of its prims is given a physics shape. A standard box and sphere (one with no transforms – no path cuts, slices, holes, twists, dimples) is represented by its pure physics shape. A transformed box or sphere and all other prims are represented by an approximation made up by one or more convex hulls.

You can, however, directly set the physics shape of each prim to be one of three shape types: a prim, a convex hull, or no shape at all. You do this in new viewers by editing the object and selecting the physics shape type (not available in current IW viewers). Scripts can also change the prim physics shape via llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, …]). I have written a script to help you set the physics shape of an object. It is describe at the end of this article.

The physics shape type of prim (PHYSICS_SHAPE_PRIM) means to use whichever set of internal shapes best fit the prim. For PhysX this can be a pure shape (box or sphere) or a set of convex hulls that wrap the prim to make an accurate physics shape.

The physics shape type of convex (PHYSICS_SHAPE_CONVEX) means to create one convex hull that wraps the prim. This does mean that any holes or concavities in the prim are filled in. But, this also reduces the physical complexity of the prim.

The physics shape type of none (PHYSICS_SHAPE_NONE) means that the prim is phantom. There is no physics shape backing the prim.

Planning Explicit Shapes

Deciding to adjust the overall physics shape of your build permits greater flexibility and allows for stunning detailed vehicles, but requires some planning on your part. A tall sail boat will have much detailing on its rigging but each of those lines and stays cost dozens of physic shapes, many unneeded. Even with simpler designs, use of fanciful shapes can well increase the physics cost. For example, this fantasy sailboat is made up of 19 prims using a hybrid of sculpts and prims. Its physics cost is 186 convex hulls. By eliminating the sail and sail beams physics shapes, then switching the twisted toroid forms to simple convex hulls, the same boat now has a physics cost of 30. This photo shows how it was done:

In your planning consider where passengers will be walking, where the major walls will be located. Make these surfaces prims. They can be visible ones if that works out in the design. They can be invisible if the viewable surfaces are made from sculpts. Simplify any fanciful shapes into convex hulls to reduce the physics cost. Or, if some of the detailing can be left phantom, set those prims to have no physics shape at all. Soon you can have your castle or mega-cruiser sailing through the skies or waters physically.

One final note, there is no such thing as a free lunch. Although the physics costs can be reduced by simplification, a 2000 prim object still has to be rendered by the viewers, and that process takes up a lot of rendering time. Too many moving prims can lag out viewers on slower computers. So though the regions will be OK, some people may experience problems nonetheless.

Setting Physics Shapes via Script

Eventually the new InWorldz viewers will be able to edit objects and set the physics shapes directly. That is a separate project in progress, but in the interim it is fairly straightforward to modify objects to set those properties.


The following script will do that (click on the script icon for a copy). The way it works is that you should edit each prim that you wish to modify its physics shape, and then set the description field of a prim to one of these values: physics_shape_prim, physics_shape_convex, or physics_shape_none. The values can be upper case or lower case.

The default is physics_shape_prim, so only the prims that you want to be different need the description changed. The script will use the description field shape set in the root prim as the default it applies to all the child prims. If you have an object in which you wish to set the physics shape type of all its prims to one type, just set the description field of the root prim to that shape type.

Once the description fields are filled in, drop in the following script and it will do the rest of the work. Once completed, you may remove the script as the physics shape types are properties that become part of the object.

Supported Physics Related LSL Functions

The following list of LSL physics related functions are presently supported in PhysX. Additional functions will be added in ongoing development.

Lvl Function
--- ------------------------------
1 llApplyImpulse
1 llApplyRotationalImpulse
1 llGetAccel
2 llGetCenterOfMass
1 llGetForce
1 llGetMass
1 llGetMassMKS
1 llGetOmega
2 llGetPhysicsMaterial
1 llGetStatus
1 llGetTorque
1 llGetVel
2 llGroundRepel
2 llLookAt
1 llMoveToTarget
1 llPushObject
2 llRotLookAt
1 llSetAngularVelocity
1 llSetBuoyancy
1 llSetForce
1 llSetForceAndTorque
2 llSetHoverHeight
2 llSetPhysicsMaterial
1 llSetStatus
1 llSetTorque
1 llSetVelocity
2 llStopHover
2 llStopLookAt
1 llStopMoveToTarget
1 llTargetOmega
1 llVolumeDetect

10 comments

1 ping

  1. sue says:

    now can we do the bounce butt etc on the av

  2. joseph dhnl says:

    I do not have a master degree in math. “left by the wayside” in other words. its just the way things are, but very disagreeable and not one moment of fun involved.

  3. Balpien Hammerer says:

    Sue, I think you are referring to avatar physics also known as jiggle physics. That effect is entirely viewer generated and has nothing in common with object physics. Some viewers implemented it. I recall the phoenix viewer did, and SL’s viewer 2 and 3 also implemented it, though it is not compatible with the Phoenix viewer’s implementation (meaning it behaves differently between those viewers).

  4. Siwan says:

    I’m totally befuddled by all of this, but then I’m not much of a builder … and not being able to figure out how to make sculpties in the first place is a big part of the reason why. So to simplify, Balpien, are you saying builders of ships, for example, won’t be able to add detailing like lines and sails and the curly cues like you have on your elven boat? I think I would prefer to keep the drivable versions we have now if that’s the case. I know a lot of people for whom realistic-looking ships is part of the enjoyment of sailing.

    1. Balpien Hammerer says:

      Siwan, the overall answer is that it you piece together a vehicle with prims, you will find that after a certain number of them you will not be able to make that vehicle physical because it will be too complex. The maximum number of prims for any vehicle design depends on how complex they are (simple ones are less costly, twisty ones are more costly). If you want to still make complex vehicles, you can but it requires some planning to figure out which prims you want to be physical and which other you want to be phantom or simplified.

      BTW, my elven boat I used in the example has a cost of 186 (out of a max of 256), so unaltered it can be made physical. I lowered the cost to 30 by telling the system to treat the pretty curly cues as blobs. They still look the same but if you walk into them they act kinda like spheres. That simplification meant that I could add many more prims to increase the realism of the boat.

  5. Yichard says:

    “Planning Explicit Shapes” can be done with other viewers, for instance Firestorm.
    With this, we can select prim per prim if it has a physical shape or not, into the overall physical object. This is equivalent to making these prims non-physical, and it can save a lot oh hulls.

    Go in “edit linked” mode, in the “feature” thumbnail, and select “Physics Shape type” to none (or prim, or hull, I suppose a prim may have several hulls)

    I opened the Mantis 0001735 to request to have this implemented in the Inworldz viewer. This viewer will need updates anyway, at the occasion of implementing meshes.

  6. soror Nishi says:

    Thanks for this.
    I am no maths expert either, but the important thing is that I do understand the concept. That means, for me… k.i.s.s. .. keep it simple, stupid.
    I will be making physical objects and I’ll start with very simple ones. As my understanding grows I will venture further.
    Excellent article, again, thanks.

  7. Colin Macbeth says:

    Oh boy! Vehicles, here I come! I have a dirigible I started making in SL under the old 32-# avatars rules, which needs to be finished, and a more recent futuristic one-wheeled motorcycle which I want to ‘port over as well. *rubs hands with glee*

  8. Sylar Quinto says:

    well i was directed to this link in forum ive got this message.
    [21:45] Object was too complex to be made physical: (260 of 256 convex hulls)
    [21:45] Object was too complex to be made physical: (260 of 256 convex hulls)
    [21:45] Object was too complex to be made physical: (260 of 256 convex hulls)
    [21:45] Object was too complex to be made physical: (260 of 256 convex hulls)

    please help this is getting on my nerves

  9. Balpien Hammerer says:

    Sylar, the message you see is telling you that the object you tried to make physical is above the maximum physics complexity. You need to bring the number of convex hulls down to at most 256.

    If you read this blog starting at the section “Sometimes it is too much”, it describes exactly what you can do to reduce the complexity of the physics shape.

  1. Mesh in OpenSim part 2: Even meshier | AhipCup says:

    [...] addition, InWorldz already uses complex decay for prim-based objects, and will have it for filigree as well, according to InWorldz CTO David Daeschler. InWorldz and [...]

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Site Navigation

search engine optimization