many, many changes for inline colors and other things#39
many, many changes for inline colors and other things#39wjcarpenter wants to merge 65 commits intondevenish:mainfrom
Conversation
This is useful not only for better visualizing, but it can help with selecting things when importing into a slicer or other tool for further manipulation. For example, if you create a STEP file and convert it to a OBJ file (with any convenient converter tool), you can add the OBJ file to Bambu Studio, at which point Bambu Studio prompts you to map the colors in the OBJ file to filament colors. (Unfortunately, Bambu Studio doesn't preserve colors on STL, STEP, nor 3MF files at the moment. Maybe someday.)
adds a sketch for T-slot nuts
implement overall scale factors for when you need a little nudge to m…
…respectively This is useful not only for better visualizing, but it can help with selecting things when importing into a slicer or other tool for further manipulation. For example, if you create a STEP file and convert it to a OBJ file (with any convenient converter tool), you can add the OBJ file to Bambu Studio, at which point Bambu Studio prompts you to map the colors in the OBJ file to filament colors. (Unfortunately, Bambu Studio doesn't preserve colors on STL, STEP, nor 3MF files at the moment. Maybe someday.) Partial help for issue ndevenish#19 Solution for issue #9 I discovered that this online STEP converter creates 3MF files that Bambu Studio likes (and preserves colors if the STEP file has them): https://convert3d.org/step-to-3mf/app A workflow could be: - create STEP file via gflabel, either with the default colors or your own choices for base color and label color - use that converter to convert the STEP file to 3MF - add the 3MF into Bambu Studio; you'll see the colors in the prepare tab - slice the plate - when you print the plate, Bambu studio will try to pick filaments for each color, but you can also pick whichever filaments you prefer before actually sending it to the printer This workflow is less tedious than splitting the model to parts or objects and assigning filaments manually. ----------------- (Sorry about the extra commits on this branch and PR. I had a few independent changes in separate branches and accidentally combined all of them into this branch. I took the shortest path get thingws back to where they should have been.)
You can change colors with a label. See COLOR_NOTES.md for details. In this implementation, the colors are tracked "on the side" (that is, outside of the build123d hierarchy. As far as I have been able to figure out, build123d "forgets" the colors as the sketches are built up. The original top-level "label_sketch" is still created, but it's not used for output file export or for VScode rendering. Instead, the on-the-side bookkeeping is used. Perhaps someday we'll be able to track the colors directly in the build123d hierarchy, at which point the on-the-side bookkeeping can be dropped.
Add images for examples
cut/paste glitch
The new fragment type ColorFragment ({color(red)}) is introduced. It
changes the color of subsequent fragments until the end of the line or
another ColorFragment is seen. Exported STEP and SVG files, and VScode
renders preserve those colorings (though there is a new --svg-mono
command line option to preserve the old behavior).
A couple of changes as a side effect of implementing the above:
1. (fairly major) Labels are now created as a hierarchy of
Compound objects instead of sketches. Things are labelled at
each level, so hypotherically a tool looking at a STEP, STL, or SVG
could navigate through the layers. (My experiments find little
support fot his in those other tools, though FreeCAD seems to grok
it pretty well.)
2. (minor) ModifierFragment is a subclass of Fragment, meant
for things like the ColorFragment class. These things act on
other fragments instead of being rendered themselves.
allow inline color changes
Colored fragments
The previous x/y/z scaling options were easily implemented. Just
call a single build123d scale operation on the overall assembly.
Unfortunately, build123d considers that a "CAD operation" and so
creates all new objects in the assembly, losing the label and
color attributes in the process.
This revised implementation takes a different approach. It pre-scales
the dimensions of the base (including margin) as well as any command
line specs of width, height, depth, and margin. The excellent
existing dynamic scaling of the gflabel code takes care of everything
else.
Note: If you use label divisions ({|}) with scaling, you may get
some surprises. Each division is scaled and rendered independently.
That was always the case, but x/y scaling can make it more obvious.
My advice is to use trial and error to get what you want.
Scaling with colors and labels
It seems that BambuStudio v2.5.0 introduced
|
That is pretty great news. I was looking around for a color 3MF that wasn't produced by Bambu Studio, but didn't come across one before my patience ran out. Have you had a chance to try it with a non-BBS color 3MF?
It looks like it's a bit more involved than just calling |
|
Sadly I have not tried any of the new features regarding 3mf. I think the best way forward is to implement 3mf exporting in gflabel and then try to import it. If I get around to implementing it I will pr the changes to your repo. |
These key-=value arguments are more intuitive than the previous
pairwise arguments. Example: {scale(x=2, y=0.5)}.
Text fragments are normally rendered as a single build123d Part. With this option, build123d still creates the single Sketch, but the resulting Faces are extruded to Parts individually. They are given Part labels that might make them easier to select in an external tool. The process of affiliating a character of the text fragment with a particular Face is not exact because some characters can render into multiple Faces, and the space character renders into no Faces. The Faces still get Part labels, but they may be less helpful or even confusing in some edge cases. The reason to let build123d create the Sketch of the entire text fragment is so that it does proper font spacing and other tricks. A more complete technique for the --text-as-parts option would render each character to a Sketch individually in order to count the Faces for that character. Then use that info to label the Parts. There's still no guarantee that build123d will return a Sketch with the Faces in character order. (In fact, we have observed that for some reason the first face corresponds last. We take that into account, but if that last character produced multiple Faces, we'd still be wrong in our workaround.)
Introduces --text-as-parts
|
@wjcarpenter I just got a basic version of the colored 3mf export working. Created a PR here: github.com/wjcarpenter/pull/14/ |
The type hint for the render() function is changed from Sketch to Compound. (Compound is the superclass of Sketch.) A fragment can continue to return the simple sketch, or it can return a Compound with children. If there are children, each should be a 2D shape of some kind, and each is extruded to a Part separately. If the children have color or label attributes, they are respected. The implementation of --text-as-parts is moved into the TextFragment render() function and returns a Compound with children, each with its own label.
Colored 3mf export using lib3mf
Svg fragment
I'm love 3MF export, I hadn't managed to find a way to actually get separate colors/filament types into the 3MF. It looks like @Paulomart has maybe worked this out? Is that in this branch or on your mainline to study? |
Should be already in this branch :) |
That 3MF export works great. I've used it a couple of times with colors into Bambu Studio. |
Introduces fragment
{color(green)}to be able to make color changes within a label spec. See COLOR_NOTES.md for details and examples. The ColorFragment class is a subclass of ModifierFragment. A ModifierFragment is not itself rendered in any way. Instead, it modifies the rendering of fragments that follow it on a line.CAD labels are applied to all nodes in the CAD model hierarchy. Unnecessary nodes (those with only a single child) are squeezed out of the model. The idea is to allow precise and meaningful selection in outside tools that can deal with CAD model assemblies.
Coloring and CAD model labels are exported in STEP files, SVG files, and VSCode viewing. There is a command line option to do SVG in monochrome.
Reworks the software layering to extrude Parts at the lowest level instead of at the highest level.
Re-implements the command line scaling options in a way that preserves in a way that preserves colors and CAD model labels.
Many other small changes.