package Savage.Tools.Animation;

import org.web3d.x3d.jsail.Core.*;
import org.web3d.x3d.jsail.fields.*;
import org.web3d.x3d.jsail.Networking.*;
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> Prototype definition for toggle-able Material node that can choose among an array of material nodes, and is switchable at run time. This prototype also demonstrates why it is important that only the first node in a ProtoBody can render: so that it can serve as a special node type (such as Material). </p>
 <p> Related links: Catalog page <a href="../../../../Tools/Animation/MaterialChoicePrototypeIndex.html" target="_blank">MaterialChoicePrototype</a>,  source <a href="../../../../Tools/Animation/MaterialChoicePrototype.java">MaterialChoicePrototype.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="../../../../Tools/Animation/MaterialChoicePrototype.x3d">MaterialChoicePrototype.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> Prototype definition for toggle-able Material node that can choose among an array of material nodes, and is switchable at run time. This prototype also demonstrates why it is important that only the first node in a ProtoBody can render: so that it can serve as a special node type (such as Material). </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> creator </i> </td>
			<td> Don Brutzman and MV4205 class </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 29 April 2004 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> modified </i> </td>
			<td> 28 November 2019 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="../../../../Tools/Animation/MaterialChoiceExample.x3d">MaterialChoiceExample.x3d</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/Savage/Tools/Animation/MaterialChoicePrototype.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialChoicePrototype.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> license </i> </td>
			<td> <a href="../../../../Tools/Animation/../../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 and MV4205 class
 */

public class MaterialChoicePrototype
{
	/** Default constructor to create this object. */
	public MaterialChoicePrototype ()
	{
	  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("MaterialChoicePrototype.x3d"))
    .addMeta(new meta().setName(meta.NAME_DESCRIPTION).setContent("Prototype definition for toggle-able Material node that can choose among an array of material nodes, and is switchable at run time. This prototype also demonstrates why it is important that only the first node in a ProtoBody can render: so that it can serve as a special node type (such as Material)."))
    .addMeta(new meta().setName(meta.NAME_CREATOR    ).setContent("Don Brutzman and MV4205 class"))
    .addMeta(new meta().setName(meta.NAME_CREATED    ).setContent("29 April 2004"))
    .addMeta(new meta().setName(meta.NAME_MODIFIED   ).setContent("28 November 2019"))
    .addMeta(new meta().setName(meta.NAME_REFERENCE  ).setContent("MaterialChoiceExample.x3d"))
    .addMeta(new meta().setName(meta.NAME_IDENTIFIER ).setContent("https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialChoicePrototype.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_LICENSE    ).setContent("../../license.html")))
  .setScene(new Scene()
    .addChild(new WorldInfo().setTitle("MaterialChoicePrototype.x3d"))
    .addChild(new ProtoDeclare("MaterialChoice").setName("MaterialChoice").setAppinfo("MaterialChoice selects one of several different Material values")
      .setProtoInterface(new ProtoInterface()
        .addField(new field().setName("set_index").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INPUTONLY))
        .addField(new field().setName("index").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0).setAppinfo("which Material node is chosen, with array index starting at 0"))
        .addField(new field().setName("index_changed").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
        .addField(new field().setName("set_fraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY))
        .addField(new field().setName("fraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0).setAppinfo("fraction to interpolate between current and next Material node (if any) across all field values."))
        .addField(new field().setName("next").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("Trigger next Material node"))
        .addField(new field().setName("previous").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("Trigger previous Material node"))
        .addField(new field().setName("materials").setType(field.TYPE_MFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("array of available Material nodes defaults to zeroth Material")
          .addComments(" no default initialization node since it crashes Xj3D "))
        .addField(new field().setName("appendMaterial").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("append another Material node to materials array"))
        .addField(new field().setName("deleteMaterial").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("delete Material node indicated by input index value"))
        .addField(new field().setName("deleteAllMaterials").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("deletes all Material nodes resets scene to default Material values defined in X3D Specification")))
      .setProtoBody(new ProtoBody()
        .addComments(" first node is node type for this prototype, other nodes are active but do not render ")
        .addChild(new Material("ViewedMaterialNode"))
        .addChild(new Script("MaterialAnimationScript").setDirectOutput(true).setSourceCode("""
ecmascript:

function initialize ()
{
   tracePrint ('initialize() begin...');
   if (materials[index] != null)
   {
	viewedMaterial.diffuseColor     = materials[index].diffuseColor;
	viewedMaterial.emissiveColor    = materials[index].emissiveColor;
	viewedMaterial.specularColor    = materials[index].specularColor;
	viewedMaterial.shininess        = materials[index].shininess;
	viewedMaterial.ambientIntensity = materials[index].ambientIntensity;
	viewedMaterial.transparency     = materials[index].transparency;
	interpolateMaterialValues();
   }
   else alwaysPrint ('warning: no initialization Material node provided for materials[' + index + ']'
                    + ', materials.length=' + materials.length);

   tracePrint ('initialize() complete');
}

function set_index (value, timestamp)
{
   if (value == index) return;
   else if ((value >= 0) && (value < materials.length))
   {
	index = value;
	viewedMaterial.diffuseColor     = materials[index].diffuseColor;
	viewedMaterial.emissiveColor    = materials[index].emissiveColor;
	viewedMaterial.specularColor    = materials[index].specularColor;
	viewedMaterial.shininess        = materials[index].shininess;
	viewedMaterial.ambientIntensity = materials[index].ambientIntensity;
	viewedMaterial.transparency     = materials[index].transparency;
	interpolateMaterialValues();
	index_changed = value; // chain input event to output event
	tracePrint ('set_index(' + value + ') complete');
   }
   else if (value == -1)
   {
	tracePrint ('set_index(' + value + ') out of range, use default Material values');
	index = value;
	viewedMaterial.diffuseColor     = defaultMaterial.diffuseColor;
	viewedMaterial.emissiveColor    = defaultMaterial.emissiveColor;
	viewedMaterial.specularColor    = defaultMaterial.specularColor;
	viewedMaterial.shininess        = defaultMaterial.shininess;
	viewedMaterial.ambientIntensity = defaultMaterial.ambientIntensity;
	viewedMaterial.transparency     = defaultMaterial.transparency;
	index_changed = value; // chain input event to output event
   }
   else if (priorBadIndex != value)
   {
	alwaysPrint ('set_index(' + value + ') out of range (only '
		+ materials.length + ' Material nodes)');
	priorBadIndex = value;
   }
}

function set_fraction(value, timestamp)
{
	tracePrint ('set_fraction(' + value + ')');
	if (fraction != value) // only update if value is changed
	{
		fraction = value;
		interpolateMaterialValues();
	}
}

function interpolateMaterialValues()
{
	f = fraction % 1;  // nonzero remainder (modulo 1) within range [0..1]
	tracePrint ('interpolateMaterialValues(index=' + index + ', fraction=' + fraction +  ', f=' + f + ')');
	// reset Material index if fraction is above 1
	if (Math.floor(fraction) >= 1)
	{
		index = Math.floor(fraction);
		tracePrint ('index=' + index + ' (reset from fraction)');
	}
	fraction = f;  // no need to retain integral part of fraction once index is set correspondingly
	// check OK to proceed
	if (index <  0) return;				// avoid index underflow
	if (index >= materials.length - 1) return;	// avoid index overflow
	if (f == 0.0) return; 				// avoid zero interpolation
	viewedMaterial.diffuseColor.r     = materials[index].diffuseColor.r +
		f * (materials[index+1].diffuseColor.r - materials[index].diffuseColor.r);
	viewedMaterial.diffuseColor.g     = materials[index].diffuseColor.g +
		f * (materials[index+1].diffuseColor.g - materials[index].diffuseColor.g);
	viewedMaterial.diffuseColor.b     = materials[index].diffuseColor.r +
		f * (materials[index+1].diffuseColor.b - materials[index].diffuseColor.b);
	tracePrint ('viewedMaterial.diffuseColor=' + viewedMaterial.diffuseColor);

	viewedMaterial.emissiveColor.r    = materials[index].emissiveColor.r +
		f * (materials[index+1].emissiveColor.r - materials[index].emissiveColor.r);
	viewedMaterial.emissiveColor.g    = materials[index].emissiveColor.r +
		f * (materials[index+1].emissiveColor.g - materials[index].emissiveColor.g);
	viewedMaterial.emissiveColor.b    = materials[index].emissiveColor.b +
		f * (materials[index+1].emissiveColor.b - materials[index].emissiveColor.b);

	viewedMaterial.specularColor.r    = materials[index].specularColor.r +
		f * (materials[index+1].specularColor.r - materials[index].specularColor.r);
	viewedMaterial.specularColor.g    = materials[index].specularColor.g +
		f * (materials[index+1].specularColor.g - materials[index].specularColor.g);
	viewedMaterial.specularColor.b    = materials[index].specularColor.b +
		f * (materials[index+1].specularColor.b - materials[index].specularColor.b);

	viewedMaterial.shininess        = materials[index].shininess +
		f * (materials[index+1].shininess - materials[index].shininess);
	viewedMaterial.ambientIntensity = materials[index].ambientIntensity +
		f * (materials[index+1].ambientIntensity - materials[index].ambientIntensity);
	viewedMaterial.transparency     = materials[index].transparency +
		f * (materials[index+1].transparency - materials[index].transparency);
}

function next(trigger)
{
	tracePrint ('next(' + trigger + ')');
	if ((trigger == true) && (materials.length > 0))
	{
		value = index + 1;
		if (value >= materials.length) value = 0;
		set_index (value); // update Material, test, etc.
	}
}

function previous(trigger)
{
	tracePrint ('previous(' + trigger + ')');
	if ((trigger == true) && (materials.length > 0))
	{
		value = index - 1;
		if (value < 0) value = materials.length - 1;
		set_index (value); // update Material, test, etc.
	}
}

function appendMaterial(newMaterial)
{
	tracePrint ('appendMaterial(' + newMaterial + ')');
	newMaterialCopy = new SFNode ('Material {}');
	tracePrint ('newMaterial.diffuseColor=' + newMaterial.diffuseColor);
	newMaterialCopy.diffuseColor     = newMaterial.diffuseColor;
	newMaterialCopy.emissiveColor    = newMaterial.emissiveColor;
	newMaterialCopy.specularColor    = newMaterial.specularColor;
	newMaterialCopy.shininess        = newMaterial.shininess;
	newMaterialCopy.ambientIntensity = newMaterial.ambientIntensity;
	newMaterialCopy.transparency     = newMaterial.transparency;
	materials[materials.length]      = newMaterialCopy;
	set_index (materials.length-1); // update Material, test, etc.
}

function deleteAllMaterials(trigger)
{
	if ((trigger == true) && (materials.length > 0))
	{
		materials.length = 0; // deletes all objects in materials MFNode array
		index = 0; // must be different to trigger node reset by set_index()
		set_index (-1);
		tracePrint ('deleteAllMaterials() materials.length=' + materials.length);
	}
}

function deleteMaterial(materialIndex)
{
	if ((materialIndex >= materials.length) || materialIndex < 0)
		alwaysPrint ('deleteMaterial(materialIndex=' + materialIndex + ') out of range, materials.length=' +  materials.length);
	else
	{
		for (i = materialIndex; i <= materials.length - 2; i++)
		{
			materials[i] = materials[i+1];
		}
		materials.length = materials.length - 1;
		if ((index == 0) && (materialIndex == 0) && (materials.length > 0))
		{
			index = -1; // allow reset back to 0
			set_index (0);
		}
		else if (index >= materialIndex) set_index (index-1); // decrement to remain same
		tracePrint ('deleteMaterial(materialIndex=' + materialIndex + ') complete,  materials.length=' + materials.length);
	}
}

function tracePrint(outputString)
{
	if (traceEnabled) Browser.println ('[MaterialChoice] ' + outputString);
}
function alwaysPrint(outputString)
{
	Browser.println ('[MaterialChoice] ' + outputString);
}
""")
          .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
          .addField(new field().setName("set_index").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INPUTONLY))
          .addField(new field().setName("index").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("index_changed").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
          .addField(new field().setName("set_fraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY))
          .addField(new field().setName("fraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("next").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
          .addField(new field().setName("previous").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
          .addField(new field().setName("viewedMaterial").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)
            .addChild(new Material().setUSE("ViewedMaterialNode")))
          .addField(new field().setName("defaultMaterial").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)
            .addChild(new Material()))
          .addField(new field().setName("materials").setType(field.TYPE_MFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("appendMaterial").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("append another Material node to materials array"))
          .addField(new field().setName("deleteMaterial").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("delete Material node indicated by input index value"))
          .addField(new field().setName("deleteAllMaterials").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("deletes all Material nodes resets scene to default Material values defined in X3D Specification"))
          .addField(new field().setName("priorBadIndex").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(-1))
          .setIS(new IS()
            .addConnect(new connect().setNodeField("set_index").setProtoField("set_index"))
            .addConnect(new connect().setNodeField("index").setProtoField("index"))
            .addConnect(new connect().setNodeField("index_changed").setProtoField("index_changed"))
            .addConnect(new connect().setNodeField("set_fraction").setProtoField("set_fraction"))
            .addConnect(new connect().setNodeField("fraction").setProtoField("fraction"))
            .addConnect(new connect().setNodeField("next").setProtoField("next"))
            .addConnect(new connect().setNodeField("previous").setProtoField("previous"))
            .addConnect(new connect().setNodeField("materials").setProtoField("materials"))
            .addConnect(new connect().setNodeField("appendMaterial").setProtoField("appendMaterial"))
            .addConnect(new connect().setNodeField("deleteMaterial").setProtoField("deleteMaterial"))
            .addConnect(new connect().setNodeField("deleteAllMaterials").setProtoField("deleteAllMaterials"))))))
    .addComments(" ==================== ")
    .addChild(new Anchor().setDescription("MaterialChoiceExample").setUrl(new String[] {"MaterialChoiceExample.x3d","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialChoiceExample.x3d","MaterialChoiceExample.wrl","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialChoiceExample.wrl"})
      .addChild(new Shape()
        .setGeometry(new Text().setString(new String[] {"MaterialChoicePrototype","defines a prototype","","Click text to see example scene","MaterialChoiceExample"})
          .setFontStyle(new FontStyle().setJustify(FontStyle.JUSTIFY_MIDDLE_MIDDLE).setSize(0.9)))
        .setAppearance(new Appearance()
          .setMaterial(new Material().setDiffuseColor(1.0,1.0,0.2))))));
            }
            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 MaterialChoicePrototype 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 MaterialChoicePrototype().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.Tools.Animation.MaterialChoicePrototype\" 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.Tools.Animation.MaterialChoicePrototype self-validation test confirmation: ");
                if (!validationResults.equals("success"))
                    System.out.println();
                System.out.println(validationResults.trim());

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