Friday 15 June 2012

Another fine mesh you've got me into Stanley

Before we start the lamp

As discussed previously, Mesh Studio converts a prim object to a mesh object. Happily I have a prim object for the lamp already. This is the beauty of this tool in fact. It will take all of your old primmy things and give them a mesh makeover, if you so desire. However, this is where we need to stop and take another quick look at the mechanics of mesh.

Not all meshes are created equal

Land Impact and Prim equivalence. Since mesh was introduced there have been two standards for prim accounting in Second Life. The old fashioned prim counting method and the new Land Impact (LI) accounting system.  In the old world of prim counting, A pathcut, hollowed, torus cost the same as a cube in term of prims, but to the viewer it is a far more complex shape to render (draw), the ultimate free lunch is probably the sculpted prim which for a single prim could define highly complex shapes.  A long explanation of why some shapes are more costly (and when I say costly I mean "laggy") is probably beyond the scope of this blog. However I will try to summarise the basic mechanism.

Every shape that you see in Second Life is in fact a Mesh in the more general sense. A simple cube is a made up of 8 points representing the corners of the cube and known as vertices, linked together by straight lines to form a cube. The "mesh" that we talk about when discussing the new features in Second Life is a way of representing an object, known as Collada, by using a special language to allow an object's shape to be described as a mesh or network of interconnected vertices.

If we can describe a cube in 8 vertices, it should hopefully be clear that describing a cylinder in terms of a number of points and lines is many times more complex (If I recall correctly the cylinder in Second Life is made up of 22 sides). Imagine then the relative complexity of describing a torus? Or an arbitrary sculpted prim.

With a sculpted prim you have a finite number of vertices to play with and a number of other constraints (the connections between vertices are predefined in a simple net-like structure, see below taken from the Second Life Wiki).

One thing we always knew with a sculptmap was that no matter what we did with those vertices the resulting shape would cost us one prim. This ignored the actual cost of rendering, and in effect even today you are getting a bit of a free lunch in terms of prim utilisation with a sculpted prim.

With Collada meshes we are set free from these constraint, there is no explicit limit on the number of vertices, there is no constraint over which vertices another vertex connects too, this makes for a vastly superior medium for representing shapes.

With great power comes great responsibility

Each triangle in your mesh has to be drawn on a screen "rendered", that takes time, the more triangles, the more complex the shape, the more time it takes to draw it. Take too much time to draw things and you start to slow down the frame rate.....also known as Lag!! So, if I can create an arbitrarily complex shape that would put unrealistic demands on the region it is clear that the griefing potential alone is cause enough for some constraints to be placed. The way that the Lab have chosen to do this is by introducing a new accounting method for mesh objects. A complex object will have a higher prim equivalence than a simpler object.

"But I've seen a drop dead gorgeous mesh sofa that costs only 2 prims", I hear you cry. Indeed you may have, and to explain this I need to talk about LOD.

LOD - Levels Of Detail

 Father Ted to Dougal: ...OK, one last time. These are small... but the ones out there are far away. Small... far away... ah forget it!
Remember the way that how you always used to be able to spot a sculpted object by the mangled mess of triangles that unfolded as you approached. This was down to LOD management. the theory is that there is no point putting the viewer to the trouble of rendering all 2048 triangles in your sculpty if it only fills 16 pixels on the horizon of your scene. With Sculpties the "low LOD" version were created in a very arbitrary manner. if you consider that an typical sculpt map might be defined by 32x32 image, then the medium LOD level was calculated by taking each alterate row and column reducing the map to 16x16, successively lower levels of LODS (8x8, 4x4) would be rendered as the object moved away from your point of view.

With Collada mesh LOD still exists and is still going to be cussed at by videographers and photographers however as designers we do have control over this.Instead of arbitrarily deciding what a lower LOD level looks like you are given the option to specify it by providing an alternative model to be used when the item is further away.

There are 4 LOD levels High, Medium, Low and Lowest.

What has LOD got to do with the number of prims though?

The Lab wished to introduce mesh but not have the performance of the system destroyed. They therefore came up with a complex algorithm to calculate not only the upload cost in Linden dollars but the prim equivalence. The exact mechanism is not clear however we know enough to establish some guidelines.

Sim performance is dictated by the number of triangles that are visible when rendering the scene, low LOD carries the highest cost per triangle. Why? Because the triangles in a low LOD model are potentially visible from anywhere in the region. High LOD on the other hand is only going to be seen up close and as that object will then take up more of the overall screen, its cost can be easily traded against the cost saved by not having to render the objects obscured by it.

As we specify our mesh models for upload the Lab calculates how much our models will cost as a ratio of the entire resources of the sim. Under the old rules you could have 15,000 prims per sim and thus if an object can be determined to be using more than 1/15000th of the overall resources of a sim then it should be treated as the equivalent of more than 1 prim.

Size matters

So that seems fairly straightforward right? the more complex an object at a given distance, the more impact it will be having, but it does not stop there. The size of an object is important this is because the LOD algorithm itself takes into account the size of the object before selecting a LOD level. e,g, over about 50m in size an object's full LOD is visible from anywhere in the sim. So larger objects will be having a higher impact across the sim and are therefore penalised as well.

This has been a rather long winded post and I am once again falling asleep at the keyboard. But we have not seen our lamp at all today so lat's put that to right and get out the high LOD lamp.

For those who appreciate design, the arts and crafts movement I apologise for the travesty that follows.

Building the High LOD lamp

Initially I simply recreated the lamp in prims giving it the details that had been added by the sculpt but not going much further. This came to about 15 prims. To help demonstrate how Mesh works though I wanted something more complex and so I created a number of additional details, the fluted edges, exposed bolt heads on the rim of the shade etc. The final high LOD version of the lamp is made up of about 40 prims.

Here is what it looks like

With this completed we simply add the mesh studio script into the root prim and touch the object to get a menu.
The menu tells us that this object will be created at high LOD, preserving all details, it also informs us that we have two texturable surfaces.
For now we can simply accept all these and click the "Mesh!" button. A few moments later a URL appears in the local chat window. clicking the the URL will download a zip file containing a default texture to use and the Collada (.dae) model ready to be uploaded.

To be continued.

No comments:

Post a Comment