Extensible 3D (X3D) encodings
Part 3: Compressed binary encoding
Annex C
(informative)
Examples
This annex provides a variety of X3D examples using the XML encoding. A link is provided to the equivalent Compressed binary encoding. Table C.1 lists the topics in this annex:
Table C.1 — Topics in this annex
C.1 Topics |
This example contains a simple scene defining a view of a red sphere and a blue box, lit by a directional light as shown in Figure C.1:
The input textural encoding is:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specifications/x3d-3.0.dtd"> <X3D version='3.0' profile='Interchange'> <head> <meta name='filename' content='RedSphereBlueBox.x3d'/> </head> <Scene> <Transform> <NavigationInfo headlight='false' avatarSize='0.25 1.6 0.75' type='"EXAMINE"'/> <DirectionalLight/> <Transform translation='3.0 0.0 1.0'> <Shape> <Sphere radius='2.3'/> <Appearance> <Material diffuseColor='1.0 0.0 0.0'/> </Appearance> </Shape> </Transform> <Transform translation='-2.4 0.2 1.0' rotation='0.0 0.707 0.707 0.9'> <Shape> <Box/> <Appearance> <Material diffuseColor='0.0 0.0 1.0'/> </Appearance> </Shape> </Transform> </Transform> </Scene> </X3D>
This file is encoded with all native Fast Infoset encoders without any X3D-specific compression.
The Compressed binary encoded result is available here: RedSphereBlueBox.x3db
Click here to view this example in a 3D scene window.
Reading the following file results in three spheres being drawn. The first sphere defines a unit sphere at the origin. The second sphere, named "Joe", defines a smaller sphere translated along the +x axis, the third sphere is a reference to the second sphere and is translated along the -x axis. If any changes occur to the second sphere (e.g., radius changes), the third sphere will change to the picture shown in Figure C.2:
The Input Textural Encoding is:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specifications/x3d-3.0.dtd"> <X3D version='3.0' profile='Interchange'> <head> <meta name='filename' content='Instancing.x3d'/> </head> <Scene> <Transform> <Shape> <Sphere/> </Shape> <Transform translation='2.0 0.0 0.0'> <Shape DEF='Joe'> <Sphere radius='0.2'/> </Shape> </Transform> <Transform translation='-2.0 0.0 0.0'> <Shape USE='Joe'/> </Transform> </Transform> </Scene> </X3D>
This file is encoded with all native Fast Infoset encoders without any X3D-specific compression.
The Compressed binary encoded result is available here: Instancing.x3db
Click here to view this example in a 3D scene window.
(Note that the spheres are unlit because no appearance was specified.)
A simple table with variable colours for the legs and top might be prototyped as shown in Figure C.3:
The input textural encoding is:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specifications/x3d-3.0.dtd"> <X3D version='3.0' profile='Immersive'> <head> <meta name='filename' content='Prototype.x3d'/> </head> <Scene> <ProtoDeclare name='TwoColorTable'> <ProtoInterface> <field name='legColor' type='SFColor' value='.8 .4 .7' accessType='initializeOnly'/> <field name='topColor' type='SFColor' value='.6 .6 .1' accessType='initializeOnly'/> </ProtoInterface> <ProtoBody> <Transform> <Transform translation='0.0 0.6 0.0'> <!-- table top --> <Shape> <Appearance> <Material DEF='TableTopMaterial'> <IS> <connect nodeField='diffuseColor' protoField='topColor'/> </IS> </Material> </Appearance> <Box size='1.2 0.2 1.2'/> </Shape> </Transform> <Transform translation='-0.5 0.0 -0.5'> <!-- first table leg --> <Shape DEF='Leg'> <Appearance> <Material DEF='LegMaterial' diffuseColor='1.0 0.0 0.0'> <IS> <connect nodeField='diffuseColor' protoField='legColor'/> </IS> </Material> </Appearance> <Cylinder height='1.0' radius='0.1'/> </Shape> </Transform> <Transform translation='0.5 0.0 -0.5'> <!-- another table leg --> <Shape USE='Leg'/> </Transform> <Transform translation='-0.5 0.0 0.5'> <Shape USE='Leg'/> <!-- another table leg --> </Transform> <Transform translation='0.5 0.0 0.5'> <Shape USE='Leg'/> <!--another table leg --> </Transform> <!-- End of root Transform's children --> </Transform> <!-- End of root Transform --> </ProtoBody> </ProtoDeclare> <!-- End of prototype --> <!-- The prototype is now defined. Although it contains a number of nodes, only the legColor and topColor fields are public. Instead of using the default legColor and topColor, this instance of the table has red legs and a green top: --> <ProtoInstance name='TwoColorTable'> <fieldValue name='legColor' value='1 0 0'/> <fieldValue name='topColor' value='0 1 0'/> </ProtoInstance> <NavigationInfo type='"EXAMINE"'/> <!--Use the Examine viewer--> </Scene> </X3D>
This file is encoded with all native Fast Infoset encoders without any X3D-specific compression.
The Compressed binary encoded result is available here: Prototype.x3db
Click here to view this example in a 3D scene window.
This Script node decides whether or not to open a bank vault given openVault and combinationEntered messages. To do this, it remembers whether or not the correct combination has been entered. The Script node is combined with a Sphere, a TouchSensor and a Sound node to show how scripting works. When the pointing device is over the sphere, the combinationEntered inputOnly field of the Script is sent. Then, when the Sphere is touched (typically when the mouse button is pressed) the Script is sent the openVault inputOnly field. This generates the vaultUnlocked outputOnly field which starts a ‘click’ sound. Here is the example:
The input textural encoding is:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specifications/x3d-3.0.dtd"> <X3D version='3.0' profile='Immersive'> <head> <meta name='filename' content='Scripting.x3d'/> </head> <Scene> <Script DEF='OpenVault'> <field name='openVault' type='SFTime' accessType='inputOnly'/> <field name='combinationEntered' type='SFBool' accessType='inputOnly'/> <field name='vaultUnlocked' type='SFTime' accessType='outputOnly'/> <field name='unlocked' type='SFBool' value='false' accessType='initializeOnly' /> <![CDATA[ ecmascript: function combinationEntered (value) { unlocked = value; } function openVault(value) { if (unlocked) vaultUnlocked = value; } ]]> </Script> <Shape> <Appearance> <Material diffuseColor='1 0 0'/> </Appearance> <Sphere/> </Shape> <Sound maxBack='1000' maxFront='1000' minBack='1000' minFront='1000'> <AudioClip DEF='Click' stopTime='1' description='clicking sound' url='"click.wav"'/> </Sound> <TouchSensor DEF='TS'/> <ROUTE fromNode='TS' fromField='isOver' toNode='OpenVault' toField='combinationEntered'/> <ROUTE fromNode='TS' fromField='touchTime' toNode='OpenVault' toField='openVault'/> <ROUTE fromNode='OpenVault' fromField='vaultUnlocked' toNode='Click' toField='startTime'/> </Scene> </X3D>
NOTE The openVault inputOnly field and the vaultUnlocked outputOnly field are of type SFTime, which allows them to be wired directly to a TouchSensor or TimeSensor.
This file is encoded with all native Fast infoset encoders without any X3D-specific compression.
The Compressed binary encoded result is available here: Scripting.x3db
Click here to view this example in a 3D scene window.