[X3D-Public] SFNode and MFNode
Michalis Kamburelis
michalis.kambi at gmail.com
Wed May 4 14:05:32 PDT 2011
Sajjadul Islam wrote:
> Consider the following example picked from the book "Extensible 3D
> Graphics for Web Authors":
>
> <Shape>
> <Sphere radius="10.0" Solid="true" />
>
> <Appearance>
> <ImageTexture = "earth-topo.png" />
> </Appearance>
> </Shape>
>
> In the above example Shape node contains some child nodes. This node has
> two fields of type SFNode ; one for the geometry and the other for the
> appearance. And Node of this nodes are edited explicitly by the author.
> Will they be still NULL? Should it not be something the following:
>
> <Shape geometry=? appearance=?>
> <Sphere radius="10.0" Solid="true" />
>
> <Appearance>
> <ImageTexture = "earth-topo.png" />
> </Appearance>
> </Shape>
>
>
> "?" means i do not know what to put there.
>
In the XML encoding, the field where the child is placed is implicitly
given by the type of the child. That is, the <Sphere> node is actually a
value of the "Shape.geometry" field. And the <Appearance> node is
actually a value of the "Shape.appearance" field. You just don't have to
explicitly write anywhere that <Sphere> goes to "geometry", because the
X3D XML encoding specification already says that <Sphere> by default
always goes to the "geometry" field of the parent node.
This is called "containerField". See "X3D encodings: XML encoding"
specification on http://web3d.org/x3d/specifications/, in particular
section "6 Encoding of nodes" of this specification contains a long
table with a default "containerField" value for all existing nodes.
You could as well use containerField explicitly, like below (I also
fixed small typos in your example):
<Shape>
<Sphere radius="10.0" solid="true" containerField="geometry" />
<Appearance containerField="appearance">
<ImageTexture url='"earth-topo.png"'
containerField="texture" />
</Appearance>
</Shape>
Also in the classic X3D encoding, the field name is always given
explicitly, so it's obvious where the node belongs:
Shape {
geometry Sphere { radius 10.0 solid TRUE }
appearance Appearance {
texture ImageTexture { url "earth-topo.png" }
}
}
And my two examples above are equivalent to your example, that is a good
X3D browser should treat them exactly the same. In your example, the
field names are just not specified, which is more comfortable but also
understandably may be confusing.
Hope this helps,
Michalis
More information about the X3D-Public
mailing list