Showing posts with label Render Module. Show all posts
Showing posts with label Render Module. Show all posts

Wednesday, 22 August 2012

Render Module Updates:

A lot has happened since my most recent post. It's time to share more work on the Render Module. So I am grabbing some tea and getting ready to share it with you all:

Improvements to Render Interface

Toolbar:

You don't have to edit a Render Feature to preview it. Simply ensure that the settings are set up to how you desire. Then click the preview buttons within the toolbar.

Buttons (From Left):
1) Add Render Feature
2) Render Preview Window
3) Render Preview (uses stored settings in Render Feature)
4) Add materials when editing a Render Feature


Render Task View:

Further updates to improve the completeness of the Render Task View. Render Presets and Templates are correctly set from the combo boxes. 


Material Selection:

All render materials that have been assigned within the Render Feature are now displayed in a list view. These can be selected and deleted, or if double clicked , the material properties can be edited. 


View shows material Labels:

When editing a Render Feature, all materials that are assigned to any objects has some Material Labels displayed. This is very basic admittedly, but for now will suffice to help keep track of what materials are assigned within your scene.

Render Templates:

The inclusion of the Render Templates was the last remaining major feature that was to be implemented. This has further been improved so that they are positioned in a more optimal place respective to the scene geometry and the camera. This is not perfect but is certainly ideal in most cases.

We can more easily now zoom really far out like this.


Or zoom in really close:


The Render Template will take into consideration the bounding box of the visible parts in the scene and the camera itself. It will move the template to the middle of the scene bounding box and then scale it according to  furthest point away from the bounding box center.

Material Selection & Editing:

I have finished of the material selection interface, so you can set and edit parameters. Now this has undo-redo system built in making things easier. On a similar note materials and cameras can be saved. (Material properties aren't saved yet).

The colour chooser and number inputs now correctly retrieve and store values. It needs refinement but most importantly is function. Ideally it needs a button to allow more sophisticated selection from a QtColorChooser Dialog. Other ideas are having predefined material presets, which become more important on more complex materials such as plastics and glasses.

The above screenshots show that material properties are dynamic. Just define the properties in the XML file and the GUI figures out how to use them and store them. Here's the XML sample for the right:



Well that's most of the major changes! I need help with testing and making materials and templates for people to use.

TODO List:

  1. Ability to Save Material Properties
  2. Make adjustments to the user inteface
  3. Add more render materials and scenes
  4. Python bindings
  5.  ???




Wednesday, 15 August 2012

Creating FreeCAD Lux Render Template

This is for the upcoming Render Module. Despite my very limited experience with rendering and modelling it appears that to get that 'wow' factor it will take a lot of scenes. Most people have better things to do so that is where templates come into play.

This guide will hopefully show how it will be possible to specify your own templates (for lux render):

Beginning with Blender & Lux Render:

The easiest way to create a template is to start with blender. A useful build and instruction guide for compiling Lux Render and using this in  Blender has been provided by Yorik on his blog

I don't have any clue how to use Blender, so you will have to figure that for yourselves. Nevertheless the important that you must have the scene normalised to a unit length. Ideally you have a cube with side lengths as one and build up a scene around this.
This is important because the scene will be scaled to the bounding box of the scene. I cannot guarantee this will work in all situations but it should give satisfactory results. Within blender you will need to export the scene to a  Lux Render Scene File Format with an extension .lxs 

Yorik created three example scenes that I am going to show you how to import as a Render Template in FreeCAD, these I have made available using google docs




Importing templates into FreeCAD:

For the scene template, we only need to find lights, geometry and materials information.

Materials are most likely to be used on the geometry within the scene. Using a templates like this means we can texture surfaces, which isn't going to appear within FreeCAD in the near future.

In this example open up luxscene-classic.lxs

Essentially we need everything from World Begin to World End. So extract all of this and you should be left with http://pastebin.com/qe3m0qXu 

One thing we need to change:

I discovered the long way that there is a problem with the way Blender exports the scene information to Lux Render. Unfortunately, you will need to go through the file and look for lines like these:


Transform [-0.083770856261253 0.000000133886644 -0.996485054492950 0.000000000000000 -0.000000133886729 1.000000000000000 0.000000145614280 0.000000000000000 0.996485054492950 0.000000145614365 -0.083770856261253 0.000000000000000 -0.465571254491806 -0.011301971040666 0.364225387573242 1.000000000000000]


These are transformation Matrices. These need to be removed and replaced with seperate Translation and Rotation properties for each object like so:

Tanslate x y z
Rotate angle x y z


With the rotation, you specify an angle about a given axis, so in the case of blender this may have to be done three times, in the x,y,z directions.

For example in the classic scene:

Select the Plane.006 object and look the object properties



So you would replace the Transform line with this: 
Tanslate 0.459 -0.01 0.6
Rotate 253.4 0 1 0



Place this into a file such as luxsceneClassic.lxs

Then inside the FreeCAD build folder navigate to data/Mod/Raytracing/Templates





Create a folder in Templates/Lux to hold your template such as Templates/Lux/Classic. Then copy the file luxSceneClassic.lxs you previously created inside here.

Within the same folder create an xml file and copy into this file the following excerpt:

<?xml version="1.0" encoding="iso-8859-1" ?>
<!--
 FreeCAD Scene Template for LUX Render, see http://free-cad.sourceforge.net for more information...
-->
<Document SchemaVersion="1">
  <Templates render="lux">
    <Template id="lux_classic" source="external">
      <label>Lux Classic Scene</label>
      <description> Classical Elegance</description>
      <provides>classic</provides>
      <filename>luxSceneClassic.lxs</filename>
    </Template>
  </Templates>
</Document>

For reference you only have to change the following:
  • id="lux_classic" : this attribute must be a unique identifier for the template
  • <label> Label for the scene template </label> : a graphical name for the scene
  • <description>Description for the scene template</description> : a descriptive identifier
  • <filename>luxSceneClassic.lxs</filename> the file name that contains the scene information
You should have a file structure like this:


I am not sure when you compile and build FreeCAD each time if this template folder will be deleted. Most likely not. Later, I will make a preference option so you can use your own folder. 

Using the Template:

Launch FreeCAD and switch to the Raytracing Workbench:

Create a new Render Feature.


A task view will appear. FreeCAD will automatically find your template. You can now select the template that is used in your scene. If nothing appears when you render, it is likely that the Lux Render Scene File Format has incorrect syntax...






Now position the camera where you want and hit Preview Window. Currently there might be times where the render is just a black screen - so to quickly solve this just play around with the camera a bit. 

Hopefully this make sense, feel free to post questions on here if you're stuck!

Thursday, 9 August 2012

Render Module Updates

I have been working the past couple of days tidying things up by implementing a new Render Feature into the document tree. This further abstracts data between Renderers, so technically you make simultaneous renders providing your machine is powerful enough, assign different materials to prototype different visualisations or have different views or possible even using different Render Backends... I'm not sure about the last one, atleast regarding material selection.

U-Tube Video:

I decided it was an appropriate time to showcase some of the work that I've been doing for the past two weeks with some notes to accompany it for those interested. It hopefully shows the current state of the Render Module development for those who haven't yet tried the rendering branch. Apologies for no audio commentary, but I don't have a microphone. 


Current State:

We now have a basic UI which gives the ability to start and stop render previews and set basic options such as the output size. This also can be done through python but adds little benefit... 

Currently per RenderFeature, only one Render Process can be used, which makes sense. Buttons are disabled accordingly. 

The annoying thing with QML is that basic components such as ComboBoxes and Number Inputs don't exits - you have to create them yourselves. It's actually not bad as it sounds and slowly I'm building up a slick interface.


The Render Output preview window now works correctly. It can be scaled using the mouse wheel button and dragged around. Sadly I couldn't figure out how to zoom to cursor.

Currently it just uses a polling mechanism, but I later plan to use QFileWatcher to more intelligently check when a new output is created so we don't get LibPNG checks.



Drag and Drop Material Goodness:


This feature I'm really happy with after wrestling with the QT event system for an afternoon, the Drag & Drop material interface now works. In the screenshot above the icons are missing. 

Currently it only intends to assign materials per feature, but later this behaviour can be changed. QML however is not playing very nicely with the current task view. So I may even have to make my own sub class just so that it's contents are scaled correctly, but it would mean slight inconsistency not having the OK | CANCEL buttons unless implemented within the QML File.

So that's it for now. Still more work to do on this!





Monday, 6 August 2012

Render Appearances

Firstly kudos to NASA for landing their 1 tonne Mars Rover last night whilst us Brits were snoozing in Bed. Despite being a year of Olympics, it's looking like 2012 will be the biggest year in science/engineering for a long time.

Appearances:

Lets get back on topic. A library of materials is defined within separate XML files which are specific to each Render Plugin. In most CAD packages there are generic realistic materials such as steel, copper or brass. In the base materials library these will be defined so that you can more easily switch render plugins. These XML files can provide 'built in' or 'external' materials. External materials are essentially templates defined in separate files.  See here for an example of this proposed XML description.



These Library Materials are used for reference: FreeCAD will create a new material referencing this RenderMaterial which includes a default set of values for each parameter. These parameters can be overriden to change material properties such as the Matte colours (Kd). These render materials are later used within the Render and their properties are used to define the material. I am hoping this structure provides a more flexible approach to managing a wide variety of materials from different render plugins.

These Material Libraries can be extended by adding more XML descriptions and perhaps late in the future, users can post their materials on-line in a repository which can be universally accessed.


Thursday, 2 August 2012

Render Module: It's Alive!


I think the above is how I felt when it was working. Thankfully the night I got it working, I was treat to some BBQ duck which went down a treat along with the excitement of this.

Generating the Scenefile format

I'd thought I'd share a bit on Lux Render Scene file format: Scene File Format 1.0 This is based on RenderMan's scene file format (from the guys who make Toy Story!) . The structure of the scene descriptions is very similar to Povray which despite its age is very easy to read, the only difficulty is getting used to the syntax having being so familiar with c++ development. For example:

"float focaldistance" [1.5]
Nevertheless with a bit of practice it soon becomes second nature. Essentially the steps I took at producing the scene file description were to look at the output produced from the povray example included in FreeCAD and with the wiki page on Lux Render. By making this converter I could build up some of the infrastructure with the RenderPlugin and RenderClass. An output created from the RenderPlugin which is a pretty simple plane and cube is on pastebin

Using luxrender GUI I could then import and quickly find problems with the syntax. Sadly nothing works perfect the first time and I was getting outputs like the following:



It took a lot of perserverence to get correct. From here it took several tweaks to get it to work but mainly the following
  1. Triangular Mesh Indices were in the incorrect order (BRep_IncrementMesh) produces them in the incorrect order.
  2. Lot of formatting problems with the output
  3. Quite surprisingly but 'LookAt' descriptor must come before the Camera descriptor which is mentioned in the documentation!

Drum Roll Please... Finaly we got some output! 



Giving the program a few more tweaks and letting the material colour inherit from the Part Appearance colour property, eventually we get some nice looking eye candy! We can make things made in FreeCAD look sexy.


Just for proof, to show that it did originate from FreeCAD 


This is just beginning there's still more work to do and more graphical goodness to share!





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!