<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "https://www.web3d.org/specifications/x3d-3.0.dtd">
<X3D profile='Immersive' version='3.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-3.0.xsd'>
  <head>
    <meta content='GridXZ_20x20Movable.x3d' name='title'/>
    <meta content='MV4204 class' name='creator'/>
    <meta content='22 November 2000' name='created'/>
    <meta content='28 November 2019' name='modified'/>
    <meta content='Line grid authoring tool for precise measurement in 3D space: drag plane to move along Y axis, click numbers to hide grid. Oriented along XZ plane, size 20m by 20m, default block size 1m by 1m.' name='description'/>
    <meta content='https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/GridXZ_20x20Movable.x3d' name='identifier'/>
    <meta content='X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit' name='generator'/>
    <meta content='../../license.html' name='license'/>
  </head>
  <Scene>
    <!-- Viewpoint above X axis, rotated left and oriented down to face center -->
    <WorldInfo title='GridXZ_20x20Movable.x3d'/>
    <Viewpoint description='XZ grid (0 10 25 relative)' orientation='1 0 0 -0.4' position='0 10 25'/>
    <Transform center='25 10 0' rotation='0 1 0 1.57079'>
      <Viewpoint description='XZ grid (25 10 0 relative)' orientation='1 0 0 -0.4' position='25 10 0'/>
    </Transform>
    <Transform DEF='GridLocation'>
      <Group>
        <TouchSensor DEF='TextLabelTouchSensor' description='select and hold to hide grid'/>
        <Transform translation='0 -0.5 0'>
          <Billboard>
            <Shape>
              <Text DEF='CenterText' string='"origin"'>
                <FontStyle DEF='LABEL_FONT' family='"SANS"' justify='"MIDDLE" "MIDDLE"' size='.4'/>
              </Text>
              <Appearance DEF='DefaultAppearance'>
                <Material/>
              </Appearance>
            </Shape>
          </Billboard>
        </Transform>
        <Transform translation='10 -0.5 10'>
          <Billboard>
            <Shape>
              <Text DEF='SouthEastText' string='"10 0 10"'>
                <FontStyle USE='LABEL_FONT'/>
              </Text>
              <Appearance USE='DefaultAppearance'/>
            </Shape>
          </Billboard>
        </Transform>
        <Transform translation='10 -0.5 -10'>
          <Billboard>
            <Shape>
              <Text DEF='NorthEastText' string='"10 0 -10"'>
                <FontStyle USE='LABEL_FONT'/>
              </Text>
              <Appearance USE='DefaultAppearance'/>
            </Shape>
          </Billboard>
        </Transform>
        <Transform translation='-10 -0.5 -10'>
          <Billboard>
            <Shape>
              <Text DEF='NorthWestText' string='"-10 0 -10"'>
                <FontStyle USE='LABEL_FONT'/>
              </Text>
              <Appearance USE='DefaultAppearance'/>
            </Shape>
          </Billboard>
        </Transform>
        <Transform translation='-10 -0.5 10'>
          <Billboard>
            <Shape>
              <Text DEF='SouthWestText' string='"-10 0 10"'>
                <FontStyle USE='LABEL_FONT'/>
              </Text>
              <Appearance USE='DefaultAppearance'/>
            </Shape>
          </Billboard>
        </Transform>
      </Group>
      <Switch DEF='GridOnOffSwitch' whichChoice='0'>
        <Group>
          <PlaneSensor DEF='GridSensor' description='click and drag to move grid'/>
          <Script DEF='LineSensorAxisY'>
            <field accessType='inputOnly' name='set_translation' type='SFVec3f'/>
            <field accessType='outputOnly' name='translation_changed' type='SFVec3f'/>
            <![CDATA[
ecmascript:

function set_translation (location, timeStamp)  {
	translation_changed [0] = 0;
	translation_changed [1] = location.y;
	translation_changed [2] = 0;
//	Browser.println ('location=' + location + ', translation_changed=' + translation_changed); 
}
]]>
          </Script>
          <Shape DEF='LinesAlignedAlongZ'>
            <IndexedLineSet colorIndex='1 0 0 0 0 2 0 0 0 0 1 0 0 0 0 2 0 0 0 0 1' colorPerVertex='false' coordIndex='1 22 -1 2 23 -1 3 24 -1 4 25 -1 5 26 -1 6 27 -1 7 28 -1 8 29 -1 9 30 -1 10 31 -1 11 32 -1 12 33 -1 13 34 -1 14 35 -1 15 36 -1 16 37 -1 17 38 -1 18 39 -1 19 40 -1 20 41 -1 21 42 -1'>
              <Coordinate DEF='EndPoints' point='0 0 0 -10 0 10 -9 0 10 -8 0 10 -7 0 10 -6 0 10 -5 0 10 -4 0 10 -3 0 10 -2 0 10 -1 0 10 0 0 10 1 0 10 2 0 10 3 0 10 4 0 10 5 0 10 6 0 10 7 0 10 8 0 10 9 0 10 10 0 10 -10 0 -10 -9 0 -10 -8 0 -10 -7 0 -10 -6 0 -10 -5 0 -10 -4 0 -10 -3 0 -10 -2 0 -10 -1 0 -10 0 0 -10 1 0 -10 2 0 -10 3 0 -10 4 0 -10 5 0 -10 6 0 -10 7 0 -10 8 0 -10 9 0 -10 10 0 -10'/>
              <Color color='0.4 0.4 0.4 0.8 0.2 0 0.4 0.1 0.05'/>
            </IndexedLineSet>
          </Shape>
          <Transform DEF='LinesAlignedAlongX' rotation='0 1 0 1.57079'>
            <Shape USE='LinesAlignedAlongZ'/>
          </Transform>
          <Transform translation='10.5 0 0'>
            <Billboard>
              <Shape>
                <Text string='"X"'>
                  <FontStyle USE='LABEL_FONT'/>
                </Text>
                <Appearance DEF='LABEL_APPEARANCE'>
                  <Material diffuseColor='1 1 .3' emissiveColor='.33 .33 .1'/>
                </Appearance>
              </Shape>
            </Billboard>
          </Transform>
          <Transform translation='0 0 10.5'>
            <Billboard>
              <Shape>
                <Text string='"Z"'>
                  <FontStyle USE='LABEL_FONT'/>
                </Text>
                <Appearance USE='LABEL_APPEARANCE'/>
              </Shape>
            </Billboard>
          </Transform>
        </Group>
      </Switch>
    </Transform>
    <Script DEF='CenterTextScript'>
      <field accessType='inputOnly' name='set_translation' type='SFVec3f'/>
      <field accessType='outputOnly' name='value' type='MFString'/>
      <![CDATA[
ecmascript:

// eventOut 'value' is an MFString array to match type of destination Text node string field

function initialize ( ) { 
//	Browser.println ('Grid script initialized, print function works');
//	trace ('Grid script initialized, trace function works');
}

function set_translation (location, timeStamp)  {
	numberOfPlaces = 1000;
	value[0] = (Math.round (location.x * numberOfPlaces) / numberOfPlaces) + ' '
                 + (Math.round (location.y * numberOfPlaces) / numberOfPlaces) + ' '
                 + (Math.round (location.z * numberOfPlaces) / numberOfPlaces); 
//	Browser.println ('location=' + location); 
}
]]>
    </Script>
    <Script DEF='SouthEastTextScript'>
      <field accessType='inputOnly' name='set_translation' type='SFVec3f'/>
      <field accessType='outputOnly' name='value' type='MFString'/>
      <![CDATA[
ecmascript:

function set_translation (location, timeStamp)  {
	numberOfPlaces = 1000;
	value[0] =  10 + ' '
                 + (Math.round (location.y * numberOfPlaces) / numberOfPlaces) + ' '
                 +  10; 
}
]]>
    </Script>
    <Script DEF='NorthEastTextScript'>
      <field accessType='inputOnly' name='set_translation' type='SFVec3f'/>
      <field accessType='outputOnly' name='value' type='MFString'/>
      <![CDATA[
ecmascript:

function set_translation (location, timeStamp)  {
	numberOfPlaces = 1000;
	value[0] =  10 + ' '
                 + (Math.round (location.y * numberOfPlaces) / numberOfPlaces) + ' '
                 + -10; 
}
]]>
    </Script>
    <Script DEF='NorthWestTextScript'>
      <field accessType='inputOnly' name='set_translation' type='SFVec3f'/>
      <field accessType='outputOnly' name='value' type='MFString'/>
      <![CDATA[
ecmascript:

function set_translation (location, timeStamp)  {
	numberOfPlaces = 1000;
	value[0] = -10 + ' '
                 + (Math.round (location.y * numberOfPlaces) / numberOfPlaces) + ' '
                 + -10; 
}
]]>
    </Script>
    <Script DEF='SouthWestTextScript'>
      <field accessType='inputOnly' name='set_translation' type='SFVec3f'/>
      <field accessType='outputOnly' name='value' type='MFString'/>
      <![CDATA[
ecmascript:

function set_translation (location, timeStamp)  {
	numberOfPlaces = 1000;
	value[0] = -10 + ' '
                 + (Math.round (location.y * numberOfPlaces) / numberOfPlaces) + ' '
                 +  10; 
}
]]>
    </Script>
    <Script DEF='SwitchTextOnOffScript'>
      <field accessType='inputOnly' name='isTouched' type='SFBool'/>
      <field accessType='outputOnly' name='touchChoice' type='SFInt32'/>
      <![CDATA[
ecmascript:

function isTouched (value, timeStamp)  {
	if (value == true)
		touchChoice = -1;
	else	touchChoice =  0; 
}
]]>
    </Script>
    <ROUTE fromField='translation_changed' fromNode='GridSensor' toField='set_translation' toNode='LineSensorAxisY'/>
    <!-- Send changed position to text-construction scripts -->
    <ROUTE fromField='translation_changed' fromNode='LineSensorAxisY' toField='set_translation' toNode='GridLocation'/>
    <ROUTE fromField='translation_changed' fromNode='LineSensorAxisY' toField='set_translation' toNode='CenterTextScript'/>
    <ROUTE fromField='translation_changed' fromNode='LineSensorAxisY' toField='set_translation' toNode='SouthEastTextScript'/>
    <ROUTE fromField='translation_changed' fromNode='LineSensorAxisY' toField='set_translation' toNode='NorthEastTextScript'/>
    <ROUTE fromField='translation_changed' fromNode='LineSensorAxisY' toField='set_translation' toNode='NorthWestTextScript'/>
    <ROUTE fromField='translation_changed' fromNode='LineSensorAxisY' toField='set_translation' toNode='SouthWestTextScript'/>
    <!-- Send text showing changed position to output Text nodes -->
    <ROUTE fromField='value' fromNode='CenterTextScript' toField='string' toNode='CenterText'/>
    <ROUTE fromField='value' fromNode='SouthEastTextScript' toField='string' toNode='SouthEastText'/>
    <ROUTE fromField='value' fromNode='NorthEastTextScript' toField='string' toNode='NorthEastText'/>
    <ROUTE fromField='value' fromNode='NorthWestTextScript' toField='string' toNode='NorthWestText'/>
    <ROUTE fromField='value' fromNode='SouthWestTextScript' toField='string' toNode='SouthWestText'/>
    <!-- Enable/disable grid visibility based on user touching coordinate labels -->
    <ROUTE fromField='isActive' fromNode='TextLabelTouchSensor' toField='isTouched' toNode='SwitchTextOnOffScript'/>
    <ROUTE fromField='touchChoice' fromNode='SwitchTextOnOffScript' toField='whichChoice' toNode='GridOnOffSwitch'/>
  </Scene>
</X3D>