issue126:freecad
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue126:freecad [2017/11/05 09:58] – d52fr | issue126:freecad [2017/11/09 15:06] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 2: | Ligne 2: | ||
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.** | 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, | ||
+ | |||
+ | Dans l' | ||
**What is a mesh? | **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.** | 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' | ||
+ | |||
+ | Un maillage peut être vu comme une représentation d'un objet à deux dimensions (une surface), située dans l' | ||
**According to the specific application, | **According to the specific application, | ||
+ | |||
+ | Cependant, suivant l' | ||
**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 | **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 | ||
Once a STL file has been saved, this can be used with most 3D printers to print a physical copy of our original shape.** | Once a STL file has been saved, this can be used with most 3D printers to print a physical copy of our original shape.** | ||
+ | |||
+ | FreeCAD sait déjà construire plusieurs types de maillage de base, tels que les formes simples (cylindre, cône, sphère) définies dans l' | ||
+ | |||
+ | Une fois qu'un fichier STL a été sauvegardé, | ||
**Importing and using meshes | **Importing and using meshes | ||
Ligne 18: | Ligne 32: | ||
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.** | 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.** | ||
+ | |||
+ | Importer et utiliser des maillages | ||
+ | |||
+ | Une autre fonctionnalité intéressante de l' | ||
+ | |||
+ | D' | ||
**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. | **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. | ||
Ligne 37: | Ligne 57: | ||
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. ** | 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. ** | ||
+ | |||
+ | Cependant, certaines précautions doivent être prises quand on travaille sur des modèles avec énormément de triangles. Le maillage de l'ange utilisé ci-dessus est déjà tout à fait capable de dépasser la quantité de mémoire gérée par FreeCAD ; aussi, il peut être judicieux de sauvegarder notre travail à des étapes rapprochées. | ||
+ | |||
+ | Créer nos propres maillages | ||
+ | |||
+ | Le format de fichier STL n'est à la base qu'un fichier texte avec une structure interne très simple. Par exemple, pour créer un maillage qui ne contient qu'une seule facette carrée, nous pouvons utiliser le code suivant : | ||
+ | |||
+ | 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 | ||
+ | |||
+ | La plupart des informations sont immédiatement compréhensibles. Le mot-clé « normal » indique le vecteur normé de la facette, nous disant en gros quelle face de la facette doit être considérée comme « extérieure | ||
**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. | **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, | 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, | ||
+ | |||
+ | Cette structure très simple rend très facile l' | ||
+ | |||
+ | Tout point P de la surface de la sphère peut être défini en utilisant l' | ||
**Once we have our double for loop set-up, we need to transform the more or less rectangular shapes we obtain between θ and θ + δθ horizontally, | **Once we have our double for loop set-up, we need to transform the more or less rectangular shapes we obtain between θ and θ + δθ horizontally, | ||
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.** | 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.** | ||
+ | |||
+ | Une fois que nous avons paramétré notre double boucle for, nous devons transformer les formes plus ou moins rectangulaires, | ||
+ | |||
+ | Pour aller vers des objets plus complexes, un anneau - ou, en termes mathématiques, | ||
**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:// | **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:// | ||
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:// | 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:// | ||
+ | |||
+ | Le programme en Python pour créer ce fichier de maillage a un code vraiment très similaire au précédent. Cependant, dans ce cas, φ doit itérer sur la totalité de la circonférence (de -π à π) pour terminer la forme en tube de l' | ||
+ | |||
+ | Une fois fait le code de base terminé, nous pouvons nous amuser avec ses mathématiques. Par exemple, nous pouvons tordre la matière de l' | ||
**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.** | **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.** | ||
+ | |||
+ | Un avantage d' | ||
**What next? | **What next? | ||
Ligne 57: | Ligne 110: | ||
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.** | 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.** | ||
+ | |||
+ | Et ensuite ? | ||
+ | |||
+ | Dans cet article sur l' | ||
+ | |||
+ | Dans la prochaine partie, nous utiliserons cette technique en combinaison avec d' | ||
issue126/freecad.1509872332.txt.gz · Dernière modification : 2017/11/05 09:58 de d52fr