• Aucun résultat trouvé

Structure of the visual description

technical report after the first year of the project

6.2 Structure of the visual description

To define generic graphical interfaces controling complex system, we need first to define physically all the compo-nent of such system. Also the differents physical and logical compocompo-nents of the systeme we want to control and to represent in the GUI in a 3D way are :

Figure 6.1: Basic properties of the system

the elementary objects, in their forms (but really more, sure), as a collection it means a set of existing or not elementary objects as cubes, circles, spheres, boxes, triangles, ...

127

128 CHAPTER 6. BATIC3S VISUAL MODEL

the geographical positions with their dependences and spatial constraint

All these objects have many characteristics, different or not, like their possible transformations (translation, rotation and scale). This two first points (dimensions and positions) represents the geometrical description of the components of the system. it can be completly defined as an instance from generic objects already deined in a database, or created if needed.

the hierarchical structure of the machine

All the component of the system depends on the other. We had to identify and represent the multiple and needed relationships between all the components. Basically, in such complex system, objects are included in other, or are composed of many others, smaller or not. Sometimes it depends on the 3D representation and on the scale used. Logically, we represent this hierarchy in atree. We often see this 2D’tree in the GUI in such framework (trouver une reference la dessus). We define also many levels that represent the machine, depending of what we want to show to the user (or depending of what the user need to see).

For example, a car is composed of many elements: first, we can see the entire car, then the tyres, or the engine, etc.. . If we go down in the levels, we can focus on the engine, and see the major component of it. Then, we can continue if needed to next and next level until the GUI will show us elementary pieces or component of a small part of the engine. This is what we call the hierarchical structure of the system.

As we said, it’s usually represented in a 2D way with a tree. It will be different in a 3D way, more difficult but give more sens and will be more intuitive for the user.

the input / output of each of them, and their possible state. We don’t want to focus on it for the moment in this paper

6.2.1 Approach

We propose the approach for building initial visual model as the following processus in the three main points :

6.2.2 Define the collection of elementary objects

The main idea is to define elementary object as circle, cube, etc. and to populate a database of it.

We use a modeling software to create basics objects. We choseWings3D as modeling software which is a powerful freeware soft, easy to use. We can naturally decide to use another one, in respect of the condition we force to, that is to generate an OBJ file as output format. This format is a common and standart format for 3D modeled object, and at least, easy to parse to populate a database of object, as we will see in this document.

The figure 6.2 describe simply the structure of an.obj file.

Figure 6.2: Structure of an.obj file

The structure of such a file is presented on the figure 6.2. Each line of this file represents one information.

If the first character is ”v”, it’s a 3D point that is defined. ”f” is a reference to 3 points to describe a face. For further informations about theOBJ format, see [12].

Two sort of objects are identified in the system : the instance of generic object, and the others, that we are forced to modelise because they are specific one. Instance of generic objects comes from cube, sphere, boxes, and so on; Specific components must be described and modeled, like spring in the drink vending machine (we choose to implement as all as first case study). Generic elementary object can be combined to produce specific one.

6.3. 3D ENGINE 129

Then, the following step is to integrate this collection in a database in order to describethe physical structureof the system. The database already contained generic objects, then derived it to create instance of them we need and that we specified before. A script is devoted to parse.obj files to populate the database with specific objects. The database is a very useful tools for us in this processus : it allow designer to create instance of generic components only with modification of physical and geometrical parameters of the pieces. The database and its structure of the database will be more precised further in the document

The 3D Engine has just to load a collection from the database to represent the physical structure of the machine. We can also imagine many collection for the same system. The representation change, but not the model, nor the logic or the behaviour of the system.

6.2.3 Allowed transformations for each component

Define the geomety and the form of an object is not enough to allow a 3D visual representation. We need to store and define the transformation we can apply on for each component of the system, like translation, rotation and scale. these property are extensibles. First we define the possible transformation we can apply on object reference. Then, we will specify in the hierarchical structure definition all the transformation allowed for each component.

6.2.4 Define the hierarchical structure with the help of a set of oper-ateur

We introcuce here the last part of the batic3s visual representation but will be more precise further in the document. The aim of this part is to easy define, with generics tools, the hierarchical structure of such complex systems.

First we propose to define some operators which can be applied on objects, depending of the level they are in the structure we define, and depending of the representation we want to have. These operators help us to solve such operation between object like collection, blending, combination, assembling, including, revulsing, gluing, sticking, intersect and so on. The list of operator can be extended. This approach will be more describe further in the document.

