home *** CD-ROM | disk | FTP | other *** search
- # Script to generate raw triangle data from
- # Mira Imaging, Inc.'s HyperSpace format.
- # Script by Dan Farmer
- # Use redirection to produce output file (awk hsm2raw.awk face.hsm > face.raw)
- #---------------------------------------
- # Phase I, build array of vectors from the first data block
- # awk allows a string to be used as an index into an array, so the
- # first "word", p1, etc., is used in just this way. ($1==Word #1, etc.)
-
- # $1 $2 $3 $4 $5 $6
- # ---------------------------------------
- # p1 = pnt( -0.78, -0.61, -0.50 );
- #
- # Phase II, build the output data from the arrays built above. Data has
- # both 3 and 4 point patches. These are all written as single triangles.
- #
- # $1 $2 $3 $4 $5 $6
- # ----------------------------
- # poly { p430 p421 p301 }
- # poly { p302 p306 p429 p430 }
-
- # Patch to triangle : <1 2 3> <1 3 4>
- #---------------------------------------
- # Phase I: store vectors
- $3== "pnt(" {
- gsub(",","") # remove all commas
- vector[$1]= $4 " " $5 " " $6 # store vector points
- }
-
- # Phase II: write vectors
- $1=="poly" {
- if(NF == 6) { # Already a triangle. (NF==Number of Fields)
- printf("%s ", vector[$3] ) # point #1
- printf("%s ", vector[$4] ) # point #2
- printf("%s\n", vector[$5] ) # point #3
-
- }
- if(NF == 7) { # Polygon. Break into 2 triangles.
- printf("%s ", vector[$3] ) # point #1
- printf("%s ", vector[$4] ) # point #2
- printf("%s\n", vector[$5] ) # point #3
-
- printf("%s ", vector[$3] ) # point #1
- printf("%s ", vector[$5] ) # point #3
- printf("%s\n", vector[$6] ) # point #4
- }
- }
-