1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.1//EN" "https://www.web3d.org/specifications/x3d-3.1.dtd">
|
3 | <X3D profile='Immersive' version='3.1' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-3.1.xsd'> |
4 | <head> |
5 | <meta name='title' content='CreateX3DFromStringRandomSpheres.x3d'/> |
6 | <meta name='description' content='Sample world constructed in a Script node using the EcmaScript Browser call createX3DFromString.'/> |
7 | <meta name='creator' content='originally by Vincent Gardet, revised by Curt Blais, adapted to X3D by Don Brutzman and MV4205 class'/> |
8 | <meta name='created' content='3 May 2007'/> |
9 | <meta name='modified' content='12 October 2023'/> |
10 | <meta name='reference' content='CreateVrmlFromStringRandomBoxes.x3d'/> |
11 | <meta name='Image' content='CreateX3DFromStringRandomSpheres.png'/> |
12 | <meta name='reference' content='See CreateVrmlFromString tutorial at'/> |
13 | <meta name='reference' content='http://www.gardet.nom.fr/vrmlcity/tut_cvfs.htm'/> |
14 | <meta name='subject' content='create X3D from string, ecmascript'/> |
15 | <meta name=' warning ' content=' X3D browser support for Browser.createX3DFromString() is poor '/> |
16 | <meta name=' warning ' content=' Xj3D fails on embedded quote marks in sceneString Script '/> |
17 | <meta name=' warning ' content=' this scene will not work in VRML97 browsers '/> |
18 | <meta name='identifier' content='https://www.web3d.org/x3d/content/examples/Basic/course/CreateX3DFromStringRandomSpheres.x3d'/> |
19 | <meta name='generator' content='X3D-Edit 4.0, https://savage.nps.edu/X3D-Edit'/> |
20 | <meta name='license' content='../license.html'/> |
21 | </head> |
22 | <Scene> |
23 | <WorldInfo title='CreateX3DFromStringRandomSpheres.x3d'/> |
24 | <NavigationInfo avatarSize='0.1 1.6 2.0' headlight='false' speed='5' type='"EXAMINE" "WALK" "ANY"'/> |
25 | <Background skyAngle='1.1 1.57' skyColor='.3 .3 1 .4 .4 1 .7 .7 .9'/> |
26 | <DirectionalLight direction='0 -.5 -1'/> |
27 | <DirectionalLight direction='-1 -.5 .5' intensity='.9'/> |
28 | <DirectionalLight direction='1 -.5 .5' intensity='.8'/> |
29 | <Viewpoint description='Interaction view' position='50 1.6 150'/> |
30 | <Viewpoint description='Plan (top-down) view' orientation='1 0 0 -1.54' position='50 200 50'/> |
31 | <Shape> |
32 | <Appearance> |
33 | <Material diffuseColor='.3 .3 1' transparency='0.5'/> |
34 | </Appearance> |
35 | <Box size='1000 0.01 1000'/> |
36 | </Shape> |
37 | <Transform translation='50 1.6 140'> |
38 | <!-- the following is a common interaction design pattern in X3D --> |
39 | <Billboard> |
40 | <Shape> |
41 | <Appearance> |
42 | <Material diffuseColor='0.1 0.3 0.2' emissiveColor='0.3 0.6 0.9'/> |
43 | </Appearance> |
44 | <Text string='"Ten random spheres" "computed at runtime" "" "(view console for results)"'> |
45 | <FontStyle justify='"MIDDLE" "MIDDLE"'/> |
46 | </Text> |
47 | </Shape> |
48 |
<!-- ROUTE information for TouchText node:
[from isActive to SphereGeneratorScript.recompute
]
-->
<TouchSensor DEF='TouchText' description='Touch text to recompute random spheres'/> |
49 | <!-- Transparent Box makes the text much more accessible/clickable --> |
50 | <Shape> |
51 | <Box size='8 2 0.1'/> |
52 | <Appearance> |
53 | <Material transparency='1'/> |
54 | </Appearance> |
55 | </Shape> |
56 | </Billboard> |
57 | </Transform> |
58 | <!-- ROOT is used at initialize time as parent for randomly generated Shape children --> |
59 |
<!-- Group
HoldsAutogeneratedContent is a DEF node that has 1 USE node: USE_1 --> <Group DEF='HoldsAutogeneratedContent'/> |
60 |
<!-- ROUTE information for SphereGeneratorScript node:
[from TouchText.isActive to recompute
]
-->
<Script DEF='SphereGeneratorScript' directOutput='true'> |
61 | <field name='ModifiableExternalNode' type='SFNode' accessType='initializeOnly'> |
62 | <Group USE='HoldsAutogeneratedContent'/> |
63 | </field> |
64 | <field name='recompute' type='SFBool' accessType='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 = '<X3D version="3.1" profile="Interchange">\n' + ' <Scene>\n' + ' <Transform translation="' + rand1 + ' 0 ' + rand2 + '" >\n' + ' <Shape>\n' + ' <Appearance>\n' + ' <Material diffuseColor="' + R() + ' ' + R() + ' ' + R() + '"/>\n' + ' </Appearance>\n' + ' <Sphere radius="' + (rand3 / 2) + '"/>\n' + ' </Shape>\n' + ' </Transform>\n' + ' </Scene>\n' + '</X3D>\n' + '<!--==============================================-->\n'; Browser.println (sceneString); // newNode = Browser.createVrmlFromString(sceneString); newNode = Browser.createX3DFromString(sceneString); ModifiableExternalNode.children[i] = newNode[0]; } }
]]>
|
|
66 | </Script> |
67 | < ROUTE fromNode='TouchText' fromField='isActive' toNode='SphereGeneratorScript' toField='recompute'/> |
68 | </Scene> |
69 | </X3D> |
Event Graph ROUTE Table with 1 ROUTE connection 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.
TouchText
TouchSensor isActive SFBool |
SphereGeneratorScript
Script recompute SFBool |
SphereGeneratorScript
Script |
No ROUTE connection found for output events from this node. Contains SFNode field with direct access to another node. |
<!--
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)
-->
<!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources, and X3D Scene Authoring Hints. -->