Skip to content

Commit

Permalink
Pull all shading related material attributes from external styles #4053
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrej730 committed Dec 14, 2023
1 parent cb8462a commit 8270367
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions src/blenderbim/blenderbim/bim/module/style/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,20 +329,47 @@ def _execute(self, context):
self.report({"ERROR"}, db["msg"])
return {"CANCELLED"}

props_to_copy = [
"diffuse_color",
"metallic",
"roughness",
"specular_intensity",
"use_nodes",
]
for prop_name in props_to_copy:
setattr(material, prop_name, getattr(db["data_block"], prop_name))

self.copy_material_attributes(db["data_block"], material)
if material.use_nodes:
tool.Blender.copy_node_graph(material, db["data_block"])
bpy.data.materials.remove(db["data_block"])

def copy_material_attributes(self, source, target):
ID_properties = bpy.types.ID.bl_rna.properties
material_props = bpy.types.Material.bl_rna.properties
allowed_prop_groups = ("grease_pencil", "lineart", "cycles")

def set_prop(prop_name):
setattr(target, prop_name, getattr(source, prop_name))

def set_prop_group(prop_group):
source_prop_group = getattr(source, prop_group)
target_prop_group = getattr(target, prop_group)
if target_prop_group is None or target_prop_group is None:
return
for prop_name in source_prop_group.bl_rna.properties.keys():
prop = source_prop_group.bl_rna.properties[prop_name]
if prop.type in ("POINTER", "COLLECTION"):
continue
if prop.is_readonly:
continue
source_value = getattr(source_prop_group, prop_name)
setattr(target_prop_group, prop_name, source_value)

for prop_name in material_props.keys():
if prop_name in ID_properties:
continue
prop = material_props[prop_name]
if prop.type == "COLLECTION":
continue
if prop.type == "POINTER":
if prop_name in allowed_prop_groups:
set_prop_group(prop_name)
continue
if prop.is_readonly:
continue
set_prop(prop_name)


class DisableEditingStyles(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.disable_editing_styles"
Expand Down

0 comments on commit 8270367

Please sign in to comment.