# Blender Material Color in Mitsuba (or any other) Shader

I have imported a large WRL file (contains >3000 parts) with colors included (one material for each part!). In Cycles and Blender-Render, the colors are rendered just fine.

But what do I do if I want Mitsuba, Luxrender or Yafaray as renderer? Is there a way to get the Blender-material-color and put that in a 3rd-party material?

I know how to make a material with python and apply it to a mesh. But how do I get the color of the selected object's blender-material?

How to make a Mitsuba, Luxrender or Yafaray matrial is one thing I yet have to find out too.

• Luxrender and Yafaray provide addons for blender which allow the creation of their respective materials from Blender's GUI.
– gandalf3
Feb 12 '15 at 9:07
• Like the "Convert to" button? Yes, unfortunately this does not work :-\
– gilu
Feb 12 '15 at 9:10
• More like an interface specifically designed for creating a material for whichever render engine
– gandalf3
Feb 12 '15 at 9:11
• For BI you can get the diffuse color with bpy.data.materials["Material Name"].diffuse_color. Cycles is trickier due to its node-based nature.
– gandalf3
Feb 12 '15 at 9:13
• Right! But I've imported a WRL with the correct color from CAD. It creates a Blender material with the color from CAD. Now I need ot get this color with python. How can I do that?
– gilu
Feb 12 '15 at 9:14

You can read the mat color from Blender Internal material like so:

# from material
mat = bpy.data.materials['Material_Name']
color = mat.diffuse_color

# or from object
ob = bpy.context.active_object
if len(ob.data.materials):
# get 1st material slots material
mat = ob.data.materials[0]
else:
# no slots
print("No Material")
mat = None
if mat:
color = mat.diffuse_color


To change LuxRenders material diffuse color:

mat.luxrender_material.luxrender_mat_matte.Kd_color = color


Mitsuba:

mat.mitsuba_material.mitsuba_bsdf_diffuse.reflectance_color = color


In Yafaray there is no need to change anything, it will use:

mat.diffuse_color


Here we go! After a few tries it works!

import bpy

if bpy.context.selected_objects != []:
for ob in bpy.context.selected_objects:
if ob.type == 'MESH':
objcolor = ob.active_material.diffuse_color
ob.active_material.mitsuba_material.mitsuba_bsdf_diffuse.reflectance_color = objcolor
ob.active_material.luxrender_material.luxrender_mat_matte.Kd_color = objcolor


This is it! Select all objects and run this script. The diffuse color will be added to Mitsuba and Luxrenderer.

• Nice usage of active_material! If my answer helped and you figured it out pls mark it as correct;) Feb 12 '15 at 9:53