package Savage.Weapons.Missiles;

import org.web3d.x3d.jsail.Core.*;
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.Navigation.*;
import org.web3d.x3d.jsail.Networking.*;
import org.web3d.x3d.jsail.PointingDeviceSensor.*;
import org.web3d.x3d.jsail.Shape.*;
import org.web3d.x3d.jsail.Text.*;
import org.web3d.x3d.jsail.Texturing.*;
import org.web3d.x3d.jsail.Time.*;

// Javadoc metadata annotations follow, see below for X3DJSAIL Java source code.
/**
 * <p> Rapier missile system prototype. </p>
 <p> Related links: Catalog page <a href="../../../../Weapons/Missiles/RapierMissileSystemPrototypeIndex.html" target="_blank">RapierMissileSystemPrototype</a>,  source <a href="../../../../Weapons/Missiles/RapierMissileSystemPrototype.java">RapierMissileSystemPrototype.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="../../../../Weapons/Missiles/RapierMissileSystemPrototype.x3d">RapierMissileSystemPrototype.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> creator </i> </td>
			<td> Oliver Tan </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 28 January 2004 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> modified </i> </td>
			<td> 28 November 2019 </td>
		</tr>
		<tr style="color:burntorange">
			<td style="text-align:right; vertical-align: text-top;"> <i> warning </i> </td>
			<td> check whether size is to scale </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> Rapier missile system prototype. </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/Weapons/Missiles/RapierMissileSystemPrototype.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/Savage/Weapons/Missiles/RapierMissileSystemPrototype.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> generator </i> </td>
			<td> X3D-Edit 3.2, <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> reference </i> </td>
			<td> <a href="http://www.army-technology.com/projects/jernas/jernas1.html" target="_blank">http://www.army-technology.com/projects/jernas/jernas1.html</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> subject </i> </td>
			<td> Rapier, Rapier missile, missile </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> license </i> </td>
			<td> <a href="../../../../Weapons/Missiles/../../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 Oliver Tan
 */

