Raytracing Workbench

The Raytracing module is used to generate photorealistic images of your models, by rendering them with an external renderer. The Raytracing workbench works with templates, the same way as the Drawing workbench, by allowing you to create a Raytracing project, in which you add views of your objects. The project can then be exported to a ready-to-render file, or be rendered directly.



Currenly, two renderers are supported: povray and luxrender. To be able to render directly from FreeCAD, at least one of those renderers must be installed on your system, and its path configured in the FreeCAD Raytracing preferences. Without any renderer installed, yhough, you are still able to export a scene file that can be used in any of those renderers later, or on another machine.

The raytracing workbench works with templates, which are complete scene files for the given external renderer, including lights and possibly additional geometry such as ground planes. These scene files contain placeholders, where FreeCAD will insert the position of the camera, and geometry and materials information of each of the objects you insert in the project. That modified scene file is what is then exported to the external renderer.

Typical workflow

 * 1) Create or open a FreeCAD project, add some Part-based objects (meshes are currently not supported)
 * 2) Create a Raytracing project (luxrender or povray)
 * 3) Select the objects you wish to add to the raytracing project and add them to the project with the "Insert Part" tool
 * 4) Export or render directly

Creating a povray file manually
The utility tools described above allow you to export the current 3D view and all of its content to a Povray file. First, you must load or create your CAD data and position the 3D View orientation as you wish. Then choose "Utilities->Export View..." from the raytracing menu.



You get ask for a location to save the resulting *.pov file. After that you can open it in Povray and render:



As usual in a rendererer you can make big and nice pictures:



Scripting
Here is how to use these features from python:

Links
About POV-Ray:


 * http://www.spiritone.com/~english/cyclopedia/
 * http://www.povray.org/
 * http://en.wikipedia.org/wiki/POV-Ray

Currently there is a new Renderer Workbench in development to support multiple back-ends such as Lux Renderer and Yafaray. Information for using the development version can be viewed at Render_project

For Development status of the Render Module look here Raytracing_project

Open-source renderers (for future implementation):


 * http://www.yafaray.org/
 * http://www.luxrender.net/

Templates
FreeCAD comes with a couple of default templates for povray and luxrender, but you can easily create your own. All you need to do is to create a scene file for the given renderer, then edit it manually with a text editor to insert special tags that FreeCAD will recognize and where it will insert its contents (camera and objects data)

Povray
Povray scene files (with extension .pov) can be created manually with a text editor (povray is made primarily to be used as a scripting language), but also with a wide range of 3D applications, such as blender. On the povray website you can find further information and a list of applications able to produce .pov files.

When you have a .pov file ready, you need to open it with a text editor, and do two operations:


 * 1) Strip out the camera information, because FreeCAD will place its own camera data. To do so, locate a text block like this: camera { ... }, which describes the camera parameters, and delete it (or put "//" in front of each line to comment them out).
 * 2) Insert the following line somewhere: //RaytracingContent. This is where FreeCAD will insert its contents (camera and objects data). You can, for example, put this line at the very end of the file.

Note that FreeCAD will also add some declarations, that you can use in your template, after the //RaytracingContent tag. These are:


 * cam_location: the location of the camera
 * cam_look_at: the location of the target point of the camera
 * cam_sky: the up vector of the camera.
 * cam_angle: the angle of the camera

If you want, for example, to place a lamp above the camera, you can use this:

light_source { cam_location + cam_angle * 100 color rgb <10, 10, 10> }

Luxrender
Luxrender scene files (with extension.lxs) can either be single files, or a master .lxs file that includes world definition (.lxw), material definition (.lxm) and geometry definition (.lxo) files. You can work with both styles, but it is also easy to transform a group of 4 files in a single .lxs file, by copying the contents of each .lxw, .lxm and .lxo file and pasting it at the point where that file is inserted in the master .lxs file.

Luxrender scene files are hard to produce by hand, but are easy to produce with many 3D applications such as blender. On the luxrender website, you'll find more information and plugins for the main 3D applications out there.

If you will work with separated .lxw, .lxm and .lxo files, beware that the final .lxs exported by FreeCAD might be at a different location than the template file, and therefore these files might not be found by Luxrender at render time. In this case you should or copy these files to the location of your final file, or edit their paths in the exported .lxs file.

After you have your scene file ready, to turn it into a FreeCAD template, you need to perform the following steps:


 * 1) Locate the camera position, a single line that begins with LookAt, and delete it (or place a "#" at the beginnignof the line to comment it out)
 * 2) At that place, insert the following line: #RaytracingCamera
 * 3) At a desired point (for example just after the end of the materials definition, before the geometry information, or at the very end, just before the final WorldEnd line, insert the following line: #RaytracingContent. That is where FreeCAD will insert its own objects.

Note that in luxrender, the objects stored in a scene file can define transformation matrixes, that perform location, rotation or scaling operations. These matrixes can stack and affect everything that come after them, so, by placing your #RaytracingContent tag at the end of the file, you might see your FreeCAD objects affected by a transformation matrix placed earlier in the template. To make sure that this doesn't happen, place your #RaytracingContent</tt> tag before any other geometry object present in the template. FreeCAD itself won't define any of those transformation matrixes.