Sunday, May 6, 2007

Sculpted Prims... with POV-Ray?

Wouldn't you know, they debuted sculpted prims and the Linux voice client on the beta grid while I'm stuck on a business trip with an ancient Dell laptop that barely runs SL, and no 3D software installed? So I downloaded a copy of POV-Ray and set to work on the sculpted prims.

Now, POV-Ray is nowhere near the best choice for this sort of thing. It's just a renderer - you have to do all your modeling in another application, or by describing in plain text the mathematical shapes which make up the model. There's really no good way to accurately turn a CSG model into a texture suitable for sculpted prims. But I like a challenge, so I faked it as best I could.

First I made a texture which, when applied to a model, would give it a color based on its position along each of the three axes. The red component went from 0 where X was -0.5, through 255 where X was +0.5. Green went from 0 to 255 along the Z axis, again bounded from -0.5 to +0.5 (Y and Z are swapped in POV-Ray from the way they are in Second Life). And blue went from 0-255 along the Y axis.

But then the problem was: how to convert this into a texture which could be applied to a sculpted prim in Second Life?

Because the sculpted prim is mapped like a sphere, the first thing which occurred to me was to put a "spherical" camera in the center of the model, set the model to show up in reflections but be invisible to camera, and then surround the model with a 100% reflective sphere. This is far from perfect - as I discovered, most "undercuts" in the model don't work properly. But as long as the model is mostly convex, it works pretty well. For example, here's a simple bottle I made:



It's just a 2D B├ęzier spline rotated around an axis. Here's the POV-Ray code for it:


#declare t_sculpty = texture {
pigment {
average
pigment_map {
[1 gradient x color_map {[0 rgb 0][1 rgb <1,0,0>]}]
[1 gradient y color_map {[0 rgb 0][1 rgb <0,0,1>]}]
[1 gradient z color_map {[0 rgb 0][1 rgb <0,1,0>]}]
}
translate -0.5
}
finish { ambient 3 diffuse 0 }
}

lathe { bezier_spline 24,
<0.000,0.005>, <0.000,0.005>, <0.102,0.005>, <0.102,0.005>,
<0.102,0.005>, <0.102,0.102>, <0.060,0.154>, <0.214,0.212>,
<0.214,0.212>, <0.370,0.270>, <0.450,0.307>, <0.450,0.410>,
<0.450,0.410>, <0.450,0.511>, <0.450,0.957>, <0.450,0.974>,
<0.450,0.974>, <0.450,0.990>, <0.371,0.997>, <0.352,0.990>,
<0.352,0.990>, <0.332,0.985>, <0.175,0.975>, <0.000,0.975>
sturm
translate y*-0.5
scale <1,-1,1>
texture { t_sculpty }
}

sphere { 0, 1.001 inverse
finish { ambient 0 diffuse 0 reflection 1 }
}

camera { spherical location 0 look_at z*-1 }

(I got the points for the spline by drawing a curve in The GIMP, then hovering the mouse over all the control points and handles in sequence.) If you render that out to a 64x64 image (using the highest antialiasing you can!), you get this:


If you then bring that image into Second Life and use it for the sculpted prim, it'll be a really fat bottle. (The closer you can get the model to the boundaries of ±0.5 meters, the better the model will ultimately look.) So I made the bottle as fat as possible in POV-Ray, and then scaled down the prim's X and Y size in Second Life.

So that was amusing, but not very challenging - time to try something else! Admittedly, I'm not a great POV-Ray modeler; fortunately, one of my Gmail accounts had a nifty model I'd gotten from another POV-Ray user, and after a little bit of work, I got bits of it into Second Life:


It's untextured yet, but I think it's still pretty recognizable. Only the primary and secondary hulls are sculpted; the engine nacelles, pylons, "deflector dish" and top/bottom "sensor domes" are regular prims.


Because the sculpted prims use a grid of 32x32 points, some of the fine details get lost. You can see the details at the front of the secondary hull aren't very crisp; neither is the shuttlecraft bay at the back:


Still, it's an awesome addition to the SL modeler's arsenal (and this is only version one of the sculpted prims; Qarl Linden is busy at work on version two). But it looks like I need to try fighting my way through Blender's bizarre interface again if I want to do this right, as I doubt there'll be an exporter for Animation:Master anytime soon...

Addendum: And now a heart-shaped gemstone, textured appropriately!

3 comments:

Merlin Alphabeta said...

Dude that's totally awesome...

I've been trying to figure that out for a minute. I've been playing with spherical projection cams in SL for a long time...

IM me in world sometime...

Anonymous said...

I'm a mathematician and I would love to make sculpties by numbers insteat of mouse clicks - but what happens if the sculpty I need is NOT so fat and some sides con't come near the +-0.5 mark?

Gary Arthur Douglas II (In Second Life, "Gary Bukowski") said...

Dude - that is freaking beautiful. You brought a tear to my eye.

I salute you. Vulcan style. Live long and prosper.