home *** CD-ROM | disk | FTP | other *** search
/ 3D Graphics Tutorial Collection / 3D Graphics Tutorial Collection.iso / pc / AMAPI / AMAPI5~1.ZIP / installs / Win / Amapi3D515TE.exe / data1.cab / Common / Macros / Helico.tcl < prev    next >
Encoding:
Text File  |  2000-08-01  |  2.2 KB  |  88 lines

  1. #SPEC -realnameid 0
  2.  
  3. # messages table
  4. #@@%000@@FR@@Faire une helicoide@@
  5. #@@%000@@US@@Helicoidal curve@@
  6.  
  7. # no shape
  8. if {[llength [.amapi scene]] == 0} return
  9.  
  10. # it's not a curve
  11. newshape shape [.amapi current]
  12. if {[shape -curve] == 0} return
  13.  
  14. # set closed flag
  15. set closed [shape -closed]
  16.  
  17. # call tool ruler (get origin & offset)
  18. set result [ruler -peakAPoint]
  19. set orig [.match $result orig -point3d]
  20. set offset [.match $result vector -vector]
  21.  
  22. # user canceled ruler
  23. if {$offset == "" || $orig == ""} return
  24.  
  25. # verify origin belongs to curve
  26. set points [shape -points]
  27. for {set i 0} {$i < [llength $points]} {incr i} {
  28.     if {[vertex dist [lindex $points $i] $orig] < 0.001} break
  29. }
  30. if {$i == [llength $points]} return
  31. set index $i
  32.  
  33. #calculate new shape
  34. newshape result {
  35.     # if cloded curve
  36.     if {$closed == 1} {
  37.         addpoint [lindex $points $index]
  38.         set ind [expr {$index + 1}]
  39.         set numpts [llength $points]
  40.         
  41.         for {set i 0} {$i < $numpts} {incr i} {
  42.             if {$ind == $numpts} {
  43.                 set ind 0
  44.             }
  45.         
  46.             set x [expr {[lindex $offset 0] * ($i + 1) / $numpts}]
  47.             set y [expr {[lindex $offset 1] * ($i + 1) / $numpts}]
  48.             set z [expr {[lindex $offset 2] * ($i + 1) / $numpts}]
  49.             
  50.             addpoint [vertex add [list $x $y $z] [lindex $points $ind]]
  51.             
  52.             incr ind
  53.         }
  54.     } else {
  55.         # first mountain
  56.         set ind 0
  57.         set numpts $index
  58.         for {set i 0} {$i < $numpts} {incr i} {
  59.             set x [expr {[lindex $offset 0] * $i / $numpts}]
  60.             set y [expr {[lindex $offset 1] * $i / $numpts}]
  61.             set z [expr {[lindex $offset 2] * $i / $numpts}]
  62.             addpoint [vertex add [list $x $y $z] [lindex $points $ind]]
  63.             
  64.             incr ind
  65.         }
  66.         
  67.         # second mountain
  68.         set ind $index
  69.         set numpts [expr {[llength $points] - $index - 1}]
  70.         for {set i 0} {$i <= $numpts} {incr i} {
  71.             if {$numpts != 0} {
  72.                 set x [expr {[lindex $offset 0] * ($numpts - $i) / $numpts}]
  73.                 set y [expr {[lindex $offset 1] * ($numpts - $i) / $numpts}]
  74.                 set z [expr {[lindex $offset 2] * ($numpts - $i) / $numpts}]
  75.             } else {
  76.                 set x [lindex $offset 0]
  77.                 set y [lindex $offset 1]
  78.                 set z [lindex $offset 2]
  79.             }
  80.             addpoint [vertex add [list $x $y $z] [lindex $points $ind]]
  81.             
  82.             incr ind
  83.         }
  84.     }
  85. }
  86. result -status open
  87. result -checkin
  88.