Building Primitive Shapes

Motivation

Shapes are the building blocks of a X3D world. Primitive Shapes are standard building blocks:

Syntax: Shape

  • A Shape node builds a shape
    • appearance - color and texture
    • geometry - form, or structure

XML Encoding

<Shape>
  <!-- appearance ... -->
  <!-- geometry ... -->
<Shape>

Classic Encoding

Shape {
  appearance ...
  geometry ...
}

Specifying appearance

  • Shape appearance is described by appearance nodes
  • For now, we’ll use nodes to create a shaded white appearance:

XML Encoding

<Shape>
  <Appearance>
    <Material/>
  </Appearance>
  <!-- geometry ... -->
</Shape>

Classic Encoding

Shape {
  appearance Appearance {
    material Material { }
  }
  geometry ...
}

Specifying geometry

Shape geometry is built with geometry nodes:

XML Encoding

<Box ... />
<Cone ... />
<Cylinder ... />
<Sphere ... />
<Text ... />

Classic Encoding

Box { ... }
Cone { ... }
Cylinder { ... }
Sphere { ... }
Text { ... }
  • Geometry node fields control dimensions
    • Dimensions usually in meters, but can be anything

A sample primitive shape

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>
    <Shape>
      <Appearance>
        <Material/>
      </Appearance>
      <Cylinder
          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

Building multiple shapes

  • Shapes are built centered in the world
  • A X3D file can contain multiple shapes
  • Shapes overlap when built at the same location

A sample file with multiple shapes

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>
    <Shape>
      <Appearance>
        <Material/>
      </Appearance>
      <Box
          size='1 1 1'/>
    </Shape>
    <Shape>
      <Appearance>
        <Material/>
      </Appearance>
      <Sphere
          radius='0.7'/>
    </Shape>
    <!-- ... -->
  </Scene>
</X3D>

Classic Encoding

#X3D V3.3 utf8

Shape {
  appearance Appearance {
    material Material { }
  }
  geometry Box {
    size 1.0 1.0 1.0
  }
}

Shape {
  appearance Appearance {
    material Material { }
  }
  geometry Sphere {
    radius 0.7
  }
}

...

Multiple Shapes

View scene in this window.

Download ZIP Archive

Summary