Thursday, 2 August 2012

Render Module: Structure

Render Module Structure:

I had trouble sleeping last night and having to wake up early to lift roof trusses didn't leave me in a good state. Thankfully many cups of tea help with such situations so bare with me...

I have decided to split the render module into many discrete objects to allow different back-ends to be easily abstracted. Fundamentally the module will be split into two major components, the Render Part that stores all the data and manages the rendering and also the Appearances part. In the crude diagram below I've broken down the structure I am planning on implementing, which so far seems logical. 

Material Data Model:

Currently there is a planned Material Data Model but has yet to be implemented amongst the many other things in store for FreeCAD - it was last discussed on the forums but sadly there was no outcome. Eventually this will store useful data on material properties such as mechanical, electrical, thermal properties that will be used in many other areas of FreeCAD such as FEA simulations, and also in the proposed mechanics / dynamics simulation workbench which is waiting for the Assembly model to be developed. 

With this in mind I decided that Appearances Part should be kept separate so that it can be more easily integrated in the future and if needs be provide backwards compatibility. Also the 3D Inventor View will need to have materials described so that it's appearance matches the part's material. This may lead to some more eye candy in terms of 'Shaders' but that requires learning GLSL. Oh dear.

Render Module:

This will provide the interface for adding scene information such as the camera, lights, parts with its materials and providing convenient methods to control the overall rendering process.

In the context of programming this will be an abstract class that requires its methods to be redefined by a render plugin. Each specific Render Plugin will generate the scene graph file format and other information specific to that Render Backend. To the user/programmers perspective its parent they shouldn't have to worry much about what Backend is used. Like the rest of Freecad this will have python bindings (I still cannot get my head around python due to its syntax)

The Render Process

The  Render Plugin attaches a specific Render Process that controls the Render Program in a new process which is silently run in the background. These are typically console based but it may spawn a GUI to begin rendering. The Render process  feeds the require parameters and scene file to the render progress and is started. The Render Process should then give the output back to the user. Errors and other states will be handled and in the eventuality of the renderer crashing, FreeCAD should be spared by being in a separate process.

Hopefully this may make some sense!