[GRASS-dev] Re: Nviz animation wish

Maris Nartiss maris.gis at gmail.com
Mon Feb 5 04:35:04 EST 2007


Hi Michael and others,

as I wrote, some time a go I found using NVIZ animation tools too
complex and ended with custom script controlling camera position, view
angle and scene contents. As whole NVIZ is just a large tcl/tk script,
it's not so hard to create own, similar script. Today I wonder how
it's possible, that script was working, but as I have some nice
animations created with that script [1], it should be working ;)

So - if You are short on time to learn how to use NVIZ animation tools
and not affraid from tcl code, feel free to use it for ideas.


NVIZ dev's - sorry for ugly hack around Your hard work,
Maris.

[1] http://mpa.itc.it/markus/grass61/demos/rlake/

2007/1/29, Michael Barton <michael.barton at asu.edu>:
> This discussion has been enlightening. However, it might be good to get back
> to the original wish that prompted it.
>
> Currently, in the NVIZ animation panel, you can set key frames and NVIZ will
> interpolate between the key frames to produce an on-screen animation. It
> will optionally save an image sequence (as per discussion below) that can be
> transformed into an animation file by 3rd party software. This is fine.
> However, the only characteristics animated are the position and orientation
> of the 2.5D rendering.
>
> What I asked was if this could be enhanced to also include the color and
> other features of the rendering. That is, keyframe 1 shows the landscape
> with one color drape, keyframe 2 shows it in a second color drape, and
> keyframe 3 shows it in a 3rd color drape. Then when the animation is run,
> you would see the landscape changing smoothly from color 1 to 2 to 3. If
> desired, you would still output these to an image sequence (rather than to
> an mpeg or other animation file). Similarly, could it handle something like
> z-exaggeration or lighting direction?
>
> So, does the Togl command that drives the keyframe animation now also accept
> color rendering (and other) information, or only position and orientation?
>
> Michael
>
>
>
-------------- next part --------------
# How it works:
# 1) Create NVIZ state file;
# 2) Copy surface ID that You will change (in this example it is lake with changing water level);
# 3) Set camera position;
# 4) Play script in NVIZ.
#
# This script is based on d.nviz output. I wrote it a year(?) a go and now wonder - how it is
# possible that it works?
# Anyway - a good beginning for creating own, custom animation script.
#
# Maris, 05. 02. 2007.
#


# NVIZ state file
SendScriptLineWait "load_state_aux /some/path/to/nviz_state3" script_play

puts "Starts... ";
set FRAMES 264;

# surf*foo is random generated when loading surface. Some normal way must exist,
# currently it is copied from state file.
set mhandle3 [ReturnMapHandle surf*1138896892];

# More info in source:
# src/vizualisation/nviz/anim_support.c
SendScriptLine "Nclear_keys"
SendScriptLine "Nupdate_frames"
SendScriptLine "Nset_numsteps $FRAMES"
SendScriptLine "Nupdate_frames"
#SendScriptLine "Nset_interp_mode linear"
SendScriptLine "Nset_interp_mode spline"
SendScriptLine "Nset_tension 0.1"
SendScriptLine "Nupdate_frames"

# Single camera position with real coordinates
# position.c
SendScriptLine "Nmove_to_real 584633.854316 6409321.829185 90"
SendScriptLine "Nset_focus_real 573750.33564192 6401754.65674798 55"
SendScriptLine "Nadd_key 1 KF_ALL_MASK 1 0.0"

SendScriptLine "Nmove_to_real 591744.816528 6402709.021853 280"
SendScriptLine "Nset_focus_real 573750.33564192 6401754.65674798 55"
SendScriptLine "Nadd_key 2 KF_ALL_MASK 1 0.0"

SendScriptLine "Nmove_to_real 590487.090928 6392080.094127 600"
SendScriptLine "Nset_focus_real 573750.33564192 6401754.65674798 55"
SendScriptLine "Nadd_key 3.5 KF_ALL_MASK 1 0.0"

SendScriptLine "Nmove_to_real 580760.958497 6386028.557726 1000"
SendScriptLine "Nset_focus_real 573750.33564192 6401754.65674798 55"
SendScriptLine "Nadd_key 5.5 KF_ALL_MASK 1 0.0"

SendScriptLine "Nmove_to_real 570099.802071 6387302.139704 2000"
SendScriptLine "Nset_focus_real 573750.33564192 6401754.65674798 55"
SendScriptLine "Nadd_key 9 KF_ALL_MASK 1 0.0"

set num 0

for {set frame 1} {$frame <= $FRAMES} {incr frame} {
set name frame
set num2 [format "%04d" $num]
append name $num2 ".ppm"
# Change perspective per frame(zoom out) :)
#set persp [expr ($frame  * 2)+60 ]
#SendScriptLine "Nchange_persp $persp"

SendScriptLine "global NVIZ_BLANK_MAPS"
 SendScriptLine "set NVIZ_BLANK_MAPS {}"
 if {$frame < $FRAMES} then { ; # Maps are redrawn on evey fourth frame.
  if {[lsearch {} $frame] == -1} then {
   if {[lsearch {} $frame] > -1}  then {
    SendScriptLine "lappend NVIZ_BLANK_MAPS [ExtractMapID $mhandle3]"
   } else {
    set foo [expr int($frame/3)+1]; # redraw every 3rd frame
    # list of all maps - frames. Nasty, but works :)
    # First - set values for displayed surface
    SendScriptLine "$mhandle3 set_att topo [lindex {bun_391 at lake_fill bun_392 at lake_fill bun_393 at lake_fill } $foo]"
    # Then set surface color
    SendScriptLine "$mhandle3 set_att color [lindex {bun_391 at lake_fill bun_392 at lake_fill bun_393 at lake_fill } $foo]"
    # IIRC this was surface position - I set it a bit abowe it's values, so it always is on top.
    SendScriptLine "$mhandle3 set_trans 0 0 [lindex {40.0 40.1 40.2} $foo]"
    # Last thing - set resolution.
    SendScriptLine "$mhandle3 set_res poly 1 1"
#    puts "foo: $foo frame $frame";
   }
  }
 }
SendScriptLine "Ndo_framestep $frame 1"
#puts "Ndo_framestep $frame 1"
after 1;
SendScriptLine "Nwrite_ppm $name "
incr num
}
SendScriptLine "Noff_screen 0"
SendScriptLine "set ScriptPlaying 0"
puts "DONE!"



More information about the grass-dev mailing list