Zonja Capalini

2889: Working with very large linksets in Opensim

[Update 20090721:] Added links to source code and a reference, corrected some typos.

[Update 20090723:] You can download an OAR with the sample bottle and the generator at rexxed.com: http://www.rexxed.com/2009/07/klein-bottle/

[Update 20090725:] OSGrid users: the sample bottle and the generator are now available at my store in OSGrid.

Introduction

Most objects in Opensim and Second Life are made of prims. Indeed, if we exceptuate avies, wearables (i.e., non-attachable clothes and body parts), Linden trees and particles, everything you see is made of prims. Prims are small, often uncomplicated geometrical shapes, like a cube, a sphere or a cylinder. By combining (“linking”) prims, builders create more complex objects like houses, vehicles, shoes, hair, jewellery, etc. When prims are linked, the resulting object remembers the order in which they were linked (which is important, for example when an object is scripted) and some other properties; the set comprised of the linked prims and these additional properties is called a link set or linkset.

Linksets in Second Life have several limitations: two prims can’t be linked if they are too far apart, and an object cannot contain more than 256 prims. This is the cause all kind of problems. For example, if you buy a big house, i.e., a house that has more than 256 prims or that it is very large (and therefore its prims are very far apart), the house can’t be assembled into a single object, because of the above rules. Then the house is normally packaged with a rezzer, a scripted assistant that helps you to position the house; once the house is positioned to your liking, you normally ask the rezzer to freeze the house in place, and then delete the rezzer.

0628 - A Klein bottle of 2889 prims (2)

Opensim (when used with an appropriate viewer, like the Hippo viewer) supports large linksets, i.e., objects comprising more than 256 prims. In this post I’ll describe some experiments I made with large and very large linksets. In one of these experiments, I created a single object consisting of 2889 prims. Such extremely large linksets are difficult to manage and create, but once you get them built they work wonderfully.

Klein bottles

0322 - Sculpture by Miki Gymnast at Wales Springs

In August 2008, I visited in the Wales Springs region of Second Life a fantastic sculpture by Suzanne Graves. The sculpture reminded me of a Klein bottle [indeed, technically speaking Ms. Graves’ surface is not Klein-like, because it has an odd number of curls], and I decided to try to write a script to generate Klein bottles (you can find the script in the appendix at the end of this post).

After some attempts, I got the scripts working, and I generated a nice bottle, which I placed on top of my club, in the center of the Condensation Land region in SL. I made a fun video of my friend Ludmilla and myself dancing inside the bottle :-)

Since the bottle existed in Second Life and consisted of thousands of prims, it could not be linked into a single object. The bottle stayed there several months, and when the Openspace fiasco started we had to concentrate in a single island and I had to delete it because Condensation Land got cramped and Second Life has a 15,000 prim limitation.

When I migrated the Condensation Land archipielago to Opensim, I was not able to migrate the bottle, because it was not linked. I still had the program, though. Some tests I made when testing the brand-new Rezzable Private Grid Alpha indicated that the script could not be run unchanged (I tried to run it and brought the sim to its knees :-/). But now I was the owner of my own grid, and could look at the Opensim console while working with the script, so that I could see if something was going wrong, stop the server, etc. And the Hippo Opensim viewer, since version 0.5.0, allowed linksets larger that 256 prims! I absolutely wanted to test this feature and see what could I do with it.

The Opensim experience

I had to adapt my Klein bottle generator for Opensim — the technical details are in the Appendix at the end of the post. Once the generator had run (which took around two hours), I had a collection of 2888 unlinked prims, i.e., the bottle itself (2880 prims), and 8 prims that had beed doubly generated because of a small bug in the program. I then created a central transparent prim destined to serve as the root prim, and started to link the vertices to the root prim.

Up to around 1000 prims everything worked flawlessly. When I tried to link more prims, the linking operation started to be progressively slower; in some cases, I was thrown out of the grid and had to relog. When I got over 2000 prims, further linking was simply impossible: the client got so busy that it stopped responding to pings from the client, and the regions started to drop the scene; the client itself timed out, and threw me out before the linking operation was complete…

