So you made a nifty bas relief of some coolio stones. And now you want to use that in yer builds, but it would be handy to have one that's a bit rounder....
One way is to take the flat plane and roll it up into a cylinder.
This code snippit does this. The idea is to plot the values from the plane, around a circle, for each slice of the sculpt map.
This code assumes that the sculpt map is saved in PPM ASCII format. I am using AWK as its a clean protocode. So it should be usable in most any language.
This code takes the Z value, and encodes it into the X,Y values based on a simple sin/cos calculation. The Z value adjusts the Radius length used to calculate the point. This bends the height map around the curve!
| Code: |
#!/usr/local/bin/gawk -f
#
BEGIN {
print "P3 256 256 255" ;
PI = 3.1415926535897932384626433832795 ;
DEG_TO_RAD = PI / 180 ;
deg = ( 360 / 256 ) ;
radius = ( 256 / PI ) / 2 ;
dia = radius*2 ;
while( getline tstr < "test.ppm" > 0 ) {
tcnt = tcnt + 1 ;
if( tcnt > 1 ) {
split( tstr, tary, " " ) ;
x = tary[1] ;
y = tary[2] ;
z = tary[3] / 20 ;
rads = ( deg * y ) * DEG_TO_RAD ;
r = radius + z ;
x = (r*sin(rads))+127.5 ;
y = (r*cos(rads))+127.5 ;
printf "%s %s %s\n",int(x)-1,int(y)-1,tary[1] ;
}
}
}
|