package X3dForAdvancedModeling.GeometricShapes;

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.Navigation.*;
import org.web3d.x3d.jsail.Rendering.*;
import org.web3d.x3d.jsail.Shape.*;

// Javadoc metadata annotations follow, see below for X3DJSAIL Java source code.
/**
 * <p> Icosahedron is a polyhedron with twenty faces, subdivided to level 1, where all 42 vertices and 80 faces produce regular (equilateral) triangles. </p>
 <p> Related links: Catalog page <a href="../../../GeometricShapes/IcosahedronSubdivisionLevel1Index.html" target="_blank">IcosahedronSubdivisionLevel1</a>,  source <a href="../../../GeometricShapes/IcosahedronSubdivisionLevel1.java">IcosahedronSubdivisionLevel1.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="../../../GeometricShapes/IcosahedronSubdivisionLevel1.x3d">IcosahedronSubdivisionLevel1.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> IcosahedronSubdivisionLevel1.ply </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> Icosahedron is a polyhedron with twenty faces, subdivided to level 1, where all 42 vertices and 80 faces produce regular (equilateral) triangles. </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 13 September 2014 </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> creator </i> </td>
			<td> Don Brutzman </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="../../../GeometricShapes/Icosahedron.x3d">Icosahedron.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="https://en.wikipedia.org/wiki/Icosahedron" target="_blank">https://en.wikipedia.org/wiki/Icosahedron</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="https://en.wiktionary.org/wiki/icosahedron" target="_blank">https://en.wiktionary.org/wiki/icosahedron</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="https://en.wikipedia.org/wiki/Platonic_solid" target="_blank">https://en.wikipedia.org/wiki/Platonic_solid</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="https://en.wikipedia.org/wiki/Geodesic_grid" target="_blank">https://en.wikipedia.org/wiki/Geodesic_grid</a> </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/X3dForAdvancedModeling/GeometricShapes/IcosahedronSubdivisionLevel1.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/GeometricShapes/IcosahedronSubdivisionLevel1.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> generator </i> </td>
			<td> Meshlab X3D Exported, <a href="http://meshlab.sourceforge.net" target="_blank">http://meshlab.sourceforge.net</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://savage.nps.edu/X3D-Edit" target="_blank">https://savage.nps.edu/X3D-Edit</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> license </i> </td>
			<td> <a href="../../../GeometricShapes/../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 Don Brutzman
 */

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

	/** Create and initialize the X3D model for this object. */
	public final void initialize()
	{
            try { // catch-all
  x3dModel = new X3D().setProfile(X3D.PROFILE_INTERCHANGE).setVersion(X3D.VERSION_3_1)
  .setHead(new head()
    .addMeta(new meta().setName(meta.NAME_TITLE      ).setContent("IcosahedronSubdivisionLevel1.x3d"))
    .addMeta(new meta().setName(meta.NAME_REFERENCE  ).setContent("IcosahedronSubdivisionLevel1.ply"))
    .addMeta(new meta().setName(meta.NAME_DESCRIPTION).setContent("Icosahedron is a polyhedron with twenty faces, subdivided to level 1, where all 42 vertices and 80 faces produce regular (equilateral) triangles."))
    .addMeta(new meta().setName(meta.NAME_CREATED    ).setContent("13 September 2014"))
    .addMeta(new meta().setName(meta.NAME_MODIFIED   ).setContent("20 October 2019"))
    .addMeta(new meta().setName(meta.NAME_CREATOR    ).setContent("Don Brutzman"))
    .addMeta(new meta().setName(meta.NAME_REFERENCE  ).setContent("Icosahedron.x3d"))
    .addMeta(new meta().setName(meta.NAME_REFERENCE  ).setContent("https://en.wikipedia.org/wiki/Icosahedron"))
    .addMeta(new meta().setName(meta.NAME_REFERENCE  ).setContent("https://en.wiktionary.org/wiki/icosahedron"))
    .addMeta(new meta().setName(meta.NAME_REFERENCE  ).setContent("https://en.wikipedia.org/wiki/Platonic_solid"))
    .addMeta(new meta().setName(meta.NAME_REFERENCE  ).setContent("https://en.wikipedia.org/wiki/Geodesic_grid"))
    .addMeta(new meta().setName(meta.NAME_IDENTIFIER ).setContent("https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/GeometricShapes/IcosahedronSubdivisionLevel1.x3d"))
    .addMeta(new meta().setName(meta.NAME_GENERATOR  ).setContent("Meshlab X3D Exported, http://meshlab.sourceforge.net"))
    .addMeta(new meta().setName(meta.NAME_GENERATOR  ).setContent("X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit"))
    .addMeta(new meta().setName(meta.NAME_LICENSE    ).setContent("../license.html")))
  .setScene(new Scene()
    .addChild(new WorldInfo().setTitle("IcosahedronSubdivisionLevel1.x3d"))
    .addChild(new Background().setSkyColor(new MFColor(new double[] {0.5,1.0,0.9})))
    .addChild(new Viewpoint().setDescription("Icosahedron, subdivision level 1").setPosition(0.0,0.0,6.0))
    .addChild(new Shape("IcosahedronSubdivisionLevel1")
      .setGeometry(new IndexedFaceSet().setSolid(false).setCoordIndex(new int[] {0,1,2,-1,0,3,4,-1,5,6,7,-1,5,8,9,-1,10,11,12,-1,10,13,14,-1,15,16,17,-1,15,18,19,-1,20,21,22,-1,20,23,24,-1,25,26,27,-1,25,28,29,-1,23,13,1,-1,4,17,24,-1,2,12,27,-1,26,18,3,-1,7,14,22,-1,21,16,8,-1,28,11,6,-1,9,19,29,-1,30,0,2,-1,0,31,1,-1,2,1,32,-1,31,0,4,-1,0,30,3,-1,4,3,33,-1,34,5,7,-1,5,35,6,-1,7,6,36,-1,35,5,9,-1,5,34,8,-1,9,8,37,-1,32,10,12,-1,10,36,11,-1,12,11,38,-1,36,10,14,-1,10,32,13,-1,14,13,39,-1,33,15,17,-1,15,37,16,-1,17,16,40,-1,37,15,19,-1,15,33,18,-1,19,18,41,-1,39,20,22,-1,20,40,21,-1,22,21,34,-1,40,20,24,-1,20,39,23,-1,24,23,31,-1,38,25,27,-1,25,41,26,-1,27,26,30,-1,41,25,29,-1,25,38,28,-1,29,28,35,-1,31,23,1,-1,23,39,13,-1,1,13,32,-1,31,4,24,-1,4,33,17,-1,24,17,40,-1,30,2,27,-1,2,32,12,-1,27,12,38,-1,30,26,3,-1,26,41,18,-1,3,18,33,-1,34,7,22,-1,7,36,14,-1,22,14,39,-1,34,21,8,-1,21,40,16,-1,8,16,37,-1,35,28,6,-1,28,38,11,-1,6,11,36,-1,35,9,29,-1,9,37,19,-1,29,19,41,-1})
        .setCoord(new Coordinate().setPoint(new MFVec3f(new double[] {0.0,1.0,0.0,0.5,0.809017,0.309017,0.5,0.809017,-0.309017,-0.5,0.809017,-0.309017,-0.5,0.809017,0.309017,0.0,-1.0,0.0,0.5,-0.809017,-0.309017,0.5,-0.809017,0.309017,-0.5,-0.809017,0.309017,-0.5,-0.809017,-0.309017,1.0,0.0,0.0,0.809017,-0.309017,-0.5,0.809017,0.309017,-0.5,0.809017,0.309017,0.5,0.809017,-0.309017,0.5,-1.0,0.0,0.0,-0.809017,-0.309017,0.5,-0.809017,0.309017,0.5,-0.809017,0.309017,-0.5,-0.809017,-0.309017,-0.5,0.0,0.0,1.0,-0.309017,-0.5,0.809017,0.309017,-0.5,0.809017,0.309017,0.5,0.809017,-0.309017,0.5,0.809017,0.0,0.0,-1.0,-0.309017,0.5,-0.809017,0.309017,0.5,-0.809017,0.309017,-0.5,-0.809017,-0.309017,-0.5,-0.809017,0.0,0.850651,-0.525731,0.0,0.850651,0.525731,0.850651,0.525731,0.0,-0.850651,0.525731,0.0,0.0,-0.850651,0.525731,0.0,-0.850651,-0.525731,0.850651,-0.525731,0.0,-0.850651,-0.525731,0.0,0.525731,0.0,-0.850651,0.525731,0.0,0.850651,-0.525731,0.0,0.850651,-0.525731,0.0,-0.850651}))))
      .setAppearance(new Appearance()
        .setMaterial(new Material().setDiffuseColor(0.2,0.5,0.8)))));
            }
            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 IcosahedronSubdivisionLevel1 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 IcosahedronSubdivisionLevel1().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: \"X3dForAdvancedModeling.GeometricShapes.IcosahedronSubdivisionLevel1\" 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("X3dForAdvancedModeling.GeometricShapes.IcosahedronSubdivisionLevel1 self-validation test confirmation: ");
                if (!validationResults.equals("success"))
                    System.out.println();
                System.out.println(validationResults.trim());

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