[Addon/Plugin] LuxRender Material Converter

Attaching and configuring materials with LuxRender has always taken up too much of my time. When I have a perfectly good scene with working materials in Blender Internal (imported from say, OBJ), applying the materials and textures to work with LuxRender (LuxBlend) can take hours! I found the Cycles Material Converter Addon, and wanted to have that same functionality. Using that as a base, I rewrote/adapted it to work for Luxrender instead of Cycles. I am grateful for Silvio’s work on that concept and Addon, which got me motivated.

It is in it’s beginning beta stages, but works perfectly well. It automatically converts colors, image maps and bump maps. You can import a huge OBJ scene with hundreds of objects that have materials, and within seconds, have them all converted for rendering with LuxRender. This allows you to spend time enhancing the key materials you want to get just right. It will automatically convert a material with the words “flame” and “bulb” or “lightbulb” to area lights, same with metal and a few other key words (like “skin”), etc. I intend to expand that functionality as time goes on. It is currently at version 1.1 and available here.

Sounds good, could you post some images?

@matali, sure thing. As soon as I get home later, I will throw some examples up. There are some examples at the link on the original post too.

nice, it will be better to add this in official luxrender addon

I had to log out and restart thread, as I added more than 3 images and I tried to re-choose ones that made sense and wouldn’t let me. Anyway, these are more or less step-by-step from OBJ import to LuxRender render. The whole process took about 15 minutes (including the quick LuxRender). The OBJ scene has a large amount of grouped objects and over 2 million faces. Here we go:


Out-of-box Blender Internal render after OBJ import


Then in ‘Material Property’ mode pressing ‘converter button’


Out-of-box (my defaults) Bidirectional LuxRender render stopped at 9 minutes

That gives an idea how the workflow can be drastically reduced once materials are setup in Blender. I tried my converter tool with a .blend file I downloaded online for testing and it failed. Why? The .blend file was referencing image maps that were not included. So that would be a key factor in getting the tool to work, having referenced files exist locally. However, I will update code to trap mis-referenced maps, so it doesn’t choke and leave the scene half-baked.

Thanks. That was my original plan. I had just added some images, but it timed out and I had to log in again. I will wait to see if they went on to moderator preview before I re-post. Next time, text will be created in Notepad first!

Tex Type: IMAGE
FEEDBACK: Found IMAGE shader node Texture.006
Traceback (most recent call last):
File “E:\greensoft\3d\blender\Blender 2.76 (With V-Ray Additions)\2.76\scripts
\addons\materials_lux_converter.py”, line 781, in execute
AutoNode(False)
File “E:\greensoft\3d\blender\Blender 2.76 (With V-Ray Additions)\2.76\scripts
\addons\materials_lux_converter.py”, line 204, in AutoNode
teximgpath = tex.texture.image.filepath
AttributeError: ‘NoneType’ object has no attribute ‘filepath’

@Oyster, that message shouldn’t be choking if the texture_slot has an image file associated with it. The system console lines above that error message will say what the object and material is just before error. While in ‘Blender Render’, if you go into Texture Properties and select ‘Texture.006’, does it show the filepath and file name in the Image Datablock window below? The tool also prints out a log file in the render output folder, which may also shed light on what may be happening. Are there 6 image textures associated with that material, or is that just how it is named?

I have updated the Addon to enhance the metal material conversion. Now it not only will convert based on material name with metal, but also if the material has the word ‘silver’, ‘gold’, or ‘copper’ it will use the LuxRender version of that metal. I also added a toggle to disable image mapping to glass. In some cases, you may want the image mapping - like stained glass windows, or unusual circumstances. The author of the model may have thought it was necessary to map an image to glass. I left toggle to respect original intent, if needed.


I also added more log reporting which is saved to your render output folder. Here is a quick 30 minute render showing results without any material tweaking from an OBJ scene. Here (below) you can see the armillary had the word ‘gold’ in the material and was converted. Candle holder must have had ‘gold’ in it too. Also, the bottles previously were image mapped, and with that option toggled to ‘disable’, they render as glass with whatever coloring went into transmission channel.


Gold objects converted due to material names.

Version 1.2 can be downloaded here: Luxrender Converter 1.2

thanks for updating. I think I found what’s wrong with my blender file: for the texture, I have not selected a diskfile for it. Blender internal render can render this object without taking texture into account. But as for your converter, it hangs. So could you add something like this?


if no image is found:
     texture=None
else:
     texture=image

btw, where can we find “Cycles Material Converter Addon”?

Thanks

bug.zip (79.6 KB)

No problem. Actually I did just that further on down in code where it tries to associate an image. Thanks for pointing out that it needs to happen earlier when iterating texture slots. That .blend file to test is a great idea. I will correct and make available. I will be adding features as time goes on, as well. I am actually working on a Cycles converter that has more in common with my code than the original. It will also automatically convert objects to their materials (like metal and glass, etc.) based on the material name as well as whatever can be gleaned from the Blender Internal material. As far as the original Cycles Converter script, you can find it here under ‘materials’. Thanks for testing!

My last post hasn’t shown here yet, but I have already updated the tool to skip over texture slots that do not have images or image paths. This is version 1.3 (found here) and I updated some bits for streamlining and better rendering. For instance, if a material had word ‘mirror’ in it and also had the word ‘wood’, it would do some other checks to distinguish mirror from wood and would not also turn wood part into mirror. My next big update will be procedural textures, but haven’t started that. I did take a stab at applying same coding to a Cycles Converter. It hardly resembles the original version found in Blender Addons catalog. When I get that one a little more bullet-proof (Cycles has way more parameters then Lux), I will post a new thread accordingly. In the meantime, this is a comparison of both tools on exact same scene, with no adjustments, except for Cycles needs a new sun compared to Blender Internal, so I added that and made appropriate strength. Sun at same angle on both. Interesting how aspect ratio is different, but Lux adds its own camera parameters, and I left at my default (whatever that was). Cycles definitely faster to get a viewable image - I stopped the Lux version at 10 minutes, while Cycles with 85 samples stopped at about 6.


LuxRender version


Cycles version

Hi MarsThunder,

The link is broken please? :slight_smile:

So sorry, The link is this: converter. My bad, I changed the name from v1.1…

When active Addon this error occurs.


You have to install LuxRender addon first. That is what it is looking for. You can download from here. After opening Blender with ‘Message Console’ on, you should see this for successful LuxRender install:

[Lux 2015-Dec-15 12:56:11] Attempting to import pylux module from “C:\Users\mars
h\AppData\Roaming\Blender Foundation\Blender\2.76\scripts\addons\luxrender”
[Lux 2015-Dec-15 12:56:11] Pylux module imported successfully

Then when you load a blend file and press ‘convert button’, your message console should start like this:

read blend: C:\Users\marsh\Documents\3D\Blender\contest_swars.blend
WM_OT_context_toggle
WM_OT_context_toggle_enum
WM_OT_context_cycle_int
WM_OT_context_cycle_enum
WM_OT_context_cycle_array
WM_OT_context_menu_enum
WM_OT_context_toggle
WM_OT_context_toggle_enum
WM_OT_context_cycle_int
WM_OT_context_cycle_enum
WM_OT_context_cycle_array
WM_OT_context_menu_enum
This is the Lux Material Converter
Starting convert here…
** Image Map on Glass Enabled
Iterating Objects - Now on Camera
Iterating Objects - Now on Plane
Object Loop -----------------------------------------------
Object Loop Technical Active Object: <bpy_struct, Object(“SketchUp.000”)>
Object Loop Current Object: Plane

Hope that helps!

Thks “Maestro”! it’s ok.

>>>I had found that tool as well - not well known
You are absolutly right! First time I find it!!! Thks @Oyster!

Hi, it is me again.I am sorry to say I find another bug
what you only to replay it is simple: import the obj file from http://colacola.se/expo_tac2.htm, then switch to luxrender and then apply your script. Then I get

Traceback (most recent call last):
File “E:\greensoft\3d\blender\Blender 2.76 (With V-Ray Additions)\2.76\scripts\addons\materials_lux_converter.py”, line 839, in execute
File “E:\greensoft\3d\blender\Blender 2.76 (With V-Ray Additions)\2.76\scripts\addons\materials_lux_converter.py”, line 670, in AutoNode
color_image.outputs.new(‘NodeSocketColor’, ‘Color’)
TypeError: bpy_struct: item.attr = val: enum “” not found in (‘nk’, ‘amorphous carbon’, ‘copper’, ‘gold’, ‘silver’, ‘aluminium’)

Hi again,

Hey that is a good OBJ to test. My super-complicated tests coming from DAZ3D scenes do great, yet this one missed a couple of materials. Didn’t blow up, but didn’t get some colors I think. I will check the logs, update code and then upload new version. Thank you for your input!

This is what I got after the convert:


I have tweaked the plugin even more. It now responds to ‘metal2’ materials with textures. That was problem with that joystick object. I have also updated the bump scale so it is dependent on the object X-direction size (may need enhancing later due to strange long skinny objects). The new version 1.5 is here. The difference from last version convert seen here:


Also, the logo on the non-metal base is truly just a bump map, so it is showing truly as a relief and not a colored sticker or decal. Perhaps there was one originally, but did not appear in the downloaded files I got.