What to do? I then realized that I was always using the same linking approach, imported from my SL experience: I was selecting a moderately big number of prims, say 150, and trying to link them to the previously linked large linkset. Maybe if I separately linked the remaining prims into another large linkset, I would be able later to link the two linksets between them? Well, I tried this approach, and it worked! :-) I had to create another, temporary root prim, link the remaining prims to the secondary root prim, link then the two linksets, enter “select linked prims”, unlink the secondary root prim, take the object, and re-rezz it. And that was it! The final linking took some time, but I was not thrown out of Opensim :-), and both taking the object and re-rezzing it took an inordinately big amount of time, but apart from that (which is very understandable if you think of what’s really going on under the hoods) everything worked fine. I was able to move the huge 2889-prims linkset, to rotate it, to copy it, to make it full bright, to apply some glow, and even to set it rotating! :-)

0627 - A Klein bottle of 2889 prims!!! (1)

What seems to be happening (this is all inference, I have not looked at the code)? Well, it appears that if you link “n” prims to an existing linkset, this is equivalent to recreating the linkset “n” times, one for each newly linked prim. This is not a problem when the existing linkset is small and the number of prims is also small, but if you’re attempting to link, say, 300 new prims to an existing linkset of 2000 prims, this involves 300 recalculations of a linkset averaging 2150 prims, and this is too much for the client, which hangs miserably.

To the contrary, if you’ve got two large linksets and you try to link them, there’s only one recalculation operation for the new linkset. And this operation, albeit slow, occurs in a lapse of time small enough so that the client does not crash.

Here’s a video of the new bottle, rotating on top of my club in the Condensation Land grid:

Appendix: Program code

Here is the code for the scripts (I’ll post a link to a downloadable version of the code as soon as I find some time) [Update:] including links to the downloadable source. The main script goes inside a standard cube, and works in the following way: a Klein bottle is a bidimensional surface immersed into a 3D space; apart from an irrelevant twist, it can be considered as the product of two circumferences, and therefore it can be parameterized using two variables “u” and “v”. Some formulas I found at Planetmath calculate the corresponding 3D points taking “u” and “v” as an input.

We generate only the edges (each edge will be a prim; the code for generating the vertices is commented out; I didn’t figure how to generate the sides). Since we are parameterizing in “u” and “v” and we can only generate a finite number of prims, we have to decide on how many partitions of 2*PI we’ll use for “u” and “v”. These are the “m” and “n” variables of our program. In our example, we generate 120 partitions of “u” (the “slices”) and 8 partitions of “v” (the “stripes”).

The program calculates the vertices, and then computes the positions of the edges; the edges are generated by rezzing a small prim (“Cylinder”), which is then rotated, resized and colored; part of this job is done by a small script residing inside “Cylinder”; the script auto-deletes itself on completion.

The drawLineSegment routine I cannibalized from somewhere, but I didn’t write the reference [ I know, I know! :-) If someone knows the reference, I’ll happily include it here] [Update] http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryBezierCurveDemo (thanks, Trevor! :-)).

Please note that I had to insert a llSleep call after each rezzing — otherwise XEngine starts to choke, compilation starts to fail, and the bottle generation aborts.

0629 - Generator code
Download source code

This is the small script that goes inside “Cylinder”.

0629 - Edge code
Download source code

July 20, 2009 - Posted by | OpenSim, Second Life, SL Exodus, Tech News | , , , , , ,

