Physics Optimization
Physics Optimization:
(See handy script at bottom of page)
NOTE: Setting prims to Phantom does not stop them from being calculated by the physics engine!
- The less the physics engine has to calculate, the smoother your region will perform. Creating clean low poly physics shapes for your complicated meshes is helpful, but you can also remove prim, mesh, and sculpted objects from the physics calculations completely.
- Physics Optimization also helps with Pathfinding. Pathfinding objects will only have to calculate to go around simple objects instead of complex builds, making everything work smoother and faster without sacrificing looks.
- The way to Physics Optimize is to link your complicated builds to a simple shape like a cube or cylinder. The simple shape should be the root prim and then set all child prims to PRIM_PHYSICS_SHAPE_NONE (in Edit > Features > Physics Shape Type)
Manual Instructions:
1. Build your object as you normally would
2. Create a simple shape, such as a cube or cylinder
3. Right click on your object, hold down shift and select the simple shape last
4. Press control and L to link it all (the simple shape should now be the root prim highlighted in yellow)
5. Tick edit linked parts
6. Hold down shift and de-select the root prim (the simple shape)
7. Under the edit menu, in the features tab, select physics shape type, and from the drop down menu select, physics type none. This will set all the child prims to none.
8. Select the root prim (the simple shape) and make it transparent.
Using the script below:
Or to make it even simpler just follow the above instructions 1 to 4 and then use the handy script attached below. Just drop it in the root prim (The new simple shape you just linked your build to)
Tip: Cubes, spheres, and circular cylinders are the cheapest shapes to use. Up to 14 cubes equates to the same value as one cut hollowed cube. Other shapes, such as pyramids, with no cuts, twists, hollows, or holes, or any shape set to PRIM_PHYSICS_SHAPE_CONVEX_HULL for a potentially more accurate (albeit more expensive) r for its physics shape type are more expensive. Any shape that contains holes, cuts, twists, or hollows (such as a torus) fall into the most expensive category.
Here we linked a tree to a cube and set all child prims to physics shape type None (in Edit > Features > Physics Shape Type):
Collision:
When you are physics optimizing you need to plan where you want the collision to be, because all the individual shapes set to physics none will act as though they are phantom. In this example we are using a tree. The actual original tree will be set to physics none and act as though it is phantom so an avatar will be able to walk through it. The root prim, which in this case is a cylinder, will be the only solid part of the whole linked set. By putting the root prim/simple shape around the tree trunk, you simulate a solid and avatars will collide with it.
Here we used a cylinder, but we could have also used a stretched cube to achieve a similar effect.
For more complicated builds you can set certain parts to PRIM_PHYSICS_SHAPE_PRIM and others to PRIM_PHYSICS_SHAPE_NONE. The parts set to prim will act solid, and the parts set to physics shape type none will act as phantom. Alternatively, all prims could be set to PRIM_PHYSICS_SHAPE_CONVEX_HULL for a potentially more accurate (albeit more expensive) result. This still produces a physics shape significantly simpler than the default. However, this second option will have no effect on sculpts.
More Examples:
- Here is another example scenario. This is a sculpted prim fence. The physics shape is not as clean as it could be, and the edges don't cover all edges of the fence itself. To fix it, I created a cube physics shape, linked the fence to the cube with the cube as the root prim, and set the fence to None. As you can see, the resulting physics shape is lower in polygons and better covers the fence area.
- This is a tree comprised of many sculpted pieces. Keep in mind that the physics engine needs to calculate every part of the physics shape in the second picture. Here I created a cylinder for the physics shape to fit on the bottom of the tree trunk. By linking the cylinder to the tree, and setting the tree to physics shape None, I have a much cleaner static object.
- These gates are nice clean and simple except for the hippo on the top. We can remove the hippo from the physics engine calculations.
- This entrance has a lot of complicated geometry in one linkset. We only need simple physics here for avatars and pathfinding characters to collide with.
Use the following script to set all child prims to None. Be sure to check what physics are needed for your linkset prior to using, and/or add a simple cube as the root prim. <lsl> default {
state_entry() { llShout(0, "Setting all child prims to PRIM_PHYSICS_SHAPE_NONE"); llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN, [PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_NONE]); llRemoveInventory(llGetScriptName()); }
} </lsl>
- For more detailed information, have a look at this Havok Technical Artist Optimization Guide, a direct excerpt from Havok's documentation. (Havok is the physics and AI engine provider used by Second Life for its physics and pathfinding simulations.) This guide provides details on the best way to optimize your collision shapes and is used by leading artists throughout the games industry.
Back to Good_Building_Practices