Outils pour utilisateurs

Outils du site


issue126:freecad

Ceci est une ancienne révision du document !


In this series, we will be examining the world of FreeCAD, an open-source CAD modelling application that is still in Beta, but has been gaining acceptance in recent years. Naturally, it is readily available in the Ubuntu repositories. In the last article on using FreeCAD, we worked on an architectural project in two different ways. In the first place, we used the Arch workbench to create a modern architectural project, in which supplementary information is given to the computer, so using FreeCAD to create a Building Integrated Model (BIM). Since this approach is in an early stage of development, and is limited to simple forms, we then used a more traditional approach to create volumes in the same way as in previous projects, but on a larger scale. The sweeping technique allowed us to create an element with the shape of an arch by sweeping one sketch (a profile) around another sketch (the outline of an arch). In today’s edition, we will concentrate on a more complex primitive object that allows us to create forms and volumes with less regularity, the mesh.

Dans cette série, nous examinerons le monde de FreeCAD, une application Open Source de modélisation par CAO qui est encore en bêta, mais qui a reçu un bon accueil ces dernières années. Naturellement, elle est facilement disponible dans les dépôts d'Ubuntu. Dans le précédent article sur l'utilisation de FreeCAD, nous avons travaillé sur un projet architectural de deux manières différentes. D'abord, nous avons utilisé l'atelier Arch pour créer un projet architectural moderne, dans lequel des informations supplémentaires sont fournies à l'ordinateur, de sorte que FreeCAD est utilisé pour créer un Modèle Intégré de Construction (Integrated Model - BIM). Comme cette approche n'en est qu'au début de son développement, et qu'elle est limitée à des formes simples, nous avons ensuite utilisé une approche plus traditionnelle pour créer des volumes de la même manière que pour les projets précédents, mais à une échelle plus grande. La technique du balayage nous a permis de créer un élément avec la forme d'une arche en balayant une esquisse (un profil) le long d'une autre esquisse (le trait formant une arche).

Dans l'article d’aujourd’hui, nous nous concentrerons sur un objet primitive plus complexe qui nous permet de créer des formes et des volumes ayant une moindre régularité, le maillage.

What is a mesh? A mesh can be taken as a representation of a two-dimensional object (a surface), situated within tridimensional space. Mesh objects can be made up of very many types of elementary elements, some of which can be rather complex such as Non-Uniform Rational B-Splines (NURBS). However, the most common varieties are simple triangles and flat four-sided elements. This is for several reasons, including the fact that most complex surfaces can be approximated by triangles with a reasonable level of precision - much in the same way that the plots of simple mathematical functions are often represented on-screen with an array of straight segments, when in reality some of these functions have no straight bits all along their length. Another aspect of the equation is that many computer meta-languages describing scenes in 3D -such as OpenGL- have primitives for such triangles.

Qu'est-ce qu'un maillage ?

Un maillage peut ~tre vu comme une représentation d'un objet à deux dimensions (une surface), située dans espace tridimensionnel. Les objets maillés peuvent être composés de nombreux types d'éléments élémentaires (!), certains desquels peuvent être plutôt complexes comme les B-slines Rationnelles Non-uniformes (NURBS - Non-Uniform Rational B-Splines). Cependant, les variantes les plus communes sont de simples triangles et des éléments à quatre côtés. l y a plusieurs raisons à cela, dont le fait que les surfaces les plus complexes peuvent être approximées par des triangles avec un niveau de précision raisonnable - d'une façon assez voisine de certaines fonctions mathématiques qui sont souvent représentées à l'écran avec une matrice de segments droits, alors que ces fonctions n'ont en réalité aucun bout de ligne droite dans toute leur forme. Un autre aspect de l'équation est que beaucoup de méta-langages informatiques décrivant des scènes en 3D - comme OpenGL - ont des primitives pour de tels triangles.

