Tuesday, 26 June 2012

Too much information

Too much information running through my brain, too much information driving me insane. - The Police.
Level Of Detail (LOD) seems to vex us and yet it can be quite hard to find out exactly what it is. In previous entries we established that in Second Life there are 4 LOD levels, this applies to all objects, prim, sculpt or mesh though the standard prims are very "LOD resistant." LOD resistant is a term used to convey the ability of an object to remain visibly intact at lower LOD levels. In sculpt maps this was achieved by making sure that key "structural" vertices were reinforced by ensuring that vertex with those coordinates appeared in each of the reduced sculpt map images. With Mesh we have to control this ourselves as shown in the last blog.

But when does one LOD get shown as opposed to another?
The best answer I have found to this is still asserted to be an approximation but it's close enough to work with.
The LOD boundaries can be approximated using the following equations.

Medium LOD = r/0.24
Low LOD = r/0.06
Lowest LOD = r/0.03 

where r is the "radius," determined as being the distance from the centre of a prim to one corner of the bounding box of the prim.
(Bounding box is a theoretical box of the same dimensions as the object.)

Thus if for a given object r is 10m then it will display the high LOD until the viewer is about 10/0.24 or ~42m away. After this, the medium LOD will appear and then the low LOD when the camera has withdrawn to 167m. Finally, the lowest LOD will appear at 333m. Which the observant will note is a fair way across the next door sim.

Clearly, a smaller object with a value of r of say 1m will have a different set of LOD boundaries. (4, 17m and 33m respectively). 
Ignoring mega prims, for now, the largest object we can have is 64mx64mx64m. This would have an r value of ~45m. The high LOD for this would be visible all the way out as far as 187m.

The fact that the highly detailed mesh is visible across most of the sim is the basic reason why larger mesh objects have a higher Land Impact penalty applied to them.

To close this post and draw a line under the LOD discussions for now, here are a series of images comparing the carefully LOD controlled mesh lamp with the standard sculpted lamp. To be fair to sculpt aficionados, though, there is not attempt in the sculpt to harden it against LOD.
High LOD - Mesh on Left (LI=1) , sculpt+prims on right (LI=5)

Medium LOD - Mesh on Left (LI=1) , sculpt+prims on right (LI=5)

Low LOD - Mesh on Left (LI=1) , sculpt+prims on right (LI=5)

Lowest LOD - Mesh on Left (LI=1) , sculpt+prims on right (LI=5)


Friday, 22 June 2012

Less is more, more or less

In the previous post we uploaded our first mesh lamp. Up close it looks just as we wanted but stepping away even a little the lamp melts into an indeterminate jumble of mangled mesh.

This is the same issue as we had with sculpts. The randomly generated lower LOD meshes are little better than the arbitrary chops applied to the sculpt maps. But we have more power now, with mesh we do not have to accept the manufactured mesh we can submit our own objects.

The LOD generation tool has some strengths here. By manually tweeking the settings we can influence the number of triangles at each level. in the preview window and work out more or less what our target should be for each model and thus set our expectations.
 
Here we have the mesh upload dialogue in Firestorm. We have loaded the Collada file of our lamp, and are generating all other LODs. In the preview window I am displaying the medium level of LOD. This is the level that most people will see if standing on the other side of the room, so it is important enough to focus on. This generated LOD is not ideal but its not awful, the form is more or less intact.
But wait a minute! Look at the Land Impact noted on the left hand side at the bottom.

This object would have a land impact of 9.323 prims, this would be rounded up to 10 prims.  The download impact is the highest of the three factors, Download, Physics and Server. Download represents the streaming impact and is for the most part defined by the number of triangles in the object. As mentioned in previous blog entries, triangles in the lower LOD models have a higher cost so by tweaking those settings we can drastically alter the streaming impact and drive down the Land Impact of the model.




In the image above we have altered the Triangle limit parameters for the generator to work with when constructing the lower LODs. By reducing the limits at each level we have managed to bring down the cost to 1.704 (2) prims.

That is much more like it! But look at the quality, the generated medium LOD is OK but its really starting to look a bit shabby. Its at this point where we can take advantage of  another one of the benefits that mesh has over sculpts; the ability to define explicit models for each of the LOD levels.

So let's look at our model and start to simplify it. We should keep in mind that the Medium level of detail can be seen from relatively close (the mathematics behind the distances for each LOD level is something I can cover in another blog, but for another explanation, in nice clear terms with no maths in sight, I highly recommend Loki's excellent blog).



















On the left is the high LOD model on the right is the reduced detail medium LOD model. The simplifications are quite straight forward. All of the surface details have been removed to give a plain rectangular column, I enlarged it slightly to the same volume as the external dimensions of the ribbing. The cross struts in the shade were simplified to square profiles not circular (Squares are much lower cost than circles) and that was about all. This does not seem like much of a simplification but we will also use the Mesh Studio tool to help us reduce the detail further.

When we generated the high LOD model we simply took the Mesh Studio defaults. Mesh Studio however has options to tune the way in which the prims are translated to mesh along with a number of useful presets. With the script installed in our medium model we can touch it to obtain a menu like the following

