AllwineDesigns / stl_cmd

stl_cmd - commands for binary STL file manipulation
Other
50 stars 9 forks source link

Convert all stl_cmds to accept input from stdin and output to stdout #1

Open jallwine opened 6 years ago

jallwine commented 6 years ago

This is still very rough, but the idea is to make it easier to pipe STL data around to multiple commands. Some hypothetical examples:

# create a cube with a hole in it without any temporary files
stl_cube -w 10 | stl_cylinder -r 5 -h 10 | stl_boolean -d > cube_with_hole.stl

# get the bbox of all files in a directory
stl_cat *.stl | stl_bbox

# layout multiple models created with stl_cmds in a single STL file (using stl_transform exclusively to position more than two models would be cumbersome, so might need to add some basic transforms to the stl_cmds that create primitives)
stl_cube -w 10 | stl_transform -tx 11 | stl_cylinder -r 10 -h 10 | stl_transform -tz 5 | stl_merge > print_bed.stl

# put two STL files side by side in a single STL file (some hypothetical command line arguments used as well)
stl_transform -center -z0 file1.stl | stl_transform -center -z0 -tx w | stl_merge > print_bed.stl

stl_cmds that generate primitives or models of any kind would need to accept input from stdin and forward it on to stdout before adding its model data to the end of the stream. I think the stream would just be one STL file after another, so stl_cmds would use some shared interface to iterate over all STL files in the stream and perform their work on them. Some commands would just consume the input, like stl_bbox or stl_count. Others would combine multiple models through some kind of operation like stl_boolean and stl_merge. A new command stl_cat could be used to add STL files to the stream. stl_transform could perform a transformation on all files in the stream or if a filename is provided, add a single transformed model to the stream.

Again, this hasn't been thoroughly thought out, just a patchwork of ideas right now.

jallwine commented 6 years ago

The STL header could be used to tag files in the stream and filter them down the line. For example:

# create a cube, sphere and cylinder. Translate the sphere in x 10, and the cube in y 10, leaving the cylinder centered at the origin.
stl_cube -tag cube | stl_sphere -tag sphere | stl_cylinder -tag cylinder | stl_transform -select sphere -tx 10 | stl_transform -select cube -ty 10
jallwine commented 6 years ago

Or, rather than adding -select to every command make any file input argument accept some kind of selector format: @index[integer index] | @select[tag] | @file[filename] | filename