As we say, we represent logically the hierarchy of objects in a tree. With the use of a xml-like langage, we can specify very simply but efficiently such structure, with operator that allow to described and fixed this kind of information. As we said, we will precised it and give an example of the structure further in the document.

With this process, we have two possibilities to define this structure. First, as we have done before, we can write it simply in a text file. The second, more convivial and intuitive, consist in using a visual tool that allow us to define this hierarchy graphically, and build this file automatically. This tools will be able to read this xml-like file too. We will realize next year a prototype of such helpful tool

The other goal of this set of operator is to give high level abstraction of object’s property. This mean that with this set, the system will be able to recognize objet near from another one without calculation, or to determine if an objet is in or behind for example, of another one. We can also get this semantics information always without calculate difference or distance between geographical coordonate of objects. This will give more semantics approach to the representation model, and avoid many computation.

Finally, the main goal of all this appraoch is for the engine renderer to have only the database to read for representing the visual aspect of the object, combined with the xml-like file to build and represents the hierachical structure of the system. Each file can represent a well-defined structure. Naturally, we can define more than one file for more than one hierarchical structure if needed. With this approach, sure that it will be easier, for the renderer engine to represent it and for the designer af the system to define it.

6.3 3D engine

6.3.1 Introduction

We propose now to focus on the technical aspect of the 3D engine, developped in Java with the JoGL API.

6.3.2 Structural approach

JoGL is a free library developed by Sun and Silicon Graphics (this last is at the origin of OpenGL), under BSD license. It’s the reference API to use OpenGL in Java. With this library, it’s possible to send OpenGL commands to the graphic card, with the same function names as if we coded in C / C++. For an introduction to this API, see [1]. The list of all the OpenGL commands is presented in the reference book [43]. By using Java, a fall of performance is inevitable because of the virtual machine, but this fall tends to become negligible. The principal

130 CHAPTER 6. BATIC3S VISUAL MODEL

advantage of Java, it is the possibility of producing a portable code, easily reusable, that particularly interests us for this project.

The code is thus natively object oriented. The classes were distributed in three different packages : batic3s, toolBoxandtoolBox.object3D. Here you can find the complete list of all the classes of these packages :

batic3s Batic3s -Renderer

toolbox Camera -Color -FpsCounter-SpriteDrawer TextureReader -TextureCollection-Vector3D toolbox.object3D Object3DStructure-Object3D -Object3DDrawer

Object3DLoader-Object3DLoaderFromDatabase Object3DMaterials-Object3DNode

Some of these classes will be studied more precisely in the section 6.3.3. The packagebatic3s contains two classes,Batic3s andRenderer. Batic3s contains themain method. When the program starts, it creates a GUI with Swing elements, the whole is structured in aJFrame(see figure 6.3). It is also at the start of the application that an instance ofRenderer is created. Renderer is an important class, it’s the one who manages OpenGL initializations, rendering, updates of the scene, the possibility to pick a 3D object with the mouse, the keyboard events, etc.

Figure 6.3: Example of OpenGL rendering in a Java application

In the packagetoolbox, we have a collection of tools to support various tasks. Camera makes it possible to manage the properties of the camera (position, aperture, distance of clipping plans). It is possible to use cartesian or polar coordinates for positioning. Two interesting methods aregoto2DandbackTo3D, which allows to switch between an orthogonal projection and a perspective projection. These projections are used to trace, respectively, 2D pictures and 3D objects. Color is a very simple class to describe a color. FpsCounter makes it possible to count the number of images per seconds (frame rate).SpriteDrawer can trace 2D pictures,TextureReaderloads texture files, whereasTextureCollectionrepresents a collection of the latter. Lastly,Vector3D is used to handle vectors.

The packagetoolbox.object3D, as for him, contains all the classes which are directly related to a 3D object.

Object3DStructurerepresents the structure of such an object, i.e. the description of its geometry (list of the points, faces, normals and texture coordinates). Object3D refers to anObject3DStructure, and adds the possibility to apply geometrical transformations to him. That makes it possible to preserve only once the structure of the object in memory, even if this one is present at several places in the scene. It is possible to choose a global color or a texture by calling the methodssetGlobalColor orsetTextureNum of anObject3D. Other methods can be used to

6.3. 3D ENGINE 131

