FreeCAD / pov ray tutorial

A place to share learning material: written tutorials, videos, etc.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
schupin
Posts: 476
Joined: Sun Jan 21, 2018 1:43 pm

FreeCAD / pov ray tutorial

Post by schupin »

|
|
EDIT : vocx has improved this tutorial and writen it on the wiki.
Wiki FreeCAD/PovRay tutorial
|
|
  1. 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)
    beforeAfter.png
    beforeAfter.png (358.71 KiB) Viewed 8287 times
  2. 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 Image
    • Select all the object you want to add to your scene and click on Image
      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 Image
      Your pov ray file is now ready, it contains all your objects, and the camera informations
    • Press Image to save the .pov file
  3. 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
      We will not touch the camera section and, almost not touch the mesh part. The main modifcations/additions will be made on the other parts.
    • 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 :

      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 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      .
      .
      .
      
      Now, you'll have to do the most painfull part : modify the texture of each object in the meshes.
      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 :

      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
        }
      }
      
      This code shows how the part named Body017 in FreeCAD will be rendered by pov ray (that what the "texture" means).
      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 that

      Code: Select all

      // instance to render
      object {Pov_Body017
       texture {
      	Tmirror
        }
      }
      We will define the Tmirror at the beggining of the file.
      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 :

      Code: Select all

      #include "metals.inc"
      #declare Tsilver = texture{  
              T_Silver_5E
          } 
      
      You can also use an inclusion an modify it on your texture definition.

      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 :

      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} ;
              }
      
      And this Twood is put on each object I want to render in wood in the mesh part.

      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)
      You can, of course add other light sources !
    • 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)
      Note that all these containers can be in any order !
  4. 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)
That's all on my tuto/walk through rendering FreeCAD scene with pov ray. If you want any detail on a specific point, I'll try to answer.

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)
MeubleNida5.pov.txt
(787.98 KiB) Downloaded 218 times
Last edited by schupin on Wed May 08, 2019 2:11 pm, edited 7 times in total.
freecad-heini-1
Veteran
Posts: 7791
Joined: Tue Jan 07, 2014 11:10 am
Contact:

Re: FreeCAD / pov ray tutorial

Post by freecad-heini-1 »

schupin wrote: Mon Dec 10, 2018 10:18 pm
  1. 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)
    beforeAfter.png
Hi Schupi,
thank you so much for your tutorial. For me it seems to be complicated and brakes my motivation.

Please give Cadray's a try?
https://forum.freecadweb.org/viewtopic. ... 63#p165463
phpBB [video]

Best regards
Wilfried
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: FreeCAD / pov ray tutorial

Post by triplus »

Thanks @schupin, for creating the tutorial.

P.S. When it comes to FreeCAD raytracing, questions we get are still more or less focused on POV-Ray.
schupin
Posts: 476
Joined: Sun Jan 21, 2018 1:43 pm

Re: FreeCAD / pov ray tutorial

Post by schupin »

freecad-heini-1 wrote: Tue Dec 11, 2018 6:50 am
Please give Cadray's a try?
https://forum.freecadweb.org/viewtopic. ... 63#p165463
Best regards
Wilfried
Hi Wilfried,

PovRay can run on any OS and also on very old systems (I did the pictures presented here on a 2009 computer).

I just launched Cadray's to get a look. You're right that it's very confortable to be able to change the view and position instantaneously.
But as in PovRay, if you want to make a "nice" render, you'll have to really work on what you ask the soft. The good point seems that you can directly load textures from images (like in blender or other soft)
When I'll finally change my computer, I'll give it a real try ;)
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: FreeCAD / pov ray tutorial

Post by Kunda1 »

@schupin awesome tutorial!
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
mario52
Veteran
Posts: 4701
Joined: Wed May 16, 2012 2:13 pm

Re: FreeCAD / pov ray tutorial

Post by mario52 »

hi

good work an d good tutorial

i suggest to create a wiki page with your tutorial and create the link of your page in Raytracing_Module section POVRay

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: FreeCAD / pov ray tutorial

Post by Kunda1 »

mario52 wrote: Sat Dec 15, 2018 10:10 am i suggest to create a wiki page with your tutorial and create the link of your page in Raytracing_Module section POVRay
Yes, it would be great if this info doesn't get buried in the forum.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: FreeCAD / pov ray tutorial

Post by vocx »

I took the initial post and made it a new tutorial in the wiki: Tutorial FreeCAD POV ray.
assembly_edited.png
assembly_edited.png (611.91 KiB) Viewed 7203 times
I used simpler bodies so that the modelling and rendering process is easier to recreate. Naturally, this can be extended to more bodies and textures.

The files used are here.
  • assembly.FCStd, the FreeCAD model
  • assembly.pov, original POV-Ray project file exported from FreeCAD
  • assembly_edited.pov, final, manually edited POV-Ray project file with textures, lighting, and radiosity
Produce the render with

Code: Select all

povray assembly.pov +W800 +H600 +AM2 +A
The .pov files are plain text files. As the forum doesn't allow attaching .pov files directly, the files were given the .txt extension. After downloading them, remove this extension.
assembly.FCStd
(86.89 KiB) Downloaded 214 times
assembly.pov.txt
(33.08 KiB) Downloaded 187 times
assembly_edited.pov.txt
(34.01 KiB) Downloaded 200 times
Last edited by vocx on Thu May 02, 2019 6:18 pm, edited 1 time in total.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: FreeCAD / pov ray tutorial

Post by yorik »

Excellent and highly precious tutorial! Thanks a lot for writing!
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: FreeCAD / pov ray tutorial

Post by Kunda1 »

Nice!! Thanks vocx!
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply