Thursday, 20 February 2014

So what are the laws of Physics?

I've been reworking the Mansard Roof on Maison Horta in Mesh. It is currently a sculptie created a year or two back using Sculpt Studio. The challenge is to get the LI low and have a reliable physics profile and resilent LOD. Nothing new there.

Sculpted mansard with sculpted stone dormas
 I detached the dorma and made a prim model using simple wedges for the most part. The final model being 13 prims with 5 distinct texture faces. I generated the Mesh using Mesh Studio and then switched to Blender. 

The Mesh Studio model

I knew that some of my joints were inaccurate, this was in part my sloppiness and in part lack of precision in the shear and taper options. Blenders remove doubles command allows you to merge vertices that are in close proximity and when used sensibly can tighten up all those poor joins.
Blender model - perspective makes the angles look wrong.

The Blender model can be further optimised, by hand editing we can eliminate unnecessary vertices that lie on un-attached edges (such as the top edge) and their associated geometry, the aim as always is to look for new ways to divide up the shape into triangles. Even now there are a few more savings that could be made but I prefer in this case to avoid long thin triangles.
Optimised by hand.
For medium LOD I can use my intimate knowledge of the use of the item to make firm decisions. The interior will never be visible from far enough away to drop to medium LOD, therefore I can cull all the interior faces. I make sure to keep a triangle with the correct material assigned though to ensure we comply with the basic Rule of SL Mesh that all LODs must share the same materials.

For Low LOD, I am going to use the same model as Medium. This will push up my streaming cost but so long as I stay under 1.5 I will be happy, and it will ensure that the house remains good looking for those spectacular New Babbage roofline shots that people love.

And so... physics. The point of this blog. In second life the laws of physics or not so predicatble as those in in real life. I've noticed this in the past but rarely taken the time to explore much. You may have noticed that when you import a Mesh the calculated physics cost in the upload dialogue is close to useless and this is true of both TPV and Lab viewers.

So how do we get the correct balance of physics shape to physics cost?

Given that my next article in Prim Perfect will need to examine physics, I decided to experiment. The first and simplest task was to use the model itself. In this instance it is actually a pretty simple Mesh so we'll see what happens.

Firstly, we specify the model as before and then for physics we select "Use HIGH". We will not touch analyse. As you can see the uploader predicts a physics cost of 0.440. Brilliant. All good then.

Using High LOD model, No analysis.

But when we get it onto the grid and rez it what we find is a different story...
The physics cost is not 0.44, it is nothing even close to that. The physics cost has rocketed to 1.4. It all works nicely though. But perhaps if we were to use the analyze function we'd get better results. maybe that elusive 0.44.

In the screenshot below we see the upload screen. This time we have selected the Analyse option. We are using the Solid method as in general this is best for block builds (use surface for curved builds). In pracatice you can try the 3 methods and see whcih gives the best (simplest) physics that looks right.
The analyse function has returned and told us that the physics mesh has be decomposed into 6 hulls. That seems plausible so we can accept that and go ahead with the import.
another aspect to note however. The Analyse function has pushed our import cost up. It is now going to cost us 13 Lindens whereas before we only paid 11. What is going on?

So now we have imported the mesh with our highly analysed decomposition, surely we must get better results in world....Errr no.

This is odd. We have used the self same mesh and rather than letting the system make some estimate (using an as yet unknown methodology) we have let the Havok system break up the mesh we provided into the most optimal collision shapes it can. The result, our physics cost has rocketted from 1.4 to 2.6 taking our overall LI from a rounded down 1 to a rounded up 3.

If a non-analysed collision mesh can be much lower (in some cases) how does that occur?  you might be tempted to think that the non-analysed collision mesh is inferior. Well it does not seem to be. I can happily walk back and forth through the gaps. But when we take a look at the Metadata view of the physics we see something very peculiar indeed.

Analysed Mesh with physics shape in blue
First, let's look at the physics model generated for the analysed mesh. A nice tight fit, and near perfect match to our physics template. This may be overkill for out needs but we'll come to that later.

Sure enough we can walk through the doors and if we walk into the wall we will slowly climb the slope or walk on the spot on the flat side.
 No surprises at all, physics mesh doing exactly what we expect, and a good job too given how much we are paying for it in LI.

Now, let's take a look at the physics metadata for the non-analysed physics.

Non-analysed mesh with physics in blue
Wait a minute, that's not what we asked for, that's not what we are observing either.
The physics shape revealed by the "render meta-data" option in the viewer is showing us what appears to be a default convex hull. But that cannot be right. I can walk through the doors and collide with the walls with the accuracy of the analysed mesh above, and yet the viewer is telling me that the physics shape does not even know about the doors.

Is this a viewer bug? I have not tried the Lab viewer yet.

trying to walk through with "convex hull" physics
The last couple of images show the difference in behaviour of the same object. Firstly with "convex hull", secondly with "prim". as you can see, with "prim" I can walk through the gap. This is not news... However, the physics shape is the same in both cases, you can clearly see that I am standing "inside" the supposed physics shape

walking through the same model but using "non-analysed" prim physics.

Time lapse video: Building using Mesh Studio

Hi all,
I recently made a free gift to accompany the February edition of Prim Perfect and the resumption of my Mesh creation articles. I decided to film the build and have since turned it into a shortish (10 minute) time lapse.
You can't really call it a tutorial, but perhaps it will show you how simple Mesh Studio is to use.

I have placed it on Vimeo.