Skip to content

Commit

Permalink
Remove number suffixes from material names (causing issues with mat4cad)
Browse files Browse the repository at this point in the history
  • Loading branch information
30350n committed Dec 7, 2024
1 parent 88461b3 commit 39de3fa
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pcb2blender_importer/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def merge_materials(meshes):
merged_materials = {}
for mesh in meshes:
for i, material in enumerate(mesh.materials):
name = material.name.rsplit(".", 1)[0]
name = remove_blender_name_suffix(material.name)
color = rgb2hex(material.diffuse_color)
if merged_material := merged_materials.get((name, color)):
mesh.materials[i] = merged_material
Expand All @@ -55,9 +55,10 @@ def enhance_materials(materials):
continue
node_tree = material.node_tree

if mat4cad_mat := Material.from_name(material.name):
material_name = remove_blender_name_suffix(material.name)
if mat4cad_mat := Material.from_name(material_name):
pass
elif mat4cad_mat := Material.from_name(KICAD_2_MAT4CAD.get(material.name, "")):
elif mat4cad_mat := Material.from_name(KICAD_2_MAT4CAD.get(material_name, "")):
pass
else:
shader_nodes = (node for node in node_tree.nodes if node.type == "BSDF_PRINCIPLED")
Expand All @@ -73,6 +74,16 @@ def enhance_materials(materials):

mat4cad_mat.setup_node_tree(node_tree)

def remove_blender_name_suffix(name: str):
if name[-4] != ".":
return name

prefix, suffix = name.rsplit(".", 1)
if not suffix.isnumeric():
return name

return prefix

def setup_pcb_material(node_tree: NodeTree, images: dict[str, bpy.types.Image], stackup):
node_tree.nodes.clear()

Expand Down

0 comments on commit 39de3fa

Please sign in to comment.