fix(gltf): append materials (link=False) for proper PBR export to GLB
Linked materials are external references — Blender's GLTF exporter cannot traverse their node trees to extract Principled BSDF PBR values (metallic, roughness, base color, normal maps). Appended materials are local copies that the exporter can fully traverse. Changes: - asset_library.py: add link=True parameter (default unchanged for renders) - export_gltf.py: call apply_asset_library_materials with link=False - export_gltf.py: add export_materials='EXPORT' + export_image_format='AUTO' to embed textures and ensure full PBR data in the GLB Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -113,20 +113,26 @@ def main() -> None:
|
||||
mark_sharp_edges_by_proximity(sharp_edge_midpoints)
|
||||
print(f"Marked sharp edges from {len(sharp_edge_midpoints)} hint points")
|
||||
|
||||
# Apply asset library materials if provided
|
||||
# Apply asset library materials if provided.
|
||||
# link=False (append) is required for GLB export: the GLTF exporter can only
|
||||
# traverse local (appended) Principled BSDF node trees to extract PBR values.
|
||||
# Linked materials are external references whose node data is not accessible.
|
||||
if args.asset_library_blend and material_map:
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
from asset_library import apply_asset_library_materials
|
||||
apply_asset_library_materials(args.asset_library_blend, material_map)
|
||||
apply_asset_library_materials(args.asset_library_blend, material_map, link=False)
|
||||
|
||||
# Export GLB
|
||||
# Export GLB with full PBR material data
|
||||
try:
|
||||
bpy.ops.export_scene.gltf(
|
||||
filepath=args.output_path,
|
||||
export_format="GLB",
|
||||
export_apply=True,
|
||||
use_selection=False,
|
||||
export_materials="EXPORT", # export all materials (Principled BSDF → glTF PBR)
|
||||
export_image_format="AUTO", # embed textures (base color, normal, roughness maps)
|
||||
export_colors=False, # skip vertex colors (we use library materials)
|
||||
)
|
||||
except Exception as exc:
|
||||
print(f"GLB export failed: {exc}", file=sys.stderr)
|
||||
|
||||
Reference in New Issue
Block a user