From comp.graphics.raytracing Tue Jun 7 15:39:54 1994 Path: uniol!zib-berlin.de!news.dfn.de!Germany.EU.net!EU.net!howland.reston.ans.net!sol.ctr.columbia.edu!caen!siemens.engin.umich.edu!jmayer From: jmayer@siemens.engin.umich.edu (Jonathan Mayer) Newsgroups: comp.graphics.raytracing Subject: PERL+RIB=POVRAY Date: 6 Jun 1994 04:53:18 GMT Organization: University of Michigan Engineering, Ann Arbor Lines: 141 Distribution: world Message-ID: <2sua3uINNnf0@srvr1.engin.umich.edu> NNTP-Posting-Host: siemens.engin.umich.edu Summary: Converts some RIB files to POV files. Keywords: renderman, rib, pov, povray, perl, fantastic sex X-Newsreader: TIN [version 1.2 PL2] Here's another script some of you might be useful. This too is still under development, but it's meant to convert Renderman .RIB files over into POV-Ray scene files. Note that it doesn't implement anything NEAR the complete Renderman file format. However, the one thing that it DOES do well is convert over the .RIB files automatically generated using the macintosh application "Swivel 3D" (hint! hint!). Caveat: seems to work well on small Swivel 3D .RIB files.. however, in larger files certain triangles mysteriously vanish. I believe this is caused by some artificial limit on the number of objects in a scene within POV-Ray, but I'm not 100% sure. I'm real proud of this script. It's tiny and fast. This stuff is (c) me -- don't distribute in modified form. If you improve it, e-mail your fixes to me and I'll include 'em. Use at yer own risk. rib2pov -------------------- cut here, eh? ----------------------->8 #! /usr/um/bin/perl # RIB2POV # v.1.0: (c) Jonathan Mayer, 1994 jmayer@engin.umich.edu # # version 1.0 # Converts Renderman RIB files to POVRAY scene description files. # Note that this converter isn't terribly flexible, and is really only # meant to convert RIB files automatically generated by the macintosh # application SWIVEL 3D. It ignores anything it doesn't understand. # I don't know RIB -- I'm making certain assumptions. # # Permission to freely distribute and modify is granted by the # author, provided that all changes are documented and that the # original credits aren't removed, ok? Just check with me before # distributing yer modifications. -jm $COM = "\/\/"; print "$COM Translated by rib2pov, jmayer@engin.umich.edu\n"; print "$COM On ",time,"\n\n"; $StackBreak = "\n**BREAK**\n"; #this is hokey $curobj = ""; @attrStack = (); # this isn't used @objStack = (); # but this is $srcPoly = 0; # just some bookkeeping $destTri = 0; sub POPOBJECT { local ($l); while (($l = pop (@objStack)) ne $StackBreak) { print $l,"\n"; } } while (<>) { if (/^attribute \"identifier\" \".+\" \"(\S+)\"/) { push (@objStack, $curobj); push (@objStack, $StackBreak); push (@objStack, "}"); $curobj = $1; next; } next if ($curobj eq ""); if ((/^polygon ...\[(.*)\]/) || (/^gpolygon \[\d+\] ...\[(.*)\]/)) { # for random polygon A B C D E F... # creates triangles: ... $srcPoly++; local (@n) = split (/[ \t\n]+/, $1); local (@vertexes) = (); ### print "POLY\n"; while (@n) { $Z = pop (@n); $Y = pop (@n); $X = pop (@n); push (@vertexes, "< $X, $Y, $Z >"); ### print " VERTEX: < $X, $Y, $Z >\n"; } local($C); local($A) = pop (@vertexes); local($B) = pop (@vertexes); while (@vertexes) { ### print " TRIANGLE"; $destTri++; $C = pop (@vertexes); # make triangle ABC push (@objStack, "\t}"); push (@objStack, "\t\t$C"); push (@objStack, "\t\t$B,"); push (@objStack, "\t\t$A,"); push (@objStack, "\ttriangle {"); # set stuff up for next triangle $B = $C; } ### print "\n"; next; } if (/^scale (\S+) (\S+) (\S+)\b/) { push (@objStack, "\tscale <$1, $2, $3>"); next; } if (/^translate (\S+) (\S+) (\S+)\b/) { push (@objStack, "\ttranslate <$1, $2, $3>"); next; } if (/^rotate (\S+) (\S+) (\S+) (\S+)\b/) { $rX = $1 * $2; $rY = $1 * $3; $rZ = $1 * $4; push (@objStack, "\trotate <$rX, $rY, $rZ>"); } if (/^color \[(\S+) (\S+) (\S+)\]/) { push (@objStack, "\tpigment { color red $1 green $1 blue $1 }"); next; } if (/^attributeend\b/) { push (@objStack, "\#declare $curobj = union {"); push (@objStack, "\/\/ Object: \"$curobj\" ;)"); push (@objStack, " "); &POPOBJECT; $nextobj = pop (@objStack); push (@objStack, "\tobject { $curobj }"); $curobj = $nextobj; next; } } print "\n\n\/\/ THE END. translated by rib2pov, jmayer@engin.umich.edu ;)\n\n"; print STDERR " Translated $srcPoly polygons into $destTri triangles.\n"; exit (0); # gracefully exit stage left. end of rib2pov ------------- cut here, eh? ----------------------->8 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "Of course ... lager ... the only thing that can kill a vindaloo!" - Red Dwarf Jonathan Mayer - jmayer@engin.umich.edu - jmayer@lylahfive.reslife.cornell.edu