Tutorial FreeCAD POV ray/fr

Introduction
Ce tutoriel montre comment produire un rendu dans FreeCAD à l'aide du rendu POV-Ray. Cela suppose que l'utilisateur a déjà créé une pièce ou un assemblage dans FreeCAD ou en a importé un. Il utilise le Module Raytracing pour générer le fichier en vue du rendu.

Ce tutoriel est basé sur le post de forum créé par schupin FreeCAD / pov ray tutorial qui comprend également un fichier nécessaire à la production du rendu.



Les fichiers utilisés dans ce tutoriel sont au post #8 du fil en question.

Configuration de base
Suivez les étapes de base décrites dans la documentation du Module Raytracing.

Pour que le rendu direct fonctionne, l'exécutable doit être défini dans. Définissez son emplacement dans votre système, par exemple. D'autres options utilisées par le renderer peuvent également être définies ici comprenant la largeur et la hauteur  de l'image ainsi que l'utilisation de l'antialiasing {{incode|+ A} }.

Mise en place du fichier .pov
1. Créez un assemblage à l'aide de corps à partir de l'Atelier Part ou Atelier PartDesign ou de tout autre atelier générant des objets solides par exemple Atelier Architecture. Attribuez des couleurs ou des matériaux aux corps individuels qui composent l'assemblage correspondant approximativement à la couleur souhaitée dans votre rendu.



2. Si votre modèle est très détaillé, assurez-vous que la valeur du corps est défini sur une valeur basse comprise entre  et  voire moins. Plus cette valeur est basse, plus le maillage exporté sera détaillé et donc meilleure sera la qualité du rendu.



3. Créez un projet POV-Ray en cliquant sur. Si la fenêtre d'affichage est définie sur Vue Orthographique remplacez-la par Caméra Perspective car le rendu fonctionnera normalement avec une caméra avec vue en perspective. L'utilisation de la vue en perspective vous permettra de mieux voir le type de scène qui sera rendu.

4. Sélectionnez tous les objets que vous souhaitez ajouter à votre scène puis sélectionnez l'objet créé puis cliquez sur.

méfiez-vous des objets qui ne sont pas actuellement visibles dans la fenêtre de visualisation 3D. S'ils sont invisibles mais inclus dans la scène, ils seront toujours restitués. D'autre part, si vous voulez vraiment omettre le rendu d'un corps, ne le sélectionnez pas pour l'inclure dans le projet POV-Ray.

tous les objets du projet POV-Ray auront un nom basé sur leur nom interne FreeCAD. Il est important de noter les noms POV-Ray car d'autres options, telles que les textures de matériau, seront affectées à ces noms POV-Ray.

5. Dans la fenêtre 3D, effectuez un zoom, un panoramique et une rotation de la vue pour configurer la scène à votre guise. Assurez-vous que les objets sont centrés dans la fenêtre puis sélectionnez l'objet créé et appuyez sur.

6. Le fichier POV-Ray est maintenant prêt. Il contient les objets sélectionnés et les informations de la caméra. Sélectionnez l'objet créé puis appuyez sur  pour enregistrer le fichier.

7. Le fichier créé peut maintenant être rendu directement à partir de FreeCAD. Sélectionnez l'objet créé puis appuyez sur. Lorsque l'image contextuelle apparaît à l'écran, cliquez dessus pour l'envoyer à FreeCAD dans son propre onglet de fenêtre.



7.1. Avec le fichier déjà créé, il est également possible d'exécuter  à partir des lignes de commande.

Les options définissent les dimensions horizontale et verticale en pixel de l'image finale.

Les options (type 2, sur-échantillonnage récursif) et  activent l'anticrénelage pour produire une image plus lisse.

8. En double-cliquant sur l'objet, vous pouvez voir qu'il utilise le modèle. Ce modèle crée un fichier de base qui produira une image simple et sombre.

Pour améliorer l'apparence de l'image, utilisez un meilleur modèle. Double-cliquez sur l'objet et choisissez le modèle. Exportez ensuite un nouveau fichier puis réexécutez le rendu. L'image doit être plus lumineuse et généralement meilleure.



