GithubHelp home page GithubHelp logo

christophschranz / tweaker-3 Goto Github PK

View Code? Open in Web Editor NEW
91.0 11.0 25.0 5.01 MB

A performant auto-rotate software for objects in 3D Printing, whose parameter are trained by an evolutionary algorithm.

License: GNU General Public License v3.0

Python 100.00%

tweaker-3's Introduction

Tweaker-3

The Tweaker is an auto-rotate module which finds the STL or 3MF object's optimal orientation on the printing platform to improve the efficiency of 3D printing.

Auto-rotation of a model
Author: Christoph Schranz, 12.01.2016.
Salzburg Research

Quickstart:

Make sure the required packages are installed using pip install -r requirements.txt.

python Tweaker.py -i demo_object.stl -vb

If you want to install this module as a CLI package install it via pip:

pip install git+https://github.com/ChristophSchranz/Tweaker-3.git
tweaker3 -i demo_object.stl 

Extended mode:

This mode yields the most reliable results, but needs slightly more computation time. This is the suggested mode.

python Tweaker.py -i death_star.stl -vb -x

Minimise the necessary support material:

If you want to optimise the print in terms of minimal support surfaces instead of the default volume, add the parameter -min sur or --minimize surfaces

python Tweaker.py -i demo_object.stl -min sur -x

Convert a 3mf object to stl without tweaking:

python Tweaker.py -i pyramid.3mf -c -o pyramid.stl

Choose the output type of the STL format:

python Tweaker.py -i pyramid.3mf -t asciistl

You can choose the output types "asciistl" and "binarystl" (default). "3mf" is not supported yet.

Just see the results:

python Tweaker.py -i demo_object.stl -r

Show the progress of tweaking:

python Tweaker.py -i demo_object.stl -x -p

Favour Side:

In some cases the surface of one side of an object
may be more important than those of the others. Therefore, a selected orientation (and all close ones in terms of a small scalar product) can be weighted by using the flag --favside (fs) Here is an example of how to favour facets in the direction x=1, y=-1.0, z=2.5 with a weighting factor of 3.0:

python Tweaker.py -i demo_object.stl -vb -x -fs "[[0,-1,2.5],3.0]"

Find Help:

python Tweaker.py -h

Version:

python Tweaker.py -v

Further Repos:

Previous Version

The Tweaker's initial repository is here:

Plugin for Ultimaker Cura

The Tweaker-3 is available in Cura as Auto-Orientation in the Marketplace (Cura >= 4) respectively the plugin manager.

Plugin for OctoPrint - PrePrintService

The Tweaker-3 is available as PrePrint-Service-Plugin for OctoPrint and can be installed as described in this instruction. Note that this module combines the auto-rotation functionality with slicing via Slic3r.

Interested in how the algorithm works?

This Whitepaper declares this program. Additionally, background infos and benchmarks are provided.

Support this Project

This project is maintained and continuously improved since 2017 in my spare time to provide an effective auto-rotation module for you and the open-source 3D printing community. If this software helps you, please support this project now!

Be my GitHub-Sponsor or my Patreon or donate a cup of coffee anonymously: 🐣
via Paypal

Thank you for supporting this project! ☺️

tweaker-3's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tweaker-3's Issues

Query Not an Issue

I am using this plugin in one of my project. Thanks for a good plugin. I am trying to understand for example if the model has been optimized already in terms minimum support material necessary using Cura or any other software, then how do I find out whether it still needs improvement of it is already been optimized (or rortated)? Because this tool simply rotates what ever model I use. It will be useful to know this information. So I don't need to apply the plugin unnecessarily.

Please let me know or please point me to the right direction where I can find this information? I can't see this in the wiki

Thank You
Shan

Favorite side function documentation

When it comes to 3D printing object for production the strength of the object in a given orientation is important. I have been trying to generate two objects with Tweaker-3, one upstanding and one laying on one of the side. The documentation on the -fs function is a little bit vague. Thus, I can seem to figure out if there is a way using the favorite side function in order to achieve restrictions on certain axis rotations?

Cura Plugin

I was looking for the "Auto Orientation" plugin in Cura's Plugin Marketplace but I don't see it anywhere.

