BIFS Tutorial - Part I

Very simple scenes

In this first part, we will explain the MPEG-4 Scene structure and show how to create very simple scenes with basic geometric shapes such as rectangles, circles.


Empty Initial Scene:

Here is an empty MPEG4 document (vide.xmt, vide.bt) where you will have to, throughout the tutorial:

The content of the document will be explained while stepping through this tutorial.


Define a 2D graphical context for the scene:

Simply said, a BIFS scene is described as a tree in which leaves are media object (text, 2D/3D objects, video, audio) and intermediate nodes define groups of objects, sub-tree transformation rules (2D space, 3D space, color, ...). The root of this tree defines the graphical context of the presentation, either a 2D world or a 3D world. We will only consider 2D scenes in this tutorial, hence the root node shall be Layer2D or OrderedGroup node. We will first use the OrderedGroup node. This node allows grouping and ordered rendering of child nodes in the 2D plane. By default children appear in their declaration order: the first child is drawn in the background, the last on top of all others. The OrderedGroup.order field is used to modify this behavior. The XMT-A syntax is :

<OrderedGroup order="0 1 2 3">

<children> ... </children>

</OrderedGroup>


Some vocabulary:

Nodes in the scene may have properties, called fields, that can be modified at run time. In XMT-A, a node is described by an XML element, and a field is described by an XML element or attribute, depending on the type of the field (elements for fields that can contain nodes, attributes otherwise). More info on this can be found in the VRML 2.0 standard. In this tutorial, we will use the N.c syntax to address field c in node N.


Adding a graphical primitive:

Let's add a 2D shape to our empty scene. The node used to describe a shape (2D or 3D) is the Shape node. This node has two fields, Shape.geometry used to define the shape itself, and Shape.appearance used to define its visual aspect (3D lightening, texture, color, striking, ...). To insert a rectangle 50x40 pixels centered in the scene, the following XMT code must be inserted in OrderedGroup.children:

<Shape>
<geometry>
<Rectangle size="50 40"/>
</geometry>
</Shape>

The resulting file is rect.xmt, rect.bt, compiled in rect.mp4, the resulting scene is 100 pixels wide, 100 pixels heigh with the rectangle in its center. The rectangle is not filled, and has a light grey line of 1 pixel width. These values are the default values for any 2D shape.

Note :

As any XML language, an XMT document can become quite large on disk. The compilation step (BIFS is BInary Format for Scene) significantly reduces the file size: the previous XML file is 1237 bytes, the compiled mp4 file is 614 bytes and the BIFS stream itself is 63 octets. We will explain later on why the overhead of mp4 and how to reduce the data rates for small bandwidth.


Note on coordinate systems:

The 2D system defined by BIFS or World Coordinate System, is centered in the middle of the parent 2D plane (the main scene for 2D scenes), with Y-axis towards the top of the scene and X-axis towards the right of the scene. Measure Unit is in pixel or in meter, but we will only use pixel metrics with our 2D scenes. Each graphical object has its own coordinate system, or Local Coordinate System, which can be transformed through dedicated nodes.

Systèmes de coordoonées Monde et Local


Filling and striking:

Let's change the previous scene by filling the rectangle and changing the strike width and color:.

<Shape>
<geometry><Rectangle size="50 40"/></geometry>
<appearance>
<Appearance>
<material>
<Material2D emissiveColor="1 0 0" filled="true">
<lineProps><LineProperties lineColor="1 1 0" width="2"/></lineProps>
</Material2D>
</material>
</Appearance>
</appearance>
</Shape>

Here is the resulting scene: rect2.xmt, rect2.bt, rect2.mp4.

The aspect of the shape is controled by the Shape.appearance field. This field may be empty (previous example) or may contain an Appearance node.

The Appearance node has 3 fields describing its aspect (Appearance.material), potential texturing to apply (Appearance.texture) and potential transformations to apply to the texture (Appearance.textureTransform). We will look at texturing later on in this tutorial. For a 2D shape, the Appearance.material field usually contain a Material2D node. This node allows specifying aspect through 4 fields:

The detailed rules for filling and striking shapes can be found here.

Note : Colors are described as Red, Green, Blue levels in the interval [0, 1] (hence "0 0 0" is black and "1 1 1" is white).


Adding a background:

A default color for the scene background can be specified by using the Background2D node. This node is a bindable node (cf VRML), hence the position of its declaration doesn't really matter, the first Background2D node found in the scene will be "bound", that is will be used to select the background color. The Background2D node can also be used to specify an image in the background rather than a color, we will explain how to use images in BIFS later on. For now let's just add a blue background:

<Background2D backColor="0 0 0.7" />

Here is the resulting scene: rect3.xmt, rect3.bt, rect3.mp4


Complex graphical shapes:

BIFS defines the following 2D graphical primitives: Rectangle, Circle, IndexedFaceSet2D, IndexedLineSet2D, PointSet2D, Curve2D, Bitmap and Text. We have just seen the Rectangle one, Circle is roughly the same. Bitmap is used for still images and video display, and Text for ... text. Let's have a look at the other ones..

PointSet2D, IndexedLineSet2D and IndexedFaceSet2D, Curve2D :

These primitives all use a set of 2D coordinates (points) described in the Coordinate2D node. The first three ones may be colored on a point/line/face basis through a Color node.

The syntax defining 5 points with a Coordinate2D node is :

<Coordinate2D point="0 0 10 -10 20 +33 -30 -20 +50 -60"/>

The point (0,0) is the center of the local coordinate system.

The syntax defining 5 colorswith a Color node is :

<Color color="1 1 1 0.5 1 1 1 0.5 1 1 1 0.5 0.5 0.5 0.5"/>

The differences between these primitives is how points and colors are interpreted to define the shape.

Description

Examples

The PointSet2D primitive places points descibed in the Coordinate2D node in the scene and draw them with colors described in the Color node.

point.xmt, point.bt, point.mp4

The IndexedLineSet2D primitive displays line segments. The point list to be used is given by the coordIndex field. Index -1 indicates the end of a line sequence. The color to be used for the line is given by the colorIndex field.

line.xmt, line.bt, line.mp4 

The IndexedFaceSet2D primitive displays closed polygons (filled or unfilled). The point list to be used is given by the coordIndex field. Index -1 indicates the end of a polygon.The color to be used for strike/fill is given by indexes in the colorIndex field.

face.xmt, face.bt, face.mp4

The Curve2D primitive displays lines and bezier curves. The point list to be used is given by a Coordinate2D node in the point field and the type of the curve segment is given in order in the type field (move, line, Cubic Bezier)

curve.xmt, curve.bt, curve.mp4

More details on these nodes can be found here.


Exercises:

Exercise 1 : Based on rect.xmt example, change the scene size and the rectangle size. Check that world coordinate system and local coordinate system of the rectangle match.

Exercise 2 : Based on rect.xmt example, change the pen width, color and type.

Exercise 3 : Based on rect2.xmt example, change the fill color and strike properties.

Exercise 4 : Repeat previous exercises and change the Rectangle into a circle (radius of the circle is given by the field Circle.radius).

Exercise 5 : Use previous examples to draw the following picture:


Conclusion

In this part we have seen common 2D primitives used in BIFS. Of course this is only an overview and you should exercise these primitives a bit more, but using these you can already achieve nice vectorial drawings such as the following images.


[ Home ] [ Very Simple Scenes] [ Some Animation ]


Last Modified: 02/04/2005
Cyril Concolato & Jean Le Feuvre © 2002-2005