<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "https://www.web3d.org/specifications/x3d-3.0.dtd">
<X3D profile='Immersive'  version='3.0 xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation =' https://www.web3d.org/specifications/x3d-3.0.xsd ' >
<head>
<meta name='titlecontent=' LoadSensorPrototype.x3d '/>
<meta name='descriptioncontent='LoadSensor prototype for VRML 97 use. Assumes correct loading of resources and provides output events based on timeOut delay.'/>
<meta name='createdcontent='26 December 2003'/>
<meta name='modifiedcontent='20 October 2019'/>
<meta name='creatorcontent='Don Brutzman'/>
<meta name='hintcontent='Set LoadSensorScript traceEnabled true/false to enable/disable console trace text.'/>
<meta name=' warning content=' This LoadSensor implementation for VRML 97 only emulates LoadSensor events and cannot sense actual loading of watchList resources. Use an X3D-compliant browser for complete LoadSensor capability. '/>
<meta name='referencecontent=' LoadSensorExample.x3d '/>
<meta name='referencecontent=' LoadSensorPrototypeInitializationTrace.txt '/>
<meta name='identifiercontent=' https://www.web3d.org/x3d/content/examples/Basic/development/LoadSensorPrototype.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../license.html'/>
</head>
<!--

to top <!-- Event Graph ROUTE Table shows event connections -->
 
<!-- Index for DEF nodes: Clock, LoadSensorScript

Index for ProtoDeclare definition: LoadSensor
-->
<Scene>
<WorldInfo title='LoadSensorPrototype.x3d'/>
<ProtoDeclare name='LoadSensorappinfo='LoadSensor monitors the progress and success of downloading URL elements over a network. Only nodes that contain a valid URL field (i.e. descendants of X3DUrlObject) may be specified as watchList children. Multiple nodes may be watched with a single LoadSensor.'  documentation=' https://www.web3d.org/specifications/ISO-IEC-19775/Part01/components/networking.html#LoadSensor ' >
<ProtoInterface>
<field name='enabledtype='SFBoolvalue='trueaccessType='inputOutput'
 appinfo='Enables/disables the sensor node.' />

<field name='timeOuttype='SFTimevalue='0accessType='inputOutput'
 appinfo='Maximum time for which the LoadSensor will monitor loading starting from when the sensor becomes active. timeOut=0 ordinarily indicates an indefinite time out period; i.e. the LoadSensor will wait until loading has completed either with success or failure timeOut=0 causes immediate loading for this implementation.' />

<field name='watchListtype='MFNodeaccessType='initializeOnly'
 appinfo='Zero or more nodes with url fields to monitor.' />

<field name='set_watchListtype='MFNodeaccessType='inputOnly'
 appinfo='Change watchList MFNode array.' />

<field name='isActivetype='SFBoolaccessType='outputOnly'
 appinfo='isActive=true when loading begins isActive=false when loading ends.' />

<field name='isLoadedtype='SFBoolaccessType='outputOnly'
 appinfo='isLoaded=true when loading succeeds isLoaded=false when loading fails or timeOut reached.' />

<field name='loadTimetype='SFTimeaccessType='outputOnly'
 appinfo='loadTime event is generated when loading has successfully completed.' />

<field name='progresstype='SFFloataccessType='outputOnly'
 appinfo='progress [0..1] indicates fraction of loading complete.' />

<field name='metadatatype='SFNodeaccessType='initializeOnly'
 appinfo='associated Metadata node.' />
</ProtoInterface>
<ProtoBody>
<Group>
<IS>
<connect nodeField='enabledprotoField='enabled'/>
<connect nodeField='cycleIntervalprotoField='timeOut'/>
</IS>
</TimeSensor>
<!-- ROUTE information for LoadSensorScript node:  [from Clock.fraction_changed to fraction ] [from loopStart to Clock.startTime ] [from isActive to Clock.enabled ] -->
<Script DEF='LoadSensorScriptdirectOutput='true'>
<field name='ClockNodetype='SFNodeaccessType='initializeOnly'>
<TimeSensor USE=' Clock'/>
</field>
<field name='loopStarttype='SFTimeaccessType='outputOnly'/>
<field name='fractiontype='SFFloataccessType='inputOnly'/>
<field name='priorFractiontype='SFFloatvalue='0accessType='initializeOnly'/>
<field name='progresstype='SFFloataccessType='outputOnly'/>
<field name='watchListtype='MFNodeaccessType='initializeOnly'/>
<field name='set_watchListtype='MFNodeaccessType='inputOnly'/>
<field name='isActivetype='SFBoolaccessType='outputOnly'/>
<field name='isLoadedtype='SFBoolaccessType='outputOnly'/>
<field name='loadTimetype='SFTimeaccessType='outputOnly'/>
<field name='traceEnabledtype='SFBoolvalue='falseaccessType='initializeOnly'/>
<IS>
<connect nodeField='watchListprotoField='watchList'/>
<connect nodeField='set_watchListprotoField='set_watchList'/>
<connect nodeField='isActiveprotoField='isActive'/>
<connect nodeField='isLoadedprotoField='isLoaded'/>
<connect nodeField='loadTimeprotoField='loadTime'/>
<connect nodeField='progressprotoField='progress'/>
</IS>
<![CDATA[
            
ecmascript:

function initialize ()
{
	enabled = ClockNode.enabled;
	tracePrint ('initialize() enabled=' + enabled);
	if (enabled)
	{
		isActive = true;
		// isLoaded event only sent upon completion
		progress = 0.0;
		tracePrintEvents ();
		timeOut = ClockNode.cycleInterval;
		tracePrint ('timeOut=' + timeOut);
		if (timeOut <= 0.0) // instantaneous, no loop
		{
			isActive = false;
			isLoaded = true;
			progress = 1.0;
			loadTime = timestamp;
			tracePrintEvents ();
		}
	}
}
function fraction (value, timestamp)
{
	enabled = ClockNode.enabled;
	if (enabled)
		tracePrint ('progress=' + value + ', priorFraction=' + priorFraction);
	// use priorFraction to check for looping, then stop loop
	if (enabled && ((value >=1) || (value < priorFraction)))
	{
		isActive = false;
		isLoaded = true;
		loadTime = timestamp;
		progress = 1;
		tracePrintEvents ();
		tracePrint ('complete');
                loopStart = true;
	}
	else progress= value; // output event
	priorFraction = progress;
}
function set_watchList (value, timestamp)
{
	watchList = value;
}
function tracePrintEvents ()
{
	tracePrint ('isActive=' + isActive);
	tracePrint ('isLoaded=' + isLoaded);
	tracePrint ('loadTime=' + loadTime);
	tracePrint ('progress=' + progress);
}
function tracePrint (outputString)
{
	if (traceEnabled) Browser.println ('[LoadSensor]' + outputString);
}
function alwaysPrint (outputString)
{
	Browser.println ('[LoadSensor]' + outputString);
}

          
]]>
</Script>
< ROUTE  fromNode=' LoadSensorScript' fromField='loopStart' toNode=' Clock' toField='startTime'/>
< ROUTE  fromNode=' LoadSensorScript' fromField='isActive' toNode=' Clock' toField='enabled'/>
< ROUTE  fromNode=' Clock' fromField='fraction_changed' toNode=' LoadSensorScript' toField='fraction'/>
<Collision enabled='false'>
<IS>
<connect nodeField='proxyprotoField='metadata'/>
</IS>
</Collision>
</Group>
</ProtoBody>
</ProtoDeclare>
<!-- ====================================== -->
<!-- Example use -->
<Anchor description='LoadSensorExampleparameter='"target=_blank"'
  url=' LoadSensorExample.x3d"https://www.web3d.org/x3d/content/examples/Basic/development/LoadSensorExample.x3d" "LoadSensorExample.wrl" "https://www.web3d.org/x3d/content/examples/Basic/development/LoadSensorExample.wrl" ' >
