1 # test performance of display of heavy scene involving multiple interactive
2 # objects, on example of 1000 spheres
4 #Category: Visualization
5 #Title: Display of complex scene and animation
10 vinit View1 w=1024 h=1024
13 # parameter NB defines number of spheres by each coordinate
15 puts "Creating [expr $NB * $NB * $NB] spheres..."
17 for {set i 0} {$i < $NB} {incr i} {
18 for {set j 0} {$j < $NB} {incr j} {
19 for {set k 0} {$k < $NB} {incr k} {
22 ttranslate s$i$j$k 3.*$i 3.*$j 3.*$k
27 puts "Measuring FPS of display of spheres as separate objects..."
34 puts [set fps_separate [vfps]]
37 puts "Measuring FPS of display of spheres as single object..."
38 eval compound $slist c
42 puts [set fps_compound [vfps]]
45 # redisplay individual spheres, trying to avoid unnecessary internal updates
46 #vfrustumculling 0 ;# try to disable updates of frustum culling structures
47 eval vdisplay -mutable $slist
49 # auxiliary procedure to make random update of variable
50 proc upd {theValueName theDeltaName theTime theToRand} {
51 upvar $theValueName aValue
52 upvar $theDeltaName aDelta
54 # set colors to corner spheres
55 if { $theToRand == 1 } {
56 set aValue [expr $aValue + $aDelta * $theTime / 100.0]
57 set aDelta [expr 0.5 * (rand() - 0.5)]
61 set aRes [expr $aValue + $aDelta * $theTime / 100.0]
64 # move corner spheres in cycle
65 proc animateSpheres {{theDuration 10.0}} {
66 set nb [expr $::NB - 1]
68 # set colors to corner spheres
69 for {set i 0} {$i < $::NB} {incr i $nb} {
70 for {set j 0} {$j < $::NB} {incr j $nb} {
71 for {set k 0} {$k < $::NB} {incr k $nb} {
72 # vaspects -noupdate s$i$j$k -setcolor red -setmaterial plastic
73 vaspects -noupdate s$i$j$k -setcolor red
86 set aTimeFrom [clock clicks -milliseconds]
87 uplevel #0 chrono anAnimTimer reset
88 uplevel #0 chrono anAnimTimer start
90 for {set aFrameIter 1} { $aFrameIter > 0 } {incr aFrameIter} {
91 set aCurrTime [expr [clock clicks -milliseconds] - $aTimeFrom]
92 if { $aCurrTime >= [expr $theDuration * 1000.0] } {
93 puts "Nb Frames: $aFrameIter"
94 puts "Duration: [expr $aCurrTime * 0.001] s"
95 set fps [expr ($aFrameIter - 1) / ($aDuration * 0.001) ]
97 uplevel #0 chrono anAnimTimer stop
98 uplevel #0 chrono anAnimTimer show
102 set aRandTime [expr $aCurrTime - $aPrevRand]
103 if { $aRandTime > 1000 } {
105 set aPrevRand $aCurrTime
108 #puts "PTS: $aCurrTime ms"
109 for {set i 0} {$i < $::NB} {incr i $nb} {
110 for {set j 0} {$j < $::NB} {incr j $nb} {
111 for {set k 0} {$k < $::NB} {incr k $nb} {
112 uplevel #0 vsetlocation -noupdate s$i$j$k [upd x$i$j$k dx$i$j$k $aRandTime $toRand] [upd y$i$j$k dy$i$j$k $aRandTime $toRand] [upd z$i$j$k dz$i$j$k $aRandTime $toRand]
117 set aDuration [expr [clock clicks -milliseconds] - $aTimeFrom]
120 # sleep 1 ms allowing the user to interact with the viewer
126 puts "Animating movements of corner spheres (10 sec)..."
127 puts "(you can interact with the view during the process)"
128 set fps_animation [animateSpheres 10.0]
131 puts "Performance counters (FPS = \"Frames per second\"):"
133 puts "Spheres as separate interactive objects:"
134 puts " Actual FPS: [lindex $fps_separate 1]"
135 puts " FPS estimate by CPU load: [expr 1000. / [lindex $fps_separate 3]]"
137 puts "Spheres as one interactive object (compound):"
138 puts " Actual FPS: [lindex $fps_compound 1]"
139 puts " FPS estimate by CPU load: [expr 1000. / [lindex $fps_compound 3]]"
141 puts "Animation FPS: $fps_animation"
143 puts "Scene contains [lindex [trinfo c] 3] triangles"
145 puts "Print 'animateSpheres 10.0' to restart animation"