change the geometrical transformations. The classObject3DDrawer is used to trace aObject3Dby respecting its various properties of transformations, color, etc. Object3DLoader allows us to load the contents of a file OBJ.

In this project, we wish to be able to preserve the initial state of a system in a MySQL database, we will return on that later (see chapter 6.4). It is the classObject3DLoaderFromDatabase which allows to read the database.

Object3DMaterials is used to store the various face colors of our 3D objects. That means that the faces will be related to an index of color.

The classObject3DNode brings the concept of hierarchy of the system, it represents a node of the tree. We saw that aObject3Dis related to anObject3DStructure. In the same manner, anObject3DNodeis related to an Object3D. This class inherits the classDefaultMutableTreeand thus has some methods to handle trees. We can for example add children nodes to a parent node, or calculate thebounding box 1of a node which would not have geometry.

6.3.3 Study of the most important classes

Here are some precisions concerning the principal classes of the prototype. It is advisable to read these paragraphs in parallel with the javadoc.

Object3DStructure

This class defines the geometrical structure of a 3D objet, like the one on the figure 6.4.

Figure 6.4: Some instance variables of anObject3DStructure

Four methods are designed to ask the particuliarities of the object. It is getHasPointNormals, getHas-FaceNormals,getHasTextureCoordsandgetHasColors. Those thus make it possible to know if the structure has, respectively, a normal by point or face, textures co-ordinates, or colors for each face. The four preceding methods are in particular used by the class Object3DDrawer (see section 6.3.3). A Object3DStructure has in general a name which can be read or written withgetNameandsetName.

Object3D

AnObject3D has a geometrical structure, it thus contains a reference to anObject3DStructure. This structure can be read or modified with the methodsgetObject3DStructureandsetObject3DStructure.

The instance variableglobalColormakes it possible to apply a color to the totality of the faces of the 3D object.

This color also influences the objects having a texture. To apply a texture to an 3D object, it is necessary to use the methodsetTextureNum by giving him the index of the texture we want to use from theTextureCollection (see section 6.3.3). To remove any texture, we should give him the index -1. Geometrical transformations can be applied to Object3D by using the methodssetScale,setRotationandsetTranslation. This thus makes it possible to create objects having the same form - the same reference to Object3DStructure - and to place them at various places in various colors. The classObject3DDrawer undertakes to trace them at the good place.

1abounding boxrepresents a box which includes all the children of a node.

132 CHAPTER 6. BATIC3S VISUAL MODEL

Figure 6.5: Relations between an object, his structure and the drawer.

Object3DNode

An instanciation of this class represents a node of the hierarchical tree. The class DefaultMutableTreeNode, defined by Java, allows various treatments on the node of a tree, such as for example adding a child to a node, finding the root of the tree starting from any node, etc. For this reason,Object3DNode is a subclass of DefaultMutableTreeNode. To these basic methods for tree handling is added other methods in relation to the needs of Batic3s. For instancedrawAllFromThisNodewhich is used to trace all the objects which are downward of a certain node. Only the visible nodes in the hierarchical representation of the system are traced. When a Object3DNodeis instanciated, it receives a single id. This last can make it possible to find the reference of a node by using the methodfindNodeFromNodeId. That is particularly interesting forobject picking 2. Each node has a name, it is the latter which is shown in the tree. To assign to a node a geometrical representation, we use the methodsetCorrespondingObject3D.

Object3DDrawer

The classObject3DDrawer is used in a static way. It is the methodDraw that makes it possible to trace an Object3D. This method is particularly complete, because it takes account of the properties of the object. For example if it has a texture, it will be automatically used. In the same way for the normals, as they are normals by faces or points. If the object is active, it will be highlighted with the color of its state as well as an effect of flickering. If the object has an alpha component3nonopaque, theblending4will be activated. AnObject3D can contain geometrical transformations, they will be taken into account to trace the object with good dimensions and at the right place. These transformations are done in the following order: scale, rotation and at last translation.

Camera

The classCamerais used to manage all the aspects of the camera. Two modes of positioning are envisaged, the first uses the instance variablespositionand lookAt to specify the position of the camera and a point towards which it is directed. This solution is not ideal for our project, it is preferable to use polar coordinates as we can see it on the figure 6.6.

2Method making it possible to find the reference of an object on which we clicked in the 3D view.

3the component of a color which indicates the degree of transparency.

4Method allowing to trace transparent objects.