I realize it says it's in the Cura Marketplace for Cura versions >=4 in the README.md, but that file was last modified before Cura 5 came out. Does it perhaps not support Cura 5?

NOT AN ISSUE: Suggestion

I developed small dos scripts to allow right-clicking a STL file and do things.
image

I prefer to not PR that because I don't know if the REG file (to add right-click menu) will work on other computer (I can't try).
Also, the user has to install your software in C:\stlTweaker and put the content of my zip into your installation folder.

So, take it as a small feature to improve or as a suggestion in your README.md

File on Mega.nz

Chokes on binary STL

I tried running python Tweaker.py -i gauntlet.stl -x -p -r with this file and I got this error:

Traceback (most recent call last):
  File "/home/stuart/Downloads/Tweaker-3/FileHandler.py", line 26, in load_mesh
    objs = self.load_ascii_stl(f)
  File "/home/stuart/Downloads/Tweaker-3/FileHandler.py", line 72, in load_ascii_stl
    for line in f:
  File "/usr/lib/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9e in position 81: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "Tweaker.py", line 120, in <module>
    objs = FileHandler.load_mesh(args.inputfile)
  File "/home/stuart/Downloads/Tweaker-3/FileHandler.py", line 30, in load_mesh
    objs = self.load_binary_stl(f)
  File "/home/stuart/Downloads/Tweaker-3/FileHandler.py", line 91, in load_binary_stl
    f.read(80-5)
  File "/usr/lib/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9e in position 76: invalid start byte

3mf with multiple objects

Hey there - first of all, thanks so much for this awesome project @ChristophSchranz!

I've noticed that Tweaker accepts 3mf files, but that it doesn't quite know how to handle multiple objects within one 3mf file, so it just selects one and smart-rotates that one.

Would it be possible for it to rotate and return multiple objects?

Here's an example file;
Multi-instance-control-box.zip

Kind of wrong placement

Hi there,
I am using tweaker for a custom slicer and in most cases tweaker works great and orientates the models perfectly. This model is consistently placed on the end even though it makes for a lot more overhanging parts.

image
image

The rounded corners might be the reason why it chooses to place it like this, but it would be pretty bad to print the part like this.
Otherwise love the feature, it makes it awesome to work with downloaded STL files.

Still in development?

Hello,

Is this project still in development?
Is it still useful to use this software? I wanted to try it but I got error when trying to use minimal support (cmd not recognized).
I also tried -vol that returns errors.

High Memory Usage

Giving tweaker a larger stl (180mb) tweaker seems to use a little over 2GB of memory to orient this file. Is there anything that can be done to minimize memory usage?

Questions about porting Tweaker-3; question about death star algorithm

Hi,

I am the developer of a web-based slicing program called Symple Slicer:

https://github.com/SynDaverCO/symple-slicer

I think the auto-rotation feature would be very handy for our slicer. I have quite a bit of experience porting Python code to JavaScript, but before I launch into that, I was wondering if you were aware of anyone who may have already ported Tweaker-3 to JavaScript?

Secondly, I looked though your whitepaper and while most of it was beyond my understanding, I am curious about the death star algorithm. You say in your paper that "since the bottom area would be a circle without any
resulting area, the area cumulation algorithm fails." In Symple Slicer, I needed to have an option for the user to lay a print flat on the print bed and complex shapes presented a challenge. I solved my problem by using an off-the-shelf algorithm to compute the convex hull of the STL file, as the convex hull provides a convenient representation of all faces that can sit against the bed.

Since the convex hull of the death star is precisely a sphere with a large flat circular face, I wonder if that could be used in Tweaker-3 to simplify the death star problem and maybe give you solution that is more deterministic. Computing the convex hull of geometry is not trivial, but there are well developed algorithms out there for doing it.

SyntaxError: invalid syntax w/ demo.stl

I cloned the repo and ran the first command in the readme and get the below syntax error. Am I possibly missing some dependancy?

a483e711095a:Tweaker-3 speredni$ python Tweaker.py -i demo_object.stl -vb
Traceback (most recent call last):
  File "Tweaker.py", line 8, in <module>
    from MeshTweaker import Tweak
  File "/Users/speredni/Documents/Tweaker-3/MeshTweaker.py", line 451
    print("\nProgress is: {}".format(progress), end="")
                                                   ^
