Last active
October 26, 2021 20:59
-
-
Save tovacinni/9a2327491d0655ee78d2a8393daa8f55 to your computer and use it in GitHub Desktop.
Filter out safe-to-load watertight STLs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This simple script will filter out STLs which will not properly load | |
# with trimesh as a watertight mesh, and save them as space efficient ply files. | |
import os | |
import sys | |
import glob | |
import trimesh | |
if __name__ == '__main__': | |
path = sys.argv[1] | |
stl_paths = glob.glob(path + "/*") | |
output_path = sys.argv[2] | |
if not os.path.exists(output_path): | |
os.makedirs(output_path) | |
for stl_path in stl_paths: | |
try: | |
mesh = trimesh.load(stl_path) | |
assert(mesh.is_watertight or "Mesh not watertight!") | |
name = os.path.basename(os.path.splitext(stl_path)[0]) | |
mesh.export(os.path.join(output_path, name + ".ply"), "ply") | |
except KeyboardInterrupt: | |
sys.exit() | |
except: | |
print(f"Issues found in {stl_path}, not exporting") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment