<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "https://www.web3d.org/specifications/x3d-3.3.dtd">
<X3D profile='Immersive'  version='3.3 xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation =' https://www.web3d.org/specifications/x3d-3.3.xsd ' >
<head>
<meta name='titlecontent='Loader.x3d'/>
<meta name='descriptioncontent='This example illustrates use of JavaScript to load a scene from a file through use of the Browser object. When a button is selected to provide a new url for a file to load, the Script adds the new world, waits for the load to complete, then adds the loaded Shape into a rendered group.'/>
<meta name='creatorcontent='David R. Nadeau'/>
<meta name='translatorcontent='Don Brutzman'/>
<meta name='createdcontent='1 July 1998'/>
<meta name='translatedcontent='2 February 2014'/>
<meta name='modifiedcontent='20 October 2019'/>
<meta name='Imagecontent='Loader.png' />
<meta name='referencecontent='Button.x3d'/>
<meta name='referencecontent='originals/loader.wrl'/>
<meta name='referencecontent=' http://www.siggraph.org/s98 '/>
<meta name='referencecontent=' http://www.siggraph.org/s98/conference/courses/18.html '/>
<meta name='referencecontent=' http://www.sdsc.edu/~moreland/courses/Siggraph98/vrml97/slides/mt0469.htm '/>
<meta name='referencecontent=' http://www.sdsc.edu/~moreland/courses/Siggraph98/vrml97/vrml97.htm '/>
<meta name='referencecontent=' https://www.web3d.org/x3d/content/examples/X3dResources.html '/>
<meta name='identifiercontent=' https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Siggraph98Course/Loader.x3d '/>
<meta name='generatorcontent='Vrml97ToX3dNist, http://ovrt.nist.gov/v2_x3d.html'/>
<meta name='generatorcontent='X3D-Edit, 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: Button1, Button2, Button3, Label, Loaded, Loader

Index for Viewpoint node: Viewpoint_1 Index for ExternProtoDeclare definition: Button
-->
<Scene>
<WorldInfo info='"Copyright (c) 1998, David R. Nadeau"title='Load VRML using a script'/>
<NavigationInfo/>
<Viewpoint description='Entry view'/>
<Background skyAngle='1.37 1.57 1.77skyColor='0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.8 0.2 0.0 0.0 0.0'/>
<ExternProtoDeclare name='Button'
  url=' "Button.x3d#Button" "https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Siggraph98Course/Button.x3d#Button" "Button.wrl#Button" "https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Siggraph98Course/Button.wrl#Button" ' >
<field name='urltype='MFStringaccessType='inputOutput'/>
<field name='textureUrltype='MFStringaccessType='inputOutput'/>
<field name='url_changedtype='MFStringaccessType='outputOnly'/>
<field name='translationtype='SFVec3faccessType='initializeOnly'/>
</ExternProtoDeclare>
<!-- ROUTE information for Button1 node:  [from url_changed to Loader.loadUrl ] -->
<ProtoInstance name='ButtonDEF='Button1'>
<fieldValue name='urlvalue=' "One.x3d"
"https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Siggraph98Course/One.x3d" '/>

<fieldValue name='textureUrlvalue=' "one.jpg"
'/>

<fieldValue name='translationvalue='-4.0 2.0 0.0'/>
</ProtoInstance>
<!-- ROUTE information for Button2 node:  [from url_changed to Loader.loadUrl ] -->
<ProtoInstance name='ButtonDEF='Button2'>
<fieldValue name='urlvalue=' "Two.x3d"
"https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Siggraph98Course/Two.x3d" '/>

<fieldValue name='textureUrlvalue=' "two.jpg"
'/>

<fieldValue name='translationvalue='-4.0 0.0 0.0'/>
</ProtoInstance>
<!-- ROUTE information for Button3 node:  [from url_changed to Loader.loadUrl ] -->
<ProtoInstance name='ButtonDEF='Button3'>
<fieldValue name='urlvalue=' "Three.x3d"
"https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Siggraph98Course/Three.x3d" '/>