SyntaxError: invalid syntax

Python version info:

Python 2.7.16 (default, Dec  3 2019, 07:02:07) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin

Pip installation error.

Python 3.10.6
Pip 22.2.2

`C:\Windows\System32>pip install git+https://github.com/ChristophSchranz/Tweaker-3.git
Collecting git+https://github.com/ChristophSchranz/Tweaker-3.git
Cloning https://github.com/ChristophSchranz/Tweaker-3.git to c:\users\meyverick\appdata\local\temp\pip-req-build-v3a_o4vf
Running command git clone --filter=blob:none --quiet https://github.com/ChristophSchranz/Tweaker-3.git 'C:\Users\Meyverick\AppData\Local\Temp\pip-req-build-v3a_o4vf'
Resolved https://github.com/ChristophSchranz/Tweaker-3.git to commit f9db764
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error

Γ— Getting requirements to build wheel did not run successfully.
β”‚ exit code: 1
╰─> [59 lines of output]
running egg_info
creating tweaker3.egg-info
writing tweaker3.egg-info\PKG-INFO
writing dependency_links to tweaker3.egg-info\dependency_links.txt
writing entry points to tweaker3.egg-info\entry_points.txt
writing requirements to tweaker3.egg-info\requires.txt
writing top-level names to tweaker3.egg-info\top_level.txt
writing manifest file 'tweaker3.egg-info\SOURCES.txt'
Traceback (most recent call last):
File "C:\Users\Meyverick\AppData\Local\Programs\Python\Python310\lib\site-packages\pip_vendor\pep517\in_process_in_process.py", line 363, in
main()
File "C:\Users\Meyverick\AppData\Local\Programs\Python\Python310\lib\site-packages\pip_vendor\pep517\in_process_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "C:\Users\Meyverick\AppData\Local\Programs\Python\Python310\lib\site-packages\pip_vendor\pep517\in_process_in_process.py", line 130, in get_requires_for_build_wheel
return hook(config_settings)
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools\build_meta.py", line 320, in get_build_requires
self.run_setup()
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools\build_meta.py", line 335, in run_setup
exec(code, locals())
File "", line 1, in
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools_init
.py", line 87, in setup
return distutils.core.setup(**attrs)
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools_distutils\core.py", line 185, in setup
return run_commands(dist)
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools_distutils\core.py", line 201, in run_commands
dist.run_commands()
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools_distutils\dist.py", line 973, in run_commands
self.run_command(cmd)
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools\dist.py", line 1217, in run_command
super().run_command(command)
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools_distutils\dist.py", line 992, in run_command
cmd_obj.run()
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 308, in run
self.find_sources()
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 316, in find_sources
mm.run()
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 560, in run
self.add_defaults()
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 597, in add_defaults
sdist.add_defaults(self)
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools\command\sdist.py", line 106, in add_defaults
super().add_defaults()
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools_distutils\command\sdist.py", line 250, in add_defaults
self._add_defaults_python()
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools\command\sdist.py", line 117, in _add_defaults_python
build_py = self.get_finalized_command('build_py')
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools_distutils\cmd.py", line 306, in get_finalized_command
cmd_obj.ensure_finalized()
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools_distutils\cmd.py", line 109, in ensure_finalized
self.finalize_options()
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools\command\build_py.py", line 37, in finalize_options
orig.build_py.finalize_options(self)
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools_distutils\command\build_py.py", line 59, in finalize_options
self.package_dir[name] = convert_path(path)
File "C:\Users\Meyverick\AppData\Local\Temp\pip-build-env-rv6wsqfl\overlay\Lib\site-packages\setuptools_distutils\util.py", line 139, in convert_path
raise ValueError("path '%s' cannot end with '/'" % pathname)
ValueError: path './' cannot end with '/'
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

Γ— Getting requirements to build wheel did not run successfully.
β”‚ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.`

Model in ASCII .stl can't be tweaked, but same model in binary .stl works

Hi,

