X3D file structure
This article or section is currently under construction
In principle, someone is working on it and there should be a better version in a not so distant future.
If you want to modify this page, please discuss it with the person working on it (see the "history")
Introduction
X3D scene files have a common file structure:
- File header (XML, ClassicVRML, Compressed Binary)
- X3D header statement
- Profile statement
- A head section with Component and Meta statements (both optional)
- X3D root node
- X3D scene graph child nodes
We shall shortly describe these elements below. But before, let's have a look at the code of a simple exemple scene, inserted XML comments identify the elements:
<?xml version="1.0" encoding="UTF-8"?>
<!-- -------------------- X3D header and X3D root with profile declaration -->
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.2//EN"
"http://www.web3d.org/specifications/x3d-3.2.dtd">
<X3D profile='Immersive' version='3.2'
xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance'
xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.2.xsd'>
<!-- -------------------- head section with included meta data -->
<head>
<meta content='HelloWorld.x3d' name='title'/>
<meta content='Simple X3D example' name='description'/>
<meta content='30 October 2000' name='created'/>
<meta content='7 August 2010' name='modified'/>
<meta content='Don Brutzman' name='creator'/>
<meta content='http://www.web3D.org' name='reference'/>
<meta content='http://x3dGraphics.com' name='reference'/>
<meta content='http://www.web3d.org/x3d/content/examples/HelloWorld.x3d' name='identifier'/>
<meta content='http://www.web3d.org/x3d/content/examples/HelloWorldTall.png' name='image'/>
<meta content='http://www.web3d.org/x3d/content/examples/license.html' name='license'/>
<meta content='X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit' name='generator'/>
</head>
<!-- -------------------- the X3D scene -->
<Scene>
<!-- Example scene to illustrate X3D nodes and fields (XML elements and attributes) -->
<Group>
<Viewpoint centerOfRotation='0 -1 0' description='Hello world!' position='0 -1 7'/>
<Transform rotation='0 1 0 3'>
<Shape>
<Sphere/>
<Appearance>
<Material diffuseColor='0 0.5 1'/>
<ImageTexture url='"earth-topo.png" "earth-topo.jpg" "earth-topo-small.gif" "http://www.web3d.org/x3d/content/examples/Basic/earth-topo.png" "http://www.web3d.org/x3d/content/examples/Basic/earth-topo.jpg" "http://www.web3d.org/x3d/content/examples/Basic/earth-topo-small.gif"'/>
</Appearance>
</Shape>
</Transform>
<Transform translation='0 -2 0'>
<Shape>
<Text string='"Hello" "world!"'>
<FontStyle justify='"MIDDLE" "MIDDLE"'/>
</Text>
<Appearance>
<Material diffuseColor='0.1 0.5 1'/>
</Appearance>
</Shape>
</Transform>
</Group>
</Scene>
<!-- -------------------- footer, closing X3D toot element -->
</X3D>
File and X3D header
Since X3D has grown out of VRML it has both an XML and a VRML syntax. In addition, both formats can be delivered in compressed format.
The following file extensions should be used for X3D contents:
X3D Encoding | File Extension | MIME Type |
---|---|---|
Classic VRML | .x3dv | model/x3d+vrml |
XML | .x3d | model/x3d+xml |
Binary | .x3db | model/x3d+binary |
E.g. if you have an apache server you could add the following lines to a *.conf file:
AddType model/x3d+xml .x3d AddType model/x3d+vrml .x3dv AddType model/x3d+binary .x3db AddEncoding gzip .x3dvz AddEncoding gzip .x3dbz
Profiles, components
X3D X3D has a modular architecture that includes four baseline profiles which are are predefined collections of components.
In addition, within the head section, authors can specify more precisely what components are needed. Components are predefined collections of nodes and match chapters in the specification. Each profile can be augmented by adding other components
Both the mandatory profile definition and the optional components statements tells the X3D browser what level of support is needed for run-time operation.
The specification includes four profiles:
- Interchange is the basic profile for communicating between applications. It supports geometry, texturing, basic lighting, and animation
- Interactive enables basic interaction with a 3D environment by adding various sensor nodes for user navigation and interaction (e.g., PlanseSensor, TouchSensor, etc.), enhanced timing, and additional lighting (Spotlight, PointLight).
- Immersive enables full 3D graphics and interaction, including audio support, collision, fog, and scripting.
- Full includes all defined nodes including NURBS, H-Anim (animated interactive Avatars) and GeoSpatial components.
Meta statements
Meta statements provide information about the X3D scene as a whole
Information is provided as name-value pairs, for example
<meta name='created' value='1 January 2008'/>
This approach is thus very general and a wide variety of metadata can be represented. The X3D approach matches same approach used by HTML for regular hypertext web pages.
The X3D scene graph
Each X3D file only can include one X3D scene according to XML principles. In other words there must be a single root element.
At the content level, the same principle as for HTML applies. There can be only a single scene in the same way that in HTML there is only one body
A very minimalistic valid X3D file would look like this
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.2//EN"
"http://www.web3d.org/specifications/x3d-3.2.dtd">
<X3D profile='Immersive' version='3.2'
xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance'
xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.2.xsd'>
<head>
</head>
<Scene>
<!-- Scene graph with a single red ball -->
<Shape>
<Sphere radius='2.0'/>
<Appearance>
<Material diffuseColor='1.0 0.0 0.0'/>
</Appearance>
</Shape>
</Scene>
</X3D>
X3D ClassicVRML syntax
In our tutorials we shall not explain VRML syntax. See the VRML Primer and Tutorial we made over 10 years ago. We just point out that X3D/ClassicVRML is different from VRML1997, i.e. the ClassicVRML profile looks like VRML and uses the same syntax, but there are some changes between the last VRML standard (ISO/IEC 14772-1) and the new X3D-based ISO/IEC 19776-2. In particular, the scripting interface has been totally overhauled.
It is also important to understand the most X3D clients can render VRML 1997 (and the other way round if the VRML client is recent).
#X3D V3.2 utf8
PROFILE Immersive
META "title" "HelloWorld.x3d"
META "description" "Simple X3D example"
META "created" "30 October 2000"
META "modified" "7 August 2010"
META "creator" "Don Brutzman"
META "reference" "http://www.web3D.org"
META "reference" "http://x3dGraphics.com"
META "identifier" "http://www.web3d.org/x3d/content/examples/HelloWorld.x3d"
META "image" "http://www.web3d.org/x3d/content/examples/HelloWorldTall.png"
META "license" "http://www.web3d.org/x3d/content/examples/license.html"
META "generator" "X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit"
NavigationInfo { type [ "EXAMINE" "ANY" ] } ### Default X3D NavigationInfo
# Example scene to illustrate a single X3D node in VRMLClassic syntax
Shape {
geometry Sphere { }
appearance Appearance {
material Material {
diffuseColor 0 0.5 1
}
}
}