Building a X3D World

X3D file structure

X3D files contain:

  • The file header
  • Comments - notes to yourself
  • Nodes - nuggets of scene information
  • Fields - node attributes you can change
  • Values - attribute values
  • Routes - connections between fields
  • more …

A sample X3D file

XML Encoding

<?xml version="1.0" encoding="UTF-8"?>

<X3D profile='Full' version='3.3' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.3.xsd'>
  <Scene>
  <!-- A Cylinder -->
  <Shape>
    <Appearance>
      <Material/>
    <Appearance>
    <Cylinder
        height='2.0'
        radius='1.5'/>
    </Shape>
  </Scene>
</X3D>

Classic Encoding

#X3D V3.3 utf8
# A Cylinder
Shape {
  appearance Appearance {
    material Material { }
  }
  geometry Cylinder {
    height 2.0
    radius 1.5
  }
}

Cylinder

View scene in this window.

Download ZIP Archive

Understanding the header

#X3D V3.3 utf8

  • #X3D: File contains X3D text
  • V3.3 : Text conforms to version 3.3 syntax
  • utf8 : Text uses UTF8 character set

Understanding UTF8

  • utf8 is an international character set standard
  • utf8 stands for:
    • UCS (Universal Character Set) Transformation Format, 8-bit
    • Encodes 24,000+ characters for many languages
    • ASCII is a subset

Using comments

# A Cylinder
  • Comments start with a number-sign (#) and extend to the end of the line

Using nodes

XML Encoding

<Cylinder/>

Classic Encoding

Cylinder {
}
  • Nodes describe shapes, lights, sounds, etc.
  • Every node has:
    • A node type (Shape, Cylinder, etc.)
    • A pair of curly-braces
    • Zero or more fields inside the curly-braces

Using node type names

Node type names are case sensitive:

  • Each word starts with an upper-case character
  • The rest of the word is lower-case

Some examples:

Appearance, Cylinder, Material, Shape

Using fields and values

XML Encoding

<Cylinder
    height='2.0'
    radius='1.5'/>

Classic Encoding

Cylinder {
  height 2.0
  radius 1.5
}
  • Fields describe node attributes

Every field has:

  • A field name (height, radius, etc.)
  • A data type (float, integer, etc.)
  • A default value
  • Different node types have different fields
  • Fields are optional
    • A default value is used if a field is not given
  • Fields can be listed in any order
    • The order doesn’t affect the node

Summary

  • The file header gives the version and encoding
  • Nodes describe scene content
  • Fields and values specify node attributes
  • Everything is case sensitive