Saturday, December 16, 2006

Success!

Day 33

Well, Johanna's Necklace Generator is almost finished! After two days of fruitless script-bashing, I swallowed my pride and asked for help on the Scripters of Second Life group. A very polite young man (from Canada, which explains the politeness) spent about an hour and a half with me, ripping out my Euler rotations and replacing them with quaternion math, and then bashing on those until they finally started doing what I needed.

The Necklace Generator is pretty simple, really — to use, at least! It's a script which you put into a cylinder, along with an object representing the chain link you want to use. Edit the script and tell it the name of the link object, how long the link is (which will usually be a little less than the actual length, assuming the links go through each other), whether or not you want it to rotate every other link 90 degrees, how far down you want the chain to come in back, and a couple of other things.

Then you edit your cylinder and stretch it to the dimensions you want. The dimension along the X axis of the cylinder controls how wide the necklace is from front to back (I know, that should be the Y axis, but that would add a whole new layer of math to everything... no thanks!), the Y dimension controls how wide the necklace is from side to side, and the height of the cylinder controls how far down it comes in front. (If you set its Z dimension to 0.010, it suppresses the drop entirely.) How far down it comes in back is controlled by a variable, as mentioned above; it's pretty much a percentage of how far down it comes in front.

Then you just touch the cylinder, and it thinks for a LONG time, and...


...several months later, you have a necklace chain wrapped around the cylinder! (Well, as long as you leave the cylinder with rotation <0,0,0> — it'll ignore the cylinder's rotation and act like it's unrotated regardless.) That slice cut out of the cylinder is to remind me which way is "front". I suppose I'll eventually make a special cylinder texture for the Necklace Generator.


After seeing it, I'm not really sure I like the style of that link — the rings are so thin they disappear when seen edge-on — but you get the idea. And from further away, it doesn't look too bad on the Cheapside Horde cross. As you can see below, the rotations aren't perfect, but it's close enough that only a couple minutes' tweaking are enough to bring everything in line, which is still much better than having to build the whole chain by hand!


The only thing I have left to do is add an option to make it automatically come to a point in front, for pendants and the like.

Also, I'm trying out some new textures for gems. I loaded a test pattern texture (I think it was from Robin Wood's in-world texture tutorial) onto a cylinder tortured into a gemstone shape to see how the faces were actually patterned. After doing a little unrotating, I came up with this texture:



Basically, it's a straight-on view of the gemstone's table and crown, taking up the top 80% of the image (I pasted shrunken copies underneath it as a "bleed" area), with the bottom 20% being the crown "unwrapped" with The GIMP's Polar Coords filter (Filters -> Distorts -> Polar Coords, with "To Polar" unchecked), cropped to the area beneath the points of the table and above the curves of the girdle, and then resized vertically to take up the bottom 20%.

When uploaded to Second Life, and applied to the gemstone, a little massaging the repeats and offsets just a touch, it resulted in this:


It looks a little blurry, because I made the texture at too small a size. But that doesn't matter for this particular gem, because unless people are looking really closely, they probably won't notice.


This is the gem on top of a cube sized to <0.010,0.010,0.010> — the smallest you can make a prim in Second Life without resorting to prim torture:

The gem's prim is actually <0.020,0.020,0.010>, so it's twice as big around as it could be! (I needed to make it bigger to get the proper slope for the crown.) It's a sphere, set to dimple B=0.95, E=1.00, converted into a cylinder, tapered to X=0.95, Y=0.95, and then resized to <0.020,0.020,0.010>.

If you care to try it, feel free to grab the gemstone texture and put it on the prim! The table (the flat part on top) should have its horizontal and vertical repeats per face set to 0.400, the rotation to -90.00 degrees, and the vertical offset at 0.1. The crown (the sloped edges) should be set with a horizontal repeat per face of 1.000, flipped; vertical repeat per face of 4.000, rotation of 0 degrees, a horizontal offset of 0.000, and a vertical offset of 0.300.

(Edit: For some reason, when I followed my original instructions just to make sure I had them right, they didn't produce the results I expected! Above are the corrected instructions.)

3 comments:

SLNatalia said...

Wow Johanna, you put me to shame with your scripting skills! I cant understand a word below like the 3rd line of the original Necklace Generator! :P

Thank you for your great posts! I am learning a lot about what is possible with scripting!

Johanna Hyacinth said...

You're welcome! You know, it strikes me that I've been totally remiss -- the way SL does building is different enough from the way I've done 3D modeling in other programs outside of SL that I found it worthy of posting the little tricks that I learn, but the scripting is so similar to other computer languages that I just skip right over it!

I'll have to see what I can do about that.

ChrisAlex Sands said...

DOH! sometimes i feel a little stupid: while i was reading the part "...feel free to grab the gemstone texture..." i searched the article for a link or SLURL to get the gem texture from :-O Finally i decided to just right click and "safe as" the actual graphics in the article itself... the 128x128 size really didnt ring a bell... ouch!