<?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='Room.x3d' name='title'/>
    <meta content='A simple room containing protoype instances for chair, desk lamp, wall clock, etc.' name='description'/>
    <meta content='Frederic Roussille' name='creator'/>
    <meta content='1 April 2001' name='created'/>
    <meta content='20 October 2019' name='modified'/>
    <meta content='https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/Room.x3d' name='identifier'/>
    <meta content='X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit' name='generator'/>
    <meta content='../license.html' name='license'/>
  </head>
  <Scene>
    <!-- externprodeclare : chair -->
    <WorldInfo title='Room.x3d'/>
    <ExternProtoDeclare name='Chair' url='"Chair.x3d#Chair" "https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/Chair.x3d#Chair" "Chair.wrl#Chair" "https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/Chair.wrl#Chair"'>
      <field accessType='inputOutput' name='diffuseColor' type='SFColor'/>
    </ExternProtoDeclare>
    <ExternProtoDeclare name='Desk' url='"Desk.x3d#Desk" "https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/Desk.x3d#Desk" "Desk.wrl#Desk" "https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/Desk.wrl#Desk"'>
      <field accessType='inputOutput' name='diffuseColor' type='SFColor'/>
    </ExternProtoDeclare>
    <ExternProtoDeclare name='WallLamp' url='"WallLamp.x3d#WallLamp" "https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/WallLamp.x3d#WallLamp" "WallLamp.wrl#WallLamp" "https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/WallLamp.wrl#WallLamp"'>
      <field accessType='inputOutput' name='lampColor' type='SFColor'/>
      <field accessType='inputOutput' name='lightColor' type='SFColor'/>
      <field accessType='inputOutput' name='lightIntensity' type='SFFloat'/>
      <field accessType='inputOutput' name='lightAttenuation' type='SFVec3f'/>
      <field accessType='inputOutput' name='radius' type='SFFloat'/>
      <field accessType='inputOutput' name='lightLocation' type='SFVec3f'/>
    </ExternProtoDeclare>
    <NavigationInfo headlight='false'/>
    <Viewpoint description='entry' orientation='1 0 0 -0.2' position='16 23 75'/>
    <Transform scale='0.4 0.4 0.6'>
      <Group>
        <!-- floor -->
        <Shape DEF='wall'>
          <ElevationGrid height='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0' solid='false' xDimension='9' xSpacing='10' zDimension='9' zSpacing='10'/>
          <Appearance DEF='wallpaper'>
            <ImageTexture url='"WallPaper.jpg" "https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/WallPaper.jpg"'/>
            <TextureTransform scale='2 2'/>
            <Material/>
          </Appearance>
        </Shape>
        <!-- left wall -->
        <Transform rotation='0 0 1 1.57'>
          <Shape USE='wall'/>
        </Transform>
        <!-- right wall -->
        <Transform rotation='0 0 1 1.57' translation='80 0 0'>
          <Shape USE='wall'/>
        </Transform>
        <!-- top -->
        <Transform translation='0 80 0'>
          <Shape USE='wall'/>
        </Transform>
        <!-- front wall -->
        <Transform rotation='1 0 0 1.57'>
          <Shape>
            <Appearance USE='wallpaper'/>
            <IndexedFaceSet coordIndex='0 1 2 7 -1 2 3 6 7 -1 4 5 6 3 -1' solid='false'>
              <Coordinate point='0 0 0 25 0 0 25 0 -45 55 0 -45 55 0 0 80 0 0 80 0 -80 0 0 -80'/>
            </IndexedFaceSet>
          </Shape>
        </Transform>
        <!-- door with its interpalotors and sensors -->
        <Transform DEF='transform_door' center='25 0 0'>
          <Transform translation='40 22.5 0'>
            <Shape>
              <Appearance>
                <ImageTexture url='"Door.jpg" "https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/Door.jpg"'/>
              </Appearance>
              <Box size='30 44.5 2'/>
            </Shape>
            <TouchSensor DEF='touch_door' description='touch door to open/close'/>
          </Transform>
          <Script DEF='open_door_js'>
            <field accessType='inputOnly' name='set_open' type='SFTime'/>
            <field accessType='outputOnly' name='keyValue_changed' type='MFRotation'/>
            <field accessType='initializeOnly' name='open' type='SFBool' value='false'/>
            <![CDATA[
ecmascript:

function set_open() {
    keyValue_changed[0][0] = 0;
    keyValue_changed[0][1] = 1;
    keyValue_changed[0][2] = 0;
    keyValue_changed[1][0] = 0;
    keyValue_changed[1][1] = 1;
    keyValue_changed[1][2] = 0;
    keyValue_changed[1][3] = -0.754;
    keyValue_changed[2][0] = 0;
    keyValue_changed[2][1] = 1;
    keyValue_changed[2][2] = 0;

  if(open == false) {
    keyValue_changed[0][3] = 0;
    keyValue_changed[2][3] = -1.57;
    open = true;
  } else {
      if(open == true) {
         keyValue_changed[0][3] = -1.57;
         keyValue_changed[2][3] = 0;
         open = false;
      }
   }
}
]]>
          </Script>
          <TimeSensor DEF='clock' cycleInterval='4.5'/>
          <OrientationInterpolator DEF='open_door' key='0 0.5 1' keyValue='0 1 0 0 0 1 0 0 0 1 0 0'/>
        </Transform>
        <!-- link to nps site -->
        <Anchor description='link to NPS web page' url='"https://www.nps.edu"'>
          <Transform translation='40 22.5 -20'>
            <Shape>
              <Appearance>
                <Material diffuseColor='0 0 0'/>
              </Appearance>
              <Box size='30 44.5 1'/>
            </Shape>
          </Transform>
        </Anchor>
      </Group>
      <!-- Door sound -->
      <Sound direction='0 1 1' location='40 0 0' maxBack='150' maxFront='150'>
        <AudioClip DEF='grinding_door' description='GrindingDoor' url='"GrindingDoor.wav" "https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/GrindingDoor.wav"'/>
      </Sound>
    </Transform>
    <!-- chair inserted -->
    <Transform scale='1.5 1.5 1.5' translation='10 5.3 35'>
      <ProtoInstance name='Chair'>
        <fieldValue name='diffuseColor' value='0 0.3 0.7'/>
      </ProtoInstance>
    </Transform>
    <!-- desk inserted -->
    <Transform rotation='0 1 0 -0.754' scale='0.8 0.8 0.7' translation='18 8.1 28'>
      <ProtoInstance name='Desk'/>
    </Transform>
    <!-- left wall_lamp -->
    <Transform rotation='0 1 0 1.57' scale='2 2 2' translation='0.05 23 20'>
      <ProtoInstance name='WallLamp'>
        <fieldValue name='lampColor' value='0 0 1'/>
        <fieldValue name='lightColor' value='1 1 1'/>
        <fieldValue name='lightIntensity' value='0.8'/>
        <fieldValue name='lightAttenuation' value='0 0 0'/>
        <fieldValue name='radius' value='100'/>
        <fieldValue name='lightLocation' value='0 0 5'/>
      </ProtoInstance>
    </Transform>
    <!-- right wall_lamp -->
    <Transform rotation='0 1 0 -1.57' scale='2 2 2' translation='31.99 23 20'>
      <ProtoInstance name='WallLamp'>
        <fieldValue name='lampColor' value='0 0 1'/>
        <fieldValue name='lightColor' value='1 1 1'/>
        <fieldValue name='lightIntensity' value='0.8'/>
        <fieldValue name='lightAttenuation' value='0 0 0'/>
        <fieldValue name='radius' value='100'/>
        <fieldValue name='lightLocation' value='0 0 -5'/>
      </ProtoInstance>
    </Transform>
    <!-- clock inserted on the wall -->
    <Transform translation='16 22.5 0'>
      <Inline url='"WallClock.x3d" "https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/WallClock.x3d" "WallClock.wrl" "https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/WallClock.wrl"'/>
    </Transform>
    <!-- desk lamp inserted in the scene -->
    <Transform scale='15 15 15' translation='16 8.6 25'>
      <Inline url='"DeskLamp.x3d" "https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/DeskLamp.x3d" "DeskLamp.wrl" "https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/DeskLamp.wrl"'/>
    </Transform>
    <!-- routes for the door -->
    <ROUTE fromField='touchTime' fromNode='touch_door' toField='startTime' toNode='clock'/>
    <ROUTE fromField='touchTime' fromNode='touch_door' toField='set_open' toNode='open_door_js'/>
    <ROUTE fromField='touchTime' fromNode='touch_door' toField='startTime' toNode='grinding_door'/>
    <ROUTE fromField='keyValue_changed' fromNode='open_door_js' toField='set_keyValue' toNode='open_door'/>
    <ROUTE fromField='fraction_changed' fromNode='clock' toField='set_fraction' toNode='open_door'/>
    <ROUTE fromField='value_changed' fromNode='open_door' toField='set_rotation' toNode='transform_door'/>
  </Scene>
</X3D>