Tutorial Render with Blender: Difference between revisions
(→Prepare the lighting of the scene: Render of the assembly in Blender with a sun lamp added that emits parallel light rays with a certain angle) |
(Templates to categorize the page.) |
||
(25 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
<translate> |
<translate> |
||
<!--T:1--> |
|||
{{TutorialInfo |
{{TutorialInfo |
||
|Topic=Rendering |
|Topic=Rendering |
||
Line 11: | Line 12: | ||
}} |
}} |
||
==Introduction== |
==Introduction== <!--T:2--> |
||
<!--T:3--> |
|||
This tutorial shows how to produce a rendered image in Blender, beginning from a part or assembly created with FreeCAD. It assumes that the user already created the part in FreeCAD, which is then exported to Blender for rendering. |
|||
This tutorial shows how to produce a rendered image in [https://www.blender.org/ Blender], beginning from a part or assembly created with FreeCAD. It assumes that the user already created the part in FreeCAD, or has imported it into it. Then this part is exported to Blender for rendering. |
|||
<!--T:4--> |
|||
It uses Blender 2.80 with the EEVEE and Cycles renderers. It shows various [[Python]] commands that can be used to perform actions quicker. |
|||
It produces a rendering with Blender 2.80 with both the EEVEE and Cycles renderers. It shows various [[Python]] commands that can be used to perform actions quicker both in FreeCAD and Blender. |
|||
<!--T:93--> |
|||
== FreeCAD == |
|||
A similar description of this process is described in a series of videos, [https://www.youtube.com/watch?v=U7e6-Wfv2b0 Render Solidworks and FreeCAD Models in Blender], by Joko Engineering. |
|||
== FreeCAD == <!--T:5--> |
|||
<!--T:6--> |
|||
1. Create an assembly using bodies from the [[Part Workbench|Part]] or [[PartDesign Workbench|PartDesign Workbenches]], or any other workbench that produces solid objects, for example, the [[Arch Workbench|Arch Workbench]]. Assign colors or materials to the individual bodies that make the assembly, approximately matching the color that you want in your render. |
1. Create an assembly using bodies from the [[Part Workbench|Part]] or [[PartDesign Workbench|PartDesign Workbenches]], or any other workbench that produces solid objects, for example, the [[Arch Workbench|Arch Workbench]]. Assign colors or materials to the individual bodies that make the assembly, approximately matching the color that you want in your render. |
||
</translate> |
|||
[[Image:01_T03_FreeCAD_Blender_model.png|600px|center]] |
[[Image:01_T03_FreeCAD_Blender_model.png|600px|center]] |
||
<translate> |
|||
<!--T:7--> |
|||
{{Caption|align=center|Assembly of three bodies created in FreeCAD, and with colors or materials assigned.}} |
{{Caption|align=center|Assembly of three bodies created in FreeCAD, and with colors or materials assigned.}} |
||
<!--T:8--> |
|||
2. If your model is very detailed, make sure the {{PropertyView|Deviation}} of the body is set to a low value, between {{incode|0.1}} and {{incode|0.01}}, or even smaller. The lower this value is, the more detailed the exported mesh will be, and thus the better the quality of the render will be. |
2. If your model is very detailed, make sure the {{PropertyView|Deviation}} of the body is set to a low value, between {{incode|0.1}} and {{incode|0.01}}, or even smaller. The lower this value is, the more detailed the exported mesh will be, and thus the better the quality of the render will be. |
||
<!--T:9--> |
|||
[[Image:02_T03_FreeCAD_Blender_deviation.png|center]] |
[[Image:02_T03_FreeCAD_Blender_deviation.png|center]] |
||
<!--T:10--> |
|||
{{Caption|align=center|Deviation property of the bodies created in FreeCAD; the deviation needs to be small in order to export the parts with good resolution.}} |
{{Caption|align=center|Deviation property of the bodies created in FreeCAD; the deviation needs to be small in order to export the parts with good resolution.}} |
||
<!--T:11--> |
|||
3. Select your model and export it as {{incode|Wavefront OBJ}}. Select the {{incode|Part}}, then {{MenuCommand|File → Export}}, or press {{KEY|Ctrl}}+{{KEY|E}}. |
|||
3. Select the {{incode|Part}}, then {{MenuCommand|File → Export}}, or press {{KEY|Ctrl}}+{{KEY|E}}, and export it as {{incode|Wavefront OBJ}}. |
|||
<!--T:12--> |
|||
Alternatively, the export can be done from the [[Python]] console. Define a list of objects to be exported and use the exporting function with a file name. |
Alternatively, the export can be done from the [[Python]] console. Define a list of objects to be exported and use the exporting function with a file name. |
||
</translate> |
|||
{{Code|code= |
{{Code|code= |
||
import importOBJ |
import importOBJ |
||
Line 41: | Line 57: | ||
importOBJ.export(objs, "/home/user/assembly.obj") |
importOBJ.export(objs, "/home/user/assembly.obj") |
||
}} |
}} |
||
<translate> |
|||
<!--T:13--> |
|||
{{Emphasis|Note:}} If the resulting OBJ file appears to be empty, you may have to export the individual bodies. In this case, select each of the bodies under the part, and repeat the export. |
|||
{{Emphasis|Note:}} when exporting to OBJ, two files are created; the first one contains the mesh information itself, {{incode|assembly.obj}}; the second one contains the definition of the materials, which in most cases is just the color, {{incode|assembly.mtl}}. |
|||
<!--T:14--> |
|||
{{Emphasis|Note 2:}} if the resulting OBJ file appears to be empty, you may have to export the individual bodies. In this case, select each of the bodies under the part, and repeat the export. |
|||
</translate> |
|||
{{Code|code= |
{{Code|code= |
||
import importOBJ |
import importOBJ |
||
Line 52: | Line 74: | ||
importOBJ.export(objs, "/home/user/assembly.obj") |
importOBJ.export(objs, "/home/user/assembly.obj") |
||
}} |
}} |
||
<translate> |
|||
== Blender == |
== Blender == <!--T:15--> |
||
=== Prepare the model === |
=== Prepare the model === <!--T:16--> |
||
<!--T:17--> |
|||
3. Open Blender. Change the {{incode|Timeline}} panel into a {{incode|Python Console}} ({{KEY|Shift}}+{{KEY|F4}}). This will help you to input commands and see the results. You may also divide this panel and set an {{incode|Info}} panel to see other actions as you click on the interface. |
|||
4. Open Blender. Change the {{incode|Timeline}} panel into a {{incode|Python Console}} ({{KEY|Shift}}+{{KEY|F4}}). This will help you to input commands and see the results. You may divide this panel, to keep the console on one side, and make the other division an {{incode|Info}} panel; this will allow you to see the code of the actions as you click on the interface. |
|||
<!--T:18--> |
|||
Make sure you are using the EEVEE renderer. In the {{incode|Properties}} panel go to {{incode|Render}}, and for {{incode|Render Engine}} select {{incode|Eevee}}. |
Make sure you are using the EEVEE renderer. In the {{incode|Properties}} panel go to {{incode|Render}}, and for {{incode|Render Engine}} select {{incode|Eevee}}. |
||
</translate> |
|||
{{Code|code= |
{{Code|code= |
||
bpy.context.scene.render.engine = 'BLENDER_EEVEE' |
bpy.context.scene.render.engine = 'BLENDER_EEVEE' |
||
}} |
}} |
||
<translate> |
|||
<!--T:19--> |
|||
4. Import the model file from the menu, {{MenuCommand|File → Import → Wavefront (.obj)}}. |
|||
5. Import the model file from the menu, {{MenuCommand|File → Import → Wavefront (.obj)}}. |
|||
<!--T:20--> |
|||
Alternatively, importing can be done from the {{incode|Python Console}}. |
Alternatively, importing can be done from the {{incode|Python Console}}. |
||
</translate> |
|||
{{Code|code= |
{{Code|code= |
||
obj_file = "/home/user/assembly.obj" |
obj_file = "/home/user/assembly.obj" |
||
bpy.ops.import_scene.obj(filepath=obj_file) |
bpy.ops.import_scene.obj(filepath=obj_file) |
||
}} |
}} |
||
<translate> |
|||
<!--T:21--> |
|||
4. Change the scale. If the bodies appear to be very large you may have to change the units so the objects appear at the right scale. |
|||
6. Change the scale. |
|||
<!--T:22--> |
|||
If the bodies appear to be very large you may have to change the units so the objects appear at the right scale. |
|||
<!--T:23--> |
|||
In the {{incode|Properties}} panel go to {{incode|Scene}}, {{incode|Units}}, and select the appropriate {{incode|Unit System}}, {{incode|Unit Scale}}, and {{incode|Length}}. |
In the {{incode|Properties}} panel go to {{incode|Scene}}, {{incode|Units}}, and select the appropriate {{incode|Unit System}}, {{incode|Unit Scale}}, and {{incode|Length}}. |
||
<!--T:24--> |
|||
For small parts, you may wish to keep the length to {{incode|Millimeters}}, and the scale to {{incode|0.001}}. For bigger parts, for example, the model of a building, you may have to set these values to {{incode|Meters}} and {{incode|0.001}}. Try other values of scale if you need. |
|||
For small parts, you may wish to keep the length to {{incode|Millimeters}}, and the scale to {{incode|0.001}}. For bigger parts, for example, the model of a building, you may have to set these values to {{incode|Meters}} and {{incode|0.001}}. Try other values of scale as required. |
|||
<!--T:25--> |
|||
This can be set also from the Python console, for example |
|||
This can be set also from the {{incode|Python console}}. |
|||
</translate> |
|||
{{Code|code= |
{{Code|code= |
||
bpy.context.scene.unit_settings.length_unit = 'MILLIMETERS' |
bpy.context.scene.unit_settings.length_unit = 'MILLIMETERS' |
||
Line 86: | Line 126: | ||
bpy.context.scene.unit_settings.scale_length = 0.001 |
bpy.context.scene.unit_settings.scale_length = 0.001 |
||
}} |
}} |
||
<translate> |
|||
<!--T:26--> |
|||
{{Emphasis|Note:}} changing the scale and units of the model is only necessary if you wish to add elements to your scene at their true dimensions. If you just want to render your scene quickly, you may not need to do any adjustment. |
|||
{{Emphasis|Note:}} changing the scale and units of the scene is only necessary if you wish to work with objects at their true dimensions. If you just want to render your scene quickly, you may omit any adjustment. |
|||
<!--T:27--> |
|||
4.1. If you zoom out, and the view cuts the imported parts, you may have to adjust the view clip values. |
|||
6.1. If you zoom out, and the view cuts the imported parts, you may have to adjust the view clip values. |
|||
<!--T:28--> |
|||
Hit {{KEY|N}} to show the auxiliary panel; go to the {{incode|View}} section and set the {{incode|End}} to a large value, for example, {{incode|1E6 mm}} or {{incode|1000 m}}. |
Hit {{KEY|N}} to show the auxiliary panel; go to the {{incode|View}} section and set the {{incode|End}} to a large value, for example, {{incode|1E6 mm}} or {{incode|1000 m}}. |
||
<!--T:29--> |
|||
If you wish, also adjust the size of the grid; go to {{incode|Overlays}} then {{incode|Guides}}, and set the {{incode|Scale}} of the grid to {{incode|0.001}}. |
|||
6.2. If you wish, also adjust the size of the grid; go to {{incode|Overlays}}, then {{incode|Guides}}, and set the {{incode|Scale}} of the grid to {{incode|0.001}}. |
|||
<!--T:30--> |
|||
5. Fix the rotation of the objects. |
|||
7. Fix the rotation of the objects. |
|||
<!--T:31--> |
|||
When imported, objects may appear rotated around one of the axes, for example, 90 degrees around the X axis. |
When imported, objects may appear rotated around one of the axes, for example, 90 degrees around the X axis. |
||
Hit {{KEY|N}} to show the auxiliary panel; select an object, go to the {{incode|Transform}} section and set the {{incode|Rotation}} to {{incode|0°}} in each field. Do this for every object. |
Hit {{KEY|N}} to show the auxiliary panel; select an object, go to the {{incode|Transform}} section and set the {{incode|Rotation}} to {{incode|0°}} in each field. Do this for every object. |
||
<!--T:32--> |
|||
This can be automated by a small script that just sets the rotation of each imported body to zero, with the exception of the objects inside the {{incode|fixed_objs}} tuple. This can be useful if you are importing objects into an existing scene where other objects are already in their right positions. |
This can be automated by a small script that just sets the rotation of each imported body to zero, with the exception of the objects inside the {{incode|fixed_objs}} tuple. This can be useful if you are importing objects into an existing scene where other objects are already in their right positions. |
||
</translate> |
|||
{{Code|code= |
{{Code|code= |
||
fixed_objs = ('Camera', 'Cube', 'Light') |
fixed_objs = ('Camera', 'Cube', 'Light') |
||
Line 115: | Line 164: | ||
[[Image:03_T03_FreeCAD_Blender_imported_assembly.png|center]] |
[[Image:03_T03_FreeCAD_Blender_imported_assembly.png|center]] |
||
<translate> |
|||
<!--T:33--> |
|||
{{Caption|align=center|Assembly created in FreeCAD imported into Blender; the model was rotated and the units for the scene were adjusted to match the imported objects.}} |
{{Caption|align=center|Assembly created in FreeCAD imported into Blender; the model was rotated and the units for the scene were adjusted to match the imported objects.}} |
||
=== Prepare the camera of the scene === |
=== Prepare the camera of the scene === <!--T:34--> |
||
<!--T:35--> |
|||
6. Set the camera in the right position. |
|||
8. Set the camera in the right position. |
|||
<!--T:36--> |
|||
Adjust the viewport to the right angle to see the model, and then hit {{KEY|Ctrl}}+{{KEY|Alt}}+{{KEY|0}} (numerical pad), or use the menu {{MenuCommand|View → Align View → Align Active Camera to View}}. |
|||
Adjust the viewport to look at the model in the desired orientation, then hit {{KEY|Ctrl}}+{{KEY|Alt}}+{{KEY|0}} (numerical pad), or use the menu {{MenuCommand|View → Align View → Align Active Camera to View}}. |
|||
<!--T:37--> |
|||
6.1. If you don't see anything in the camera view, you may need to adjust the clipping. Selecting the camera in the {{incode|Outliner}}, go to the {{incode|Properties}} panel, then {{incode|Object Data}}, then {{incode|Lens}}, then set the {{incode|Clip End}} to a large value, for example, {{incode|1E3 mm}} or {{incode|1000 m}}. |
|||
8.1. If you don't see anything in the camera view, you may need to adjust the clipping. Selecting the camera in the {{incode|Outliner}}, go to the {{incode|Properties}} panel, then {{incode|Object Data}}, then {{incode|Lens}}, then set the {{incode|Clip End}} to a large value, for example, {{incode|1E3 mm}} or {{incode|1000 m}}. |
|||
</translate> |
|||
{{Code|code= |
{{Code|code= |
||
bpy.context.object.data.clip_end = 1e+03 |
bpy.context.object.data.clip_end = 1e+03 |
||
}} |
}} |
||
<translate> |
|||
<!--T:38--> |
|||
Now you can already quickly render the model by pressing {{KEY|F12}}, which will open the {{incode|Image Editor}} with the rendered result. Press {{KEY|Esc}} to exit, and return to the {{incode|3D Viewport}}. |
|||
If you can see the object through the camera view, now you can quickly render the model by pressing {{KEY|F12}}, which will open the {{incode|Image Editor}} with the result. Press {{KEY|Esc}} to exit, and return to the {{incode|3D Viewport}}. |
|||
</translate> |
|||
[[Image:04_T03_FreeCAD_Blender_first_render.png|600px|center]] |
[[Image:04_T03_FreeCAD_Blender_first_render.png|600px|center]] |
||
<translate> |
|||
<!--T:39--> |
|||
{{Caption|align=center|First render of the assembly in Blender with the camera with correct clipping, but no lighting}} |
|||
{{Caption|align=center|First render of the assembly in Blender, with the camera with correct clipping but no lighting}} |
|||
<!--T:40--> |
|||
You can toggle between camera view and the 3D viewport by pressing {{KEY|0}} in the numerical pad; pressing {{KEY|F12}} will render the camera view in any moment. |
You can toggle between camera view and the 3D viewport by pressing {{KEY|0}} in the numerical pad; pressing {{KEY|F12}} will render the camera view in any moment. |
||
<!--T:41--> |
|||
If the camera looks very small in the 3D viewport, go to the {{incode|Properties}} panel, then {{incode|Object Data}}, then {{incode|Viewport Display}}, and set a larger value for the {{incode|Size}}, for example, {{incode|20 mm}}. Also activate the {{incode|Limits}} checkbox to see the clipping distance of the camera. |
|||
8.2. If the camera looks very small in the 3D viewport, go to the {{incode|Properties}} panel, then {{incode|Object Data}}, then {{incode|Viewport Display}}, and set a larger value for the {{incode|Size}}, for example, {{incode|20 mm}}. Also activate the {{incode|Limits}} checkbox to see the clipping distance of the camera. |
|||
</translate> |
|||
{{Code|code= |
{{Code|code= |
||
bpy.context.object.data.display_size = 20 |
bpy.context.object.data.display_size = 20 |
||
bpy.context.object.data.show_limits = True |
bpy.context.object.data.show_limits = True |
||
}} |
}} |
||
<translate> |
|||
=== Prepare the lighting of the scene === |
=== Prepare the lighting of the scene === <!--T:42--> |
||
<!--T:43--> |
|||
7. Select the light in the {{incode|Outliner}}, go to the {{incode|Properties}} panel, then {{incode|Object Data}}, then press on {{incode|Sun}}, and set the {{incode|Strength}} to {{incode|5.0}}. |
|||
9. Select the light in the {{incode|Outliner}}, go to the {{incode|Properties}} panel, then {{incode|Object Data}}, then press on {{incode|Sun}}, and set the {{incode|Strength}} to {{incode|5.0}}. |
|||
</translate> |
|||
{{Code|code= |
{{Code|code= |
||
bpy.context.object.data.type = 'SUN' |
bpy.context.object.data.type = 'SUN' |
||
bpy.context.object.data.energy = 5 |
bpy.context.object.data.energy = 5 |
||
}} |
}} |
||
<translate> |
|||
<!--T:44--> |
|||
This will turn the light into a sun lamp. This type of lamp emits an infinite number of parallel light rays with a certain angle. |
|||
This will turn the light into a Sun lamp. This type of lamp emits an infinite number of parallel light rays that all arrive to the scene with a fixed angle. |
|||
<!--T:45--> |
|||
You may position the sun lamp anywhere on the viewport above your model so that you can define the direction of the rays of light. For a sun lamp it doesn't matter how close or far you place the lamp, only the direction of the rays, which are defined by the rotation of the object. |
|||
You may position the Sun lamp anywhere on the viewport above your model so that you define the direction of the rays of light. For a Sun lamp it doesn't matter how close or far you place the lamp, only the direction of the rays, which are defined by the rotation of the {{incode|Light}} object. |
|||
</translate> |
|||
{{Code|code= |
{{Code|code= |
||
bpy.context.active_object.location = (150, 100, 100) |
bpy.context.active_object.location = (150, 100, 100) |
||
bpy.context.active_object.rotation_euler = (0.6, 0.05, 1.88) |
bpy.context.active_object.rotation_euler = (0.6, 0.05, 1.88) |
||
}} |
}} |
||
<translate> |
|||
<!--T:46--> |
|||
Press {{KEY|F12}} again to see a preliminary render of the model. |
Press {{KEY|F12}} again to see a preliminary render of the model. |
||
</translate> |
|||
[[Image:05_T03_FreeCAD_Blender_render_sun_lamp.png|600px|center]] |
[[Image:05_T03_FreeCAD_Blender_render_sun_lamp.png|600px|center]] |
||
<translate> |
|||
<!--T:47--> |
|||
{{Caption|align=center|Render of the assembly in Blender with a sun lamp added that emits parallel light rays with a certain angle}} |
|||
{{Caption|align=center|Render of the assembly in Blender with a Sun lamp added that emits parallel light rays with a fixed angle}} |
|||
=== |
=== More setup: floor, global lighting, reflections, and soft shadows === <!--T:48--> |
||
<!--T:49--> |
|||
8. Add a floor plane. Click {{KEY|Shift}}+{{KEY|A}} then {{incode|Mesh}}, {{incode|Plane}}, and give it dimensions 10 times larger than your model. This will serve as a ground plane or table top on which the model is standing. Also move the plane a bit down ({{incode|-1 mm}} is enough), so that it does not intersect the model. |
|||
10. Add a floor plane. Press {{KEY|Shift}}+{{KEY|A}} then choose {{incode|Mesh}}, {{incode|Plane}}, and give it dimensions about 10 times larger than your model. This mesh object will serve as a floor plane or table top on which the model is standing. Also move the plane a bit down so that it does not intersect the model; {{incode|-1 mm}} below the object is enough. |
|||
</translate> |
|||
{{Code|code= |
{{Code|code= |
||
bpy.ops.mesh.primitive_plane_add(size=1500, view_align=False, enter_editmode=False, location=(0, 0, -1)) |
bpy.ops.mesh.primitive_plane_add(size=1500, view_align=False, enter_editmode=False, location=(0, 0, -1)) |
||
}} |
}} |
||
<translate> |
|||
<!--T:50--> |
|||
9. Set the world illumination. In the {{incode|Properties}} panel go to {{incode|World}}, and set {{incode|Color}} to a light blue-gray value, and the {{incode|Strength}} to {{incode|0.3}}. |
|||
11. Set the world illumination. In the {{incode|Properties}} panel go to {{incode|World}}, and set {{incode|Color}} to a light blue-gray value, {{incode|RGB (0.358, 0.512, 0.527)}}, and set the {{incode|Strength}} to {{incode|0.3}}. |
|||
<!--T:51--> |
|||
10. Set reflections. The EEVEE renderer of Blender produces fast renders by deactivating particular effects. In order to obtain better images, some options need to be made active. |
|||
12. Set reflections and shadows. The EEVEE renderer of Blender produces fast renders by deactivating most effects initially. In order to obtain better images, some options need to be made active. |
|||
<!--T:52--> |
|||
Go to the {{incode|Properties}} panel, then {{incode|Render}}, and check {{incode|Screen Space Reflections}}. In the {{incode|Shadows}} section, also check {{incode|Soft Shadows}}. |
Go to the {{incode|Properties}} panel, then {{incode|Render}}, and check {{incode|Screen Space Reflections}}. In the {{incode|Shadows}} section, also check {{incode|Soft Shadows}}. |
||
</translate> |
|||
{{Code|code= |
{{Code|code= |
||
bpy.context.scene.eevee.use_ssr = True |
bpy.context.scene.eevee.use_ssr = True |
||
bpy.context.scene.eevee.use_soft_shadows = True |
bpy.context.scene.eevee.use_soft_shadows = True |
||
}} |
}} |
||
<translate> |
|||
=== Set the materials of the objects === |
=== Set the materials of the objects === <!--T:53--> |
||
<!--T:54--> |
|||
11. Turn the {{incode|Python Console}} panel into a {{incode|Shader Editor}} panel ({{KEY|Shift}}+{{KEY|F3}}). |
|||
13. Turn the {{incode|Python Console}} panel into a {{incode|Shader Editor}} panel ({{KEY|Shift}}+{{KEY|F3}}). |
|||
<!--T:55--> |
|||
11.1. Select the ground plane, go to the {{incode|Properties}} panel, then {{incode|Material}}, and click on {{incode|New}}. In the {{incode|Shader Editor}} a {{incode|Principled BSDF}} node should appear. Give it a beige {{incode|Base Color}}, turn the {{incode|Metallic}} to {{incode|0.000}}, and the {{incode|Roughness}} to {{incode|1.000}}. |
|||
13.1. Select the ground plane, go to the {{incode|Properties}} panel, then {{incode|Material}}, and click on {{incode|New}}. In the {{incode|Shader Editor}} a {{incode|Principled BSDF}} node should appear. Give it a beige {{incode|Base Color}} {{incode|RGB (0.318, 0.267, 0.187)}}, turn the {{incode|Metallic}} slider to {{incode|0.000}}, and the {{incode|Roughness}} to {{incode|1.000}}. |
|||
<!--T:56--> |
|||
[[Image:06_T03_FreeCAD_Blender_Principled_shader.png|center]] |
[[Image:06_T03_FreeCAD_Blender_Principled_shader.png|center]] |
||
<!--T:57--> |
|||
{{Caption|align=center|Principled BSDF shader used in Blender to simulate a variety of materials ranging from shiny metals to rough and opaque solids}} |
|||
{{Caption|align=center|Principled BSDF shader used in Blender to simulate a variety of materials ranging from shiny metals to rough and opaque solids.}} |
|||
<!--T:58--> |
|||
11.2. Select each of the parts of the model, and adjust the respective {{incode|Principled BSDF}} material node. For metallic parts, turn the {{incode|Metallic}} property all the way to {{incode|1.000}}. Adjust the value of {{incode|Roughness}} to be between {{incode|0.2}} and {{incode|0.7}}. The closer to {{incode|0.000}} the {{incode|Roughness}} is, the more reflective (mirror-like) it will appear. |
|||
13.2. Select each of the parts of the model, and adjust the respective {{incode|Principled BSDF}} material node. For metallic parts, turn the {{incode|Metallic}} property all the way to {{incode|1.000}}. Adjust the value of {{incode|Roughness}} to be between {{incode|0.2}} and {{incode|0.7}}. The closer to {{incode|0.000}} the {{incode|Roughness}} is, the more reflective (mirror-like) it will appear. |
|||
<!--T:59--> |
|||
For non metals, like plastics, wood and textiles, set the {{incode|Metallic}} property all the way to {{incode|0.000}}, and adjust the value of {{incode|Roughness}} to between {{incode|0.4}} and {{incode|1.0}}. |
|||
For non metals, like plastics, wood and textiles, set the {{incode|Metallic}} slider all the way to {{incode|0.000}}, and adjust the value of {{incode|Roughness}} to between {{incode|0.4}} and {{incode|1.0}}. |
|||
<!--T:60--> |
|||
In general, metals are naturally smooth and therefore their roughness is small, making them shiny (reflective). Other materials are microscopically rough, and therefore do not reflect as much light, making them more opaque. |
|||
In general, metals are naturally smooth and therefore their roughness value is small, making them very reflective (shiny). Other materials are microscopically rough, and therefore do not reflect as much light, making them opaque. |
|||
<!--T:61--> |
|||
Test different combinations of materials until they look acceptable. Press {{KEY|Z}} and then {{KEY|8}} (numeric pad) to enter {{incode|Rendered}} mode; in this mode, the EEVEE renderer shows in real time in the 3D viewport how the final image will look like. Use {{KEY|Z}} to open the pie menu and switch back to {{incode|Solid}} mode ({{KEY|Z}} {{KEY|6}}), or go to {{incode|LookDev}} mode ({{KEY|Z}} {{KEY|2}}), a mode which adds different types of lighting to the scene to test the materials. |
|||
14. Test different combinations of materials until they look acceptable. Press {{KEY|Z}} and then {{KEY|8}} (numerical pad) to enter {{incode|Rendered}} mode; in this mode, the EEVEE renderer shows in real time in the 3D viewport how the final image will look like. Use {{KEY|Z}} to open the pie menu and switch back to {{incode|Solid}} mode ({{KEY|Z}} {{KEY|6}}), or go to {{incode|LookDev}} mode ({{KEY|Z}} {{KEY|2}}), a mode which adds different types of lighting to the scene to test the appearance of the materials. |
|||
<!--T:62--> |
|||
Press {{KEY|F12}} to render the view through the camera and check the quality of your image. |
|||
Press {{KEY|F12}} to render the view through the camera and check the quality of the image. |
|||
=== Rendering and saving === |
=== Rendering and saving === <!--T:63--> |
||
<!--T:64--> |
|||
12. If your model looks reasonable well with the EEVEE renderer you can already save the image by going to {{MenuCommand|Image → Save As}} or pressing {{KEY|Shift}}+{{KEY|S}} in the {{Incode|Image Editor}}. |
|||
15. If your model looks reasonably well with the EEVEE renderer you can already save the image by going to {{MenuCommand|Image → Save As}} or pressing {{KEY|Shift}}+{{KEY|S}} in the {{Incode|Image Editor}}. |
|||
</translate> |
|||
[[Image:07_T03_FreeCAD_Blender_EEVEE_render.png|600px|center]] |
[[Image:07_T03_FreeCAD_Blender_EEVEE_render.png|600px|center]] |
||
<translate> |
|||
<!--T:65--> |
|||
{{Caption|align=center|Rendered assembly produced with EEVEE; all materials use the Principled BSDF shader; only one sun lamp is used, with some ambient background light}} |
|||
{{Caption|align=center|Rendered assembly produced with Blender EEVEE; all materials use the Principled BSDF shader; only one Sun lamp is used, with some ambient background light.}} |
|||
<!--T:66--> |
|||
13. If you want to improve the quality of the image, try the Cycles renderer. |
|||
16. If you want to improve the quality of the image, try the Cycles renderer. |
|||
<!--T:67--> |
|||
Go to the {{incode|Properties}} panel, then {{incode|Render}}, and for {{incode|Render Engine}} select {{incode|Cycles}}. With the Cycles renderer, Blender will refine the image gradually until a number of iterations have passed. Every time the viewport changes the recalculation restarts. |
Go to the {{incode|Properties}} panel, then {{incode|Render}}, and for {{incode|Render Engine}} select {{incode|Cycles}}. With the Cycles renderer, Blender will refine the image gradually until a number of iterations have passed. Every time the viewport changes the recalculation restarts. |
||
</translate> |
|||
{{Code|code= |
{{Code|code= |
||
bpy.context.scene.render.engine = 'CYCLES' |
bpy.context.scene.render.engine = 'CYCLES' |
||
}} |
}} |
||
<translate> |
|||
<!--T:68--> |
|||
16.1. Adjust the sampling rate. Go to the {{incode|Properties}} panel, then {{incode|Render}}, then in the {{incode|Sampling}} section select an appropriate number for {{incode|Render}} and {{incode|Viewport}}. |
|||
<!--T:69--> |
|||
For the {{incode|Viewport}} a small number of samples, in the range of {{incode|32}} to {{incode|128}}, is generally enough to obtain a good preview of the image. For the final image, set {{incode|Render}} to a higher number, from {{incode|128}} to {{incode|2000}}, depending on the complexity and amount of details on the scene. |
|||
<!--T:70--> |
|||
Press {{KEY|F12}} to render the final view through the camera. Depending on your graphics card (GPU) the image should take several more seconds, or minutes, to render with Cycles than with EEVEE, but the quality of the image should be better. |
Press {{KEY|F12}} to render the final view through the camera. Depending on your graphics card (GPU) the image should take several more seconds, or minutes, to render with Cycles than with EEVEE, but the quality of the image should be better. |
||
<!--T:71--> |
|||
14. When you are satisfied with the quality of the image, go to {{MenuCommand|Image → Save As}} or press {{KEY|Shift}}+{{KEY|S}}. |
|||
17. When you are satisfied with the quality of the rendering, in the {{incode|Image Editor}} go to {{MenuCommand|Image → Save As}} or press {{KEY|Shift}}+{{KEY|S}}. |
|||
</translate> |
|||
[[Image:08_T03_FreeCAD_Blender_Cycles_render.png|600px|center]] |
[[Image:08_T03_FreeCAD_Blender_Cycles_render.png|600px|center]] |
||
<translate> |
|||
<!--T:72--> |
|||
{{Caption|align=center|Rendered assembly produced with Cycles; all options, materials, and lights that were used with EEVEE were kept for use with Cycles}} |
|||
{{Caption|align=center|Rendered assembly produced with Blender Cycles; all options, materials, and lights that were used with EEVEE were kept for use with Cycles.}} |
|||
=== Rendering from the command line === <!--T:73--> |
|||
== Final notes == |
|||
<!--T:74--> |
|||
18. If the scene has been completely finished, you may wish to render from outside Blender, from the operating system's command line. This can be useful to batch render different scenes in a remote system. Both EEVEE and Cycles are supported. |
|||
<!--T:75--> |
|||
{{Code|code= |
|||
blender -b assembly.blend -E BLENDER_EEVEE -o //assembly_EEVEE_#### -t 3 -F PNG -x 1 -f 1 |
|||
}} |
|||
<!--T:76--> |
|||
{{Code|code= |
|||
blender -b assembly.blend -E CYCLES -o //assembly_CYCLES_#### -t 3 -F PNG -x 1 -f 1 |
|||
}} |
|||
<!--T:77--> |
|||
This specifies that rendering should happen in the background with {{incode|-b}}; the rendering engine is chosen with {{incode|-E}}; the output filename is selected with {{incode|-o}}; the double forward slash {{incode|//}} indicates a path relative to the input file; the hash mark {{incode|#}} is used to indicate the frame number, padded with zeroes if necessary, for example, {{incode|0001}}; the number of CPU threads used in rendering is chosen with {{incode|-t 3}}; the output file format is indicated with {{incode|-F}}, and the {{incode|-x 1}} option adds automatically the extension to the name; the final option is {{incode|-f 1}} which indicates that only the first frame will be rendered, which is the normal case for a static scene; for animations use the {{incode|-a}} switch to produce an image for each frame, which can then be assembled to produce a video file. |
|||
== Importing plugin == <!--T:78--> |
|||
<!--T:79--> |
|||
Creating the intermediate Wavefront mesh (.obj) and then importing it into Blender will work in most situations. However, there is also the option of importing the FreeCAD file (.FCStd) directly into Blender by means of a plugin. |
|||
* [https://gist.github.com/yorikvanhavre/e873d51c8f0e307e333fe595c429ba87 io_import_fcstd.py], original version for Blender 2.79 |
|||
* [https://gist.github.com/yorikvanhavre/680156f59e2b42df8f5f5391cae2660b FreeCAD .FCStd importer for Blender 2.80] |
|||
<!--T:80--> |
|||
This is a Blender plugin; for it to work, Blender needs to be able to import FreeCAD as a module from the {{incode|Python Console}}. |
|||
</translate> |
|||
{{Code|code= |
|||
import FreeCAD |
|||
}} |
|||
<translate> |
|||
<!--T:81--> |
|||
This is only possible if both Blender and FreeCAD are compiled against the same {{incode|pythonX.Y}} (major and minor) version. For example, if Blender is compiled against Python 3.7, FreeCAD must be compiled against a Python 3.7 version as well. If FreeCAD is compiled against another version, for example, Python 2.7.15 or Python 3.6.7, the plugin will not work. The micro version number (third number) does not matter, that is, the plugin should work if one software is compiled against Python 3.7.5 and the other against Python 3.7.8. |
|||
<!--T:82--> |
|||
In addition, the FreeCAD precompiled Python module, {{incode|FreeCAD.so}} on Linux and {{incode|FreeCAD.pyd}} on Windows, should be in the Python path used by Blender to import modules. This path can be set up in different ways, depending on the operating system and Python distribution. |
|||
<!--T:83--> |
|||
In Blender you can see all paths searched by inspecting the {{incode|sys.path}} variable. The FreeCAD module should be found in any of those directories. |
|||
</translate> |
|||
{{Code|code= |
|||
import sys |
|||
print(sys.path)}} |
|||
<translate> |
|||
<!--T:84--> |
|||
* A copy or symbolic link inside one of those directories could be created pointing to the FreeCAD module. |
|||
</translate> |
|||
{{Code|code= |
|||
ln -s /usr/lib/freecad/lib/FreeCAD.so $HOME/.config/blender/2.80/scripts/addons |
|||
ln -s /usr/lib/freecad/lib/FreeCAD.so $HOME/.local/lib/python3.7/site-packages |
|||
}} |
|||
<translate> |
|||
<!--T:85--> |
|||
* Another possibility is adding the module directly into the path inside Blender. |
|||
</translate> |
|||
{{Code|code= |
|||
import sys |
|||
sys.path.append("/usr/lib/freecad/lib/FreeCAD.so") |
|||
}} |
|||
<translate> |
|||
== Final notes == <!--T:86--> |
|||
EEVEE is not a physically accurate renderer, however its main strength is that it is a real time renderer so it is able to produce quick images directly in the 3D viewport. In many cases, these images have enough quality for final production which means it's possible to obtain a good result in a very short time. |
|||
<!--T:87--> |
|||
On the other hand, Cycles is a true raytracing renderer which means it is more accurate at calculating light paths in a scene in order to produce a photorealistic result. Cycles is still the recommended renderer when the best quality is desired. |
|||
EEVEE is not a physically accurate renderer, however its main strength is that it is a real time engine so it is able to produce quick renderings directly in the 3D viewport. In many cases these images have enough quality for final production, which means it is possible to obtain a good result in a very short time. In cases where complex light interactions are desired (reflections, refractions, volumetric light, and caustics) EEVEE is more limited, and requires some options and tricks to work around some of these limitations. |
|||
<!--T:88--> |
|||
In many cases, the scene prepared with EEVEE can be used immediately without change in Cycles in order to produce a better rendering. However, in cases were complex light interactions are desired (reflections, refractions, volumetric light, and caustics) EEVEE is limited, and requires some tricks and options to work around some of these limitations. |
|||
On the other hand, Cycles is a true raytracing renderer which means it is more accurate at calculating light paths in a scene. Cycles is the recommended renderer when the best quality is desired (photorealistic results), at the cost of more rendering time. |
|||
<!--T:89--> |
|||
Obtaining good results is highly dependent on configuration of the rendering options, the materials, and the lighting. The {{incode|Principled BSDF}} material shader is a generic solution that works well for many cases, however, to produce trully photorealistic results, the use of texture maps and normal maps, along with careful lighting of the scene is still very important. |
|||
Both renderers can be used to leverage the advantages of each. In many cases the scene can be quickly prepared and tested with EEVEE to obtain preliminary renderings; then the same scene can be used with minor changes with Cycles in order to produce a higher quality, final rendering. In particular, when a scene that was setup with EEVEE will be used with Cycles, the lights may need to be adjusted in value and position as both renderers treat light in different ways. |
|||
<!--T:90--> |
|||
{{Userdocnavi}} |
|||
Obtaining good results is highly dependent on the rendering options, the materials, and the lighting. The {{incode|Principled BSDF}} material shader is a generic solution that works well for many cases, however, to produce truly photorealistic results, the use of texture maps and normal maps, along with careful lighting of the scene is still very important. |
|||
[[Category:Tutorials]] |
|||
</translate> |
</translate> |
||
{{Tutorials navi{{#translation:}}}} |
|||
{{Raytracing Tools navi{{#translation:}}}} |
|||
{{Userdocnavi{{#translation:}}}} |
Revision as of 05:30, 25 February 2020
Topic |
---|
Rendering |
Level |
Intermediate |
Time to complete |
60 minutes |
Authors |
vocx |
FreeCAD version |
0.18 or greater |
Example files |
none |
See also |
None |
Introduction
This tutorial shows how to produce a rendered image in Blender, beginning from a part or assembly created with FreeCAD. It assumes that the user already created the part in FreeCAD, or has imported it into it. Then this part is exported to Blender for rendering.
It produces a rendering with Blender 2.80 with both the EEVEE and Cycles renderers. It shows various Python commands that can be used to perform actions quicker both in FreeCAD and Blender.
A similar description of this process is described in a series of videos, Render Solidworks and FreeCAD Models in Blender, by Joko Engineering.
FreeCAD
1. Create an assembly using bodies from the Part or PartDesign Workbenches, or any other workbench that produces solid objects, for example, the Arch Workbench. Assign colors or materials to the individual bodies that make the assembly, approximately matching the color that you want in your render.
![](/images/thumb/a/ad/01_T03_FreeCAD_Blender_model.png/600px-01_T03_FreeCAD_Blender_model.png)
Assembly of three bodies created in FreeCAD, and with colors or materials assigned.
2. If your model is very detailed, make sure the ViewDeviation of the body is set to a low value, between 0.1
and 0.01
, or even smaller. The lower this value is, the more detailed the exported mesh will be, and thus the better the quality of the render will be.
![](/images/0/06/02_T03_FreeCAD_Blender_deviation.png)
Deviation property of the bodies created in FreeCAD; the deviation needs to be small in order to export the parts with good resolution.
3. Select the Part
, then File → Export, or press Ctrl+E, and export it as Wavefront OBJ
.
Alternatively, the export can be done from the Python console. Define a list of objects to be exported and use the exporting function with a file name.
import importOBJ
objs = FreeCAD.ActiveDocument.getObjectsByLabel("Part")[0]
importOBJ.export(objs, "/home/user/assembly.obj")
Note: when exporting to OBJ, two files are created; the first one contains the mesh information itself, assembly.obj
; the second one contains the definition of the materials, which in most cases is just the color, assembly.mtl
.
Note 2: if the resulting OBJ file appears to be empty, you may have to export the individual bodies. In this case, select each of the bodies under the part, and repeat the export.
import importOBJ
objs = [FreeCAD.ActiveDocument.getObjectsByLabel("Body.base")[0],
FreeCAD.ActiveDocument.getObjectsByLabel("Body.bolt")[0],
FreeCAD.ActiveDocument.getObjectsByLabel("Body.bolt.big")[0]]
importOBJ.export(objs, "/home/user/assembly.obj")
Blender
Prepare the model
4. Open Blender. Change the Timeline
panel into a Python Console
(Shift+F4). This will help you to input commands and see the results. You may divide this panel, to keep the console on one side, and make the other division an Info
panel; this will allow you to see the code of the actions as you click on the interface.
Make sure you are using the EEVEE renderer. In the Properties
panel go to Render
, and for Render Engine
select Eevee
.
bpy.context.scene.render.engine = 'BLENDER_EEVEE'
5. Import the model file from the menu, File → Import → Wavefront (.obj).
Alternatively, importing can be done from the Python Console
.
obj_file = "/home/user/assembly.obj"
bpy.ops.import_scene.obj(filepath=obj_file)
6. Change the scale.
If the bodies appear to be very large you may have to change the units so the objects appear at the right scale.
In the Properties
panel go to Scene
, Units
, and select the appropriate Unit System
, Unit Scale
, and Length
.
For small parts, you may wish to keep the length to Millimeters
, and the scale to 0.001
. For bigger parts, for example, the model of a building, you may have to set these values to Meters
and 0.001
. Try other values of scale as required.
This can be set also from the Python console
.
bpy.context.scene.unit_settings.length_unit = 'MILLIMETERS'
# or bpy.context.scene.unit_settings.length_unit = 'METERS'
bpy.context.scene.unit_settings.scale_length = 0.001
Note: changing the scale and units of the scene is only necessary if you wish to work with objects at their true dimensions. If you just want to render your scene quickly, you may omit any adjustment.
6.1. If you zoom out, and the view cuts the imported parts, you may have to adjust the view clip values.
Hit N to show the auxiliary panel; go to the View
section and set the End
to a large value, for example, 1E6 mm
or 1000 m
.
6.2. If you wish, also adjust the size of the grid; go to Overlays
, then Guides
, and set the Scale
of the grid to 0.001
.
7. Fix the rotation of the objects.
When imported, objects may appear rotated around one of the axes, for example, 90 degrees around the X axis.
Hit N to show the auxiliary panel; select an object, go to the Transform
section and set the Rotation
to 0°
in each field. Do this for every object.
This can be automated by a small script that just sets the rotation of each imported body to zero, with the exception of the objects inside the fixed_objs
tuple. This can be useful if you are importing objects into an existing scene where other objects are already in their right positions.
fixed_objs = ('Camera', 'Cube', 'Light')
for obj in bpy.data.objects:
if any(s for s in fixed_objs if s in obj.name):
print('%s %s [[No change]]' % (obj.name, obj.rotation_euler))
continue
else:
obj.rotation_euler = (0, 0, 0)
print('%s %s ... rotated' % (obj.name, obj.rotation_euler))
![](/images/d/d7/03_T03_FreeCAD_Blender_imported_assembly.png)
Assembly created in FreeCAD imported into Blender; the model was rotated and the units for the scene were adjusted to match the imported objects.
Prepare the camera of the scene
8. Set the camera in the right position.
Adjust the viewport to look at the model in the desired orientation, then hit Ctrl+Alt+0 (numerical pad), or use the menu View → Align View → Align Active Camera to View.
8.1. If you don't see anything in the camera view, you may need to adjust the clipping. Selecting the camera in the Outliner
, go to the Properties
panel, then Object Data
, then Lens
, then set the Clip End
to a large value, for example, 1E3 mm
or 1000 m
.
bpy.context.object.data.clip_end = 1e+03
If you can see the object through the camera view, now you can quickly render the model by pressing F12, which will open the Image Editor
with the result. Press Esc to exit, and return to the 3D Viewport
.
![](/images/thumb/8/81/04_T03_FreeCAD_Blender_first_render.png/600px-04_T03_FreeCAD_Blender_first_render.png)
First render of the assembly in Blender, with the camera with correct clipping but no lighting
You can toggle between camera view and the 3D viewport by pressing 0 in the numerical pad; pressing F12 will render the camera view in any moment.
8.2. If the camera looks very small in the 3D viewport, go to the Properties
panel, then Object Data
, then Viewport Display
, and set a larger value for the Size
, for example, 20 mm
. Also activate the Limits
checkbox to see the clipping distance of the camera.
bpy.context.object.data.display_size = 20
bpy.context.object.data.show_limits = True
Prepare the lighting of the scene
9. Select the light in the Outliner
, go to the Properties
panel, then Object Data
, then press on Sun
, and set the Strength
to 5.0
.
bpy.context.object.data.type = 'SUN'
bpy.context.object.data.energy = 5
This will turn the light into a Sun lamp. This type of lamp emits an infinite number of parallel light rays that all arrive to the scene with a fixed angle.
You may position the Sun lamp anywhere on the viewport above your model so that you define the direction of the rays of light. For a Sun lamp it doesn't matter how close or far you place the lamp, only the direction of the rays, which are defined by the rotation of the Light
object.
bpy.context.active_object.location = (150, 100, 100)
bpy.context.active_object.rotation_euler = (0.6, 0.05, 1.88)
Press F12 again to see a preliminary render of the model.
![](/images/thumb/c/cf/05_T03_FreeCAD_Blender_render_sun_lamp.png/600px-05_T03_FreeCAD_Blender_render_sun_lamp.png)
Render of the assembly in Blender with a Sun lamp added that emits parallel light rays with a fixed angle
More setup: floor, global lighting, reflections, and soft shadows
10. Add a floor plane. Press Shift+A then choose Mesh
, Plane
, and give it dimensions about 10 times larger than your model. This mesh object will serve as a floor plane or table top on which the model is standing. Also move the plane a bit down so that it does not intersect the model; -1 mm
below the object is enough.
bpy.ops.mesh.primitive_plane_add(size=1500, view_align=False, enter_editmode=False, location=(0, 0, -1))
11. Set the world illumination. In the Properties
panel go to World
, and set Color
to a light blue-gray value, RGB (0.358, 0.512, 0.527)
, and set the Strength
to 0.3
.
12. Set reflections and shadows. The EEVEE renderer of Blender produces fast renders by deactivating most effects initially. In order to obtain better images, some options need to be made active.
Go to the Properties
panel, then Render
, and check Screen Space Reflections
. In the Shadows
section, also check Soft Shadows
.
bpy.context.scene.eevee.use_ssr = True
bpy.context.scene.eevee.use_soft_shadows = True
Set the materials of the objects
13. Turn the Python Console
panel into a Shader Editor
panel (Shift+F3).
13.1. Select the ground plane, go to the Properties
panel, then Material
, and click on New
. In the Shader Editor
a Principled BSDF
node should appear. Give it a beige Base Color
RGB (0.318, 0.267, 0.187)
, turn the Metallic
slider to 0.000
, and the Roughness
to 1.000
.
![](/images/4/47/06_T03_FreeCAD_Blender_Principled_shader.png)
Principled BSDF shader used in Blender to simulate a variety of materials ranging from shiny metals to rough and opaque solids.
13.2. Select each of the parts of the model, and adjust the respective Principled BSDF
material node. For metallic parts, turn the Metallic
property all the way to 1.000
. Adjust the value of Roughness
to be between 0.2
and 0.7
. The closer to 0.000
the Roughness
is, the more reflective (mirror-like) it will appear.
For non metals, like plastics, wood and textiles, set the Metallic
slider all the way to 0.000
, and adjust the value of Roughness
to between 0.4
and 1.0
.
In general, metals are naturally smooth and therefore their roughness value is small, making them very reflective (shiny). Other materials are microscopically rough, and therefore do not reflect as much light, making them opaque.
14. Test different combinations of materials until they look acceptable. Press Z and then 8 (numerical pad) to enter Rendered
mode; in this mode, the EEVEE renderer shows in real time in the 3D viewport how the final image will look like. Use Z to open the pie menu and switch back to Solid
mode (Z 6), or go to LookDev
mode (Z 2), a mode which adds different types of lighting to the scene to test the appearance of the materials.
Press F12 to render the view through the camera and check the quality of the image.
Rendering and saving
15. If your model looks reasonably well with the EEVEE renderer you can already save the image by going to Image → Save As or pressing Shift+S in the Image Editor
.
![](/images/thumb/9/96/07_T03_FreeCAD_Blender_EEVEE_render.png/600px-07_T03_FreeCAD_Blender_EEVEE_render.png)
Rendered assembly produced with Blender EEVEE; all materials use the Principled BSDF shader; only one Sun lamp is used, with some ambient background light.
16. If you want to improve the quality of the image, try the Cycles renderer.
Go to the Properties
panel, then Render
, and for Render Engine
select Cycles
. With the Cycles renderer, Blender will refine the image gradually until a number of iterations have passed. Every time the viewport changes the recalculation restarts.
bpy.context.scene.render.engine = 'CYCLES'
16.1. Adjust the sampling rate. Go to the Properties
panel, then Render
, then in the Sampling
section select an appropriate number for Render
and Viewport
.
For the Viewport
a small number of samples, in the range of 32
to 128
, is generally enough to obtain a good preview of the image. For the final image, set Render
to a higher number, from 128
to 2000
, depending on the complexity and amount of details on the scene.
Press F12 to render the final view through the camera. Depending on your graphics card (GPU) the image should take several more seconds, or minutes, to render with Cycles than with EEVEE, but the quality of the image should be better.
17. When you are satisfied with the quality of the rendering, in the Image Editor
go to Image → Save As or press Shift+S.
![](/images/thumb/4/47/08_T03_FreeCAD_Blender_Cycles_render.png/600px-08_T03_FreeCAD_Blender_Cycles_render.png)
Rendered assembly produced with Blender Cycles; all options, materials, and lights that were used with EEVEE were kept for use with Cycles.
Rendering from the command line
18. If the scene has been completely finished, you may wish to render from outside Blender, from the operating system's command line. This can be useful to batch render different scenes in a remote system. Both EEVEE and Cycles are supported.
blender -b assembly.blend -E BLENDER_EEVEE -o //assembly_EEVEE_#### -t 3 -F PNG -x 1 -f 1
blender -b assembly.blend -E CYCLES -o //assembly_CYCLES_#### -t 3 -F PNG -x 1 -f 1
This specifies that rendering should happen in the background with -b
; the rendering engine is chosen with -E
; the output filename is selected with -o
; the double forward slash //
indicates a path relative to the input file; the hash mark #
is used to indicate the frame number, padded with zeroes if necessary, for example, 0001
; the number of CPU threads used in rendering is chosen with -t 3
; the output file format is indicated with -F
, and the -x 1
option adds automatically the extension to the name; the final option is -f 1
which indicates that only the first frame will be rendered, which is the normal case for a static scene; for animations use the -a
switch to produce an image for each frame, which can then be assembled to produce a video file.
Importing plugin
Creating the intermediate Wavefront mesh (.obj) and then importing it into Blender will work in most situations. However, there is also the option of importing the FreeCAD file (.FCStd) directly into Blender by means of a plugin.
- io_import_fcstd.py, original version for Blender 2.79
- FreeCAD .FCStd importer for Blender 2.80
This is a Blender plugin; for it to work, Blender needs to be able to import FreeCAD as a module from the Python Console
.
import FreeCAD
This is only possible if both Blender and FreeCAD are compiled against the same pythonX.Y
(major and minor) version. For example, if Blender is compiled against Python 3.7, FreeCAD must be compiled against a Python 3.7 version as well. If FreeCAD is compiled against another version, for example, Python 2.7.15 or Python 3.6.7, the plugin will not work. The micro version number (third number) does not matter, that is, the plugin should work if one software is compiled against Python 3.7.5 and the other against Python 3.7.8.
In addition, the FreeCAD precompiled Python module, FreeCAD.so
on Linux and FreeCAD.pyd
on Windows, should be in the Python path used by Blender to import modules. This path can be set up in different ways, depending on the operating system and Python distribution.
In Blender you can see all paths searched by inspecting the sys.path
variable. The FreeCAD module should be found in any of those directories.
import sys
print(sys.path)
- A copy or symbolic link inside one of those directories could be created pointing to the FreeCAD module.
ln -s /usr/lib/freecad/lib/FreeCAD.so $HOME/.config/blender/2.80/scripts/addons
ln -s /usr/lib/freecad/lib/FreeCAD.so $HOME/.local/lib/python3.7/site-packages
- Another possibility is adding the module directly into the path inside Blender.
import sys
sys.path.append("/usr/lib/freecad/lib/FreeCAD.so")
Final notes
EEVEE is not a physically accurate renderer, however its main strength is that it is a real time engine so it is able to produce quick renderings directly in the 3D viewport. In many cases these images have enough quality for final production, which means it is possible to obtain a good result in a very short time. In cases where complex light interactions are desired (reflections, refractions, volumetric light, and caustics) EEVEE is more limited, and requires some options and tricks to work around some of these limitations.
On the other hand, Cycles is a true raytracing renderer which means it is more accurate at calculating light paths in a scene. Cycles is the recommended renderer when the best quality is desired (photorealistic results), at the cost of more rendering time.
Both renderers can be used to leverage the advantages of each. In many cases the scene can be quickly prepared and tested with EEVEE to obtain preliminary renderings; then the same scene can be used with minor changes with Cycles in order to produce a higher quality, final rendering. In particular, when a scene that was setup with EEVEE will be used with Cycles, the lights may need to be adjusted in value and position as both renderers treat light in different ways.
Obtaining good results is highly dependent on the rendering options, the materials, and the lighting. The Principled BSDF
material shader is a generic solution that works well for many cases, however, to produce truly photorealistic results, the use of texture maps and normal maps, along with careful lighting of the scene is still very important.
Template:Tutorials navi
![](/images/thumb/9/94/User_hub.png/24px-User_hub.png)
- Getting started
- Installation: Download, Windows, Linux, Mac, Additional components, Docker, AppImage, Ubuntu Snap
- Basics: About FreeCAD, Interface, Mouse navigation, Selection methods, Object name, Preferences, Workbenches, Document structure, Properties, Help FreeCAD, Donate
- Help: Tutorials, Video tutorials
- Workbenches: Std Base, Arch, Assembly, CAM, Draft, FEM, Inspection, Mesh, OpenSCAD, Part, PartDesign, Points, Reverse Engineering, Robot, Sketcher, Spreadsheet, Start, Surface, TechDraw, Test Framework, Web
- Hubs: User hub, Power users hub, Developer hub