[X3D-Public] Displaying a graph in X3D.

John Carlson john.carlson3 at sbcglobal.net
Fri Apr 9 05:12:34 PDT 2010


Here's my first cut at displaying a bunch of dynamically spheres in random locations.  It doesn't pass the schematron, (Exception:null)
The StringSensor doesn't appear to be working.  But it is does display 3 spheres at the beginning in Octaga.  FreeWRL core dumps.  Xj3D complains about USE and DEF (see how I am using them in the same element).  Not sure what else to do.

John

<?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 profile="Immersive" version="3.0"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.0.xsd">
    <head>
        <meta name="author" content="John Carlson"/>
    </head>
    <Scene>
        <ProtoDeclare name="GraphNode">
            <ProtoInterface>
                <field name="translation" type="SFVec3f" accessType="inputOutput" value="0 0 0"/>
            </ProtoInterface>
            <ProtoBody>
                <Transform scale="0.2 0.2 0.2">
                    <IS>
                        <connect nodeField='translation'
			protoField='translation'/>
                    </IS>
                    <Shape>
                        <Appearance>
                            <Material diffuseColor="1 0 0"/>
                        </Appearance>
                        <Sphere/>
                    </Shape>
                </Transform>
            </ProtoBody>
        </ProtoDeclare>
        <NavigationInfo type="&quot;EXAMINE&quot; &quot;ANY&quot;"/>
        <Viewpoint description="Nodes" orientation="1 0 0 -0.4" position="0 5 12"/>
        <StringSensor DEF="Keystrokes" USE="Keystrokes" enabled="true"/>
        <ProtoInstance name="GraphNode" DEF="Node1">
            <fieldValue name="translation" value="0 2 0"/>
        </ProtoInstance>
        <ProtoInstance name="GraphNode" DEF="Node2">
            <fieldValue name="translation" value="0 -2 0"/>
        </ProtoInstance>
        <ProtoInstance name="GraphNode" DEF="Node3">
            <fieldValue name="translation" value="0 0 0"/>
        </ProtoInstance>
 <Script DEF="NewNode" USE="NewNode">
                    <field accessType="inputOnly" name="set_rightstring" type="SFString"/>
<![CDATA[
ecmascript:

var protoDecl;

function initialize() {
	scene = Browser.currentScene;
	protoDecls = scene.protoDeclarations;


        for(i=0; i < protoDecls.length; i++) {
        	if (protoDecls[i].name == 'GraphNode') {
                	protoDecl = protoDecls[i];
		}
        }

      
}

function set_rightstring(rightstr) {
        instance =  protoDecl.newInstance();
	instance.translation = new SFVec3f(Math.random()*4-2, Math.random()*4-2, Math.random()*4-2);
	scene = Browser.currentScene;
        scene.rootNodes[scene.rootNodes.length] = instance;
}
]]>
                </Script>
        <ROUTE fromField="enteredText" fromNode="Keystrokes"
          toField="set_rightstring" toNode="NewNode"/>

    </Scene>
</X3D>




More information about the X3D-Public mailing list