public class RapierMissileSystemPrototype
{
	/** Default constructor to create this object. */
	public RapierMissileSystemPrototype ()
	{
	  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_0)
  .setHead(new head()
    .addMeta(new meta().setName(meta.NAME_TITLE      ).setContent("RapierMissileSystemPrototype.x3d"))
    .addMeta(new meta().setName(meta.NAME_CREATOR    ).setContent("Oliver Tan"))
    .addMeta(new meta().setName(meta.NAME_CREATED    ).setContent("28 January 2004"))
    .addMeta(new meta().setName(meta.NAME_MODIFIED   ).setContent("28 November 2019"))
    .addMeta(new meta().setName(meta.NAME_WARNING    ).setContent("check whether size is to scale"))
    .addMeta(new meta().setName(meta.NAME_DESCRIPTION).setContent("Rapier missile system prototype."))
    .addMeta(new meta().setName(meta.NAME_IDENTIFIER ).setContent("https://www.web3d.org/x3d/content/examples/Savage/Weapons/Missiles/RapierMissileSystemPrototype.x3d"))
    .addMeta(new meta().setName(meta.NAME_GENERATOR  ).setContent("X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit"))
    .addMeta(new meta().setName(meta.NAME_REFERENCE  ).setContent("http://www.army-technology.com/projects/jernas/jernas1.html"))
    .addMeta(new meta().setName(meta.NAME_SUBJECT    ).setContent("Rapier, Rapier missile, missile"))
    .addMeta(new meta().setName(meta.NAME_LICENSE    ).setContent("../../license.html")))
  .setScene(new Scene()
    .addComments(" This is only a representational model. It is not created to scale. ")
    .addChild(new WorldInfo().setTitle("RapierMissileSystemPrototype.x3d"))
    .addChild(new ExternProtoDeclare("RapierMissile").setName("RapierMissile").setUrl(new String[] {"RapierMissilePrototype.x3d#RapierMissile","https://www.web3d.org/x3d/content/examples/Savage/Weapons/Missiles/RapierMissilePrototype.x3d#RapierMissile","RapierMissilePrototype.wrl#RapierMissile","https://www.web3d.org/x3d/content/examples/Savage/Weapons/Missiles/RapierMissilePrototype.wrl#RapierMissile"})
      .addField(new field().setName("rocketAppearance").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)))
    .addChild(new ProtoDeclare("RapierMissileSystem").setName("RapierMissileSystem")
      .addComments(" This is only a representational model. It is not created to scale. ")
      .setProtoInterface(new ProtoInterface()
        .addField(new field().setName("material").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)
          .addChild(new Material().setDiffuseColor(.3,.6,.9)))
        .addField(new field().setName("imageTexture").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)
          .addChild(new ImageTexture().setUrl(new String[] {"cammie1.jpg","https://www.web3d.org/x3d/content/examples/Savage/AircraftFixedWing/AV8bHarrierUnitedStates/cammie1.jpg"}))))
      .setProtoBody(new ProtoBody()
        .addChild(new Viewpoint().setDescription("Rapier Missile System").setPosition(0.0,0.0,3.0))
        .addChild(new Viewpoint().setDescription("Rapier Missile System Oblique").setOrientation(0.0,1.0,0.0,-1.571).setPosition(-3.0,0.5,0.0))
        .addChild(new Transform().setRotation(0.0,1.0,0.0,1.57)
          .addChild(new Transform().setRotation(0.0,0.0,1.0,-1.571)
            .addChild(new Shape()
              .setAppearance(new Appearance("LauncherSkin")
                .setIS(new IS()
                  .addConnect(new connect().setNodeField("material").setProtoField("material"))
                  .addConnect(new connect().setNodeField("texture").setProtoField("imageTexture")))))
            .addChild(new Transform("MissileSystem")
              .addChild(new Transform().setRotation(0.0,0.0,1.0,1.571)
                .addChild(new Transform().setTranslation(0.0,-0.075,0.25)
                  .addChild(new Transform().setScale(0.5,0.5,0.5)
                    .addChild(new Transform().setRotation(0.0,0.0,1.0,-1.571).setTranslation(-0.05,0.1,0.0)
                      .addChild(new Transform()
                        .addChild(new Shape()
                          .setAppearance(new Appearance().setUSE("LauncherSkin"))
                          .setGeometry(new Extrusion().setCreaseAngle(3.14).setCrossSection(new MFVec2f(new double[] {-0.2,-1.4,-0.2,-0.3,0.05,0.2,0.1,0.2,0.1,-1.4,-0.2,-1.4})).setSolid(false).setSpine(new MFVec3f(new double[] {0.0,0.0,0.0,0.0,0.1,0.0}))))
                        .addChild(new Transform().setTranslation(-0.05,0.05,-0.75)
                          .addChild(new Shape()
                            .setAppearance(new Appearance().setUSE("LauncherSkin"))
                            .setGeometry(new Cylinder().setHeight(0.2).setRadius(0.15))))
                        .addChild(new Transform().setTranslation(-0.05,0.05,-1.4)
                          .addChild(new Shape()
                            .setAppearance(new Appearance().setUSE("LauncherSkin"))
                            .setGeometry(new Cylinder().setHeight(0.2).setRadius(0.15))))
                        .addChild(new Transform().setTranslation(-0.05,0.05,-0.5)
                          .addChild(new Shape()
                            .setAppearance(new Appearance().setUSE("LauncherSkin"))
                            .setGeometry(new Cylinder().setHeight(0.2).setRadius(0.05))))))
                    .addChild(new Transform().setTranslation(0.0,0.1,-0.55)
                      .addChild(new Transform("MissileGripPair")
                        .addChild(new Transform().setScale(0.49,1.0,0.8)
                          .addChild(new Transform().setTranslation(0.0,0.15,-0.3)
                            .addChild(new Transform("MissileGrip").setTranslation(0.2,0.0,0.0)
                              .addChild(new Transform().setRotation(0.0,1.0,0.0,1.571)
                                .addChild(new Transform().setScale(0.04,0.04,0.04)
                                  .addChild(new Transform()
                                    .addChild(new Transform().setRotation(1.0,0.0,0.0,1.571)
                                      .addChild(new Transform("U1")
                                        .addChild(new Shape()
                                          .setAppearance(new Appearance().setUSE("LauncherSkin"))
                                          .setGeometry(new Cylinder().setHeight(8)))
                                        .addChild(new Transform().setTranslation(0.0,4.0,0.0)
                                          .addChild(new Shape()
                                            .setGeometry(new Sphere())
                                            .setAppearance(new Appearance().setUSE("LauncherSkin"))))
                                        .addChild(new Transform().setTranslation(0.0,-4.0,0.0)
                                          .addChild(new Shape()
                                            .setGeometry(new Sphere())
                                            .setAppearance(new Appearance().setUSE("LauncherSkin"))))))
                                    .addChild(new Transform().setTranslation(0.0,0.0,4.0)
                                      .addChild(new Transform().setRotation(0.0,0.0,1.0,-0.7)
                                        .addChild(new Transform().setTranslation(0.0,5.0,0.0)
                                          .addChild(new Transform()
                                            .addChild(new Shape()
                                              .setAppearance(new Appearance().setUSE("LauncherSkin"))
                                              .setGeometry(new Cylinder().setHeight(10)))
                                            .addChild(new Transform().setTranslation(0.0,5.0,0.0)
                                              .addChild(new Shape()
                                                .setGeometry(new Sphere())
                                                .setAppearance(new Appearance().setUSE("LauncherSkin"))))
                                            .addChild(new Transform().setTranslation(0.0,-5.0,0.0)
                                              .addChild(new Shape()
                                                .setGeometry(new Sphere())
                                                .setAppearance(new Appearance().setUSE("LauncherSkin"))))))
                                        .addChild(new Transform().setTranslation(0.0,10.0,0.0)
                                          .addChild(new Transform().setTranslation(0.0,0.0,-4.0)
                                            .addChild(new Transform().setRotation(1.0,0.0,0.0,1.571)
                                              .addChild(new Transform().setScale(1.0,0.8,1.0).setTranslation(0.0,0.2,0.0)
                                                .addChild(new Transform().setUSE("U1")))))))))))))
                          .addChild(new Transform().setRotation(1.0,0.0,0.0,-1.4).setTranslation(0.0,0.15,-0.3)
                            .addChild(new Transform().setRotation(0.0,1.0,0.0,3.142)
                              .addChild(new Transform().setUSE("MissileGrip")))))))
                    .addChild(new Transform().setTranslation(0.0,0.1,-1.2)
                      .addChild(new Transform().setUSE("MissileGripPair")))
                    .addChild(new Transform().setRotation(1.0,0.0,0.0,-3.142).setTranslation(0.0,0.2,-0.95)
                      .addChild(new Transform().setUSE("MissileGripPair")))
                    .addChild(new Transform().setRotation(1.0,0.0,0.0,-3.142).setTranslation(0.0,0.2,-1.6)
                      .addChild(new Transform().setUSE("MissileGripPair"))))
                  .addChild(new Transform()
                    .addChild(new Transform("TopMissile")
                      .addChild(new Transform().setRotation(0.0,1.0,0.0,-1.57).setScale(0.1,0.1,0.1).setTranslation(0.0,0.2,-0.2)
                        .addChild(new Transform()
                          .addChild(new ProtoInstance("RapierMissile").setContainerField("children")
                            .addFieldValue(new fieldValue().setName("rocketAppearance")
                              .addChild(new Appearance().setUSE("LauncherSkin"))))))
                      .addChild(new TouchSensor("shootTopMissile").setDescription("touch missile to launch it"))
                      .addChild(new PositionInterpolator("topMissilePathInterpolator").setKey(new double[] {0.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0}).setKeyValue(new MFVec3f(new double[] {0.0,0.0,1.0,0.0,0.05,2.0,0.0,0.1,3.0,0.0,0.15,4.0,0.0,0.2,5.0,0.0,0.25,6.0,0.0,0.3,7.0,0.0,0.35,8.0,0.0,0.4,9.0,0.0,0.45,10.0,0.0,0.5,11.0})))
                      .addChild(new TimeSensor("topMissileClock").setCycleInterval(10))
                      .addChild(new ROUTE().setFromNode("topMissileClock").setFromField("fraction_changed").setToNode("topMissilePathInterpolator").setToField("set_fraction"))
                      .addChild(new ROUTE().setFromNode("topMissilePathInterpolator").setFromField("value_changed").setToNode("TopMissile").setToField("set_translation"))
                      .addChild(new ROUTE().setFromNode("shootTopMissile").setFromField("touchTime").setToNode("topMissileClock").setToField("set_startTime"))))
                  .addChild(new Transform("BottomMissile")
                    .addChild(new Transform().setRotation(0.0,1.0,0.0,-1.57).setScale(0.1,0.1,0.1).setTranslation(0.0,-0.05,-0.15)
                      .addChild(new Transform()
                        .addChild(new ProtoInstance("RapierMissile").setContainerField("children")
                          .addFieldValue(new fieldValue().setName("rocketAppearance")
                            .addChild(new Appearance().setUSE("LauncherSkin"))))))
                    .addChild(new TouchSensor("shootBottomMissile").setDescription("touch missile to launch it"))
                    .addChild(new PositionInterpolator("bottomMissilePathInterpolator").setKey(new double[] {0.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0}).setKeyValue(new MFVec3f(new double[] {0.0,0.0,1.0,0.0,0.05,2.0,0.0,0.1,3.0,0.0,0.15,4.0,0.0,0.2,5.0,0.0,0.25,6.0,0.0,0.3,7.0,0.0,0.35,8.0,0.0,0.4,9.0,0.0,0.45,10.0,0.0,0.5,11.0})))
                    .addChild(new TimeSensor("bottomMissileClock").setCycleInterval(10))
                    .addChild(new ROUTE().setFromNode("bottomMissileClock").setFromField("fraction_changed").setToNode("bottomMissilePathInterpolator").setToField("set_fraction"))
                    .addChild(new ROUTE().setFromNode("bottomMissilePathInterpolator").setFromField("value_changed").setToNode("BottomMissile").setToField("set_translation"))
                    .addChild(new ROUTE().setFromNode("shootBottomMissile").setFromField("touchTime").setToNode("bottomMissileClock").setToField("set_startTime")))))
              .addChild(new CylinderSensor("MissileSystemRotation").setDescription("Rotate the missile system.").setMaxAngle(0).setMinAngle(-1.3))
              .addChild(new ROUTE().setFromNode("MissileSystemRotation").setFromField("rotation_changed").setToNode("MissileSystem").setToField("rotation")))))))
    .addChild(new Anchor().setDescription("RapierMissileSystemExample").setUrl(new String[] {"RapierMissileSystemExample.x3d","https://www.web3d.org/x3d/content/examples/Savage/Weapons/Missiles/RapierMissileSystemExample.x3d","RapierMissileSystemExample.wrl","https://www.web3d.org/x3d/content/examples/Savage/Weapons/Missiles/RapierMissileSystemExample.wrl"})
      .addChild(new Shape()
        .setGeometry(new Text().setString(new String[] {"Rapier Missile System Prototype","contains prototype definitions","","Click on text to see these Appearances in","RapierMissileSystemExample"})
          .setFontStyle(new FontStyle().setJustify(FontStyle.JUSTIFY_MIDDLE_MIDDLE).setSize(0.5)))
        .setAppearance(new Appearance()
          .setMaterial(new Material().setDiffuseColor(0.0,0.6,0.6))))));
            }
            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 RapierMissileSystemPrototype 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 RapierMissileSystemPrototype().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.Weapons.Missiles.RapierMissileSystemPrototype\" 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.Weapons.Missiles.RapierMissileSystemPrototype self-validation test confirmation: ");
                if (!validationResults.equals("success"))
                    System.out.println();
                System.out.println(validationResults.trim());

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