<Shape>
<Text string='"LoadSensorPrototype" "defines a prototype" "" "Click on this text to see" "LoadSensorExample scene"'>
<FontStyle justify='"MIDDLE" "MIDDLE"size='0.7'/>
</Text>
<Appearance>
<Material diffuseColor='1 1 0.2'/>
</Appearance>
</Shape>
</Anchor>
</Scene>
</X3D>
<!--

to top <!-- Event Graph ROUTE Table shows event connections -->
 
<!-- Index for DEF nodes: Clock, LoadSensorScript

Index for ProtoDeclare definition: LoadSensor
-->

Event Graph ROUTE Table entries with 3 ROUTE connections total, showing X3D event-model relationships for this scene.

Each row shows an event cascade that may occur during a single timestamp interval between frame renderings, as part of the X3D execution model.

The following ROUTE begins an event-routing loop! Loop occurs at nodeDepth=3.
 
ROUTE Clock.fraction_changed TO LoadSensorScript.fraction
Clock
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
(1)
LoadSensorScript
Script
fraction
SFFloat

 
 
then
LoadSensorScript
Script
isActive
SFBool

ROUTE
event to
(2)
Clock
TimeSensor
enabled
SFBool

 
 
then
Clock
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
(3)
LoadSensorScript
Script
fraction
SFFloat
 
 
 
then
LoadSensorScript
Script
loopStart
SFFloat

ROUTE
event to
(2)
Clock
TimeSensor
startTime
SFTime

 
 
then
Clock
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
(3)
LoadSensorScript
Script
fraction
SFFloat


     
The following ROUTE begins an event-routing loop! Loop occurs at nodeDepth=3.
 
ROUTE LoadSensorScript.loopStart TO Clock.startTime
LoadSensorScript
Script
loopStart
SFFloat

ROUTE
event to
(1)
Clock
TimeSensor
startTime
SFTime

 
 
then
Clock
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
(2)
LoadSensorScript
Script
fraction
SFFloat

 
 
then
LoadSensorScript
Script
isActive
SFBool

ROUTE
event to
(3)
Clock
TimeSensor
enabled
SFBool
 
 
 
then
LoadSensorScript
Script
loopStart
SFFloat

ROUTE
event to
(3)
Clock
TimeSensor
startTime
SFTime
LoadSensorScript
Script
isActive
SFBool

ROUTE
event to
(1)
Clock
TimeSensor
enabled
SFBool

 
 
then
Clock
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
(2)
LoadSensorScript
Script
fraction
SFFloat

 
 
then
LoadSensorScript
Script
isActive
SFBool

ROUTE
event to
(3)
Clock
TimeSensor
enabled
SFBool
 
 
 
then
LoadSensorScript
Script
loopStart
SFFloat

ROUTE
event to
(3)
Clock
TimeSensor
startTime
SFTime


-->

<!-- Online at
https://www.web3d.org/x3d/content/examples/Basic/development/LoadSensorPrototypeIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/Basic/development/LoadSensorPrototype.x3d -->

<!-- Color legend: X3D terminology <X3dNode DEF='idName' field='value'/> matches XML terminology <XmlElement DEF='idName' attribute='value'/>
(Light-blue background: event-based behavior node or statement) (Grey background inside box: inserted documentation) (Magenta background: X3D Extensibility)
    <ProtoDeclare name='ProtoName'> <field name='fieldName'/> </ProtoDeclare> -->

to top <!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources, and X3D Scene Authoring Hints. -->