The default resolution shown above is 4/24. This tells us that straight paths (edges) will be rendered with 4 vertices whilst curves will have 24 sides. Clicking on the "Resolution" button takes us to a different dialogue where we can tune the resolution. For the medium resolution we will select the Low Poly option. This uses just two points per side to define a straight edge and 16 for a curve. The result for us will be a blockier curve to the lamp shade whilst saving over 1/3 of the vertices.

Having set the resolution we can return to the main dialogue and press the "Mesh!" button. A few seconds later a URL will be printed in to the local chat channel and opening that URL in your browaser will down load a zip file containing your collada mesh file exactly as we did for the high LOD model.

Before we upload anything we will continue to optimise.
First we will create a low LOD model. At this stage we can expect the model to be being viewed from quite a distance and as such we can take some liberties with the model.

 The bulb inside the shade has been removed completely, there is a subtle issue here, that relates to the texturing (or materials in Mesh speak), we won't examine this in detail but take care to ensure that your models always show the same number of texture faces in the hover text before you generate the mesh. SL will not allow you to combine objects that do not have the same material structure.

Apart from the bulb, we have removed the cross members on the shade and made the bulb holder itself square. The apertures in the shade itself have been closed in.

In the illustration above you will notice that the inside of the shade is transparent. This is a nother feature of Mesh Studio. All faces that are 100% transparent are assumed to be hidden and will not have mesh generated for them. I have made the assumption that our lamp, when viewed from afar is likely tobe viewed from above and so the inside of the shade will be invisible.

For the final cost savings, we go back to the resolution settings dialogue in Mesh Studio.
We could have used the low LOD preset of 2/8 which would have rendered our lamp shade as an octagon, but because of its shape we can be pretty comfortable taking this down to 6 sides (a hexagon).

This leaves just one final LOD to define. Lowest.
The Lowest LOD pays the highest price for each vertex so we need to keep this  as low as possible whilst still serving its purpose. In the case of our lamp I have arbitrarily decided that it will render as noth but a flat plane. As mentioned above I do need to have two texturable surfaces in order for Second Life to accept this model as part of the same mesh as the others.

 The image shows that I have reduce the model to a simple cube and set the four vertical faces to be transparent. the top and bottom faces (not seen here) are textured (one in brass and one in lightbulb) to represent our two materials.

We are no ready to upload.
 First step is as before, in our viewer we go to the mesh upload dialogue. For each of the four LODs we select "Load from File" and specify the appropriate model.
You may be surprised to note how many vertices we saved with the simplifications between the High and Medium levels alone. The Land Impact of our model is now down to 1.460, 2 prims still ,but we have defined an elegant set of models for each LOD now, and so we can look at the rest of the upload options.

Next we move on to the physics tab.
Another difference between mesh and sculpts is that you can specify a special physics shape, this is in the form of a mesh and adds to the overall cost of the model by affecting the "physics" weigfht shown in the dialogue above. The physics of the lamp is not very important and so I have specified the lowest LOD model as the physics. In this case it has not affected the overall cost of the object.
 Finally the "upload options" tab. This is where sundry options exist. To be honest I have played only a little with this, the key parameter here is scale. For ease of construction I was working on a large scale model. 3m high, a little on the large side for a table lamp.
Scaling is optional. Once uploaded you can scale the model inworld. The same Land Impact will be gained but by tweaking things in the dialogue we can see how the scale will affect our Land Impact before we upload and in some cases that might send us back to the modelling stage to make some additional tweaks, thus saving an upload fee.

By scaling this down by a factor of 0.5 we have a still oversized lamp but have already gained the lowest Land Impact (0.5). This means that a single lamp willcost us 1 prim, moreover two of them linked together would cost us 1 prim too!

Finally we hit the upload button and our mesh will be transferred to our inworld inventory.

In the next blog, we will look at LOD and compare our new mesh with the old sculpted lamp.

Monday, 18 June 2012

The devil is in the detail

In the last post we concluded a rather arduous journey through the world of mesh and levels of details with what must have seemed a very terse and over simplified view of mesh creation using Mesh Studio.

To reiterate:-
  • With this completed we simply add the mesh studio script into the root prim 
  • 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.
Well, yes it was short and to the point but in all honestly, for the high LOD mesh that we just created that really is all that there is to it.

So let's get on and upload this shall we?


This is the standard mesh upload dialogue. We are looking at the levels of detail tab.
The dialogue offers us 4 different levels of detail that we can load. we have to have all 4, and the system "kindly" creates the missing ones. We have only the one LOD model so we have loaded this as the high level. You can see that our model is made up of 4422 triangles. All of the other levels are generated by the SL uploader.

The SL uploader tries its best. But to be quite frank it is not very aesthetically aware. you can see that the medium LOD model that is displayed in the preview window is alrady showing signs of corruption. as soon as we step down to the lower levels it will decay into a mess.

What is more, we have calculated the land impact and it is coming out a 9.323, this mesh lamp is going to cost us 10 prims! less than the 40 for the pure rpim version but twice the 5 prims that the previous sculpted prim version cost. This cannot be right!

