<?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='GridXY_20x20Movable.x3d' name='title'/>
    <meta content='Don Brutzman' 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 Z axis, click numbers to hide grid. Oriented along XY 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/GridsExample.x3d' name='reference'/>
    <meta content='https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/GridXY_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>
    <WorldInfo title='GridXY_20x20Movable.x3d'/>
    <Viewpoint description='XY grid (0 0 30 relative)' position='0 0 30'/>
    <Viewpoint description='XY grid (35 0 20 relative)' orientation='0 1 0 1.06' position='35 0 20'/>
    <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 10.5 0'>
          <Billboard>
            <Shape>
              <Text DEF='UpperRightText' string='"10 10 0"'>
                <FontStyle USE='LABEL_FONT'/>
              </Text>
              <Appearance USE='DefaultAppearance'/>
            </Shape>
          </Billboard>
        </Transform>
        <Transform translation='-10 10.5 0'>
          <Billboard>
            <Shape>
              <Text DEF='UpperLeftText' string='"-10 10 0"'>
                <FontStyle USE='LABEL_FONT'/>
              </Text>
              <Appearance USE='DefaultAppearance'/>
            </Shape>
          </Billboard>
        </Transform>
        <Transform translation='-10 -10.5 0'>
          <Billboard>
            <Shape>
              <Text DEF='LowerLeftText' string='"-10 -10 0"'>
                <FontStyle USE='LABEL_FONT'/>
              </Text>
              <Appearance USE='DefaultAppearance'/>
            </Shape>
          </Billboard>
        </Transform>
        <Transform translation='10 -10.5 0'>
          <Billboard>
            <Shape>
              <Text DEF='LowerRightText' string='"10 -10 0"'>
                <FontStyle USE='LABEL_FONT'/>
              </Text>
              <Appearance USE='DefaultAppearance'/>
            </Shape>
          </Billboard>
        </Transform>
      </Group>
      <Switch DEF='GridOnOffSwitch' whichChoice='0'>
        <Transform rotation='1 0 0 1.57079'>
          <PlaneSensor DEF='GridSensor' description='click and drag to move grid'/>
          <Script DEF='LineSensorAxisZ'>
            <field accessType='inputOnly' name='set_translation' type='SFVec3f'/>
            <field accessType='outputOnly' name='translation_changed' type='SFVec3f'/>
            <![CDATA[
ecmascript:

// local-coordinates vertical Y is world-coordinates axis Z
function set_translation (location, timeStamp)  {
	translation_changed [0] = 0;
	translation_changed [1] = 0;
	translation_changed [2] = location.y;
//	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 rotation='1 0 0 -1.57079' 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 rotation='1 0 0 -1.57079' translation='0 0 -10.5'>
            <Billboard>
              <Shape>
                <Text string='"Y"'>
                  <FontStyle USE='LABEL_FONT'/>
                </Text>
                <Appearance USE='LABEL_APPEARANCE'/>
              </Shape>
            </Billboard>
          </Transform>
        </Transform>
      </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='UpperRightTextScript'>
      <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 + ' ' +  10 + ' '
                 + (Math.round (location.z * numberOfPlaces) / numberOfPlaces); 
}
]]>
    </Script>
    <Script DEF='UpperLeftTextScript'>
      <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 + ' ' + 10 + ' '
                 + (Math.round (location.z * numberOfPlaces) / numberOfPlaces); 
}
]]>
    </Script>
    <Script DEF='LowerLeftTextScript'>
      <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 + ' ' + -10 + ' '
                 + (Math.round (location.z * numberOfPlaces) / numberOfPlaces); 
}
]]>
    </Script>
    <Script DEF='LowerRightTextScript'>
      <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 + ' ' +  -10 + ' '
                 + (Math.round (location.z * numberOfPlaces) / numberOfPlaces); 
}
]]>
    </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='LineSensorAxisZ'/>
    <!-- Send changed position to text-construction scripts -->
    <ROUTE fromField='translation_changed' fromNode='LineSensorAxisZ' toField='set_translation' toNode='GridLocation'/>
    <ROUTE fromField='translation_changed' fromNode='LineSensorAxisZ' toField='set_translation' toNode='CenterTextScript'/>
    <ROUTE fromField='translation_changed' fromNode='LineSensorAxisZ' toField='set_translation' toNode='UpperRightTextScript'/>
    <ROUTE fromField='translation_changed' fromNode='LineSensorAxisZ' toField='set_translation' toNode='UpperLeftTextScript'/>
    <ROUTE fromField='translation_changed' fromNode='LineSensorAxisZ' toField='set_translation' toNode='LowerLeftTextScript'/>
    <ROUTE fromField='translation_changed' fromNode='LineSensorAxisZ' toField='set_translation' toNode='LowerRightTextScript'/>
    <!-- Send text showing changed position to output Text nodes -->
    <ROUTE fromField='value' fromNode='CenterTextScript' toField='string' toNode='CenterText'/>
    <ROUTE fromField='value' fromNode='UpperRightTextScript' toField='string' toNode='UpperRightText'/>
    <ROUTE fromField='value' fromNode='UpperLeftTextScript' toField='string' toNode='UpperLeftText'/>
    <ROUTE fromField='value' fromNode='LowerLeftTextScript' toField='string' toNode='LowerLeftText'/>
    <ROUTE fromField='value' fromNode='LowerRightTextScript' toField='string' toNode='LowerRightText'/>
    <!-- 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>