home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / scripts / pov / miraface / hsm2pov.awk < prev    next >
Encoding:
AWK Script  |  1992-07-13  |  2.6 KB  |  77 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 hsm2pov.awk face.hsm > face.pov)
  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. BEGIN {
  25.     print "#include \"colors.inc\""
  26.     print "#include \"textures.inc\""
  27.  
  28.     print "camera {"
  29.     print "    location  <0 0 -25>"
  30.     print "    direction <0 0 2>"
  31.     print "    up <0 1 0>"
  32.     print "    right <1.3333 0 0>"
  33.     print "    look_at <0 0 0>"
  34.     print "}"
  35.     print "object { light_source { <-35 100 -100> color red 1 green 1 blue 1}}"
  36.     print "default { texture { Phong_Shiny color Flesh } }"
  37.  
  38.     print "object {"
  39.     print "  union {"
  40. }
  41.  
  42. # Phase I: store vectors
  43. $3== "pnt(" {
  44.              gsub(",","")                        # remove all commas
  45.              vector[$1]= $4 " " $5 " " $6        # store vector points
  46.         }
  47.  
  48.  
  49.  
  50. # Phase II: write vectors
  51. $1=="poly" {
  52.             if(NF == 6) {   # Already a triangle.  (NF==Number of Fields)
  53.                 printf("    triangle{")
  54.                 printf("<%s>", vector[$3] )      # point #1
  55.                 printf("<%s>", vector[$4] )      # point #2
  56.                 printf("<%s>}\n", vector[$5] )   # point #3
  57.  
  58.             }
  59.             if(NF == 7) {   # Polygon.  Break into 2 triangles.
  60.                 printf("    triangle{")
  61.                 printf("<%s>", vector[$3] )      # point #1
  62.                 printf("<%s>", vector[$4] )      # point #2
  63.                 printf("<%s>}\n", vector[$5] )   # point #3
  64.  
  65.                 printf("    triangle{")
  66.                 printf("<%s>", vector[$3] )      # point #1
  67.                 printf("<%s>", vector[$5] )      # point #3
  68.                 printf("<%s>}\n", vector[$6] )   # point #4
  69.             }
  70.         }
  71.  
  72. END{
  73.     print "  }"
  74.     print "  rotate <0 90 90>       // Turn the face upright and facing screen"
  75.     print "}"
  76. }
  77.