home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / scripts / pov / miraface / hsm2raw.awk < prev    next >
Encoding:
Text File  |  1992-07-13  |  1.9 KB  |  48 lines

  1. # Script to generate raw triangle data from
  2. # Mira Imaging, Inc.'s HyperSpace format.
  3. # Script by Dan Farmer
  4. # Use redirection to produce output file (awk hsm2raw.awk face.hsm > face.raw)
  5. #---------------------------------------
  6. # Phase I, build array of vectors from the first data block
  7. # awk allows a string to be used as an index into an array, so the
  8. # first "word", p1, etc., is used in just this way.  ($1==Word #1, etc.)
  9.  
  10. # $1   $2 $3     $4       $5        $6
  11. # ---------------------------------------
  12. # p1   = pnt(   -0.78,   -0.61,   -0.50 );
  13. #
  14. # Phase II, build the output data from the arrays built above.  Data has
  15. # both 3 and 4 point patches.  These are all written as single triangles.
  16. #
  17. # $1   $2 $3   $4   $5   $6
  18. # ----------------------------
  19. # poly { p430 p421 p301 }
  20. # poly { p302 p306 p429 p430 }
  21.  
  22. # Patch to triangle : <1 2 3>  <1 3 4>
  23. #---------------------------------------
  24. # Phase I: store vectors
  25. $3== "pnt(" {
  26.              gsub(",","")                        # remove all commas
  27.              vector[$1]= $4 " " $5 " " $6        # store vector points
  28.         }
  29.  
  30. # Phase II: write vectors
  31. $1=="poly" {
  32.             if(NF == 6) {   # Already a triangle.  (NF==Number of Fields)
  33.                 printf("%s  ", vector[$3] )      # point #1
  34.                 printf("%s  ", vector[$4] )      # point #2
  35.                 printf("%s\n", vector[$5] )      # point #3
  36.  
  37.             }
  38.             if(NF == 7) {   # Polygon.  Break into 2 triangles.
  39.                 printf("%s  ", vector[$3] )      # point #1
  40.                 printf("%s  ", vector[$4] )      # point #2
  41.                 printf("%s\n", vector[$5] )      # point #3
  42.  
  43.                 printf("%s  ", vector[$3] )      # point #1
  44.                 printf("%s  ", vector[$5] )      # point #3
  45.                 printf("%s\n", vector[$6] )      # point #4
  46.             }
  47.         }
  48.