Post

Building Primitive Shapes

Building Primitive Shapes

Motivation

Shapes are the building blocks of an 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

1
2
3
4
<Shape>
  <!-- appearance ... -->
  <!-- geometry ... -->
<Shape>

Classic VRML Encoding

1
2
3
4
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

1
2
3
4
5
6
<Shape>
  <Appearance>
    <Material/>
  </Appearance>
  <!-- geometry ... -->
</Shape>

Classic VRML Encoding

1
2
3
4
5
6
Shape {
  appearance Appearance {
    material Material { }
  }
  geometry ...
}

Specifying geometry

Shape geometry is built with geometry nodes:

XML Encoding

1
2
3
4
5
<Box ... />
<Cone ... />
<Cylinder ... />
<Sphere ... />
<Text ... />

Classic VRML Encoding

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

A sample primitive shape

XML Encoding

1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 4.0/EN" "https://www.web3d.org/specifications/x3d-4.0.dtd">
<X3D profile='Full' version='4.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-4.0.xsd'>
  <Scene>
    <Shape>
      <Appearance>
        <Material/>
      </Appearance>
      <Cylinder
          radius='1.5'/>
    </Shape>
  </Scene>
</X3D>

Classic VRML Encoding

1
2
3
4
5
6
7
8
9
10
11
#X3D V4.0 utf8
# A cylinder
Shape {
  appearance Appearance {
    material Material { }
  }
  geometry Cylinder {
    height 2.0
    radius 1.5
  }
}

Example

Cylinder

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 4.0/EN" "https://www.web3d.org/specifications/x3d-4.0.dtd">
<X3D profile='Full' version='4.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-4.0.xsd'>
  <Scene>
    <Shape>
      <Appearance>
        <Material/>
      </Appearance>
      <Box
          size='1 1 1'/>
    </Shape>
    <Shape>
      <Appearance>
        <Material/>
      </Appearance>
      <Sphere
          radius='0.7'/>
    </Shape>
    <!-- ... -->
  </Scene>
</X3D>

Classic VRML Encoding

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#X3D V4.0 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
  }
}

...

Example

Multiple Shapes

Summary

This post is licensed under CC BY 4.0 by the author.