Tcl
blobby.tcl


return to misc index



This Tcl script provides a procedure for writing a randomized RenderMan Blobby object. Its sole input defines the number of blobbies contained in a unit cube. If you only want to see how a string is written to a file then refer to the final 4 lines of code.

For information about RenderMan blobbies and their use with RenderMan procedureal primities refer to the tutorial "RenderMan Procedural Primitives:Blobbies"


Listing 1


#___________________________________________________
proc transformation { } {
set transform "1 0 0 0  0 1 0 0  0 0 1 0  "
  
set t $transform
append t [format "%1.3f " [expr rand()]]
append t [format "%1.3f " [expr rand()]]
append t [format "%1.3f 1\n" [expr rand()]]
return $t
}
#___________________________________________________
  
#___________________________________________________
proc blobby { num } {
set ellipsoid_ID "1001 "
set index 0
  
set out "TransformBegin\n"
append out "Blobby $num \n"
  
# begin the "code" block
append out "\[\n"
for { set n 0 } { $n < $num } { incr n 1 } {
    append out $ellipsoid_ID
    append out $index
    incr index 16
    append out "\n"
    }
  
# define the blobby operator and indices of
# the blobs forming a "set" ie. group
set add_ID 0
set blob_count $num
append out "$add_ID $blob_count "
for { set n 0 } { $n < $num } { incr n 1 } {
    append out "$n "
    }
append out "\]\n"
# end of the code block
  
# begin the transforms block
append out "\[\n"
for { set n 0 } { $n < $num } { incr n 1 } {
    append out [transformation]
    }
append out "\]\n"
# end of the transforms block
  
# begin the depth map block
append out "\[ \"\" \]\n"
# end of depth map block
  
append out "TransformEnd\n"
return $out
}
#___________________________________________________
  
#___________________________________________________
#     OUTPUT
#___________________________________________________
# Here are two ways to obtain the output from the 
# blobby procedure. Either use the puts to print
# the text to the console or write it to a file.
  
# CONSOLE
set rib [blobby 6]
puts $rib
  
# FILE
set path "/Users/mk/Documents/tutorials"
set fid [open "$path/tcl/examples/blobby.rib" w]
puts $fid $rib
close $fid
          


The input parameters is:

blobby
    num    the number of blobbies
 

		



© 2002- Malcolm Kesson. All rights reserved.