puts "========"
puts "Capping plane perserving material"
puts "========"

set aHatch  [locate_data_file images/hatch_1.png]

pload MODELING VISUALIZATION

puts "Create the geometry"
box b0sole 10 10   0 30 30 70
box b0hole 20 20 -10 10 10 90
bcut b0 b0sole b0hole
box b1 40 20 0 10 30 70
box b2 20 40 0 20 10 70
box b3 0  40 0 20 10 70
box b4 0  10 0 10 30 70
box b5 0   0 0 30 10 70

set aNbParts 6
set aColors { RED YELLOW GREEN GRAY MAGENTA ORANGE }

compound b0 b1 b2 b3 b4 b5 cc

puts "Create the viewer"
vclear
vclose ALL
vinit name=View1 w=512 h=512

vpoint p0 0 0 0
vzbufftrihedron

puts "Display the geometry as dedicated objects"
for { set aPartIter 0 } { $aPartIter < $aNbParts } { incr aPartIter } {
  vdisplay -noupdate -dispMode 1 b${aPartIter}
  set aColor [lindex $aColors $aPartIter]
  vsetcolor -noupdate b${aPartIter} $aColor
}

puts "Display the geometry as sole object"
vdisplay -noupdate -dispMode 1 cc
for { set aPartIter 0 } { $aPartIter < $aNbParts } { incr aPartIter } {
  set aColor [lindex $aColors $aPartIter]
  vaspects -noupdate cc -subShapes b${aPartIter} -setColor $aColor
}
# show also connected interactive object
vconnectto co -70 0 0 cc
vsetdispmode co 1
vsetlocation cc 70 0 0
vfit


set aPln1Z 40
set aPln2Y 15

vpoint p1 0 0 1
vpoint p2 1 0 1
vpoint p3 0 1 1
vplane pp1 p1 p2 p3
vsetlocation -noupdate pp1 25 0 [expr $aPln1Z - 1]
vremove -noupdate p1 p2 p3

vpoint p1 0 1 0
vpoint p2 1 1 0
vpoint p3 0 1 1
vplane pp2 p1 p2 p3
vsetlocation -noupdate pp2 25 $aPln2Y 35
vremove -noupdate p1 p2 p3
verase pp1 pp2
vfit
vdisplay pp1 pp2
vzoom 0.8

puts "Enable capping planes"
vclipplane pln1 -set -equation 0 0 -1 $aPln1Z        -capping 1 -color 0.5 0.5 0.5 -texname $aHatch -texscale 0.02 -0.02 -useObjMaterial 1
vclipplane pln2 -set -equation 0 1 0 [expr -$aPln2Y] -capping 1 -color 0.8 0.8 0.9 -texname $aHatch -texscale 0.02 -0.02
