Studierstube scripting mentor

Creating your first applications

After the basic syntax of the file format has been explained, we can now start to introduce the most important and useful nodes and create simple scenes with them.

Defining geometry

Open Inventor offers a wide range of shape nodes that can be used to create an application's geometry. Besides the usual 3-dimensional graphics primitives and text, it is possible to create arbitrary polygon or NURBS geometry, possibly exported from a 3D modelling package.

The geometry of primitive objects and text is determined by fields provided by the shape node. For arbitrary shaped surfaces like polygon and NURBS surfaces, it is necessary to specify the coordinates of all vertices, as well as additional information like surface normals, material or texture coordinates for each vertex, explicitly. This information is stored in seperate nodes, to allow sharing of this information between multiple nodes. Vertex coordinates are set by adding a Coordinate3 node to the scene graph, which contains a single field, point, of type MFVec3f to specify the current set of vertices. This node adds the specified coordinates to the traversal state, from which they can be used by shape nodes to render their geometry. For example:

Coordinate3 {                        # defines the set of coordinates to operate on
    point [ 0 0 0 , 0 1 0, 0 0 1, 0 1 1 ]
}
IndexedFaceSet {                     # render an IndexedFaceSet
    coordinateIndex [ 0, 1, 2, -1,   # vertex indices of polygons to render, 
                      1, 2, 3, -1 ]  # -1 starts a new polygon
}

The following table lists the most important geometry nodes provided by Open Inventor. For the beginning, you will be working mostly with basic primitives and text nodes to create simple content. Generic surfaces allow users to create arbitrarily shaped surfaces.

Name Description Fields
Basic Primitives
SoCone
Cone shape SFBitMask parts
SFFloat bottomRadius
SFFloat height

SoCube

Cube with adjustable sides SFFloat width
SFFloat height
SFFloat depth
SoCylinder Cylinder shape SFFloat radius
SFFloat height
SFBitMask parts
SoSphere Sphere shape SFFloat radius
Text
SoText2 Node for rendering 2-dimensional text, always facing the viewer. Each value of the MFString input is rendered on a seperate line. MFString string
SFFloat spacing
SFEnum justification
SoText3 Node for rendering extruded, 3-dimensional text that can be freely positioned in space. Each value of the MFString input is rendered on a seperate line. MFString string
SFFloat spacing
SFEnum justification
SFBitMask parts
SoAsciiText Node for rendering flat 3D text. Each value of the MFString input is rendered on a seperate line. MFString string
SFFloat spacing
SFEnum justification
MFFloat width
Generic Surfaces
SoIndexedFaceSet
Constructs a 3D shape by drawing its faces from an indexed list of vertices SoSFNode vertexProperty
MFInt32 coordIndex
MFInt32 materialIndex
MFInt32 normalIndex
MFInt32 textureCoordIndex
SoIndexedNurbsSurface
Renders NURBS-based surfaces. SFInt32 numUControlPoints
SFInt32 numVControlPoints
MFInt32 coordIndex
MFFloat uKnotVector
MFFloat vKnotVector
SFInt32 numSControlPoints
SFInt32 numTControlPoints
MFInt32 textureCoordIndex
MFFloat sKnotVector
MFFloat tKnotVector
SoTriangleStripSet
Render and control non-indexed triangle strips SoSFNode vertexProperty
SoSFInt32 startIndex MFInt32 numVertices
SoIndexedTriangleStripSet
  SoSFNode vertexProperty
MFInt32 coordIndex
MFInt32 materialIndex
MFInt32 normalIndex
MFInt32 textureCoordIndex
SoQuadMesh
  SoSFNode vertexProperty
SoSFInt32 startIndex
SFInt32 verticesPerColumn
SFInt32 verticesPerRow
Lines & Points
SoLineSet render and organize non-indexed polylines

SoSFNode vertexProperty
SoSFInt32 startIndex
SoMFInt32 numVertices

