Pinecoast
 
Basic
Handbag
Cell Phone
Watch
 
Basic 3D Geometry
Messaging
Background
Butterflies
Fog
Color Interpolator
3D Shapes
2D Shapes
Textures
Material
IndexedFaceSet
Layering
Overlay
Shaders 1
Shaders 2
 
     


Tutorial: Basic 3D Geometry

Basic Geometry

The street light at the left will be created in this first tutorial. The model will be a made from a collection of seven geometric objects, which are cylinders, cones and a sphere. Each of these objects will be placed into a Transform node that will be used to move it into position. The objects themselves will be Shape nodes.

Basic Geometry

Every Shape node is divided into two parts: its geometry and its appearance. The geometry field of a Shape node contains the physical form of the object. In this example the contents of the geometry field will be a Cylinder, Cone or Sphere, but there are many other geometry nodes, such as IndexedFaceSet. The appearance field of a Shape node contains an Appearance node. In this tutorial, the Appearance nodes will contain Material nodes which will be used to add color. The illustration at the left shows the basic tree structure of the VRML file.

Basic Geometry

The structure of the file can also be seen in the user interface of SwirlX3D. Each node in the tree has fields that describe the node. In this case the Material node has been selected and the fields for this node are shown below. The diffuseColor field will be used later to apply color to the objects.

The base of the lamp is a cylinder of radius 0.5 with a thickness of 0.1. Within a VRML file the object is expressed as follows.

Transform 
    children Shape {
        appearance Appearance {
            material Material {
                diffuseColor 0 1 0
            }
        }
        geometry {
            Cylinder {
                height 0.1
                radius 0.5
            }
        }
    }
}

The names of the fields start with small letters and the type of nodes placed into them start with Captial letters. The colors are in RGB format with each color parameter between 0 and 1. Thus the cylinder here willl be green. This object will look the same in a VRML97 file, which has extension .wrl, or in a VRML 3.0 file, which has extension .x3dv. The X3D format is a type of XML with file extension .x3d. The contents of the file in either case is same but in a different format as can be seen from the following.

<Transform>
  <Shape>
    <Appearance>
      <Material diffuseColor="0 1 0"/>
    </Appearance>
    <Cylinder height="0.1" radius="0.5"/>
  </Shape>
</Transform>

The main column is a cylinder of radius 0.1 and height 2. The Transform node has a translation added to position the cylinder above the base. The y axis is the vertical axis in X3D.

Transform {
  translation 0 1 0
  children 
    Shape {
      appearance Appearance {
        material Material {
          diffuseColor 0 1 0
        }
      }
      geometry Cylinder {
        radius 0.1
      }
    }
}

There are two other cylinders and a cone for the cover, that are made in a similar fashion. The glass window is a cone also but it has been rotated by 180 degrees about the z axis to turn it upside down. The z axis points toward the viewer, and all angles are given in radians. The color has been made white and the material is partially transparent.

Transform {
  rotation 0 0 1 3.14159
  translation 0 2.4 0
  children
    Shape {
      appearance Appearance {
        material Material {
          diffuseColor 1 1 1
          transparency 0.2
        }
      }
      geometry Cone {
        bottomRadius 0.4
        height 0.5
      }
    }
}

Finally the light bulb is a white sphere that has been placed inside the window.

Transform {
  translation 0 2.375 0
  children
    Shape {
      appearance Appearance {
        material Material {
          diffuseColor 1 1 0.502
        }
      }
      geometry Sphere {
        radius 0.1
      }
    }
}

Download tutorial files





     
 
 

SwirlX3D Viewer


The SwirlX3D Viewer is a free standalone application for viewing VRML, X3D. It also displays sw3d archives created by the SwPublish program.
The professional version also displays files from other formst such as Collada(DAE), 3DS, OBJ, PLY, STL and IGES (IGS).
For more details ...

 

SwTranslator for VRML, X3D and Collada


The SwTranslator can export VRML, X3D, Collada(DAE), 3DS, OBJ, PLY, STL or IGES files to VRML, X3D or Collada. For X3D this offers a migration path for importing high quality 3D models from a variety of sources. For Collada, it offers an opportunity to bring geometry and animation into this increasingly popular format.
For more details ...