diff --git a/.gitignore b/.gitignore index b1cc6f0..37d24cb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build .idea dist venv -*.spec \ No newline at end of file +*.spec +*.egg-info \ No newline at end of file diff --git a/README.md b/README.md index f28f2aa..39d1d23 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,13 @@ STL Compressor is a tool designed to compress STL files efficiently. Users can c ## Usage -* Windows users can download [here](https://github.com/fan-ziqi/stl_compresser/releases) +* Windows users can download [here](https://github.com/fan-ziqi/stl_compressor/releases) * Python ```bash - git clone https://github.com/fan-ziqi/stl_compresser.git - cd stl_compresser - pip install -r requirements.txt - python stl_compresser_ui.py + pip install --upgrade stl_compressor -i https://www.pypi.org/simple/ + stl_compressor ``` ## Packaging @@ -20,5 +18,13 @@ STL Compressor is a tool designed to compress STL files efficiently. Users can c To package the application as a standalone executable, use PyInstaller: ```bash -pyinstaller --onefile --windowed stl_compresser_ui.py -``` \ No newline at end of file +pyinstaller --onefile --windowed stl_compressor/stl_compressor_ui.py +``` + +## Upload to Pypi + +```bash +python setup.py check +python setup.py sdist bdist_wheel +twine upload dist/* +``` diff --git a/output/3DBenchy.stl b/output/3DBenchy.stl deleted file mode 100644 index 322eb3a..0000000 Binary files a/output/3DBenchy.stl and /dev/null differ diff --git a/requirements.txt b/requirements.txt index 30c1128..c6d4458 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ trimesh -open3d \ No newline at end of file +open3d +fast_simplification \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..1f75f94 --- /dev/null +++ b/setup.py @@ -0,0 +1,25 @@ +from distutils.core import setup +from setuptools import find_packages + +with open("README.md", "r") as f: + long_description = f.read() + +setup( + name="stl_compressor", + version="2.2", + description="STL Compressor", + long_description=long_description, + long_description_content_type="text/markdown", + author="Ziqi Fan", + author_email="fanziqi614@gmail.com", + url="https://github.com/fan-ziqi/stl_compressor", + install_requires=[], + license="Apache License 2.0", + packages=find_packages(), + entry_points={"console_scripts": ["stl_compressor = stl_compressor.stl_compressor_ui:main"]}, + platforms=["all"], + classifiers=[ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + ], +) diff --git a/stl_compresser.py b/stl_compresser.py deleted file mode 100644 index fe09273..0000000 --- a/stl_compresser.py +++ /dev/null @@ -1,19 +0,0 @@ -import os -import trimesh - -target_number_of_triangles = 1000 - -current_directory = os.getcwd() - -input_directory = os.path.join(current_directory, 'input') -output_directory = os.path.join(current_directory, 'output') - -if not os.path.exists(output_directory): - os.makedirs(output_directory) - -for stl_file in os.listdir(input_directory): - if stl_file.lower().endswith(".stl"): - mesh = trimesh.load_mesh(os.path.join(input_directory, stl_file)) - simplified_mesh = mesh.simplify_quadric_decimation(target_number_of_triangles) - output_file_path = os.path.join(output_directory, stl_file) - simplified_mesh.export(output_file_path) diff --git a/stl_compressor/__init__.py b/stl_compressor/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/stl_compressor/stl_compressor_test.py b/stl_compressor/stl_compressor_test.py new file mode 100644 index 0000000..d87935b --- /dev/null +++ b/stl_compressor/stl_compressor_test.py @@ -0,0 +1,21 @@ +import os +import open3d as o3d + +target_number_of_triangles = 1000 + +current_directory = os.getcwd() + +input_directory = os.path.join(current_directory, 'test/input') +output_directory = os.path.join(current_directory, 'test/output') + +if not os.path.exists(output_directory): + os.makedirs(output_directory) + +for stl_file in os.listdir(input_directory): + if stl_file.lower().endswith(".stl"): + mesh = o3d.io.read_triangle_mesh(os.path.join(input_directory, stl_file)) + simplified_mesh = mesh.simplify_quadric_decimation(target_number_of_triangles) + simplified_mesh.compute_triangle_normals() + simplified_mesh.compute_vertex_normals() + output_file_path = os.path.join(output_directory, stl_file) + o3d.io.write_triangle_mesh(output_file_path, simplified_mesh) diff --git a/stl_compresser_ui.py b/stl_compressor/stl_compressor_ui.py similarity index 85% rename from stl_compresser_ui.py rename to stl_compressor/stl_compressor_ui.py index 9fcb8bf..588c840 100644 --- a/stl_compresser_ui.py +++ b/stl_compressor/stl_compressor_ui.py @@ -2,12 +2,13 @@ import tkinter as tk from tkinter import filedialog from tkinter import ttk -import trimesh +# import trimesh +import open3d as o3d import threading def choose_files(entry_widget): # Function to choose input files - paths = filedialog.askopenfilenames(filetypes=[("STL files", "*.stl")]) + paths = filedialog.askopenfilenames(filetypes=[("STL files", "*.stl"), ("STL files", "*.STL")]) if paths: entry_widget.delete(0, tk.END) entry_widget.insert(0, ";".join(paths)) @@ -27,10 +28,17 @@ def compress_stl(input_paths, output_path, target_triangles, progress_bar, progr progress_per_file = 100 / total_files for i, file_path in enumerate(files): - mesh = trimesh.load_mesh(file_path) + # mesh = trimesh.load_mesh(file_path) + # simplified_mesh = mesh.simplify_quadric_decimation(target_triangles) + # output_file_path = os.path.join(output_path, os.path.basename(file_path)) + # simplified_mesh.export(output_file_path) + + mesh = o3d.io.read_triangle_mesh(file_path) simplified_mesh = mesh.simplify_quadric_decimation(target_triangles) + simplified_mesh.compute_triangle_normals() + simplified_mesh.compute_vertex_normals() output_file_path = os.path.join(output_path, os.path.basename(file_path)) - simplified_mesh.export(output_file_path) + o3d.io.write_triangle_mesh(output_file_path, simplified_mesh) # Update progress bar progress = int((i + 1) * progress_per_file) @@ -84,6 +92,7 @@ def on_compress_finished(): # Start the thread compress_thread.start() + root = tk.Tk() root.title("STL Compressor") root.resizable(False, False) # Disable resizing @@ -142,12 +151,16 @@ def on_compress_finished(): bottom_frame = tk.Frame(window) bottom_frame.pack(side=tk.BOTTOM, fill=tk.X) -version_label = tk.Label(bottom_frame, text="STL Compressor v1.2") +version_label = tk.Label(bottom_frame, text="STL Compressor v2.2") version_label.pack(side=tk.LEFT) -licence_label = tk.Label(bottom_frame, text="Made by github@fan-ziqi") +licence_label = tk.Label(bottom_frame, text="Developed by github@fan-ziqi") licence_label.pack(side=tk.RIGHT) window.grid(row=0, column=0) -window.mainloop() +def main(): + window.mainloop() + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/input/3DBenchy.stl b/test/input/3DBenchy.stl similarity index 100% rename from input/3DBenchy.stl rename to test/input/3DBenchy.stl diff --git a/test/output/3DBenchy.stl b/test/output/3DBenchy.stl new file mode 100644 index 0000000..991d64a Binary files /dev/null and b/test/output/3DBenchy.stl differ