SoIndexedLineSet render and organize polylines with arbitrary vertex order SoSFNode vertexProperty
SoMFInt32 coordIndex
SoMFInt32 materialIndex
SoMFInt32 normalIndex
SoMFInt32 textureCoordIndex
SoNurbsCurve render and organize non-indexed NURBS curves SoSFInt32 numControlPoints
SoMFFloat knotVector
SoIndexedNurbsCurve render and organize NURBS curves with arbitrary vertex order SoSFInt32 numControlPoints
SoMFInt32 coordIndex
SoMFFloat knotVector
SoPointSet render a point cloud SoSFNode vertexProperty
SoSFInt32 startIndex
SoStroke* (Kit) This class provides a stroke geometry similar to strokes in vector drawing programs SoMFVec3f point
SoSFEnum scale
(SoSFNode) geometry
Geometry Support
SoCoordinate3 a node for providing coordinates to shape nodes SoMFVec3f point
SoNormal a node for providing normals to the state SoMFVec3f vector

Transformations

For positioning geometry in space, transformation nodes are used. A transformation nodes can be used to translate, rotate or scale geometry. All transformations are accumulated in the traversal state, therefore transformations are cumulative and affect all nodes that are traversed afterwards.

Simple animation can be realized by using animated transformation nodes. These nodes will change their transformation values at a predefined speed.

The following table lists the available transformation nodes:

Name Description Fields
SoTransform "All-purpose" transformation node. Specify the rotation by 4 numbers: the rotation axis (x,y,z vector) and the angle in radians. SoSFVec3f translation
SoSFRotation rotation
SoSFVec3f scaleFactor
SoSFRotation scaleOrientation
SoSFVec3f center
SoTranslation Node for specifying geometry translations

SoSFVec3f translation

SoScale Node for scaling geometry SoSFVec3f scaleFactor
SoRotation Specifies a rotation transformation. Specify the rotation by 4 numbers: the rotation axis (x,y,z vector) and the angle in radians.

SoSFRotation rotation

SoRotationXYZ Node for specifying rotation around a particular axis SoSFEnum axis
SoSFFloat angle
SoMatrixTransform Node that takes a matrix to specify the transformation. SoSFMatrix matrix
Animated transformations
SoRotor animated rotation node

SoSFRotation rotation
SoSFFloat speed
SoSFBool on

SoPendulum animated oscillating rotation node SoSFRotation rotation0
SoSFRotation rotation1
SoSFFloat speed
SoSFBool on
SoSFRotation rotation
SoShuttle animated oscillating translation node SoSFVec3f translation
SoSFVec3f translation0
SoSFVec3f translation1
SoSFFloat speed
SoSFBool on

The following example shows how geometry nodes and transformations are combined:

#Inventor V2.0 ascii


# This is a simple coordinate system, built from geometry primitives
 
DEF AXIS Group {               # this is our Y-axis
    Transform {
        translation 0 0.1 0    # go to center of axis
    }
    DEF LINE Cylinder {        # cylinder stretches in both directions
        radius 0.0025
        height 0.2
    }
    Transform {
        translation 0 0.1 0    # go to tip of axis
    }
    DEF ARROW Cone {           # use cone as arrow
        bottomRadius 0.005
        height 0.02
    }
    Transform {
        translation 0 0 -0.2   # un-do translations
    }
}
Transform {
    rotation 0 0 1 1.5708      # rotate 90 degrees around z-axis
}
USE AXIS                       # X-axis
Transform {
    rotation 0 1 0 1.5708      # rotate 90 degrees around y-axis
}
USE AXIS                       # Z-axis
Note that transformations accumulate during traversal - this means that temporary transformations, like the transformations needed to place the line and arrow parts correctly, must be undone explicitly. A better way to deal with this behaviour will be explained below.

Material & Appearance

Open Inventor provides several nodes that influence the appearance of geometry. All nodes that are traversed before the geometry node influence the appearance of that node. For example:

Material {               # set the color to red
    diffuseColor 1 0 0
}
DrawStyle {              # set style to wireframe
    style LINES          
}
Sphere {                 # will render a red sphere in wireframe
    radius 0.1
}

The following table lists some useful appearance nodes provided by Open Inventor:

Name Description Fields
SoBaseColor Sets the base color to be used for subsequent shapes SoMFColor rgb
SoDrawStyle Specificies common rendering properties for shapes SoSFEnum style
SoSFFloat pointSize
SoSFFloat lineWidth
SoSFUShort linePattern
SoEnvironment Node for specifying global rendering parameters SoSFFloat ambientIntensity
SoSFColor ambientColor
SoSFVec3f attenuation
SoSFEnum fogType
SoSFColor fogColor
SoSFFloat fogVisibility
SoFont Appearance node for setting fonts SoSFName name
SoSFFloat size
SoLightModel Sets the light model used for rendering (BASE_COLOR or PHONG) SoSFEnum model
SoMaterial Setting up material values for scene geometry SoMFColor ambientColor
SoMFColor diffuseColor
SoMFColor specularColor
SoMFColor emissiveColor
SoMFFloat shininess
SoMFFloat transparency
SoShapeHints Containing hints about how to render geometry SoSFEnum vertexOrdering
SoSFEnum shapeType
SoSFEnum faceType
SoSFFloat creaseAngle

Group Nodes

Group nodes are not only useful for strucutring your files to keep an overview, but can also be referenced as a single object and control how appearance and other properties are applied to their children. The basic group node is SoGroup - it has no side effect besides grouping its children into a single referenceable entity. Another important group node is SoSeparator. A separator stores the traversal state - including material, transformations, textures, cameras, lights... - and will restore the whole traversal state after traversing its children. Therefore, any state change (like material, transformation etc.) defined inside a Separator will not affect nodes that are outside this Separator. For example:

Material { diffuseColor 0 0 1 }      # sets color to blue
DEF SPHERE Sphere {}                 # renders a blue sphere
Transform { translation 1 0 0 }      # move 1 meter in x-direction
Separator {                          # push state to the stack
    Material { diffuseColor 1 0 0 }  # sets color to red
    USE SPHERE                       # renders a red sphere
}                                    # state is reset again
Transform { translation 1 0 0 }      # move 1 meter in x-direction
USE SPHERE                           # renders BLUE sphere

Note that transformations are also influenced by a separator - if the first transform in the above example would have been defined inside the separator, it would have been reset after the separator, resulting in the 2nd and 3rd sphere being drawn at the same location. Because the transformation is defined at the top level, the transformations accumulate, resulting in the three spheres being positioned next to each other.

Another fundamental group node is the Switch node, which will select one of its children for traversal, as set by the whichChild field.

The following table gives an overview of the most useful group nodes:

Name Description Fields
SoGroup Basic group node. -
SoSeparator Group node that preserves state after processing its children. SoSFEnum renderCaching
SoSFEnum boundingBoxCaching
SoSFEnum renderCulling
SoSFEnum pickCulling
SoSwitch selects one child for traversal SoSFInt32 whichChild
SoBlinker Cycling through its children at a given speed SoSFFloat speed
SoSFBool on
SoFile Include another iv-file SoSFString name
SoLevelOfDetail choose a child based on projected size SoMFFloat screenArea
SoLOD choose a child based distance between viewer and object (faster) SoMFFloat range
SoSFVec3f center
SoAbortGroup* This class implements a group-node that stops any action from traversing its children, depending on the value of the field abortActions. SoSFBitMask abortActions
SoMultiSwitch* Switch that allows to specify a subset of the children to be traversed. The ordered field determines how the children are traversed. If it is TRUE they are processed in the same order as they appear in the scene graph (left-to-right) and only once, otherwise they are traversed as they appear in the whichChildren field. This allows some fancy tricks with reusing of children several times. SoMFInt32 whichChildren
SoSFBool ordered

example1.iv contains an elaborate example that uses some of the features introduced in this section.