switch_1_00.x3d source
<?xml version="1.0" encoding="UTF-8"?>

<X3D>
<Scene>
<Viewpoint position='0 0 5'/>
<NavigationInfo
type='"EXAMINE"'
/>

<Switch DEF='Sw'>
<!-- 0 球 -->
<Shape DEF='Sp0'>
<Appearance>
<Material diffuseColor='1 1 0'/>
</Appearance>
<Sphere/>
</Shape>

<!-- 1 円錐 -->
<Shape DEF='Sp1'>
<Appearance>
<Material diffuseColor='1 0 1'/>
</Appearance>
<Cone/>
</Shape>

<!-- 2 円柱 -->
<Shape DEF='Sp2'>
<Appearance>
<Material diffuseColor='0 1 1'/>
</Appearance>
<Cylinder/>
</Shape>
</Switch>

<!-- メニュー -->
<Transform translation='-1 -1.5 0' scale='0.2 0.2 0.2'>
<Shape USE='Sp0'/>
<TouchSensor DEF='ThS0'/>
</Transform>
<Transform translation='0 -1.5 0' scale='0.2 0.2 0.2'>
<Shape USE='Sp1'/>
<TouchSensor DEF='ThS1'/>
</Transform>
<Transform translation='1 -1.5 0' scale='0.2 0.2 0.2'>
<Shape USE='Sp2'/>
<TouchSensor DEF='ThS2'/>
</Transform>

<!-- スクリプト -->
<Script DEF='Sc'>
<field accessType='inputOnly' type='SFTime' name='choiceSp'/>
<field accessType='outputOnly' type='SFInt32' name='whichChoice'/>
<field accessType='initializeOnly' type='MFNode' name='ThSs'>
<TouchSensor USE='ThS0'/>
<TouchSensor USE='ThS1'/>
<TouchSensor USE='ThS2'/>
</field>
<field accessType='initializeOnly' type='SFNode' name='thisSc'>
<Script USE='Sc'/>
</field>
<![CDATA[ecmascript:
function initialize () {

// ROUTE from TouchSensor to this script is added.
for ( var i = 0; i < ThSs.length; i++ ) {

Browser.addRoute ( ThSs[i], 'touchTime', thisSc, 'choiceSp' );

}

}

function choiceSp () {

// Shape relevant to TouchSensor whose isOver is TRUE is chosen.
for ( var i = 0; i < ThSs.length; i++ ) {

if ( ThSs[i].isOver ) whichChoice = i;

}

}
]]>
</Script>
<ROUTE fromNode='Sc' fromField='whichChoice' toNode='Sw' toField='whichChoice'/>
</Scene>
</X3D>