[Up] [Previous] [Next]

3. Open Inventor File Format

The way of describing nodes and fields in Open Inventor files follows a certain format, referred to as syntax. Syntax is just a term used to describe languages (both human and programming) that need to follow certain organizational rules in order to be recognized and understood. Here are the rules for Open Inventor files.

3.1 File Names

The usual convention for Open Inventor filenames is that they all end with the extension .iv. For example, a file containing a scene description of a boat might be named boat.iv.

3.2 First Line Syntax

The first line of an Open Inventor file must include some information that will indicate that this is, in fact, meant to be an Open Inventor file. Typically the first line will be either:

    #Inventor V2.0 ascii

or:

    #Inventor V2.0 binary

The version number indicates the version of the Open Inventor file format, in this case version 2.0. The keywords ascii and binary indicate whether the rest of the file is in a human-readable ASCII text format or not. The binary files are smaller than the text files, but files in text format are the only ones you can edit manually. You will probably want to work primarily with text files while learning Open Inventor, particularly if you want to create animated scenes.

3.3 Node and Field Syntax

Nodes and fields in Open Inventor files are organized as follows:

    NodeName {
        Field1Name Field1Value
        Field2Name Field2Value
        ...
    }

You would replace "NodeName" with the name of the particular node class you want to use, like Cone or RotationXYZ. You would replace "Field1Name" with the name of some field relevant to that particular node class, like height or angle, and so on with any other fields and their particular field values. Note that you don't have to specify all the fields that you can possibly use in conjunction with a node. Open Inventor applies some very sane default field values. You only need to specify the values that you want to change in some way.

It is important that you use the correct case when specifying node or field names. For example, Cone is not the same thing as cone. Open Inventor will recognize the former as the name of an object class that it knows about. It won't know what the lower-case name is referring to at all.

Here is an example for specifying a RotationXYZ node that would cause an approximately 180-degree rotation about the Z axis:

    RotationXYZ {
        axis Z
        angle 3.1415
    }

Note that in this example, RotationXYZ is the node name, axis and angle are the field names, and Z and 3.1415 are the respective field values (angles are always specified in radians).

3.4 Global Field Syntax

Global fields aren't strongly connected to the rest of the scene graph per se because they aren't part of any node, but they do contain values that the scene graph needs, often in more than one location. They are something that you probably won't use very often, with one exception. There is one predefined global field called realTime that contains the value of the system clock, which is useful for animations. To use this field you need to declare the global field in your scene when you use it. Here is the syntax for that declaration:

    GlobalField {
        type    "SFTime"
        realTime 0
    }

3.5 Field Connection Syntax

Here is how you connect a source field to a destination field. You connect a source multiple times, but each destination field can only be connected to one source. The syntax is essentially:

    DestNodeName {
        DestFieldName InitialFieldValue = SrcNodeName . SrcFieldName
    }

The initial field value is optional. You can specify it, but it it will be replaced by the value of the source field that you are connecting to.

Here is a complete Inventor .iv file that would display two 3D text messages rotated 90 degrees apart, both showing the current time (because the value of realTime is automatically converted to a string to satisfy the input requirements of the string field of the Text3 nodes). Note that the global field must be declared both times. In the first Text3 we set an initial value for the string field, and the second time we didn't bother. When you view the file, you won't even see the initial value that was set for the first node. To view the file the results just cut and paste the text into a file named test.iv and then do ivview -q test.iv:

    #Inventor V2.0 ascii

    Separator {
        PerspectiveCamera {
            position 50 50 280
        }
        Text3 {
            string  "undefined" =
                GlobalField {
                    type    "SFTime"
                    realTime
                }
                . realTime
        }
        RotationXYZ {
            axis    Z
            angle   1.5708
        }
        Text3 {
            string  =
                GlobalField {
                    type    "SFTime"
                    realTime
                }
                . realTime
        }
    }

3.6 Grouping with Separator Nodes

You might have noticed in the above example that there was something called a Separator node enclosing the description of the scene. Separators let you form a group of nodes and separate their effects from the rest of the scene. For example, if you added a Material node to make all objects red, then if that node was within the group of a Separator node, only the other nodes in the same group would be coloured red. Nodes outside of the group wouldn't turn red; they would remain whatever colour they are by default or through the actions of Material nodes outside of the group. It is a good idea to enclose your entire scene in a single Separator node, particularly if you want to include .iv files within each other.

More Information

More information about the Open Inventor file format is available in chapter 11 of Inventor Mentor.


MIT home page HTML written and maintained by Reid M. Pinchback (reidmp@mit.edu)
Last modified 96/06/10; copyright © 1996 MIT