Offline Rendering Utils - Request for testing

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
yorik
Site Admin
Posts: 11574
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Offline Rendering Utils - Request for testing

Postby yorik » Sun Jun 30, 2019 12:31 am

In git commit fe3cb2f0e, I added a new file to the Arch module, called OfflineRenderingUtils.py, that contains several tools to ease exporting files from FreeCAD running in non-GUI mode, namely export files with colors.

Basically you can export IFC, DAE, OBJ, STEP or PNG or even FCStd files from the command line, with the object colors saved. You must provide the colors yourself, as a dict. This is mostly useful for servers running FreeCAD to produce files.

Mostly everything is explained in the file itself: https://github.com/FreeCAD/FreeCAD/blob ... ngUtils.py

One feature is failing on some machines and not on others, though: the PNG export, which is done with coin's offscreen rendering stuff.

Does anyone fancy testing this? curious to see where it works and where it doesn't...

1) The X server needs to have Indirect Rendering enabled. On recent distros, it seems to be disabled by default. The easiest way I found to fix this is to edit (or create if inexistant) /etc/X11/xorg.conf and add this:

Code: Select all

    Section "ServerFlags"  
        Option "AllowIndirectGLX" "on"  
        Option "IndirectGLX" "on"  
    EndSection 
(if your xorg.conf already has a "ServerFlags" section, just add the two options in it). There might be other ways for other distros though, google for "enable indirect glx"

On windows I'm not sure if anything is needed... We'll see

2) In a python console running outside FreeCAD (this won't work inside FreeCAD, couldn't find out why yet...)

Code: Select all

# if needed, add the path to your FreeCAD.so or FreeCAD.pyd
import sys
sys.path.append("/path/to/FreeCAD.so")

import FreeCAD
import OfflineRenderingUtils
OfflineRenderingUtils.render("/path/to/some/test.png")
This should produce a /path/to/some/test.png file that shows a grey cube on a white background like this:
colors.png
colors.png (2.07 KiB) Viewed 174 times
If anything goes wrong, you should see some error messages.