package Savage.Environment.TimeOfDay;

import org.web3d.x3d.jsail.Core.*;
import org.web3d.x3d.jsail.EnvironmentalEffects.*;
import org.web3d.x3d.jsail.fields.*;
import org.web3d.x3d.jsail.Geometry3D.*;
import org.web3d.x3d.jsail.Grouping.*;
import org.web3d.x3d.jsail.Interpolation.*;
import org.web3d.x3d.jsail.Lighting.*;
import org.web3d.x3d.jsail.Navigation.*;
import org.web3d.x3d.jsail.Networking.*;
import org.web3d.x3d.jsail.PointingDeviceSensor.*;
import org.web3d.x3d.jsail.Rendering.*;
import org.web3d.x3d.jsail.Scripting.*;
import org.web3d.x3d.jsail.Shape.*;
import org.web3d.x3d.jsail.Text.*;

// Javadoc metadata annotations follow, see below for X3DJSAIL Java source code.
/**
 * <p> Control scene lighting to simulate time of day, and also modify Fog for visibility. </p>
 <p> Related links: Catalog page <a href="../../../../Environment/TimeOfDay/TimeOfDayIndex.html" target="_blank">TimeOfDay</a>,  source <a href="../../../../Environment/TimeOfDay/TimeOfDay.java">TimeOfDay.java</a>, <a href="https://www.web3d.org/x3d/content/examples/X3dResources.html" target="_blank">X3D Resources</a>, <a href="https://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html" target="_blank">X3D Scene Authoring Hints</a>, and <a href="https://www.web3d.org/x3d/content/X3dTooltips.html" target="_blank">X3D Tooltips</a>. </p>
	<table style="color:black; border:0px solid; border-spacing:10px 0px;">
        <caption>Scene Meta Information</caption>
		<tr style="background-color:silver; border-color:silver;">
			<td style="text-align:center; padding:10px 0px;"><i>meta tags</i></td>
			<td style="text-align:left;   padding:10px 0px;">&nbsp; Document Metadata </td>
		</tr>

		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> title </i> </td>
			<td> <a href="../../../../Environment/TimeOfDay/TimeOfDay.x3d">TimeOfDay.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> creator </i> </td>
			<td> Joe Roth </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 29 December 2000 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> modified </i> </td>
			<td> 20 October 2019 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> Control scene lighting to simulate time of day, and also modify Fog for visibility. </td>
		</tr>
		<tr style="color:burntorange">
			<td style="text-align:right; vertical-align: text-top;"> <i> warning </i> </td>
			<td> Fog affects 3D objects but not background in scene. </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> identifier </i> </td>
			<td> <a href="https://www.web3d.org/x3d/content/examples/Savage/Environment/TimeOfDay/TimeOfDay.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/Savage/Environment/TimeOfDay/TimeOfDay.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> generator </i> </td>
			<td> X3D-Edit 3.3, <a href="https://www.web3d.org/x3d/tools/X3D-Edit" target="_blank">https://www.web3d.org/x3d/tools/X3D-Edit</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> license </i> </td>
			<td> <a href="../../../../Environment/TimeOfDay/../../license.html">../../license.html</a> </td>
		</tr>
		<tr style="background-color:silver; border-color:silver;">
			<td style="text-align:center;" colspan="2">  &nbsp; </td>
		</tr>
	</table>

	<p>
		This program uses the
		<a href="https://www.web3d.org/specifications/java/X3DJSAIL.html" target="_blank">X3D Java Scene Access Interface Library (X3DJSAIL)</a>.
		It has been produced using the 
		<a href="https://www.web3d.org/x3d/stylesheets/X3dToJava.xslt" target="_blank">X3dToJava.xslt</a>
		stylesheet
	       (<a href="https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/X3dToJava.xslt" target="_blank">version control</a>)
                which is used to create Java source code from an original <code>.x3d</code> model.
	</p>

	* @author Joe Roth
 */

public class TimeOfDay
{
	/** Default constructor to create this object. */
	public TimeOfDay ()
	{
	  initialize();
	}

