@prefix :        <https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialTogglePrototype.ttl#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema:  <http://schema.org/> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix x3d:     <https://www.web3d.org/specifications/x3d-4.0.xsd#> .
@prefix x3do:    <https://www.web3d.org/specifications/X3dOntology4.0#> .

:X3D a owl:NamedIndividual, x3do:X3D ;
  x3do:hasHead :head ;
  x3do:hasScene :Scene ;
  x3do:profile 'Immersive' ;
  x3do:version '3.0' ;
  x3do:noNamespaceSchemaLocation 'https://www.web3d.org/specifications/x3d-3.0.xsd' .
:head a owl:NamedIndividual, x3do:head ;
  x3do:hasParent :X3D ;
  x3do:hasMeta :meta_1_1, :meta_1_2, :meta_1_3, :meta_1_4, :meta_1_5, :meta_1_6, :meta_1_7, :meta_1_8, :meta_1_9 .
:meta_1_1 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content 'MaterialTogglePrototype.x3d' ;
  x3do:name 'title' .
:meta_1_2 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content 'Prototype definition for toggle-able Material node that can switch between 2 sets of material values, selectable 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).' ;
  x3do:name 'description' .
:meta_1_3 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content 'Don Brutzman and MV4205 class' ;
  x3do:name 'creator' .
:meta_1_4 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content '29 April 2004' ;
  x3do:name 'created' .
:meta_1_5 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content '28 November 2019' ;
  x3do:name 'modified' .
:meta_1_6 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content 'MaterialToggleExample.x3d' ;
  x3do:name 'reference' .
:meta_1_7 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content 'https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialTogglePrototype.x3d' ;
  x3do:name 'identifier' .
:meta_1_8 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content 'X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit' ;
  x3do:name 'generator' .
:meta_1_9 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content '../../license.html' ;
  x3do:name 'license' .
:meta dcterms:title "MaterialTogglePrototype.x3d" .
:meta dcterms:description "Prototype definition for toggle-able Material node that can switch between 2 sets of material values, selectable 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)." .
:meta dcterms:creator "Don Brutzman and MV4205 class" .
:meta dcterms:created "29 April 2004" .
:meta dcterms:modified "28 November 2019" .
:meta dcterms:reference "MaterialToggleExample.x3d" .
:meta dcterms:identifier "https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialTogglePrototype.x3d" .
:meta dcterms:generator "X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit" .
:meta dcterms:license "../../license.html" .
:Scene a owl:NamedIndividual, x3do:Scene ;
  x3do:hasParent :X3D ;
  x3do:hasChildren :WorldInfo_2_1, :Anchor_2_3 ;
  x3do:hasProtoDeclare :ProtoDeclare_2_2 .
:WorldInfo_2_1 a owl:NamedIndividual, x3do:WorldInfo ;
  x3do:hasParent :Scene ;
  x3do:title 'MaterialTogglePrototype.x3d' .
:ProtoDeclare_2_2 a owl:NamedIndividual, x3do:ProtoDeclare ;
  x3do:hasParent :Scene ;
  x3do:hasProtoInterface :ProtoInterface_2_2_1 ;
  x3do:hasProtoBody :ProtoBody_2_2_2 ;
  x3do:appinfo 'MaterialToggle selects one of two different Material values' ;
  x3do:name 'MaterialToggle' .
:ProtoInterface_2_2_1 a owl:NamedIndividual, x3do:ProtoInterface ;
  x3do:hasParent :ProtoDeclare_2_2 ;
  x3do:hasField :field_2_2_1_1, :field_2_2_1_2, :field_2_2_1_3, :field_2_2_1_4, :field_2_2_1_5, :field_2_2_1_6, :field_2_2_1_7 .
:field_2_2_1_1 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :ProtoInterface_2_2_1 ;
  x3do:accessType 'inputOnly' ;
  x3do:name 'set_toggle' ;
  x3do:type 'SFBool' .
