import trimesh import numpy as np try: # 1. STL 파일 로드 mesh = trimesh.load_mesh('Bulb.STL') # 2. 메시를 연결된 컴포넌트들로 분리 # STL 파일에서 전구의 유리 부분과 필라멘트는 보통 분리된 덩어리입니다. components = mesh.split(only_watertight=False) print(f"총 {len(components)}개의 컴포넌트를 찾았습니다.") if len(components) > 1: # 3. 각 컴포넌트의 부피를 계산하여 가장 큰 것을 찾습니다. # 일반적으로 가장 큰 컴포넌트가 바깥의 유리 쉘(shell)입니다. volumes = [comp.volume for comp in components] largest_component_index = np.argmax(volumes) print("컴포넌트별 부피:") for i, vol in enumerate(volumes): print(f" - 컴포넌트 {i}: {vol:.4f}") # 가장 큰 컴포넌트(전구 유리)만 선택합니다. bulb_shell = components[largest_component_index] # 4. 필라멘트가 제거된 메시를 새로운 STL 파일로 저장합니다. bulb_shell.export('Bulb_no_filament.stl') print("\n필라멘트가 제거되었습니다. 'Bulb_no_filament.stl' 파일로 저장했습니다.") else: print("단일 컴포넌트로 이루어져 있어, 필라멘트가 유리 쉘에 붙어있는 것 같습니다.") print("이 경우, 코드만으로는 자동 분리가 어렵습니다.") print("Blender와 같은 3D 모델링 툴을 사용한 수동 편집이 필요합니다.") except Exception as e: print(f"오류가 발생했습니다: {e}")