I cobbled together a quick script to quickly swap all the materials on selected objects.
If a material is named GLSL.whatever, or Cycles.whatever, it'll switch it to whatever is appropriate for your currently selected render engine.
Note, this doesn't make the materials for you, just goes through the list and swaps materials named GLSL.materialName for Cycles.materialName or vice versa.
It's useful if you want to use GLSL (Blender Internal) for modeling, then switch to Cycles for major renders. It takes more time up front to make two materials instead of one, but it saves a ton of time during the project because you can preview your work in the realtime GLSL rendering engine.
(To use it, put it in a text window and hit alt-p to run the script, or just select run script from the text menu.)
(Disclaimer: I wrote it quickly and haven't thoroughly error checked it, so no guarantees. Try it on a test scene first. It works for me though.)
# This script should go through all the materials in the SELECTED objects and replace them with another material (that you made) who's name is prefixed with Cycles or GLSL accordingly
# Switch the renderer, select some objects, then run this script.
# You'll need two copies of every material, one for cycles and one for GLSL.
# Just name the materials CYCLES.whatever and GLSL.whatever
# eg: Cycles.black.glossy <-> GLSL.black.glossy
import bpy
context = bpy.context # only selected items
print(bpy.data.scenes["Scene"].render.engine)
RenderEngine = bpy.data.scenes["Scene"].render.engine
if RenderEngine == "BLENDER_GAME" or RenderEngine == "BLENDER_RENDER":
DesiredMaterialNamePrefix = "GLSL"
UndesiredMaterialNamePrefix = "Cycles"
elif RenderEngine == "CYCLES":
DesiredMaterialNamePrefix = "Cycles"
UndesiredMaterialNamePrefix = "GLSL"
print("---------------------------------------")
mesh_objs = [ob for ob in context.selected_objects if ob.type == 'MESH']
print("Materials in scene")
print(dir(bpy.data.materials))
for mesh in mesh_objs:
print(repr(mesh))
print("active_slot:", mesh.active_material_index)
if mesh.active_material is not None:
#print("active_material:", repr(mesh.active_material) )
print("active_material:", mesh.active_material.name)
for materialSlot, mat in enumerate(mesh.material_slots):
if not materialSlot:
print("material_slots")
if mat is not None:
print("\t[%d] = %s" % (materialSlot, mat.name))
# figure out if the undesired renderer is in the material name
# if so, change the material to match the desired renderer
# (but verify that the material actually exists before you try to make the swap)
if (mat.name.find(UndesiredMaterialNamePrefix) != -1):
print("Found material: ", mat.name)
desiredMaterialName = mat.name.replace(UndesiredMaterialNamePrefix, DesiredMaterialNamePrefix)
print("Change to: ", desiredMaterialName)
print("finding material")
newMaterial = bpy.data.materials.get(desiredMaterialName)
if newMaterial is not None:
print(repr(newMaterial))
mesh.material_slots[materialSlot].material = newMaterial
#print(newMaterial.name)
else:
print("No equivalent Material found for ", desiredMaterialName)
elif (mat.name.find(DesiredMaterialNamePrefix) != -1):
print("Found Desired Renderer: ", DesiredMaterialNamePrefix)
print(repr(mat))
print("No change necessary")
else:
print("\t[%d] is None" % materialSlot)
print()