<fieldValue name='textureUrlvalue=' "three.jpg"
'/>

<fieldValue name='translationvalue='-4.0 -2.0 0.0'/>
</ProtoInstance>
<Transform translation='-4.0 -3.5 0.0'>
<Shape>
<Appearance>
<Material/>
</Appearance>
<!-- ROUTE information for Label node:  [from Loader.string_changed to set_string ] -->
<Text DEF='Label'>
<FontStyle justify='"MIDDLE" "MIDDLE"size='0.75'/>
</Text>
</Shape>
</Transform>
<!-- ROUTE information for Loaded node:  [from Loader.node_changed to set_children ] -->
<Transform DEF='Loadedtranslation='1.0 0.0 0.0'>
<!-- load result goes here -->
</Transform>
<field name='lastUrltype='MFStringvalue=' ""
accessType='initializeOnly'/>

<field name='loadUrltype='MFStringaccessType='inputOnly'/>
<field name='vrmlLoadedtype='MFNodeaccessType='inputOnly'/>
<field name='node_changedtype='MFNodeaccessType='outputOnly'/>
<field name='string_changedtype='MFStringaccessType='outputOnly'/>
<field name='myselftype='SFNodeaccessType='initializeOnly'>
<Script USE=' Loader'>
</Script>
</field>
<![CDATA[
      
ecmascript:

function loadUrl( str, ts )
{
        lastUrl = str;
        Browser.createVrmlFromURL( str, myself, 'vrmlLoaded' );
        string_changed[0] = 'Loading...';
}
function vrmlLoaded( nd, ts )
{
        node_changed = nd;
        string_changed[0] = lastUrl[0];
}

    
]]>
</Script>
< ROUTE  fromNode=' Button1' fromField='url_changed' toNode=' Loader' toField='loadUrl'/>
< ROUTE  fromNode=' Button2' fromField='url_changed' toNode=' Loader' toField='loadUrl'/>
< ROUTE  fromNode=' Button3' fromField='url_changed' toNode=' Loader' toField='loadUrl'/>
< ROUTE  fromNode=' Loader' fromField='node_changed' toNode=' Loaded' toField='set_children'/>
< ROUTE  fromNode=' Loader' fromField='string_changed' toNode=' Label' toField='set_string'/>
</Scene>
</X3D>
<!--

to top <!-- Event Graph ROUTE Table shows event connections -->
 
<!-- Index for DEF nodes: Button1, Button2, Button3, Label, Loaded, Loader

Index for Viewpoint node: Viewpoint_1 Index for ExternProtoDeclare definition: Button
-->

Event Graph ROUTE Table entries with 5 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.

Button1
ProtoInstance
url_changed
MFString

ROUTE
event to
(1)
Loader
Script
loadUrl
MFString

 
 
then
Loader
Script
node_changed
MFNode

ROUTE
event to
(2)
Loaded
Transform
set_children
MFNode
 
 
 
then
Loader
Script
string_changed
MFString

ROUTE
event to
(2)
Label
Text
set_string
MFString


Button2
ProtoInstance
url_changed
MFString

ROUTE
event to
(1)
Loader
Script
loadUrl
MFString

 
 
then
Loader
Script
node_changed
MFNode

ROUTE
event to
(2)
Loaded
Transform
set_children
MFNode
 
 
 
then
Loader
Script
string_changed
MFString

ROUTE
event to
(2)
Label
Text
set_string
MFString


Button3
ProtoInstance
url_changed
MFString

ROUTE
event to
(1)
Loader
Script
loadUrl
MFString

 
 
then
Loader
Script
node_changed
MFNode

ROUTE
event to
(2)
Loaded
Transform
set_children
MFNode
 
 
 
then
Loader
Script
string_changed
MFString

ROUTE
event to
(2)
Label
Text
set_string
MFString


-->

<!-- Online at
https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Siggraph98Course/LoaderIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Siggraph98Course/Loader.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)
    <ProtoInstance name='ProtoName'> <field name='fieldName'/> </ProtoInstance> -->

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