	/** Create and initialize the X3D model for this object. */
	public final void initialize()
	{
            try { // catch-all
  x3dModel = new X3D().setProfile(X3D.PROFILE_IMMERSIVE).setVersion(X3D.VERSION_3_3)
  .setHead(new head()
    .addMeta(new meta().setName(meta.NAME_TITLE      ).setContent("TimeOfDay.x3d"))
    .addMeta(new meta().setName(meta.NAME_CREATOR    ).setContent("Joe Roth"))
    .addMeta(new meta().setName(meta.NAME_CREATED    ).setContent("29 December 2000"))
    .addMeta(new meta().setName(meta.NAME_MODIFIED   ).setContent("20 October 2019"))
    .addMeta(new meta().setName(meta.NAME_DESCRIPTION).setContent("Control scene lighting to simulate time of day, and also modify Fog for visibility."))
    .addMeta(new meta().setName(meta.NAME_WARNING    ).setContent("Fog affects 3D objects but not background in scene."))
    .addMeta(new meta().setName(meta.NAME_IDENTIFIER ).setContent("https://www.web3d.org/x3d/content/examples/Savage/Environment/TimeOfDay/TimeOfDay.x3d"))
    .addMeta(new meta().setName(meta.NAME_GENERATOR  ).setContent("X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit"))
    .addMeta(new meta().setName(meta.NAME_LICENSE    ).setContent("../../license.html")))
  .setScene(new Scene()
    .addChild(new WorldInfo().setTitle("TimeOfDay.x3d"))
    .addChild(new ExternProtoDeclare("ClockMechanism").setName("ClockMechanism").setUrl(new String[] {"ClockMechanismPROTO.x3d#ClockMechanism","https://www.web3d.org/x3d/content/examples/Savage/Environment/TimeOfDay/ClockMechanismPROTO.x3d#ClockMechanism","ClockMechanismPROTO.wrl#ClockMechanism","https://www.web3d.org/x3d/content/examples/Savage/Environment/TimeOfDay/ClockMechanismPROTO.wrl#ClockMechanism","http://www.cgrg.ohio-state.edu/%257Epgerstma/protolib/protolib/ClockMechanism/ClockMechanismPROTO.wrl#ClockMechanism"})
      .addField(new field().setName("set_hour").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INPUTONLY))
      .addField(new field().setName("set_minute").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INPUTONLY))
      .addField(new field().setName("set_second").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INPUTONLY))
      .addField(new field().setName("autoClock").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
      .addField(new field().setName("hour").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
      .addField(new field().setName("minute").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
      .addField(new field().setName("second").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
      .addField(new field().setName("hourHandAxis").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
      .addField(new field().setName("minuteHandAxis").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
      .addField(new field().setName("secondHandAxis").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
      .addField(new field().setName("twentyFourHours").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
      .addField(new field().setName("hour_changed").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
      .addField(new field().setName("minute_changed").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
      .addField(new field().setName("second_changed").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
      .addField(new field().setName("hourHand_changed").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
      .addField(new field().setName("minuteHand_changed").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
      .addField(new field().setName("secondHand_changed").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
      .addField(new field().setName("hourpercent_changed").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_OUTPUTONLY)))
    .addChild(new ProtoInstance("ClockMechanism", "ClockMechanism").setContainerField("children"))
    .addComments(" Note headlight turned off in NavigationInfo. Most browsers allow user toggling headlight also. ")
    .addComments(" This NavigationInfo node is bound at runtime and overrides the NavigationInfo headlight setting within the Inlined scene. ")
    .addChild(new Background().setGroundColor(new MFColor(new double[] {0.0,0.0,0.0})))
    .addChild(new Background().setGroundAngle(new double[] {0.1,1.309,1.570796}).setGroundColor(new MFColor(new double[] {0.0,0.0,0.0,0.0,0.1,0.3,0.0,0.2,0.5,0.0,0.3,0.8})).setSkyAngle(new double[] {0.1,0.15,1.309,1.57079}).setSkyColor(new MFColor(new double[] {0.4,0.4,0.1,0.4,0.4,0.1,0.0,0.1,0.3,0.0,0.2,0.6,0.8,0.8,0.8})).setBackUrl(new String[] {"urn:web3d:media:textures/panoramas/ocean_3_back.jpg","../../../Basic/UniversalMediaPanoramas/ocean_3_back.jpg","https://www.web3d.org/WorkingGroups/media/textures/panoramas/ocean_3_back.jpg","https://www.web3d.org/x3d/content/examples/Basic/UniversalMediaPanoramas/ocean_3_back.jpg","http://www.web3dmedia.com/UniversalMedia/textures/panoramas/ocean_3_back.jpg","http://www.officetowers.com/UniversalMedia/textures/panoramas/ocean_3_back.jpg","http://geometrek.com/UniversalMedia/textures/panoramas/ocean_3_back.jpg","http://www.sc.ehu.es/ccwgamoa/UniversalMedia/textures/panoramas/ocean_3_back.jpg"}).setBottomUrl(new String[] {"urn:web3d:media:textures/panoramas/ocean_3_bottom.jpg","../../../Basic/UniversalMediaPanoramas/ocean_3_bottom.jpg","https://www.web3d.org/WorkingGroups/media/textures/panoramas/ocean_3_bottom.jpg","https://www.web3d.org/x3d/content/examples/Basic/UniversalMediaPanoramas/ocean_3_bottom.jpg","http://www.web3dmedia.com/UniversalMedia/textures/panoramas/ocean_3_bottom.jpg","http://www.officetowers.com/UniversalMedia/textures/panoramas/ocean_3_bottom.jpg","http://geometrek.com/UniversalMedia/textures/panoramas/ocean_3_bottom.jpg","http://www.sc.ehu.es/ccwgamoa/UniversalMedia/textures/panoramas/ocean_3_bottom.jpg"}).setFrontUrl(new String[] {"urn:web3d:media:textures/panoramas/ocean_3_front.jpg","../../../Basic/UniversalMediaPanoramas/ocean_3_front.jpg","https://www.web3d.org/WorkingGroups/media/textures/panoramas/ocean_3_front.jpg","https://www.web3d.org/x3d/content/examples/Basic/UniversalMediaPanoramas/ocean_3_front.jpg","http://www.web3dmedia.com/UniversalMedia/textures/panoramas/ocean_3_front.jpg","http://www.officetowers.com/UniversalMedia/textures/panoramas/ocean_3_front.jpg","http://geometrek.com/UniversalMedia/textures/panoramas/ocean_3_front.jpg","http://www.sc.ehu.es/ccwgamoa/UniversalMedia/textures/panoramas/ocean_3_front.jpg"}).setLeftUrl(new String[] {"urn:web3d:media:textures/panoramas/ocean_3_left.jpg","../../../Basic/UniversalMediaPanoramas/ocean_3_left.jpg","https://www.web3d.org/WorkingGroups/media/textures/panoramas/ocean_3_left.jpg","https://www.web3d.org/x3d/content/examples/Basic/UniversalMediaPanoramas/ocean_3_left.jpg","http://www.web3dmedia.com/UniversalMedia/textures/panoramas/ocean_3_left.jpg","http://www.officetowers.com/UniversalMedia/textures/panoramas/ocean_3_left.jpg","http://geometrek.com/UniversalMedia/textures/panoramas/ocean_3_left.jpg","http://www.sc.ehu.es/ccwgamoa/UniversalMedia/textures/panoramas/ocean_3_left.jpg"}).setRightUrl(new String[] {"urn:web3d:media:textures/panoramas/ocean_3_right.jpg","../../../Basic/UniversalMediaPanoramas/ocean_3_right.jpg","https://www.web3d.org/WorkingGroups/media/textures/panoramas/ocean_3_right.jpg","https://www.web3d.org/x3d/content/examples/Basic/UniversalMediaPanoramas/ocean_3_right.jpg","http://www.web3dmedia.com/UniversalMedia/textures/panoramas/ocean_3_right.jpg","http://www.officetowers.com/UniversalMedia/textures/panoramas/ocean_3_right.jpg","http://geometrek.com/UniversalMedia/textures/panoramas/ocean_3_right.jpg","http://www.sc.ehu.es/ccwgamoa/UniversalMedia/textures/panoramas/ocean_3_right.jpg"}).setTopUrl(new String[] {"urn:web3d:media:textures/panoramas/ocean_3_top.jpg","../../../Basic/UniversalMediaPanoramas/ocean_3_top.jpg","https://www.web3d.org/WorkingGroups/media/textures/panoramas/ocean_3_top.jpg","https://www.web3d.org/x3d/content/examples/Basic/UniversalMediaPanoramas/ocean_3_top.jpg","http://www.web3dmedia.com/UniversalMedia/textures/panoramas/ocean_3_top.jpg","http://www.officetowers.com/UniversalMedia/textures/panoramas/ocean_3_top.jpg","http://geometrek.com/UniversalMedia/textures/panoramas/ocean_3_top.jpg","http://www.sc.ehu.es/ccwgamoa/UniversalMedia/textures/panoramas/ocean_3_top.jpg"}))
    .addChild(new NavigationInfo().setHeadlight(false))
    .addChild(new Group()
      .addChild(new DirectionalLight("SunLight").setAmbientIntensity(0.5).setColor(.25,.25,.25).setDirection(-0.8,-0.2,-0.2))
      .addChild(new ScalarInterpolator("LightAmbient").setKey(new double[] {0.0,0.1,0.5,0.9,1.0}).setKeyValue(new double[] {0.3,0.3,0.7,0.2,0.2}))
      .addChild(new PositionInterpolator("LightDirection").setKey(new double[] {0.0,0.1,0.5,0.9,1.0}).setKeyValue(new MFVec3f(new double[] {0.8,-0.2,-0.2,0.8,-0.2,-0.2,0.0,-1.0,-0.2,-0.8,-0.2,-0.2,-0.8,-0.2,-0.2})))
      .addChild(new Transform().setTranslation(0.0,5.0,135.0)
        .addChild(new Viewpoint().setDescription("Control Panel")))
      .addChild(new Transform().setTranslation(0.0,0.0,100.0)
        .addChild(new Transform().setRotation(-1.0,0.0,0.0,1.57).setTranslation(0.0,-10.0,0.0)
          .addChild(new Inline("Indy").setBboxCenter(0.0,1.0,0.0).setBboxSize(6.0,2.0,6.0).setUrl(new String[] {"indy.x3d","https://www.web3d.org/x3d/content/examples/Savage/Environment/TimeOfDay/indy.x3d","indy.wrl","https://www.web3d.org/x3d/content/examples/Savage/Environment/TimeOfDay/indy.wrl"})))
        .addChild(new Transform().setScale(5.0,5.0,5.0).setTranslation(-3.0,10.0,0.0)
          .addChild(new Inline("clock").setUrl(new String[] {"ClockMechanismExample2.x3d","https://www.web3d.org/x3d/content/examples/Savage/Environment/TimeOfDay/ClockMechanismExample2.x3d","ClockMechanismExample2.wrl","https://www.web3d.org/x3d/content/examples/Savage/Environment/TimeOfDay/ClockMechanismExample2.wrl"}))
          .addChild(new TouchSensor("button").setDescription("click to increment"))
          .addChild(new Transform("M")
            .addChild(new Shape()
              .setAppearance(new Appearance("green")
                .setMaterial(new Material().setEmissiveColor(0.0,1.0,0.0)))
              .setGeometry(new IndexedLineSet().setCoordIndex(new int[] {0,1,2,3,4,5,6,7,-1,7,8,9,10,11,12,13,14,-1,14,15,16,17,18,19,20,21,0,-1})
                .setCoord(new Coordinate().setPoint(new MFVec3f(new double[] {-.02,.705,.04,-.019,.711,.04,-.016,.716,.04,-.012,.721,.04,-.006,.723,.04,0.0,.724,.04,.006,.723,.04,.012,.721,.04,.016,.716,.04,.019,.711,.04,.02,.705,.04,.02,-.005,.04,.019,-.011,.04,.016,-.016,.04,.012,-.021,.04,.006,-.023,.04,0.0,-.024,.04,-.003,-.023,.04,-.012,-.021,.04,-.016,-.016,.04,-.019,-.011,.04,-.02,-.005,.04}))))))
          .addChild(new Transform("H")
            .addChild(new Shape()
              .setAppearance(new Appearance()
                .setMaterial(new Material().setEmissiveColor(0.0,1.0,0.0)))
              .setGeometry(new IndexedLineSet().setCoordIndex(new int[] {0,1,2,3,4,5,6,7,-1,7,8,9,10,11,12,13,14,-1,14,15,16,17,18,19,20,21,0,-1})
                .setCoord(new Coordinate().setPoint(new MFVec3f(new double[] {-.056,.62,.02,-.053,.637,.02,-.045,.653,.02,-.033,.665,.02,-.017,.673,.02,0.0,.676,.02,.017,.673,.02,.033,.665,.02,.045,.653,.02,.053,.637,.02,.056,.62,.02,.056,0.0,.02,.053,-.017,.02,.045,-.033,.02,.033,-.045,.02,.017,-.053,.02,0.0,-.056,.02,-.017,-.053,.02,-.033,-.045,.02,-.045,-.033,.02,-.053,-.017,.02,-.056,0.0,.02}))))))
          .addChild(new Transform("S")
            .addChild(new Shape()
              .setAppearance(new Appearance()
                .setMaterial(new Material().setEmissiveColor(0.0,1.0,0.0)))
              .setGeometry(new IndexedLineSet().setCoordIndex(new int[] {0,1,2,3,4,5,6,7,-1,7,8,9,10,11,12,13,14,-1,14,15,16,17,18,19,20,21,0,-1})
                .setCoord(new Coordinate().setPoint(new MFVec3f(new double[] {-.02,.705,.04,-.019,.711,.04,-.016,.716,.04,-.012,.721,.04,-.006,.723,.04,0.0,.724,.04,.006,.723,.04,.012,.721,.04,.016,.716,.04,.019,.711,.04,.02,.705,.04,.02,-.005,.04,.019,-.011,.04,.016,-.016,.04,.012,-.021,.04,.006,-.023,.04,0.0,-.024,.04,-.003,-.023,.04,-.012,-.021,.04,-.016,-.016,.04,-.019,-.011,.04,-.02,-.005,.04}))))))
          .addChild(new Shape()
            .setAppearance(new Appearance()
              .setMaterial(new Material().setTransparency(1)))
            .setGeometry(new Box())))
        .addChild(new Transform().setScale(5.0,5.0,5.0).setTranslation(5.0,10.0,0.0)
          .addChild(new Switch("ampmswitch").setWhichChoice(0)
            .addChild(new Group()
              .addChild(new Shape()
                .setAppearance(new Appearance().setUSE("green"))
                .setGeometry(new Text().setString(new String[] {"AM"})
                  .setFontStyle(new FontStyle()))))
            .addChild(new Group()
              .addChild(new Shape()
                .setAppearance(new Appearance().setUSE("green"))
                .setGeometry(new Text().setString(new String[] {"PM"})
                  .setFontStyle(new FontStyle())))))
          .addChild(new Script("ampm").setSourceCode("""
ecmascript:

function set_boolean ( boolean_input, eventTime)
{

        if ( boolean_input== false ) { whichchoice = 0;}

	if ( boolean_input== true ) { whichchoice = 1; }

}
""")
            .addField(new field().setName("set_boolean").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("whichchoice").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY)))
          .addChild(new Transform().setScale(4.0,1.0,1.0).setTranslation(-1.0,2.5,0.0)
            .addChild(new Shape()
              .setAppearance(new Appearance()
                .setMaterial(new Material().setTransparency(1)))
              .setGeometry(new Box()))
            .addChild(new TouchSensor("VisibilityButton").setDescription("click to change"))))
        .addChild(new Transform().setScale(5.0,5.0,5.0).setTranslation(-37.0,2.0,0.0)
          .addChild(new Shape()
            .setAppearance(new Appearance().setUSE("green"))
            .setGeometry(new Text().setString(new String[] {"Click on the clock to increment time by one hour."})
              .setFontStyle(new FontStyle().setSize(.7))))
          .addChild(new Transform().setTranslation(0.0,-1.0,0.0)
            .addChild(new Shape()
              .setAppearance(new Appearance().setUSE("green"))
              .setGeometry(new Text().setString(new String[] {"Select the word Visibility to change  visibility range"})
                .setFontStyle(new FontStyle().setSize(.7)))))))
      .addChild(new Transform()
        .addChild(new Shape()
          .setGeometry(new Extrusion().setCrossSection(new MFVec2f(new double[] {0.0,0.0,0.0,100.0,100.0,100.0,100.0,0.0,0.0,0.0})).setSolid(false).setSpine(new MFVec3f(new double[] {-50.0,-50.0,50.0,-50.0,50.0,50.0})))
          .setAppearance(new Appearance()
            .setMaterial(new Material("transparent").setDiffuseColor(0.0,0.0,0.0)))))
      .addChild(new Transform().setRotation(0.0,1.0,0.0,3.14).setTranslation(0.0,0.0,-60.0)
        .addChild(new Viewpoint().setDescription("outside")))
      .addChild(new Script("Incrementor").setSourceCode("""
ecmascript:

function set_boolean ( boolean_input, eventTime)
{
	Browser.println ('boolean_input=' + boolean_input);
	if ( boolean_input == true )
		{ hour_changed = hour_changed + 1;}

        if (hour_changed <= 11){twelvebool = false; }

	if (hour_changed > 11){twelvebool = true; }
	if (hour_changed ==24) {hour_changed = 0;}
}

// separage function needed for set_hour
// hour_changed is an output, it gets set in the function
""")
        .addField(new field().setName("set_boolean").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
        .addField(new field().setName("hour_changed").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
        .addField(new field().setName("twelvebool").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY)))
      .addChild(new Transform().setScale(5.0,5.0,5.0).setTranslation(-18.0,18.0,100.0)
        .addChild(new Switch("FogSwitch").setWhichChoice(0)
          .addChild(new Group()
            .addChild(new Shape()
              .setAppearance(new Appearance().setUSE("green"))
              .setGeometry(new Text().setString(new String[] {"Visibility Unlimited"})
                .setFontStyle(new FontStyle()))))
          .addChild(new Group()
            .addChild(new Shape()
              .setAppearance(new Appearance().setUSE("green"))
              .setGeometry(new Text().setString(new String[] {"Visibility 5000 Meters"})
                .setFontStyle(new FontStyle()))))
          .addChild(new Group()
            .addChild(new Shape()
              .setAppearance(new Appearance().setUSE("green"))
              .setGeometry(new Text().setString(new String[] {"Visibility 2500 Meters"})
                .setFontStyle(new FontStyle()))))
          .addChild(new Group()
            .addChild(new Shape()
              .setAppearance(new Appearance().setUSE("green"))
              .setGeometry(new Text().setString(new String[] {"Visibility 1000 Meters"})
                .setFontStyle(new FontStyle()))))
          .addChild(new Group()
            .addChild(new Shape()
              .setAppearance(new Appearance().setUSE("green"))
              .setGeometry(new Text().setString(new String[] {"Visibility 500 Meters"})
                .setFontStyle(new FontStyle()))))
          .addChild(new Group()
            .addChild(new Shape()
              .setAppearance(new Appearance().setUSE("green"))
              .setGeometry(new Text().setString(new String[] {"Visibility 250 Meters"})
                .setFontStyle(new FontStyle()))))
          .addChild(new Group()
            .addChild(new Shape()
              .setAppearance(new Appearance().setUSE("green"))
              .setGeometry(new Text().setString(new String[] {"Visibility 100 Meters"})
                .setFontStyle(new FontStyle()))))
          .addChild(new Group()
            .addChild(new Shape()
              .setAppearance(new Appearance().setUSE("green"))
              .setGeometry(new Text().setString(new String[] {"Visibility 50 Meters"})
                .setFontStyle(new FontStyle()))))
          .addChild(new Group()
            .addChild(new Shape()
              .setAppearance(new Appearance().setUSE("green"))
              .setGeometry(new Text().setString(new String[] {"Visibility 25 Meters"})
                .setFontStyle(new FontStyle()))))
          .addChild(new Group()
            .addChild(new Shape()
              .setAppearance(new Appearance().setUSE("green"))
              .setGeometry(new Text().setString(new String[] {"Visibility 10 Meters"})
                .setFontStyle(new FontStyle()))))
          .addChild(new Group()
            .addChild(new Shape()
              .setAppearance(new Appearance().setUSE("green"))
              .setGeometry(new Text().setString(new String[] {"Visibility 5 Meters"})
                .setFontStyle(new FontStyle()))))
          .addChild(new Group()
            .addChild(new Shape()
              .setAppearance(new Appearance().setUSE("green"))
              .setGeometry(new Text().setString(new String[] {"Visibility 1 Meter"})
                .setFontStyle(new FontStyle())))))
        .addChild(new Script("VisibilityScript").setSourceCode("""
ecmascript:

function set_boolean ( boolean_input, eventTime)
{
binder =true;
if ( boolean_input== false ) { return; }
whichchoice = whichchoice +1;
if ( whichchoice ==12 ) { whichchoice = 0; }
if (whichchoice ==0) {range = 0;}
if (whichchoice ==1) {range = 5000;}
if (whichchoice ==2) {range = 2500;}
if (whichchoice ==3) {range = 1000;}
if (whichchoice ==4) {range = 500;}
if (whichchoice ==5) {range = 250;}
if (whichchoice ==6) {range = 100;}
if (whichchoice ==7) {range = 50;}
if (whichchoice ==8) {range = 25;}
if (whichchoice ==9) {range = 10;}
if (whichchoice ==10) {range = 5;}
if (whichchoice ==11) {range = 1;}
}
""")
          .addField(new field().setName("set_boolean").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
          .addField(new field().setName("whichchoice").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
          .addField(new field().setName("range").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
          .addField(new field().setName("binder").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY)))))
    .addChild(new Fog("Foggy").setColor(0.0,0.0,0.0).setFogType("EXPONENTIAL"))
    .addComments(" The following two routes toggle the twelve Visibility Text Range labels driven by a touch sensor. ")
    .addChild(new ROUTE().setFromNode("VisibilityButton").setFromField("isActive").setToNode("VisibilityScript").setToField("set_boolean"))
    .addChild(new ROUTE().setFromNode("VisibilityScript").setFromField("whichchoice").setToNode("FogSwitch").setToField("whichChoice"))
    .addComments(" The following two routes change the visibility range on the Fog node through twelve settings. ")
    .addChild(new ROUTE().setFromNode("VisibilityScript").setFromField("range").setToNode("Foggy").setToField("visibilityRange"))
    .addChild(new ROUTE().setFromNode("VisibilityScript").setFromField("binder").setToNode("Foggy").setToField("set_bind"))
    .addComments(" The following two routes changes the am to pm text and vice-versa when the clock strikes twelve. ")
    .addChild(new ROUTE().setFromNode("Incrementor").setFromField("twelvebool").setToNode("ampm").setToField("set_boolean"))
    .addChild(new ROUTE().setFromNode("ampm").setFromField("whichchoice").setToNode("ampmswitch").setToField("whichChoice"))
    .addComments(" The following three routes rotate the hour, minute, and second hands. ")
    .addChild(new ROUTE().setFromNode("ClockMechanism").setFromField("hourHand_changed").setToNode("H").setToField("set_rotation"))
    .addChild(new ROUTE().setFromNode("ClockMechanism").setFromField("minuteHand_changed").setToNode("M").setToField("set_rotation"))
    .addChild(new ROUTE().setFromNode("ClockMechanism").setFromField("secondHand_changed").setToNode("S").setToField("set_rotation"))
    .addComments(" The following two routes incremnet the clock one hour when the button is pushed. ")
    .addChild(new ROUTE().setFromNode("button").setFromField("isActive").setToNode("Incrementor").setToField("set_boolean"))
    .addChild(new ROUTE().setFromNode("Incrementor").setFromField("hour_changed").setToNode("ClockMechanism").setToField("set_hour"))
    .addComments(" The following five routes have the clock mechanism drive the light direction, light ambient intensity, as well as the transparency of a box around the world which has the effect darkening the background nodes. ")
    .addChild(new ROUTE().setFromNode("ClockMechanism").setFromField("hourpercent_changed").setToNode("LightAmbient").setToField("set_fraction"))
    .addChild(new ROUTE().setFromNode("ClockMechanism").setFromField("hourpercent_changed").setToNode("LightDirection").setToField("set_fraction"))
    .addChild(new ROUTE().setFromNode("LightDirection").setFromField("value_changed").setToNode("SunLight").setToField("set_direction"))
    .addChild(new ROUTE().setFromNode("LightAmbient").setFromField("value_changed").setToNode("SunLight").setToField("set_ambientIntensity"))
    .addChild(new ROUTE().setFromNode("LightAmbient").setFromField("value_changed").setToNode("transparent").setToField("set_transparency")));
            }
            catch (Exception ex)
            {       
                System.err.println ("*** Further hints on X3DJSAIL errors and exceptions at");
                System.err.println ("*** https://www.web3d.org/specifications/java/X3DJSAIL.html");
                throw (ex);
            }
	}
	// end of initialize() method

	/** The initialized model object, created within initialize() method. */
	private X3D x3dModel;

	/** 
	 * Provide a 
	 * <a href="https://dzone.com/articles/java-copy-shallow-vs-deep-in-which-you-will-swim" target="_blank">shallow copy</a>
	 * of the X3D model.
	 * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html">X3D</a>
	 * @return TimeOfDay model
	 */
	public X3D getX3dModel()
	{	  
		return x3dModel;
	}
	   
    /** 
     * Default main() method provided for test purposes, uses CommandLine to set global ConfigurationProperties for this object.
     * @param args array of input parameters, provided as arguments
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html#handleArguments-java.lang.String:A-">X3D.handleArguments(args)</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html#validationReport--">X3D.validationReport()</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/CommandLine.html">CommandLine</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/CommandLine.html#USAGE">CommandLine.USAGE</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/ConfigurationProperties.html">ConfigurationProperties</a>
     */
    public static void main(String args[])
    {
        System.out.println("Build this X3D model, showing validation diagnostics...");
        X3D thisExampleX3dModel = new TimeOfDay().getX3dModel();
//      System.out.println("X3D model construction complete.");
	
        // next handle command line arguments
        boolean hasArguments = (args != null) && (args.length > 0);
        boolean validate = true; // default
        boolean argumentsLoadNewModel = false;
        String  fileName = new String();

        if (args != null)
        {
                for (String arg : args)
                {
                        if (arg.toLowerCase().startsWith("-v") || arg.toLowerCase().contains("validate"))
                        {
                                validate = true; // making sure
                        }
                        if (arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_X3D) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_CLASSICVRML) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_X3DB) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_VRML97) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_EXI) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_GZIP) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_ZIP) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_HTML) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_XHTML))
                        {
                                argumentsLoadNewModel = true;
                                fileName = arg;
                        }
                }
        }
        if      (argumentsLoadNewModel)
                System.out.println("WARNING: \"Savage.Environment.TimeOfDay.TimeOfDay\" model invocation is attempting to load file \"" + fileName + "\" instead of simply validating itself... file loading ignored.");
        else if (hasArguments) // if no arguments provided, this method produces usage warning
                thisExampleX3dModel.handleArguments(args);
	
        if (validate)
        {
            //  System.out.println("--- TODO fix duplicated outputs ---"); // omit when duplicated outputs problem is solved/refactored
		String validationResults = thisExampleX3dModel.validationReport();
            //  System.out.println("-----------------------------------"); // omit when duplicated outputs problem is solved/refactored
                System.out.print("Savage.Environment.TimeOfDay.TimeOfDay self-validation test confirmation: ");
                if (!validationResults.equals("success"))
                    System.out.println();
                System.out.println(validationResults.trim());

                // experimental: test X3DJSAIL output files
                // Environment/TimeOfDay/TimeOfDay_JavaExport.* file validation is checked when building X3D Example Archives
                String filenameX3D  = "Environment/TimeOfDay/TimeOfDay_JavaExport.x3d"; 
                String filenameX3DV = "Environment/TimeOfDay/TimeOfDay_JavaExport.x3dv"; 
                String filenameJSON = "Environment/TimeOfDay/TimeOfDay_JavaExport.json";
                thisExampleX3dModel.toFileX3D        (filenameX3D);
                thisExampleX3dModel.toFileClassicVRML(filenameX3DV);
// TODO         thisExampleX3dModel.toFileJSON       (filenameJSON);
        }
    }
}
