1 # test performance of display of heavy scene involving multiple interactive
2 # objects, on example of 1000 spheres
7 vinit View1 w=1024 h=1024
10 # parameter NB defines number of spheres by each coordinate
12 puts "Creating [expr $NB * $NB * $NB] spheres..."
14 for {set i 0} {$i < $NB} {incr i} {
15 for {set j 0} {$j < $NB} {incr j} {
16 for {set k 0} {$k < $NB} {incr k} {
19 ttranslate s$i$j$k 3.*$i 3.*$j 3.*$k
24 puts "Measuring FPS of display of spheres as separate objects..."
31 puts [set fps_separate [vfps]]
34 puts "Measuring FPS of display of spheres as single object..."
35 eval compound $slist c
39 puts [set fps_compound [vfps]]
42 # redisplay individual spheres, trying to avoid unnecessary internal updates
43 #vfrustumculling 0 ;# try to disable updates of frustum culling structures
44 eval vdisplay -mutable $slist
46 # auxiliary procedure to make random update of variable
47 proc upd {theValueName theDeltaName theTime theToRand} {
48 upvar $theValueName aValue
49 upvar $theDeltaName aDelta
51 # set colors to corner spheres
52 if { $theToRand == 1 } {
53 set aValue [expr $aValue + $aDelta * $theTime / 100.0]
54 set aDelta [expr 0.5 * (rand() - 0.5)]
58 set aRes [expr $aValue + $aDelta * $theTime / 100.0]
61 # move corner spheres in cycle
62 proc animateSpheres {{theDuration 10.0}} {
63 set nb [expr $::NB - 1]
65 # set colors to corner spheres
66 for {set i 0} {$i < $::NB} {incr i $nb} {
67 for {set j 0} {$j < $::NB} {incr j $nb} {
68 for {set k 0} {$k < $::NB} {incr k $nb} {
69 # vaspects -noupdate s$i$j$k -setcolor red -setmaterial plastic
70 vaspects -noupdate s$i$j$k -setcolor red
83 set aTimeFrom [clock clicks -milliseconds]
84 uplevel #0 chrono anAnimTimer reset
85 uplevel #0 chrono anAnimTimer start
87 for {set aFrameIter 1} { $aFrameIter > 0 } {incr aFrameIter} {
88 set aCurrTime [expr [clock clicks -milliseconds] - $aTimeFrom]
89 if { $aCurrTime >= [expr $theDuration * 1000.0] } {
90 puts "Nb Frames: $aFrameIter"
91 puts "Duration: [expr $aCurrTime * 0.001] s"
92 set fps [expr ($aFrameIter - 1) / ($aDuration * 0.001) ]
94 uplevel #0 chrono anAnimTimer stop
95 uplevel #0 chrono anAnimTimer show
99 set aRandTime [expr $aCurrTime - $aPrevRand]
100 if { $aRandTime > 1000 } {
102 set aPrevRand $aCurrTime
105 #puts "PTS: $aCurrTime ms"
106 for {set i 0} {$i < $::NB} {incr i $nb} {
107 for {set j 0} {$j < $::NB} {incr j $nb} {
108 for {set k 0} {$k < $::NB} {incr k $nb} {
109 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]
114 set aDuration [expr [clock clicks -milliseconds] - $aTimeFrom]
117 # sleep 1 ms allowing the user to interact with the viewer
123 puts "Animating movements of corner spheres (10 sec)..."
124 puts "(you can interact with the view during the process)"
125 set fps_animation [animateSpheres 10.0]
128 puts "Performance counters (FPS = \"Frames per second\"):"
130 puts "Spheres as separate interactive objects:"
131 puts " Actual FPS: [lindex $fps_separate 1]"
132 puts " FPS estimate by CPU load: [expr 1000. / [lindex $fps_separate 3]]"
134 puts "Spheres as one interactive object (compound):"
135 puts " Actual FPS: [lindex $fps_compound 1]"
136 puts " FPS estimate by CPU load: [expr 1000. / [lindex $fps_compound 3]]"
138 puts "Animation FPS: $fps_animation"
140 puts "Scene contains [lindex [trinfo c] 3] triangles"
142 puts "Print 'animateSpheres 10.0' to restart animation"