QuadTreeExamples Explanation

The following excerpt from QuadTreeExamples.xml (autotranslated to VRML as QuadTreeExamplesTranslated.wrl) explains

First: field-name information for the new extension is provided either via a <ProtoDeclaration> tag (example 3) or via a native DTD declaration (example 4):

    <!-- Example solution approach #3 -->
    <ProtoDeclare name="QuadTree-TagChildren">
      <field type="Nodes" name="upperLeftNode"  IS="GroupE.children"/>
      <field type="Nodes" name="upperRightNode" IS="GroupF.children"/>
      <field type="Nodes" name="lowerLeftNode"  IS="GroupG.children"/>
      <field type="Nodes" name="lowerRightNode" IS="GroupH.children"/>
      <field type="Nodes" name="children"/>
      <!-- PROTO body follows. -->
      <Group>
        <Group DEF="GroupE" />
        <Group DEF="GroupF" />
        <Group DEF="GroupG" />
        <Group DEF="GroupH" />
      </Group>
    </ProtoDeclare>

<!-- example solution definition #4 -->
<!ELEMENT QuadTree-TagChildren ( <!-- list of all nodes goes here --> )* >
<!ATTLIST QuadTree-TagChildren
	upperLeftNode    IDREF #IMPLIED
	upperRightNode   IDREF #IMPLIED
	lowerLeftNode    IDREF #IMPLIED
	lowerRightNode   IDREF #IMPLIED
	nodeTypeHint   NMTOKEN #FIXED "Group"
        DEF              ID    #IMPLIED
	USE              IDREF #IMPLIED>

Next: the X3D scene instantiates the extension, either via a <ProtoInstance> tag (example 3) or via a native XML tag (example 4):

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->    
<!-- Examples 3 and 4 use actual nodes for subtree references, via PROTOs or XML tags.   -->    
      <Transform DEF="Example_3" translation="0 -2 0">
        <ProtoInstance name="QuadTree-TagChildren">
          <fieldValue fieldName="upperLeftNode"><Transform USE="UPPER_LEFT"//fieldValue>
          <fieldValue fieldName="upperRightNode"><Transform USE="UPPER_RIGHT"/></fieldValue>
          <fieldValue fieldName="lowerLeftNode"><Transform USE="LOWER_LEFT"/></fieldValue>
          <fieldValue fieldName="lowerRightNode">
            <Transform translation="-6 0 4">
              <Shape>
                <Text string=' "QuadTree-TagChildren" "ProtoInstance" '/>
                <Appearance USE="WHITE"/>
              </Shape>
            </Transform>
          </fieldValue>
        </ProtoInstance>
      </Transform>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
      <Transform DEF="Example_4" translation="0 -6 0">
        <QuadTree-TagChildren>
          <fieldValue fieldName="upperLeftNode"><Transform USE="UPPER_LEFT"/></fieldValue>
          <fieldValue fieldName="upperRightNode"><Transform USE="UPPER_RIGHT"/></fieldValue>
          <fieldValue fieldName="lowerLeftNode"><Transform USE="LOWER_LEFT"/></fieldValue>
          <fieldValue fieldName="lowerRightNode">
            <Transform translation="-6 0 4">
              <Shape>
                <Text string=' "QuadTree-TagChildren" "Native tags" '/>
                <Appearance USE="WHITE"/>
              </Shape>
            </Transform>
            <WorldInfo info="this WorldInfo is here to demonstrate that the example is type MFNode/Nodes" />
          </fieldValue>
        </QuadTree-TagChildren>
      </Transform>
    </Group>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

Finally: excerpts from the autotranslated VRML shows preservation of customized field names in the PROTO:

PROTO QuadTree-TagChildren [
  exposedField MFNode upperLeftNode [ ] # IS GroupE.children
  exposedField MFNode upperRightNode [ ] # IS GroupF.children
  exposedField MFNode lowerLeftNode [ ] # IS GroupG.children
  exposedField MFNode lowerRightNode [ ] # IS GroupH.children
  exposedField MFNode children [ ]
] {
  Group {
    children [
      DEF GroupE Group {
	children IS upperLeftNode
      }
      DEF GroupF Group {
	children IS upperRightNode
      }
      DEF GroupG Group {
	children IS lowerLeftNode
      }
      DEF GroupH Group {
	children IS lowerRightNode
      }
    ]
  }
}

# ... omitted examples 1 and 2 ...

    DEF Example_3 Transform {
      children [
	QuadTree-TagChildren {
	  children [
	  ]
	  upperLeftNode USE UPPER_LEFT
	  upperRightNode USE UPPER_RIGHT
	  lowerLeftNode USE LOWER_LEFT
	  lowerRightNode Transform {
	    children [
	      Shape {
		geometry Text {
		  string [ "QuadTree-TagChildren" "ProtoInstance" ]
		}
		appearance USE WHITE
	      }
	    ]
	    translation -6 0 4
	  }
	}
      ]
      translation 0 -2 0
    }
    DEF Example_4 Transform {
      children [
	QuadTree-TagChildren {
	  children [
	  ]
	  upperLeftNode USE UPPER_LEFT
	  upperRightNode USE UPPER_RIGHT
	  lowerLeftNode USE LOWER_LEFT
	  lowerRightNode [
	    Transform {
	      children [
		Shape {
		  geometry Text {
		    string [ "QuadTree-TagChildren" "Native tags" ]
		  }
		  appearance USE WHITE
		}
	      ]
	      translation -6 0 4
	    }
	    WorldInfo {
	      info [ "this WorldInfo is here to demonstrate that the example is MFNode/Nodes" ]
	    }
	  ]
	}
      ]
      translation 0 -6 0
    }
  ]
}

Conclusion: the <fieldValue> tag (originally named <defaultValue>) enables the parser to disambiguate contained field data from contained content, just as field-name wrapper tags do. A further advantage of this approach is that strong typing of nodes is retained throughout the scene.


Revised: 22 April 2000

Uniform Resource Locator (URL): www.web3D.org/TaskGroups/x3d/translation/example/QuadTreeExamplesExplanation.html

Author: Don Brutzman