Version 6 of Scripting with Tcl for computer graphics animation

Updated 2007-03-16 16:19:11

Page by Theo Verelst

The type of language Tcl is obviously most reknowned for to be is 'scripting language' which calls for a comparison with a movie script. Of course that is no coincidence, so let's start small but good with a simple script to govern a computer graphics animation.

Without intent to affiliate with NVidia in this space, recently their Gelato language has been made freely available to run high quality rendering on computers with a recent graphics card of theirs (I think 6200+, though that cheap one is not very well compatible), which comes with a python and C interface.

Being used to Tcl since at least '94 or so, and not liking python very much, I though I´d try what the possibilities and penalties (calling of the interpreter and running a program all the time) of using Tcl for certain rendering calls would be, so I made a very small starting script to rotate the famous teapot in a gelato-rendered scene by a small tcl script run under tclsh from a Cygwin prompt:

 set d [open head.pyg r]
 set t [read $d]
 close $d

 for {set i 0} {$i<50} {incr i 2} {
   set f [open rn.pyg w]
   puts $f $t
   puts $f "Rotate ( $i, 0,0,1)"

   puts $f "Rotate (  0, 0, 0, 1 )"
   puts $f "Input (\"teapot.pyg\")"
   puts $f "PopAttributes ()"
   puts $f ""

   puts $f "Render (\"camera\")";
   puts $f ""
   close $f
   catch {exec gelato -iv -o im$i.tiff rn.pyg}
   puts "finished i=$i";
 }

That´s 25 frames, which can be made into an animation (can be added to the tcl script' by using ffmpeg (I used 'ffmpeg -s 1920x1080 -i imageout%d.jpg -r 25 -s 1920x1080 -b 50000 -f mpeg2video -y ani.mpg', and played it back using (heavy) HW accelerated PureVideo on a 1080 HD compatible screen).

http://82.170.247.158/Wiki/imageout11s.jpg

head.pyg contains mostly after the ´layered shader´ example the graphics scene in gelato-python. the loops calls gelato in a loop from the tcl interpreter, which works ok, the progress bar is visible.

The resulting 25 TIFF files (they can be made HDR too, for those who like that) were converted with this tcl script (under cygwin):

   for {set i 0}  {$i < 50} {incr i 2} {
      exec tifftopnm T/im$i.tiff 2&>/dev/null |  cjpeg  -q 95 -outfile imageout[format "%d"; [expr int($i/2)]].jpg
   }

In this case I used a 1920x1080 (HD) resolution, which made this 1 second 'animation' rendered in about 30 secs IIRC. Quite doable. Oh, I added the envmap on the teapot myself, let me see if I will get requests to put all the files together.

Perfect TCL use!


See also DataViewer


Category Animation