0027338: Minor corrections in Tcl samples and documentation
[occt.git] / samples / tcl / materials.tcl
1 # Script displays properties of different materials available in OCCT
2
3 #Category: Visualization
4 #Title: Material properties in viewer
5
6 set THE_MATERIALS {brass bronze copper gold jade neon_phc pewter obsidian plaster plastic satin silver steel stone chrome aluminium water glass diamond charcoal}
7 set THE_COLORS    {default red green blue1}
8 set THE_ROW_DIST  35
9
10 proc drawLabels {} {
11   set x 20
12   set y 15
13   set r 0.098
14   set g 0.098
15   set b 0.098
16   foreach aMatIter $::THE_MATERIALS {
17     vdrawtext "$aMatIter" "$aMatIter" -pos $x $y 0 -color $r $g $b -halign right -valign center -angle 000 -zoom 0 -height 14 -aspect regular -font Arial
18     incr y 10
19   }
20   set x 40
21   set y  5
22   foreach aColIter $::THE_COLORS {
23     if { $aColIter == "red" } {
24       set r 1.0
25       set g 0.0
26       set b 0
27     } elseif { $aColIter == "green" } {
28       set r 0.0
29       set g 1.0
30       set b 0.0
31     } elseif { $aColIter == "blue1" } {
32       set r 0.0
33       set g 0.0
34       set b 1.0
35     }
36     vdrawtext "$aColIter" "$aColIter" -pos $x $y 0 -color $r $g $b -halign center -valign center -angle 000 -zoom 0 -height 14 -aspect regular -font Arial
37     incr x $::THE_ROW_DIST
38   }
39 }
40
41 proc drawObjects {theRow theColor} {
42   set aSize    4
43   set aCtr    -2
44   set aCounter 0
45   set x [expr 30 + $theRow * $::THE_ROW_DIST]
46   set y 15
47   foreach aMatIter $::THE_MATERIALS {
48     set aSph s${theRow}_${aCounter}
49     set aBox b${theRow}_${aCounter}
50     uplevel #0 psphere $aSph $aSize
51     uplevel #0 box     $aBox $aCtr $aCtr $aCtr $aSize $aSize $aSize
52     uplevel #0 ttranslate   $aSph $x $y 0
53     uplevel #0 ttranslate   $aBox [expr $x + 10] $y 0
54     uplevel #0 vdisplay     -noredraw $aSph $aBox
55     uplevel #0 vsetmaterial -noredraw $aSph $aBox $aMatIter
56     if {$theColor != ""} {
57       uplevel #0 vsetcolor  -noredraw $aSph $aBox $theColor
58     }
59     incr aCounter
60     incr y 10
61   }
62 }
63
64 # setup 3D viewer content
65 pload MODELING VISUALIZATION
66
67 catch { vclose View1 }
68 vinit View1 w=768 h=768
69 vclear
70 vtop
71 vglinfo
72 vsetgradientbg 180 200 255 180 180 180 2
73 vlight change 0 pos -1 1 1
74 vsetdispmode 1
75 vrenderparams -msaa 8
76
77 # adjust scene bounding box
78 box bnd 0 0 0 180 210 1
79 vdisplay -noredraw bnd
80 vsetdispmode       bnd 0
81 vfit
82 vremove -noredraw  bnd
83
84 # draw spheres and boxes with different materials
85 drawLabels
86 drawObjects 0 ""
87 drawObjects 1 red
88 drawObjects 2 green
89 drawObjects 3 blue1
90 #vfit
91 vzfit