<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.1//EN" "http://www.web3d.org/specifications/x3d-3.1.dtd">
<X3D profile='Immersive' version='3.1 xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation =' http://www.web3d.org/specifications/x3d-3.1.xsd '>
<head>
<meta name='titlecontent='CreateVrmlFromStringRandomBoxes.x3d'/>
<meta name='descriptioncontent='Sample world constructed in a Script node using the EcmaScript Browser call createVrmlFromString.'/>
<meta name='creatorcontent='Vincent Gardet'/>
<meta name='translatorcontent='Curt Blais'/>
<meta name='contributorcontent='Don Brutzman'/>
<meta name='createdcontent='23 April 2002'/>
<meta name='modifiedcontent='26 May 2019'/>
<meta name='referencecontent='CreateX3dFromStringRandomSpheres.x3d'/>
<meta name='Imagecontent='CreateVrmlFromStringRandomBoxes.png'/>
<meta name='referencecontent='See CreateVrmlFromString tutorial at'/>
<meta name='referencecontent=' http://www.gardet.nom.fr/vrmlcity/tut_cvfs.htm '/>
<meta name='subjectcontent='create VRML from string, javascript'/>
<meta name='identifiercontent=' http://www.web3d.org/x3d/content/examples/Basic/course/CreateVrmlFromStringRandomBoxes.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../license.html'/>
</head>
<!--

Index for DEF nodes : BoxGeneratorScript, HoldsAutogeneratedContent, TouchText

Index for Viewpoint images : Viewpoint_1, Viewpoint_2
-->
<Scene>
<NavigationInfo avatarSize='0.1 1.6 2.0headlight='falsespeed='5type='"EXAMINE" "WALK" "ANY"'/>
<Background skyAngle='1.1 1.57skyColor='.3 .3 1 .4 .4 1 .7 .7 .9'/>
<DirectionalLight direction='0 -.5 -1'/>
<DirectionalLight direction='-1 -.5 .5intensity='.9'/>
<DirectionalLight direction='1 -.5 .5intensity='.8'/>
<Viewpoint description='Interaction viewposition='50 1.6 150'/>
<Viewpoint description='Plan (top-down) vieworientation='1 0 0 -1.54position='50 200 50'/>
<Shape>
<Appearance>
<Material diffuseColor='.3 .3 1transparency='0.5'/>
</Appearance>
<Box size='1000 0.01 1000'/>
</Shape>
<Transform translation='50 1.6 140'>
<Billboard>
<Shape>
<Appearance>
<Material diffuseColor='0.1 0.3 0.2emissiveColor='0.3 0.6 0.9'/>
</Appearance>
<Text string='"Ten random boxes" "computed at runtime"'>
<FontStyle justify='"MIDDLE" "MIDDLE"'/>
</Text>
</Shape>
<!-- ROUTE information for TouchText node:  [from isActive to BoxGeneratorScript.recompute ] -->
<TouchSensor DEF='TouchTextdescription='Touch text to recompute random boxes'/>
<!-- Transparent Box makes the text much more accessible/clickable -->
<Shape>
<Box size='8 2 0.1'/>
<Appearance>
<Material transparency='1'/>
</Appearance>
</Shape>
</Billboard>
</Transform>
<!-- ROOT is used at initialize time as parent for randomly generated Shape children -->
<Group DEF='HoldsAutogeneratedContent'>
<!-- content added here at run time -->
</Group>
<!-- ROUTE information for BoxGeneratorScript node:  [from TouchText.isActive to recompute ] -->
<Script DEF='BoxGeneratorScriptdirectOutput='true'>
<field name='ModifiableExternalNodetype='SFNodeaccessType='initializeOnly'>
<Group USE='HoldsAutogeneratedContent'/>
</field>
<field name='recomputetype='SFBoolaccessType='inputOnly'/>
<![CDATA[
      
ecmascript:

function R () {
	return Math.random();
}
function recompute (isActive) {
	if (isActive==true) initialize();
}

function initialize() {
  for (i=0; i < 10; i++) {
    rand1 = 100*R();
    rand2 = 100*R();
    rand3 = 20*R();
    rand4 = 40*R();
    rand5 = 20*R();
    sceneString ='Transform {                                                    \n' +
                      '   translation ' + rand1 + ' 0 ' + rand2 + ' \n' +
                      '   children [                                            \n' +
                      '           Shape {                                       \n' +
                      '                   appearance Appearance {               \n' +
                      '                      material Material {                \n' +
                      '                         diffuseColor ' + R() + ' ' + R() + ' ' + R() + '\n' +
                      '                      }                                  \n' +
                      '                   }                                     \n' +
                      '                   geometry Box {                        \n' +
                      '                      size ' + rand3 + ' ' + rand4 + ' ' + rand5 + '\n' +
                      '                   }                                     \n' +
                      '           }                                             \n' +
                      '   ]                                                     \n' +
                      '}                                                        \n' +
                      '#########################################################\n';
       Browser.print (sceneString);
       newNode = Browser.createVrmlFromString(sceneString);
//     newNode = Browser.createX3dFromString(sceneString);
       ModifiableExternalNode.children[i] = newNode[0];
  }
}

    
]]>
</Script>
<ROUTE fromNode='TouchTextfromField='isActivetoNode='BoxGeneratorScripttoField='recompute'/>
</Scene>
</X3D>
<!--

Index for DEF nodes : BoxGeneratorScript, HoldsAutogeneratedContent, TouchText

Index for Viewpoint images : Viewpoint_1, Viewpoint_2
-->

<!-- Color key: <X3dNode DEF='idName' field='value'/> matches <XmlElement DEF='idName' attribute='value'/>
(Light blue background: behavior node) (Grey background: inserted documentation) (Magenta background: X3D Extensibility)
-->

<!-- Additional help information about X3D scenes: X3D Resources, X3D Scene Authoring Hints and X3D Tooltips -->