<?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">
<![CDATA[
ecmascript: var key, keyValue; function initialize() { key = keyHolderNode.key; keyValue = keyValueHolderNode.description; tracePrint('key =' + key); tracePrint('keyValue =' + keyValue); keyValueToKeyValueArray (); tracePrint('keyValueArray =' + keyValueArray); forward = true; tracePrint('Initializing a new BooleanSequencer. key.length=' + key.length + '; keyValueArray.length=' + keyValueArray.length); validityCheck(); } function keyValueToKeyValueArray () { tracePrint('keyValueToKeyValueArray starting'); index = 0; complete = false; nextString = keyValue.toLowerCase(); tracePrint('initial nextString=' + nextString); tokenCount=0; while ((complete != true) && (nextString.length > 0)) { tracePrint('nextString=' + nextString); while ((nextString.substring(0,1) == ' ') || (nextString.substring(0,1) == ',')) nextString = nextString.slice(1); tracePrint('deblanked nextString=' + nextString); if (nextString.length == 0) { tracePrint ('nextString.length == 0'); complete = true; } if (nextString.length < 4) { alwaysPrint ('*** illegal keyValue input=' + nextString); valid = false; complete = true; } else if (nextString.substring(0,4) =='true') { keyValueArray[keyValueArray.length] = 1; // append newString = nextString.slice(4); nextString = newString; tokenCount++; tracePrint('found true, nextString=' + nextString + ', tokenCount=' + tokenCount); } else if (nextString.length < 5) { alwaysPrint ('*** illegal keyValue input=' + nextString); valid = false; complete = true; } else if (nextString.substring(0,5) =='false') { keyValueArray[keyValueArray.length] = 0; // append newString = nextString.slice(5); nextString = newString; tokenCount++; tracePrint('found false, nextString=' + nextString + ', tokenCount=' + tokenCount); } tracePrint(' intermediate keyValueArray=' + keyValueArray); } tracePrint('keyValueToKeyValueArray complete'); } function set_fraction(value, timeStamp) { if (recheckValidity) validityCheck(); if (!valid) return; //BooleanSequencer ignored tracePrint('fraction =' + value); //Bounds checking if (value < 0) { alwaysPrint('*** warning: fraction is less than 0. fraction reset to 0 ***'); value = 0; } else if (value > 1) { alwaysPrint('*** warning: fraction is greater than 1. fraction reset to 1 ***'); value = 1; } //Check animation direction if (value < previousFraction && forward == true) { forward = false; nextIndex = nextIndex - 1; tracePrint('Animate backward'); } else if (value > previousFraction && forward == false) { forward = true; //nextIndex = 0; tracePrint('Animate forward'); } previousFraction = value; if (forward == true) { for (i = nextIndex; i < key.length; i++) { if (value < key[i]) return; nextIndex = i + 1; tracePrint('nextIndex =' + nextIndex); if (nextIndex < key.length) { if (value <= key[nextIndex]) { //Fire event if (keyValueArray[nextIndex-1] == 0) value_changed = false; else value_changed = true; tracePrint('value_changed eventOut is:' + value_changed); } } else if (nextIndex == key.length) { //Fire event if (keyValueArray[nextIndex-1] == 0) value_changed = false; else value_changed = true; tracePrint('value_changed eventOut is:' + value_changed); } else //nextIndex > key.length { //nextIndex = 0; break; } } } else //backward { for (i = nextIndex; i > 0; i--) { if (value >= key[i]) return; nextIndex = i - 1; tracePrint('nextIndex =' + nextIndex); if (nextIndex >= 0) { if (value >= key[nextIndex]) { //Fire event if (keyValueArray[nextIndex] == 0) value_changed = false; else value_changed = true; tracePrint('value_changed eventOut is:' + value_changed); } } else //nextIndex < 0 { //nextIndex = key.length; break; } } } } function set_key(value, timeStamp) { key = value; keyHolderNode.key = key; recheckValidity = true; } function set_keyValue(value, timeStamp) { keyValue = value; keyValueHolderNode.description = keyValue; recheckValidity = true; keyValueToKeyValueArray (); keyValue_changed = keyValue; } function validityCheck() { //Check if key & keyValueArray array length matches if (key.length != keyValueArray.length) { alwaysPrint('*** error: key and keyValue arrays must be of the same length. BooleanSequencer ignored ***'); valid = false; return; } //Check if key array has values in the range of [0..1] in an increasing order if (key[0] < 0 || key[0] > 1) { alwaysPrint('*** error: key[0] value is NOT in the range of [0..1]. BooleanSequencer ignored ***'); valid = false; return; } for (i = 1; i < key.length; i++) { if (key[i] < 0 || key[i] > 1) { alwaysPrint('*** error: key[' + i + '] value is NOT in the range of [0..1]. BooleanSequencer ignored ***'); valid = false; return; } if (key[i] <= key [i-1]) { alwaysPrint('*** error: values for key[] array must be listed in an increasing order. BooleanSequencer ignored ***'); valid = false; return; } } recheckValidity = false; key_changed = key; return; } function previous (SFBoolValue, timestamp) { nextIndex = nextIndex - 1; if (nextIndex == 0) nextIndex = key.length - 1; } function next (SFBoolValue, timestamp) { nextIndex = nextIndex + 1; if (nextIndex == key.length) nextIndex = 0; } function tracePrint(outputString) { if (traceEnabled) Browser.println ('[ BooleanSequencer ]' + outputString); } function alwaysPrint(outputString) { Browser.println ('[ BooleanSequencer ]' + outputString); }
]]>
Event Graph ROUTE Table with 0 ROUTE 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.
SequencerScript
Script |
No ROUTE connection found for output from this node. Contains SFNode field with indirect access to another node. |
<!--
Online at
https://www.web3d.org/x3d/content/examples/Basic/development/BooleanSequencerPrototypeIndex.html
-->
<!--
Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/Basic/development/BooleanSequencerPrototype.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>
-->
<!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources, and X3D Scene Authoring Hints. -->