:field_2_2_1_2 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :ProtoInterface_2_2_1 ;
  x3do:accessType 'initializeOnly' ;
  x3do:appinfo 'whether to use DefaultMaterial or ToggleMaterial' ;
  x3do:name 'toggle' ;
  x3do:type 'SFBool' ;
  x3do:value false .
:field_2_2_1_3 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :ProtoInterface_2_2_1 ;
  x3do:accessType 'outputOnly' ;
  x3do:name 'toggle_changed' ;
  x3do:type 'SFBool' .
:field_2_2_1_4 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :ProtoInterface_2_2_1 ;
  x3do:accessType 'initializeOnly' ;
  x3do:appinfo 'Material node that is enabled when toggle=false' ;
  x3do:name 'defaultMaterial' ;
  x3do:type 'SFNode' .
:field_2_2_1_5 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :ProtoInterface_2_2_1 ;
  x3do:accessType 'initializeOnly' ;
  x3do:appinfo 'Material node that is enabled when toggle=true' ;
  x3do:name 'toggleMaterial' ;
  x3do:type 'SFNode' .
:field_2_2_1_6 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :ProtoInterface_2_2_1 ;
  x3do:accessType 'inputOnly' ;
  x3do:appinfo 'provide replacement default Material node' ;
  x3do:name 'set_defaultMaterial' ;
  x3do:type 'SFNode' .
:field_2_2_1_7 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :ProtoInterface_2_2_1 ;
  x3do:accessType 'inputOnly' ;
  x3do:appinfo 'provide replacement toggle Material node' ;
  x3do:name 'set_toggleMaterial' ;
  x3do:type 'SFNode' .
:ProtoBody_2_2_2 a owl:NamedIndividual, x3do:ProtoBody ;
  x3do:hasParent :ProtoDeclare_2_2 ;
  x3do:hasMaterial :ViewedMaterialNode ;
  x3do:hasChildren :MaterialAnimationScript .
:ViewedMaterialNode a owl:NamedIndividual, x3do:Material ;
  x3do:hasParent :ProtoBody_2_2_2 ;
  x3do:DEF 'ViewedMaterialNode' .
:MaterialAnimationScript a owl:NamedIndividual, x3do:Script ;
  x3do:hasParent :ProtoBody_2_2_2 ;
  x3do:hasField :field_2_2_2_2_1, :field_2_2_2_2_2, :field_2_2_2_2_3, :field_2_2_2_2_4, :field_2_2_2_2_5, :field_2_2_2_2_6, :field_2_2_2_2_7, :field_2_2_2_2_8, :field_2_2_2_2_9 ;
  x3do:hasIS :IS_2_2_2_2_10 ;
  x3do:DEF 'MaterialAnimationScript' ;
  x3do:directOutput true ;
  x3do:sourceCode """
ecmascript:

function initialize ()
{

   tracePrint ('initialize() begin...');
   if (defaultMaterial != null)
   {
	tracePrint ('defaultMaterial.diffuseColor=' + defaultMaterial.diffuseColor.toString());
	viewedMaterial.diffuseColor     = defaultMaterial.diffuseColor;
	viewedMaterial.emissiveColor    = defaultMaterial.emissiveColor;
	viewedMaterial.specularColor    = defaultMaterial.specularColor;
	viewedMaterial.shininess        = defaultMaterial.shininess;
	viewedMaterial.ambientIntensity = defaultMaterial.ambientIntensity;
	viewedMaterial.transparency     = defaultMaterial.transparency;
	tracePrint ('toggleMaterial.diffuseColor=' + toggleMaterial.diffuseColor.toString());
   }
   else alwaysPrint ('warning: no initialization Material node provided for defaultMaterial');
   if  (toggleMaterial == null)
        alwaysPrint ('warning: no initialization Material node provided for toggleMaterial');

   tracePrint ('initialize() complete');
}

function set_toggle (value, timestamp)
{
   if ((value == true) && (toggleMaterial != null))
   {
	tracePrint ('set_toggle true, toggleMaterial.diffuseColor=' + toggleMaterial.diffuseColor.toString());
	viewedMaterial.diffuseColor     = toggleMaterial.diffuseColor;
	viewedMaterial.emissiveColor    = toggleMaterial.emissiveColor;
	viewedMaterial.specularColor    = toggleMaterial.specularColor;
	viewedMaterial.shininess        = toggleMaterial.shininess;
	viewedMaterial.ambientIntensity = toggleMaterial.ambientIntensity;
	viewedMaterial.transparency     = toggleMaterial.transparency;
   }
   else if (defaultMaterial != null)
   {
	tracePrint ('set_toggle false, defaultMaterial.diffuseColor=' + defaultMaterial.diffuseColor.toString());
	viewedMaterial.diffuseColor     = defaultMaterial.diffuseColor;
	viewedMaterial.emissiveColor    = defaultMaterial.emissiveColor;
	viewedMaterial.specularColor    = defaultMaterial.specularColor;
	viewedMaterial.shininess        = defaultMaterial.shininess;
	viewedMaterial.ambientIntensity = defaultMaterial.ambientIntensity;
	viewedMaterial.transparency     = defaultMaterial.transparency;
   }
   toggle         = value; // remember state
   toggle_changed = value; // chain input boolean event to output event
   tracePrint ('set_toggle(' + value + ') complete');
}

function set_defaultMaterial(newMaterial)
{
	defaultMaterial = newMaterial;
	tracePrint('set_defaultMaterial = ' + newMaterial);
}

function set_toggleMaterial(newMaterial)
{
	toggleMaterial = newMaterial;
	tracePrint('set_toggleMaterial = ' + newMaterial);
}

function tracePrint(outputString)
{
	if (traceEnabled) Browser.println ('[MaterialToggle] ' + outputString);
}
function alwaysPrint(outputString)
{
	Browser.println ('[MaterialToggle] ' + outputString);
}
""" .
:field_2_2_2_2_1 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :MaterialAnimationScript ;
  x3do:accessType 'initializeOnly' ;
  x3do:name 'traceEnabled' ;
  x3do:type 'SFBool' ;
  x3do:value false .
