X3D separates the scene, defined in ISO/IEC 19775-1, from the ways of writing it down, each a separate standard (ISO/IEC 19776). The Web3D Consortium publishes them. A scene has the same nodes, fields and routes in every encoding. This page follows the XML encoding (19776-1) and the ClassicVRML encoding (19776-2) of version 3.3; versions 3.0, 3.1, 3.2 and 4.0 use the same structure with their own version numbers.
The encodings
| Encoding | Extension | Media type | Starts with |
|---|---|---|---|
| XML | .x3d, gzipped .x3dz or .x3d.gz | model/x3d+xml | <?xml, then an X3D element |
| ClassicVRML | .x3dv, gzipped .x3dvz or .x3dv.gz | model/x3d+vrml | #X3D V3.3 utf8 |
| Compressed binary | .x3db, gzipped .x3db.gz | model/x3d+binary (ISO/IEC 19776-3, 4.5.2) | a Fast Infoset document |
The compressed binary encoding (19776-3) is the XML encoding written as Fast Infoset (ISO/IEC 24824-1), a binary form of XML, with special encoders for arrays of numbers and optional geometry compression. Its details are not described here.
Profiles, components and units
Every scene names a profile, the set of components a browser must support to show it, and may add further components at given levels.
| Profile | For |
|---|---|
Core | the minimum: metadata and the basics, for building on |
Interchange | exchanging geometry, appearance and simple animation between programs |
CADInterchange | CAD data |
Interactive | Interchange plus sensors and event utilities |
MedicalInterchange | medical volume data |
MPEG4Interactive | the subset used with MPEG-4 |
Immersive | roughly the capability of VRML97 |
Full | every component at its highest level |
A unit statement changes the base unit of a category for the whole
scene: angle (radians by default), force (newtons),
length (metres) or mass (kilograms), with a name and a
conversion factor to the default.
XML encoding
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN"
"http://www.web3d.org/specifications/x3d-3.3.dtd">
<X3D profile="Immersive" version="3.3">
<head>
<component name="Geospatial" level="1"/>
<unit category="length" name="feet" conversionFactor="0.3048"/>
<meta name="title" content="Example"/>
</head>
<Scene>
<Shape DEF="Ball">
<Sphere radius="0.5"/>
</Shape>
</Scene>
</X3D>
| Element or attribute | Meaning |
|---|---|
X3D | the root, with profile and version; instead of the DOCTYPE, it may carry xmlns:xsd and xsd:noNamespaceSchemaLocation for schema validation |
head | optional: component (name, level), unit (category, name, conversionFactor) and meta (name, content) |
Scene | the one scene, holding the nodes |
| node element | a node; simple fields are attributes, node-valued fields are child elements |
containerField | which field of the parent a child node fills, when it is not the node’s usual one (for example proxy in Collision) |
DEF, USE | name a node, or reuse a named one; a USE element may only add containerField and class |
class | reserved for style sheets |
ROUTE | fromNode, fromField, toNode, toField |
ProtoDeclare | name; holds ProtoInterface (optional) of field elements and ProtoBody (required) |
field | name, type, accessType (inputOnly, outputOnly, initializeOnly, inputOutput), and a value attribute or child nodes |
IS, connect | inside a prototype body: connect has nodeField and protoField; IS must be a node’s first child (after any field or fieldValue) |
ExternProtoDeclare | name, nodeType, url (addresses ending # and the prototype’s name), and field elements |
ProtoInstance | name; fieldValue children (name, value) set initializeOnly and inputOutput fields |
IMPORT | inlineDEF, exportedDEF, AS |
EXPORT | localDEF, AS |
Attribute values use single or double quotes; spaces, tabs, line breaks and commas
separate numbers. Each string of an MFString is quoted inside the
attribute: url='"a.png" "b.png"'. Script and shader source goes in a
CDATA section after the field and IS elements.
ClassicVRML encoding
#X3D V3.3 utf8
PROFILE Immersive
COMPONENT Geospatial:1
UNIT length feet 0.3048
META "title" "Example"
DEF Ball Shape {
geometry Sphere { radius 0.5 }
}
The syntax is VRML97’s (see VRML syntax) with these changes:
- The header line is
#X3D, the version andutf8. - One
PROFILEstatement must follow, then anyCOMPONENT name:level,UNIT category name factorandMETA "name" "content"statements, in that order. - Field access types are
inputOnly,outputOnly,initializeOnlyandinputOutput, in place ofeventIn,eventOut,fieldandexposedField. IMPORT inline.exported AS localandEXPORT local AS exportedshare nodes with anInline’s scene.#/*starts a block comment that ends at*/#.
Its keywords are AS, COMPONENT, DEF,
EXPORT, EXTERNPROTO, FALSE,
IMPORT, IS, META, NULL,
PROFILE, PROTO, ROUTE, TO,
TRUE, UNIT, USE, inputOnly,
outputOnly, inputOutput and initializeOnly.
ISO/IEC 19776-2 also bars these as names: false, true,
head, Scene and X3D. Names follow the VRML97
rules. Commas are separators here too, and an unterminated block comment is an error.
The header has exactly one space between its three parts and ends at a line feed or
carriage return; text after utf8 and a space or tab is a comment.