feat: enhance material creation to ensure Principled BSDF node exists and set properties

This commit is contained in:
MayaTheShy
2025-11-08 23:09:41 -05:00
parent ab56fdeb21
commit 4d63f37421

View File

@@ -15,12 +15,21 @@ def create_material(name, base_color):
mat.use_nodes = True mat.use_nodes = True
nodes = mat.node_tree.nodes nodes = mat.node_tree.nodes
# Get the Principled BSDF node (created by default) # Find the Principled BSDF node (should be created by default)
bsdf = nodes.get("Principled BSDF") bsdf = None
if bsdf: for node in nodes:
bsdf.inputs['Base Color'].default_value = base_color if node.type == 'BSDF_PRINCIPLED':
bsdf.inputs['Roughness'].default_value = 0.5 bsdf = node
bsdf.inputs['Metallic'].default_value = 0.1 break
# If not found, create it
if not bsdf:
bsdf = nodes.new(type='ShaderNodeBsdfPrincipled')
# Set material properties
bsdf.inputs['Base Color'].default_value = base_color
bsdf.inputs['Roughness'].default_value = 0.5
bsdf.inputs['Metallic'].default_value = 0.1
return mat return mat
@@ -71,8 +80,6 @@ bpy.ops.export_scene.gltf(
) )
print(f"Exported model.glb (BLUE) to {output_dir}") print(f"Exported model.glb (BLUE) to {output_dir}")
print(f"Exported model.glb (BLUE) to {output_dir}")
print("\n✓ All primitive models with colors exported successfully!") print("\n✓ All primitive models with colors exported successfully!")
print(f" - RED Cube: {os.path.join(output_dir, 'cube.glb')}") print(f" - RED Cube: {os.path.join(output_dir, 'cube.glb')}")
print(f" - GREEN Sphere: {os.path.join(output_dir, 'sphere.glb')}") print(f" - GREEN Sphere: {os.path.join(output_dir, 'sphere.glb')}")