Double-cliquez de nouveau sur l'objet et choisissez maintenant le modèle. Exportez ensuite un nouveau fichier puis réexécutez le rendu. L'image devrait prendre plus de temps à produire mais le résultat devrait être de meilleure qualité.

If the rendered image is good enough, then it can be saved, and there is nothing more to do. However, in order to control precisely the appearance of the materials and produce even better results, the file needs to be edited manually.

In the following sections, we edit the basic file produced with the  template.

Editing the .pov file
9. The file generated by FreeCAD is a simple text file that can be opened with any editor. It loosely resembles a C++ source code file: directives start with a hash and are terminated by a semi-colon. Curly braces  are used to limit section blocks, and indentation is arbitrary white space. Comments are indicated with a double slash ; block comments can be defined with a pair of, like in C.

The file may look complicated at first but 90% of its content is just mesh data that doesn't require many changes, as these meshes represent the geometry of the bodies that we want to render.

The file is structured as follows:
 * Includes
 * Global settings
 * Sky sphere
 * Planes
 * Finishes and textures
 * Camera
 * Mesh and body information
 * Light source

The camera information will not be touched, neither most information in the meshes. The main modifications will be made on the other sections.

As the meshes won't be heavily modified, the file can be re-organized so this information is at the end of the file.

This is the complete content of the file, only without the meshes.

Basic re-organization
10. Open the file with a text editor, go to the end of the file, select and cut the  section, and paste it before the first  line.

The resulting file should have the and  sections next to each other, for example

Prepare lights
11. By default, the project file defines one light with a position and color.

The position of the light is defined by a vector. The can be established like an  vector or it could also be a named color such as. If the RGB values are given, they should be in the range to  for the light to have normal brightness.

Like other objects, the light can be modified with many options. The option creates a rectangular source, which is more realistic as it results in diffuse illumination that creates soft shadows. The keyword helps reduce the computation time of the light paths; the larger the value the more accurate the result will be; to avoid long rendering times you should use the smallest integer that gives an acceptable result ( or  is usually enough); to obtain the best result remove the keyword completely (long rendering time). The keyword helps improve the shadows by randomly shifting the position of the lights. The keywords and  turn the area light into a spherical source, which will produce better shadows when there are rounded objects in the scene. Including and  is helpful to attenuate the value of the light with distance, just like it happens with a real light source.

Set up the light coming from the right and above.

If the light source is supposed to be in the scene, it may be useful to see a reference on the screen where this source should be. To this effect, create a sphere of a small radius and assume this sphere represents the light source; position the sphere where you want, then move the light very close to these coordinates, and test the lighting of the scene; when you are satisfied with the position of the light, simply delete the sphere.

12. The section is used to create a realistic sky background. It is commonly defined as a and a  of at least two colors in order to produce a smooth transition from the color of the horizon to the color of the zenith of the scene.



Prepare the body textures
13. The textures of each body need to be adjusted. This is the most time-consuming job of this process.

In the file each body is described in this way
 * Face1, Face2, Face3, Face4, ...
 * Body (union of faces)
 * Object

A body mesh is defined by faces, and each face is defined by a series of triangular elements that themselves are defined by, , and. This information doesn't need to be modified at all. Then, each body is defined as the union of the specified faces. Again, this information doesn't need modification.

Finally, each to be rendered is defined as one of the specified bodies, with a particular, which itself is defined by properties like  and.

By searching the file for the keyword, it's possible to go directly to the desired part in the file, and modify its  appropriately.

As indicated in the comment, the definition of is at the top of the file, in this case before the camera information. This value can be declared in many ways, as a combination of different properties, as shown in the commented and uncommented lines.

In general, a is a container that describes a material; it includes information like the  (color or graphic),  (how the color changes with the curvature of the surface),  (interaction of the surface with the light),  (agate, brick, dents, leopard, radial, ripples, tiling, waves, wood, etc.), and other properties. There are many options that can be combined together to produce a texture. This mixing is not trivial, but there are many examples online to obtain the desired appearance of the material.

Material libraries
14. POV-Ray comes with an extensive library of materials that can be used by name. By default, the project template makes available some materials by using statements at the beginning of the file. These materials can be further modified as desired.

The library defines basic colors by name,, , , , , , , , and. It also defines several other shades as well as functions to transform colors. The library contains copper, silver, chrome, and brass textures, and  contains the gold textures.

The standard libraries are located in the installation directory of POV-ray, for example

New textures
15. For example, to create a mirror texture, the is given a high value of.

Alternatively, for metals, a predefined finish can be used.

Then it can be assigned to the specific object.

The library defines the  texture (yellow pine, ragged grain). It can be used as the basis of a more complex texture, with some additional scaling and translation.

Then it is assigned to the specific object.

The library defines  as a finish for transparent acrylic; it also defines  as an interior material which, together with the  option, is used to calculate as close as possible the effects of light passing through a transparent material. In this case, the section is used, containing external  and internal  information of the material.

Then it is assigned to the specific object.



Prepare planes
16. If not provided by the original 3D model, planes can be added to simulate a floor or table top on which the objects are standing. More planes can be defined to serve as walls or other types of boundaries.

By default, a single plane is created. It is placed 1 millimeter below the model, so that it appears as a floor. The plane is assigned a basic texture that is black and slightly reflective.

Notice that in POV-Ray the X axis is defined as horizontal (left-right), the Y axis is defined as vertical (up-down), and the Z axis is defined as depth (front-rear).

For a simple gray floor, that is barely reflective use



17. The plane can be given a more complex appearance with the help of normals and material libraries.

Define a normal map that will be used to give the plane the appearance of a parquet floor.

Then define the plane. As use a wood  defined in, and modify it with  and  so that the wood grain looks random. Then add the created normal, together with another normal; this will result in the texture of the parquet with slight imperfections. Then as, make it a little bit reflective and glossy.



18. Add a second plane, this time perpendicular to the Z direction, to serve as a backwall. Displace it just a little bit behind the model to avoid covering the mirror. Include the library, add a generic granite texture, and scale it a bit. This will result in the appearance off a simple dry wall.

A third plane can be added behind the position of the camera so that the mirror reflects a limited area between the two walls.



Prepare the global settings, radiosity
19. The global settings define ambient light.

The property inside the  controls the way POV-Ray computes diffuse light interactions between different objects. It's essential to adjust this property to obtain good rendering results.

Because it can be time consuming to test different settings you can use a variable  and a  statement to quickly set low, medium or high quality render settings. The higher the quality settings the more time is required to render an image.



20. The library defines a macro to quickly set up the  to a predefined configuration.

The value can be one of the predefined constants:

The and  values are either  or.

Therefore, to test different settings, the statement could also be written like in the following.

The exact values used by these presets can be found in the file which is found in the installation directory of POV-Ray, for example:

The Raytracing Workbench has three default templates:
 * , it doesn't use at all.
 * , it uses the preset.
 * , it uses the preset.

Final render
21. The edited file can be saved when all adjustments have been done.

The final structure is as follows:
 * Includes, with additional libraries
 * Global settings, with radiosity parameters
 * Sky sphere, with lighter color
 * Planes, positioned and with textures
 * Finishes and textures, with custom definitions
 * Camera, not changed
 * Light source, with additional properties
 * Mesh and body information, using the textures defined previously

the sections of the file can be in any order, although it is probably easier to work with the file if the mesh information is at the end.

The final rendering can be done by clicking or by running the executable from the command line.



This is the complete content of the file, only without the last section, that is, without the meshes.

Final notes
POV-Ray is a relatively old piece of software, first released in the early 1990s. Its main advantages over more modern software are
 * it is a tested solution that has existed for many years
 * runs in many operating systems
 * the scene can be set with only one text file
 * requires simple computational resources to produce a high quality image, so it works even in relatively old hardware

The user is advised to read the POV-Ray documentation and more tutorials or examples in order to get the right settings for his or her needs.
 * POV-Ray for Unix version 3.7
 * POV-Ray Tutorial
 * POV-Ray Reference