diff --git a/render-worker/scripts/export_gltf.py b/render-worker/scripts/export_gltf.py index ec6d055..4a0195e 100644 --- a/render-worker/scripts/export_gltf.py +++ b/render-worker/scripts/export_gltf.py @@ -48,12 +48,19 @@ def mark_sharp_edges_by_proximity(midpoints_mm: list, threshold_mm: float = 1.0) return import bpy # type: ignore[import] + import math for obj in bpy.data.objects: if obj.type != "MESH": continue mesh = obj.data - mesh.use_auto_smooth = True + # Blender 4.1+ removed use_auto_smooth — use shade_smooth_by_angle instead + bpy.context.view_layer.objects.active = obj + obj.select_set(True) + try: + bpy.ops.object.shade_smooth_by_angle(angle=math.radians(30)) + except Exception: + pass # fallback: stay flat-shaded mw = obj.matrix_world for edge in mesh.edges: v1 = mw @ mesh.vertices[edge.vertices[0]].co @@ -81,8 +88,8 @@ def main() -> None: # Clean scene bpy.ops.wm.read_factory_settings(use_empty=True) - # Import STL - bpy.ops.import_mesh.stl(filepath=args.stl_path) + # Import STL (bpy.ops.wm.stl_import is the Blender 4.0+ API) + bpy.ops.wm.stl_import(filepath=args.stl_path) # Scale mm → m for obj in bpy.context.selected_objects: @@ -90,6 +97,17 @@ def main() -> None: bpy.context.view_layer.objects.active = obj bpy.ops.object.transform_apply(scale=True) + # Apply smooth shading with 30° angle threshold (Blender 4.1+ API) + import math as _math + for obj in bpy.data.objects: + if obj.type == "MESH": + bpy.context.view_layer.objects.active = obj + obj.select_set(True) + try: + bpy.ops.object.shade_smooth_by_angle(angle=_math.radians(30)) + except Exception: + pass + # Mark sharp edges for better UV seams if sharp_edge_midpoints: mark_sharp_edges_by_proximity(sharp_edge_midpoints)