So how is the land impact calculated?

The truthful answer is..your guess is as good as mine. The overall algorithm is to my knowledge not public though I could well be utterly wrong in this regard.  However we do know the general principles.
In this case the land impact is 9.323, this is the largest of the 3 factors, download, physics and server.
Download is calculated by a weighted sum of the total number of traingles in the combined set of LOD models multipled by a random number that the Lab came up with (or something like that).

The fact of the matter is that triangles in the lowest LOD are REALLY expensive, having a much higher weighting than those in the next level up, which in turn have a much higher cost than the level above (medium) and the n in turn medium has a higher cost per triangle than the higest level of detail.

We can therefore mess arouns with the Triangle limit setting of the LOD generator to get a more acceptable land impact.


So here we have reduced the triangle counts for all the lower levels of LOD. Medium is now at 552, Low at 69, lowest at 17. Our object's land impact will now be 1.7 (aka 2 prims). this is great news.

We can hit upload and enjoy our mesh lamp. Except we now find of course that as soon as we pull away form the lamp the thing mangles up into the shape shown. We can set our graphics settings to forestall this but we cannot force others to do likewise.

"Surely there must be a better way?", I hear you cry.

There is, and we'll look at this in the next instalment, wherein we will look at generating specific models for the other LOD levels.


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.

Thursday, 14 June 2012

Mesh creation inworld

Mesh is for most of us a pretty new thing. Designers working in offworld 3d are more familiar with the concepts but even then there are considerations and special nuances of the Second Life importer that need to be mastered.

I am going to document a quick project that I undertook this evening in the hope that some might find it useful and perhaps demystifying mesh a little. I should of course note that I am no expert in this field, mesh is a new tool for me and I have only just begun to play with it.

The very first Mesh creation I ever made was produced in Google's Sketchup program. This is a great 3d editing application with a wonderful interface that for the most part does what you expect. However, it is far from ideal for Second Life modelling and can be hard to import and certainly quite costly.

I moved on to Blender, and perhaps I will cover Blender in a later journal entry. I would certainly recommend Gaia Clary's videos on Mesh in Blender over at Machinimatrix but please bear in mind that she is still in the process of producing them and also that the version of Blender changed form her early tutorials.

Today though we will not be using Blender or in fact any offworld tool. Those of you who have produced sculpties in the past will almost certainly have come across the rather excellent Sculpt Studio by TheBlack Box (TBB). TBB has more recently been working with a number of other inworld tool visionaries, Anjin Meili and Inventor Alchemi who were previously involved in some of the ground breaking tools that proved that sculpts could be produced inworld.

The result of this work is Mesh Studio. In some ways Mesh Studio reminds me of another sculptie tool, Sculpt Crafter (SC) by Contagious Republic. SC worked by providing a set of prims each of which held a small script that would report the details of that prim and allow the main script to produce a sculpt map based upon the extents of the shapes. Mesh Studio (MS) takes that idea to a whole new level.

With MS you do not need special prims, there are no restrictions to how you can cut, slice or hollow them. To my knowledge any torture that you can apply can be reproduced by the tool. Neither do you need to have a script in each prim which makes the entire process far simpler. To enable you to build a mesh version of a prim object all you need to do is take a script that is provided and drop it into the root prim. The object then becomes touchable and produces a menu of choices for you, the most important being "Mesh!" which produces a link to a remote server which hosts a zip file in which your mesh has been stored.

Mesh uses a format known as Collada which typically carries a ".dae" suffix to its filenames.

Getting started.

So the aim of this series of entries is to use MS to produce a viable object and to learn as we go.
A long time ago I built a lamp. It was very simple and not very pretty but was based upon a real life lamp made in the early part of the 20th century by a movement known as "Roycroft" part of the Arts and crafts movement. The real lamp looked something like this.
 
 My version in Second Life was rather simple, deliberately low prim, and it pre-dated sculpts, or my ability to produce them at least. Just recently in a bid to reduce the prim usage in my undersea home in Babbage I took the opportunity to sculpt a redesigned lamp. The two lamps are shown below the orignal prim only version and the updated sculpt version.
The prim version was 8 prims, the sculpted version (made very simply with Sculpt Crafter) is just 3 prims and is actually more realistically structured, featuring support struts for the shade and a bulb.

The sculpted lamp is actually the booty in my bottle contributed to The Great New Babbage Bar Crawl.

A few days ago I discovered that Mesh Studio existed. It has been around a while it seems but I had managed to not notice its appearance. So I trekked over to the store and bought a copy, I used a few prim based items to experiment.

So today we are going to recreate the Roycroft lamp but as a mesh.

Can we beat 3 prims? Can we make it look better?

You will have to wait to find out I am afraid. Bedtime for Beq.





A new journal unlike the old

This journal has been sitting on my shelf for sometime but has had no purpose. One thing was always clear it would not be story based, but would be used to other effects. For the moment I think I am going to use it to record my adventures away from the role play, by which I think I mean building.

I have just begun my adventures into the wonders of Mesh, in particular.

Labels