4
$\begingroup$

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.

Thanks for your help.

$\endgroup$
6
  • $\begingroup$ Luxrender and Yafaray provide addons for blender which allow the creation of their respective materials from Blender's GUI. $\endgroup$
    – gandalf3
    Commented Feb 12, 2015 at 9:07
  • $\begingroup$ Like the "Convert to" button? Yes, unfortunately this does not work :-\ $\endgroup$
    – gilu
    Commented Feb 12, 2015 at 9:10
  • $\begingroup$ More like an interface specifically designed for creating a material for whichever render engine $\endgroup$
    – gandalf3
    Commented Feb 12, 2015 at 9:11
  • $\begingroup$ 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. $\endgroup$
    – gandalf3
    Commented Feb 12, 2015 at 9:13
  • $\begingroup$ 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? $\endgroup$
    – gilu
    Commented Feb 12, 2015 at 9:14

2 Answers 2

4
$\begingroup$

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
$\endgroup$
0
3
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Nice usage of active_material! If my answer helped and you figured it out pls mark it as correct;) $\endgroup$ Commented Feb 12, 2015 at 9:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .