|
Wiki FreeCAD/PovRay tutorial
|
- Introduction
I'll try to explain here how to combine FreeCAD with pov ray to render nice scene.
For instance, we'll try to go from the first picture on FreeCAD to the second one (rendered with pov ray) - Preparing .pov file withFreeCAD
The first thing is to create a 3D scene on FreeCAD. For that, you can find a lot of tutorials.
Then, you'll launch the Raytracing workbench.
Basically, all you need to know is already explained on this page : https://www.freecadweb.org/wiki/Raytracing_Module
To sumarize :- Create a pov ray project by clicking
- Select all the object you want to add to your scene and click on
Basically you'll certainly want to add all your object.
Perhaps, you may have to add unseen object (but they might be seen by reflection (on a miror or something). At the opposite, if an object will block your view, don't put it in the pov ray project.
Note that all object on the pov ray project have a name based on their internal FreeCAD name. It's important to note what is the "pov ray name" of your object : Later, when you'll have to affect different material to different objects, you'll have to know which object correspond to Pov_Body032 and which is Pov_Body015 - Now, set your 3D view on FreeCAD to the view you want to render
- Select the pov ray project on the tree view and press
Your pov ray file is now ready, it contains all your objects, and the camera informations - Press to save the .pov file
- Modifying .pov file
You now have a .pov file that you can render (you can do it directly from FreeCAD or launchling pov ray.
The scene you'll obtain would be nice but not really nicer than what FreeCAD gives you.
I'll explain you how to change things easily and for that you'll have to edit the .pov file "manually"- .pov file structure
The .pov file generated by FreeCAD could be impressive at the first time but it's a 90 % filled by mesh informations that we will almost not touch.
All functionnalities are embedded within tags "{ }".
Your .pov file is organised like that :- Global settings
- sky_sphere
- camera
- meshes (a looooot of lines)
- light
- Small re-organization
As you see, the Light is defined at the very end of your .pov file.
I find it easier to put it before.
Then, you just have to copy this part before meshes.
For instance, you'll have something like that :Now, you'll have to do the most painfull part : modify the texture of each object in the meshes.Code: Select all
#version 3.6; . . . // Generated by FreeCAD (http://www.freecadweb.org/) #declare cam_location = <-191.422,1268.51,-2069.5>; #declare cam_look_at = <548.803,352.667,-113.581>; #declare cam_sky = <0.133269,0.915973,0.378461>; #declare cam_angle = 45; camera { location cam_location look_at cam_look_at sky cam_sky angle cam_angle right x*800/600 } //default light light_source { cam_location + cam_angle * 100 color rgb <10, 10, 10> } // Written by FreeCAD http://www.freecadweb.org/ // face number1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ . . .
You can see that all the object you had on your FreeCAD project have been written on the .pov file.
For each objects, all its triangles making its faces are defined. And each triangles are defines by vertexes, normals and indices. We don't have to touch all this.
But for each object you've add to the scene you'll find this kind of lines :This code shows how the part named Body017 in FreeCAD will be rendered by pov ray (that what the "texture" means).Code: Select all
// instance to render object {Pov_Body017 texture { pigment {color rgb <0.8,0.8,0.8>} finish {StdFinish } //definition on top of the project } }
As you see, the "finish" is defined at the begining of the file.
I think it's easier to do the same for the complete texture.
So, if you remember that Body017 is a mirror, you can change the code like thatWe will define the Tmirror at the beggining of the file.Code: Select all
// instance to render object {Pov_Body017 texture { Tmirror } }
It's very usefull if you have a lot of objects on which you want to apply the same texture.
By now, eahc of your object will be rendered depending of textures you've defined at the beggining of your file. It won't be necessary to look into your meshes again.
You just have to define theses textures. - Textures
But what are these textures ??
Textures are container defining the color and behavior of each point of an object.
In a texture, you can put a lot of things : a color (=pigment), a normal (controls how the color change regarding the normal of the surface. You can then change the normal to make the color change), a finish (controls the interaction of the surface with the light)
A lot of patterns are also defined in pov ray to help you do what you want (checker, agate, spiral, radial, wood ...) You can mix everything to do all you want ... It's not trivial but there is plenty of examples.
There are tons of things you can do in textures !!
But the thing you have to know are the "inclusions" : pov ray comes with a huge database of materials.
If you want some object look like silver, you just have to write :You can also use an inclusion an modify it on your texture definition.Code: Select all
#include "metals.inc" #declare Tsilver = texture{ T_Silver_5E }
When you use an inclusion, you often have to scale, translate or rotate the texture to fit your needs. For instance, the texture I used for the furniture was only :And this Twood is put on each object I want to render in wood in the mesh part.Code: Select all
#include "woods.inc" #declare Twood = texture { T_Wood7 scale 50.0 translate x*1 translate y*10 finish { ambient 0.01 diffuse 0.9 phong 1.0 phong_size 70 brilliance 0.5} ; }
In my exemple, the only "complexe" texture is the one for the floor that I found on a exemple on the net (you'll find it on the .pov fil at the end of this message). All other texture are from predefined includes - Planes
The planes on pov ray behave like meshes objects : you can give them a texture (predefined or not).
The .pov file generated by FreeCAD contains one plane (the floor).
I add one other plane vertically to render a wall.
Note that in pov ray, the "vertical" is on the y axis. x axis is left/rigth and the z axis is front/behind.
It could be quite disturbing some times when you want to move walls or lights...) - Lights
One light is defined while the .pov file is created by FreeCAD. It has a position and a color.
Like other objects, you can modify it by a lot of ways.
In my example, I add- a fade_distance parameter to mitigate the light
- a area_light parameter to simulate a "diffuse" light source.
- jitter is used to smooth the shadows (area_light makes smoother shadows too)
- Radiosity
The radiosity controls the way pov ray computes the light interactions with the objects.
It's primordial to add a radiosity container in your global settings to have beautiful results.
Because this part could be very time consuming, you can use a switch to quickly test your render on low settings :Code: Select all
#declare Rad_Quality = 3; global_settings { assumed_gamma 1.0 max_trace_level 10 #switch (Rad_Quality) #case (1) radiosity { // --- Settings 1 (fast) --- pretrace_start 0.08 pretrace_end 0.02 count 50 error_bound 0.5 recursion_limit 1 } #break #case (2) radiosity { // --- Settings 2 (medium quality) --- pretrace_start 0.08 pretrace_end 0.01 count 120 error_bound 0.25 recursion_limit 1 } #break #case (3) radiosity { // --- Settings 3 (high quality) --- pretrace_start 0.08 pretrace_end 0.005 count 400 error_bound 0.1 recursion_limit 2 } #break #end }
- .pov filnal structure
When you're done, the final .pov file structure looks like this :- global settings with radiosity
- sky_sphere (I didn't investigate a lot on it...)
- definition of texture(s)
- definition of plane(s)
- camera
- light(s)
- meshes (calling the textures defined at the beggining)
- .pov file structure
- Rendering
Well, you now have to render !
In povray command line, you can use +wX +hY to set the size of your final image (X is the width and Y the height : + w800 +h600 for instance)
The +a and +am2 options are usefull to trigger antialiasing
(I didn't used any other option)
PS : I highly encourage you to read complete tutorials and documentations on pov ray. I'm not an expert at all, I just spent a afternoon reading documentations to accomplish this rendering.
Also, feel free to correct me if I wrote anything false !
For the complete file, here is my .pov file (just take off the .txt extension)