feat: enhance material creation to ensure Principled BSDF node exists and set properties
This commit is contained in:
@@ -15,12 +15,21 @@ def create_material(name, base_color):
|
||||
mat.use_nodes = True
|
||||
nodes = mat.node_tree.nodes
|
||||
|
||||
# Get the Principled BSDF node (created by default)
|
||||
bsdf = nodes.get("Principled BSDF")
|
||||
if bsdf:
|
||||
bsdf.inputs['Base Color'].default_value = base_color
|
||||
bsdf.inputs['Roughness'].default_value = 0.5
|
||||
bsdf.inputs['Metallic'].default_value = 0.1
|
||||
# Find the Principled BSDF node (should be created by default)
|
||||
bsdf = None
|
||||
for node in nodes:
|
||||
if node.type == 'BSDF_PRINCIPLED':
|
||||
bsdf = node
|
||||
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
|
||||
|
||||
@@ -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("\n✓ All primitive models with colors exported successfully!")
|
||||
print(f" - RED Cube: {os.path.join(output_dir, 'cube.glb')}")
|
||||
print(f" - GREEN Sphere: {os.path.join(output_dir, 'sphere.glb')}")
|
||||
|
||||
Reference in New Issue
Block a user