:field_2_2_2_2_2 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :MaterialAnimationScript ;
  x3do:accessType 'inputOnly' ;
  x3do:name 'set_toggle' ;
  x3do:type 'SFBool' .
:field_2_2_2_2_3 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :MaterialAnimationScript ;
  x3do:accessType 'initializeOnly' ;
  x3do:appinfo 'whether to use DefaultMaterial or ToggleMaterial' ;
  x3do:name 'toggle' ;
  x3do:type 'SFBool' .
:field_2_2_2_2_4 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :MaterialAnimationScript ;
  x3do:accessType 'outputOnly' ;
  x3do:name 'toggle_changed' ;
  x3do:type 'SFBool' .
:field_2_2_2_2_5 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :MaterialAnimationScript ;
  x3do:accessType 'initializeOnly' ;
  x3do:name 'defaultMaterial' ;
  x3do:type 'SFNode' .
:field_2_2_2_2_6 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :MaterialAnimationScript ;
  x3do:accessType 'initializeOnly' ;
  x3do:name 'toggleMaterial' ;
  x3do:type 'SFNode' .
:field_2_2_2_2_7 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :MaterialAnimationScript ;
  x3do:accessType 'inputOnly' ;
  x3do:appinfo 'provide replacement Material node' ;
  x3do:name 'set_defaultMaterial' ;
  x3do:type 'SFNode' .
:field_2_2_2_2_8 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :MaterialAnimationScript ;
  x3do:accessType 'inputOnly' ;
  x3do:appinfo 'provide replacement Material node' ;
  x3do:name 'set_toggleMaterial' ;
  x3do:type 'SFNode' .
:field_2_2_2_2_9 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :MaterialAnimationScript ;
  x3do:hasMaterial :ViewedMaterialNode-USE-1 ;
  x3do:accessType 'initializeOnly' ;
  x3do:name 'viewedMaterial' ;
  x3do:type 'SFNode' .
:ViewedMaterialNode-USE-1 a owl:NamedIndividual, x3do:Material ;
  x3do:hasParent :field_2_2_2_2_9 ;
  owl:sameAs :ViewedMaterialNode . # DEF matching this USE
:IS_2_2_2_2_10 a owl:NamedIndividual, x3do:IS ;
  x3do:hasParent :MaterialAnimationScript ;
  x3do:hasConnect :connect_2_2_2_2_10_1, :connect_2_2_2_2_10_2, :connect_2_2_2_2_10_3, :connect_2_2_2_2_10_4, :connect_2_2_2_2_10_5, :connect_2_2_2_2_10_6, :connect_2_2_2_2_10_7 .
:connect_2_2_2_2_10_1 a owl:NamedIndividual, x3do:connect ;
  x3do:hasParent :IS_2_2_2_2_10 ;
  x3do:nodeField 'set_toggle' ;
  x3do:protoField 'set_toggle' .
:connect_2_2_2_2_10_2 a owl:NamedIndividual, x3do:connect ;
  x3do:hasParent :IS_2_2_2_2_10 ;
  x3do:nodeField 'toggle' ;
  x3do:protoField 'toggle' .
:connect_2_2_2_2_10_3 a owl:NamedIndividual, x3do:connect ;
  x3do:hasParent :IS_2_2_2_2_10 ;
  x3do:nodeField 'toggle_changed' ;
  x3do:protoField 'toggle_changed' .
:connect_2_2_2_2_10_4 a owl:NamedIndividual, x3do:connect ;
  x3do:hasParent :IS_2_2_2_2_10 ;
  x3do:nodeField 'defaultMaterial' ;
  x3do:protoField 'defaultMaterial' .
:connect_2_2_2_2_10_5 a owl:NamedIndividual, x3do:connect ;
  x3do:hasParent :IS_2_2_2_2_10 ;
  x3do:nodeField 'toggleMaterial' ;
  x3do:protoField 'toggleMaterial' .
:connect_2_2_2_2_10_6 a owl:NamedIndividual, x3do:connect ;
  x3do:hasParent :IS_2_2_2_2_10 ;
  x3do:nodeField 'set_defaultMaterial' ;
  x3do:protoField 'set_defaultMaterial' .
:connect_2_2_2_2_10_7 a owl:NamedIndividual, x3do:connect ;
  x3do:hasParent :IS_2_2_2_2_10 ;
  x3do:nodeField 'set_toggleMaterial' ;
  x3do:protoField 'set_toggleMaterial' .
:Anchor_2_3 a owl:NamedIndividual, x3do:Anchor ;
  x3do:hasParent :Scene ;
  x3do:hasChildren :Shape_2_3_1 ;
  x3do:description 'MaterialToggleExample' ;
  x3do:parameter '"target=_blank"' ;
  x3do:url '"MaterialToggleExample.x3d" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialToggleExample.x3d" "MaterialToggleExample.wrl" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialToggleExample.wrl"' .
:Shape_2_3_1 a owl:NamedIndividual, x3do:Shape ;
  x3do:hasParent :Anchor_2_3 ;
  x3do:hasGeometry :Text_2_3_1_1 ;
  x3do:hasAppearance :Appearance_2_3_1_2 .
:Text_2_3_1_1 a owl:NamedIndividual, x3do:Text ;
  x3do:hasParent :Shape_2_3_1 ;
  x3do:hasFontStyle :FontStyle_2_3_1_1_1 ;
  x3do:string '"MaterialTogglePrototype" "defines a prototype" "" "Click text to see example scene" "MaterialToggleExample"' .
:FontStyle_2_3_1_1_1 a owl:NamedIndividual, x3do:FontStyle ;
  x3do:hasParent :Text_2_3_1_1 ;
  x3do:justify '"MIDDLE" "MIDDLE"' ;
  x3do:size 0.9 .
:Appearance_2_3_1_2 a owl:NamedIndividual, x3do:Appearance ;
  x3do:hasParent :Shape_2_3_1 ;
  x3do:hasMaterial :Material_2_3_1_2_1 .
:Material_2_3_1_2_1 a owl:NamedIndividual, x3do:Material ;
  x3do:hasParent :Appearance_2_3_1_2 ;
  x3do:diffuseColor ( 1 1 0.2 ) .
