Chapter 2. What is X3D?

X3D [X3D] is a language to describe 3D worlds. The precise specification of the language is open to everyone. In effect, many applications can handle X3D and cooperate with each other. For example, you can create an X3D file using any popular 3D modeller (like Blender) and then load it into any X3D browser (like our view3dscene, see [Castle Game Engine]).

Many common 3D features, like triangle meshes with materials and textures, are easy to express. Yet the whole X3D standard is quite large, including advanced 3D concepts like NURBS, cube mapping, multi-texturing, particle effects, skinned humanoid animation, spatial sound, and physics.

The scene is represented as a graph of nodes. In the simple cases, the scene is just a tree of nodes. In a general case, it can be a directed graph of nodes, with possible cycles. The X3D specification lists the available node types and their fields. It is also possible to define new full-featured node types using prototypes.

An example of a simple X3D file in the classic encoding follows. You can save it as a file named test.x3dv and open with any X3D browser.

#X3D V3.2 utf8
PROFILE Interchange
Shape {
  geometry Sphere { radius 2 }
}

Example below shows the same X3D content encoded using the XML format. Note that we omitted DTD and XML schema declarations for brevity. Again, you can open this file with any X3D browser (be sure to save it with an .x3d extension).

<?xml version="1.0" encoding="UTF-8"?>
<X3D version="3.2" profile="Interchange">
  <Scene>
    <Shape>
      <Sphere radius="2" />
    </Shape>
  </Scene>
</X3D>

To enable basic animation and interactive behavior, X3D introduces the concept of events and routes. Many nodes have the ability to send events, notifying about something. There are even special nodes called sensors with the sole purpose of sending events when something happens. For example mouse sensors, that report user clicking and dragging on the scene. Independently, many nodes can also receive events, which allows to instruct the node to do something (for example, start the animation). The X3D author can declare routes that connect given node's output event (a socket used to send an event) to another node's input event (a socket used to receive an event). For example, open a door when the handle is pressed.

Below is an example of a simple interactive animation. When you click on a sphere, the TimeSensor starts ticking, which in turn makes the PositionInterpolator produce 3D positions with increasing Y value. The positions are then used to move the sphere up.

#X3D V3.2 utf8
PROFILE Interchange

DEF MyTransform Transform {
  children Shape {
    geometry Sphere { }
  }
}

DEF MyTouchSensor TouchSensor { }

DEF MyTimeSensor TimeSensor { }

DEF MyInterpolator PositionInterpolator {
  key      [ 0      1     ]
  keyValue [ 0 0 0  0 1 0 ]
}

ROUTE MyTouchSensor.touchTime TO MyTimeSensor.startTime
ROUTE MyTimeSensor.fraction_changed TO MyInterpolator.set_fraction
ROUTE MyInterpolator.value_changed TO MyTransform.set_translation