According to the specific application, however, 3D scene file formats can hold more, or less, information about the mesh. One of the file formats commonly used in 3D printing, the STereoLithography (STL) format, merely contains a list of triangles. Vertices are repeated as needed, and no further information is recorded about the actual structure of the underlying object. In a more complex case such as Computer Fluid Dynamics (CFD), toolkits such as OpenFOAM (https://openfoam.org/) have a file format that draws up the mesh using a list of vertices, then a list of faces through referral to the vertices, and finally the complete mesh as a list of faces with their relative positions and associated variables. Fluid pressure, velocity and temperature are often used, and must be stored for several points in time in auxiliary structures that hinge on the mesh.

D'après l'application particulière, cependant, les formats de fichiers d'une scène en 3D peuvent contenir plus ou moins d'information sur le maillage. Un des formats de fichiers utilisés communément en impression 3D, le format de stéréolythographie (STL) ne contient qu'une liste de triangles. Les sommets sont répétés si besoin et aucune autre information sur la structure de l'objet sous-jacent n'est enregistrée. Dans un cas plus compliqué comme la dynamique des fluides par ordinateur (CFD - Computer Fluid Dynamics), les boîtes à outils telles que OpenFOAM (https://openfoam.org/) ont un format de fichier qui dessine le maillage en utilisant une liste de sommets, puis une liste des faces faisant référence aux sommets et enfin le maillage complet sous forme de liste de faces avec leurs positions relatives et les variables associées. La pression du fluide, la vitesse et la température sont souvent utilisées et doivent être stockées pour plusieurs points temporels dans des structures auxiliaires qui s'articulent sur le maillage.

FreeCAD already knows how to build several types of basic meshes, such as the simple shapes (cylinder, cone, sphere) defined in the Part workbench. These meshes can be exported to several file formats, among them STL. Simply choose the part, then switch to the Mesh workbench and choose menu option Mesh > Create mesh form shape. A new part, with a meshed version of the original, will be inserted into the project. Also within the Mesh workbench, tools are available to export this mesh to a file (tool on the right). Once a STL file has been saved, this can be used with most 3D printers to print a physical copy of our original shape.

Importing and using meshes Another useful feature of the Mesh workbench is its capacity to import a mesh from a file, and create a new Part element from the data imported. I downloaded a test mesh named DAVID-Angel from 3D scanner producer DAVID (http://www.david-3d.com/en/support/downloads). I then used the Mesh tool (the leftmost of the pair) to import this mesh into a new FreeCAD project. The result was quite good, and one can navigate around the digital model and examine the statue’s admittedly rather plump arms from up close – if so inclined. Other parts can be added to the scene within FreeCAD, allowing us to modify the model and then export our modified version, if needed. One specific use for this could be to add supports or other auxiliary features to a model, before printing in 3D. To take an example, I added a circular base to the angel statue.

However, some care needs to be exercised when working on models with very many triangles. The angel sample mesh used above is already quite capable of exhausting FreeCAD’s memory management, so it may be judicious to save our work every few steps. Creating our own meshes The STL file format is basically just a text file with a very simple internal structure. For instance, to create a mesh that contains just one single square facet, we could use the following code: solid Square (Meshed) facet normal 0.0 0.0 1.0 outer loop vertex 1.0 1.0 0.0 vertex -1.0 1.0 0.0 vertex -1.0 -1.0 0.0 vertex 1.0 -1.0 0.0 endloop endfacet endsolid Mesh Most indications should be self-explanatory. The “normal” keyword gives the facet’s normal vector, basically telling us which side of our facet is to be considered “outward” or “inward” in respect to the complete object. If a triangular facet is required, just use three vertices to define it. If several facets are needed, iterate the facet…endfacet sequence.

This very simple structure makes writing our own programs to create a mesh file automatically an easy proposition. It could be done is just about any programming language such as Pascal, C, Java, JavaScript with Node.js, and many others, but my personal preference will go to Python - in keeping with the fact that FreeCAD is written in this language. Let us start with a simple sphere. In the following screenshot, the object to the right -seen from within FreeCAD- is an instance of the application’s inbuilt Sphere object. The object to the left, however, is a mesh that has been generated with a simple Python script. Any point P on the surface of a sphere can be defined using horizontal angle theta (θ) within the equatorial plane, and then vertical angle phi (φ) to give its height above the plane. In essence, this is what we do when using latitudes and longitudes to give the position of an object or place on the Earth’s surface. So our program simply needs to calculate a series of coordinates, while varying θ from zero to 2π radians, and φ from -π/2 to π/2. Radians are our angular measurement unit of choice, since this is what computer programs use to calculate sines and cosines.

Once we have our double for loop set-up, we need to transform the more or less rectangular shapes we obtain between θ and θ + δθ horizontally, and between φ and φ + δφ vertically - where the deltas are the difference between successive values of each respective angle. The easiest course is to cover this area with two triangles. The complete Python program is simple, but a tad longer than could be acceptable for this publication. For this reason I put it up on Pastebin at the following address: https://pastebin.com/jvv35AgZ . Please do not hesitate to use it - and to experiment. Going on to more complex objects, a ring -or, in mathematical terms, a torus- is an object that has two radii: the main ring radius in one place, and a secondary radius that defines the thickness of the object, in a plane set off at right angles to the main plane. In the following capture, we can see two copies of the mesh as imported into FreeCAD, one on the left with mesh edges apparent, and the second on the right all built up. In this way, we can see that what seem to be flat four-sided facets are in fact each a combination of two triangles.

The Python program to create this mesh file is actually rather similar to the previous code. However, in this case φ needs to iterate over a full circumference (from -π to π) to complete the ring’s tube shape along the smaller circles. As before, θ iterates over the ring’s main circle. The code can be found at: https://pastebin.com/BNxPztFP . Please note the use of r1, the outer radius, here set at 5 units, and r2, the smaller radius, here set at 1 unit. Once we have the basic code setup, we can have some mathematical fun with it. For instance, we can have our ring material twist about the main ring, by giving it a further (third) radius to offset it from its “normal” position and have that turn around a number of times while we iterate over θ. We could, for instance, use cos(3θ) and sin(3θ) to calculate its radial and vertical coordinates to have the ring “wobble” three times along the main circumference. If our resulting object is quite flat, and the number of turns is odd, it can even resemble a Moebius strip. In the next screenshot, we can see our original ring in copper, combined with the new twisted shape in grey. The Python code to create this mesh file is, as always, on Pastebin: https://pastebin.com/ZvnDdLTX .

One advantage of writing our own programs is that we can then go on to modify our objects as desired. A simple alteration in the value of δφ can make our triangles cover only half the surface of our object. If, at the same time, we give it a single twist while iterating along θ, the final appearance can resemble not a single shape, but a collection of interwoven rings. In the following screenshot, note how each ring twists once around φ while making its circuit of the main ring.

What next? In this article on using FreeCAD, we concentrated on a more complex primitive object that allows us to create forms and volumes with less regularity, the mesh. Using the widely accepted STL file format, a mesh or collection of simple triangular or four-sided facets can be retrieved either from a physical 3D scanning device, from other people’s work, or created using ad hoc programs. With a bit of mathematical expertise, the objects created can vary from the very simple to rather more complex objects. In the next part, we will use this technique in combination with other, more standard FreeCAD tools, to build a 3D representation of a modern building with a lattice roof structure.

issue126/freecad.1509953995.txt.gz · Dernière modification : 2017/11/06 08:39 de d52fr