I have tweaked lots of models with your wonderful Tweaker (probably thousands at this point ;) and most of the time it works wonderfully. So thank you so much for great work!

Only recently I stumbled on one model that can't be tweaked. Error description from "your Auto-Rotate Developer" instructed me to open new issue, so here I am.

Model seems not corrupted- it works without any problems in Mac OS X Preview, Meshmixer and PrusaSlicer. Problem seems to be in ASCII formatting of .stl file, because the same model converted to binary .stl can be tweaked just fine.

Best,
Your Grateful Auto-Rotate User

Tweaker3 Models.zip

Question: Is there a way to minimize support, assuming support is only generated "from buildplate/bed"?

Hello! Thanks for the project!

There's a model (https://cdn.thingiverse.com/assets/70/96/59/c1/62/RIGHT_Q1_single_piece_SolidSlime_1.3.stl), where I ONLY want support to be generated from buildplate, otherwise support will leave some scarred interface on some surface.
But I can only make tweaker-3 (actually, the cura wrapper plugin) to orient it in a way that it can only be printed when support is generated from anywhere, otherwise some dramatic overhang will fail.

How tweaker-3 orient it (the top part has some dangerous overhang):
image

How I assume tweaker-3 should orient it:
image

So is there any way to make Tweaker-3 optimize support while assuming support is only generated from the buildplate? Thanks.

AttributeError: 'Tweak' object has no attribute 'ANGLE_SCALE'

When trying to run python Tweaker.py -i <my_obj.STL> -vb -x -fs "[[0,-1,2.5],3]"
I get this exception:

Calculating the optimal orientation:
  spool_axle.STL
You favour the side [ 0.         -0.39872611  0.91707006] with a factor of 1.0
Traceback (most recent call last):
  File "/home/gena/workspace/work/Iambol_e_grada/Tweaker-3/Tweaker.py", line 154, in <module>
    x = Tweak(mesh, args.extended_mode, args.verbose, args.show_progress, args.favside, args.volume)
  File "/home/gena/workspace/work/Iambol_e_grada/Tweaker-3/MeshTweaker.py", line 107, in __init__
    self.favour_side(favside)
  File "/home/gena/workspace/work/Iambol_e_grada/Tweaker-3/MeshTweaker.py", line 281, in favour_side
    align = np.sum(diff * diff, axis=1) < self.ANGLE_SCALE  # 0.7654, ANGLE_SCALE ist around 0.1
AttributeError: 'Tweak' object has no attribute 'ANGLE_SCALE'

Request: support for off-axis belt printers

I own a CR-30 belt printer, which has an "infinite" horizontal Z-axis and an XY axis that's rotated 45 degrees from what you'd normally expect. In this configuration, the rotation of the part around the up-axis matters. Here's an illustrated example of a side-view of the belt with an L-shaped 3d model:

PXL_20220606_133358808

The diagonal lines indicate the XY layers. In this case, the same geometry rotated 180 degrees results in the same adhesion to the bed, but creates an unprintable overhang in the example on the right.

In addition to weird overhang behavior, the leading edge at the base of the print is also important - a long leading edge causes a long initial extrusion, which tends to adhere worse than a short leading edge. This is why suggestions to improve bed adhesion mention rotating the part 45 degrees so it has a small initial area on the bed

Can I use Tweaker to account for these things? If not, what would it take to support this use case?

Also for a bit more context, I own the Continuous Print plugin for OctoPrint and am looking for integrations that would allow on-demand slicing for heterogeneous clusters of 3d printers. Right now I handle this by slicing the same STL multiple times and adding metadata around which file is valid for which printer type - example here. I'd love to integrate with Tweaker if it solved part orientation for belt printing and I'm willing to help contribute where I can!

os.system('cls') is Windows only

In update_progress() you use os.system('cls'), which is not OS Independent. On a non-Windows system you will get the following errors:
tweaker3 -i BODY_RIGHT.stl -x -p
sh: cls: command not found
Progress is: 18
sh: cls: command not found
Progress is: 54
sh: cls: command not found
Progress is: 90

I would suggest using something along the lines of os.system('cls' if os.name == 'nt' else 'clear')
Reference: https://stackoverflow.com/a/2084628/18731807

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.