|
BIFS Tutorial - Part IVery 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.
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.
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>
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.
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.
|
Systèmes de coordoonées Monde et Local |
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).
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" />
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..
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 |
|
point.xmt, point.bt, point.mp4 |
|
line.xmt, line.bt, line.mp4 |
|
face.xmt, face.bt, face.mp4 |
|
curve.xmt, curve.bt, curve.mp4 |
More details on these nodes can be found here.
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:
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 ] |