16 Comments »

  1. This looks really cool and will be trying it out on a stand alone soon, and if I am brave enough on one of my reactiongrid sims…

    ps. I think the draw segment routine may be from here http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryBezierCurveDemo

    ..// Bezier Curve Demo 1.0.1
    // Catherine Omega Heavy Industries
    // Modified by Lionel Forager 29-12-2006: Added segment drawing between points. Corrected minor bugs.

    I have been using this Bezier script and pieces of it for lots of things.

    Comment by Trevor Meister | July 20, 2009

  2. Very cool, id love to get a copy of these scripts when they are available.

    Comment by Nebadon Izumi | July 20, 2009

  3. @Trevor: Many thanks for the reference! :-) I’ll update the post accordingly.

    @Trevor, Nebadon: Thanks! :-) Here are the sources: Main script: http://snipplr.com/view/17279/klein-bottle-generator/

    “Cylinder” script: http://snipplr.com/view/17280/klein-bottle-generator–cylinder-code/

    I’ll try to make an oar with the bottle and the generator and post it to rexxed when I find some time too.

    Comment by Zonja Capalini | July 21, 2009

  4. O.o?

    Still Purdy.

    Comment by Kasumi | July 21, 2009

  5. Ha ha ty! :-) Oh, and the code is sexay too :-P

    Comment by Zonja Capalini | July 21, 2009

  6. Nice… I really appreciate this work of yours… ;o)

    Comment by Ben Byron | July 23, 2009

  7. Many thanks, Ben! :-)

    Comment by Zonja Capalini | July 23, 2009

  8. An OAR with the Klein bottle generator and the sample 2889-prims bottle had been posted to rexxed: http://www.rexxed.com/2009/07/klein-bottle/

    And this post has been re-published at Maxping: http://www.maxping.org/technology/platforms/open-simulator/2889-working-with-very-large-linksets-in-opensim.aspx

    Comment by Zonja Capalini | July 23, 2009

  9. The sample bottle and the generator are now also available at my store at OSgrid: http://www.osgrid.org/elgg/pg/generalstore/store/22856/

    (Super-cool feature, btw! :-))

    Comment by Zonja Capalini | July 25, 2009

  10. Loaded the .oar file into one of my Reactiongrid OpenSim regions. Worked like a charm. Now to explore and investigate a bit. Thank-you so much for sharing. I posted a twitter pic via Yfrog here… http://img520.yfrog.com/i/azv.png/

    (btw, do you have a twitter profile I could follow?)

    Comment by Trevor Meister | July 26, 2009

  11. Cool! You’re very welcome!

    Re Twitter: I tried an account at Plurk, but I found it too stressing (it required too much attention). So, no Twitter, sorry. I try to post “important” things in my blog, and “less important” things in my Flickr account, http://www.flickr.com/photos/zonja/

    Comment by Zonja Capalini | July 26, 2009

  12. […] linksets can grow quite large when the linksets themselves are large: for example, the linkset for my 2889 prims Klein bottle is > 10 MB — and, unsurprisingly, moving it means that we have to perform 2889 coordinate […]

    Pingback by Moving and rotating OARs « Zonja Capalini | December 14, 2009

  13. […] The alias facility has another important use: let’s assume, for example, that we want to manipulate objects created by me — but “me” (that is, “Zonja Capalini”) is identified in the OAR by an UUID, not by my name. I do know that I’m the creator of the 2889-prims Klein bottle: […]

    Pingback by Using SQL to manipulate OARs « Zonja Capalini | January 1, 2010

  14. I used your code and was able to rez the 2889 prim object in both Second Life and in the Reaction Grid Open Sim. Second Life did not require a sleep delay. Reaction Grid required a 3 second delay in order to fully rez all 2889 pieces. I then tried to confirm that you can link the object into one link set in open sim. It was exceedingly difficult, but after many attempts and many crashes I did succeed with that. Manipulating an almost 3K prim object is hard on the RAM, but I plan to try to stretch and rotate the object in RG. Meanwhile, I am attempting to alter the script to scale the object up at rezzing, which would save on the stretching attempt. This is a bit difficult the way the script is written, but I will keep you posted on that attempt.

    Comment by Wizard Gynoid | February 22, 2010

  15. Yup, llRezObject has a built-in delay of only 0.1 second in SL, and still it works more reliably than in OpenSim — here’s an area in which clearly OpenSim needs to better; a delay of 3 secs implies that the bottle generation takes forever :-/

    I also crashed endlessly when trying to link the bottle, as you say it’s very hard on RAM — and while your client is trying to keep up, it’s very easy that it stops sending pings to the server and then your connection is aborted, in case your client hasn’t crashed first :-)

    The script is a quick and dirty hack to get the job done. Many thanks for trying it, and for reporting back here!

    Comment by Zonja Capalini | February 22, 2010

  16. […] After 20090430, I added a 2,889-prims Klein bottle, […]

    Pingback by Condensation Land: A status report « Zonja Capalini | August 25, 2010


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: