-
-
Save wakarase/720a8543f83058068dc4d3c404b0fa00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Makes all objects' material metallic.""" | |
import bpy | |
USE_TRANSMISSION = False | |
def remove(): | |
"""Removes previously created materials.""" | |
for material in bpy.data.materials: | |
if material.name == 'MyMaterial': | |
bpy.data.materials.remove(material) | |
def create_material(): | |
"""Creates a metallic material and returns it.""" | |
material = bpy.data.materials.new('MyMaterial') | |
material.use_nodes = True | |
node_tree = material.node_tree | |
assert isinstance(node_tree, bpy.types.ShaderNodeTree) | |
principled_bsdf = node_tree.nodes['Principled BSDF'] | |
assert isinstance(principled_bsdf, bpy.types.ShaderNodeBsdfPrincipled) | |
if USE_TRANSMISSION: | |
principled_bsdf.inputs['Base Color' ].default_value = (1, 1, 1, 1) | |
principled_bsdf.inputs['Metallic' ].default_value = 0.0 | |
principled_bsdf.inputs['Roughness' ].default_value = 0.0 | |
principled_bsdf.inputs['IOR' ].default_value = 1.33 | |
principled_bsdf.inputs['Transmission'].default_value = 1.0 | |
else: | |
principled_bsdf.inputs['Metallic' ].default_value = 1.0 | |
principled_bsdf.inputs['Roughness'].default_value = 0.0 | |
return material | |
def set_material(object, material): | |
"""Sets the material to all slots in the object.""" | |
for slot in object.material_slots: | |
slot.material = material | |
def set_materials(): | |
"""Makes all objects' material metallic.""" | |
material = create_material() | |
for object in bpy.data.objects: | |
set_material(object, material) | |
remove() | |
set_materials() | |
print('Done.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment