Sometimes when you can’t find quite the right tool, you have to create it yourself… today was one of those days…
I can’t see myself ever creating 3D objects with a GUI editor, so I’ve been learning OpenSCAD and it seems to be quite sufficient for most of my needs so far, but most recently I’ve wanted to apply some text to my models in a second colour, and the process at the moment seems to involve more manual steps than I’m comfortable with, so I looked into the problem and I think I’m on track towards a solution…
Although OpenSCAD can create objects with multiple colours, and Bambu Studio can handle .3mf files with multiple colours, there’s a break somewhere in the tool chain workflow that stops you going from one to the other without cumbersome manual steps. So I’ve been looking at the various file generation options in OpenSCAD and found that .csg files contain the colour information and are easy to manipulate because they’ve mostly been pre-flattened by OpenSCAD from the .scad original.
I’ve hacked up a quick parser for .csg format (which was mostly well documented online, the only missing info that I had to guess at was the format of comments in the files - nothing that OpenSCAD generated included comments) and I’ve written a filter that detects the ‘color()’ modifier and excises anything that doesn’t match a given colour from the file. So by running this once and having the code generate multiple files with each containing a single colour, I don’t need to manually separate the colours at the OpenSCAD source level and create multiple exports. There’s a possibility that the simple algorithm of just removing any objects preceded by a ‘color()’ statement may not be sufficient (e.g. in cases where sub-objects switch back to the selected colour) but I’m hoping that the simplified structure of csg files as opposed to scad files means that this isn’t going to occur in practise - it certainly hasn’t in my tests so far. Worst-case scenario is that users will just have to be careful about marking components that end up in the final object with their colour and not marking components with a colour if they are only used as modifiers to subtract from other pieces - but so far what I’ve seen suggests that that is not going to be a necessary restriction. The only tricky thing I had to be careful about was rather than actually deleting coloured objects, I had to replace them with empty geometry having zero volume, so that operations such as ‘difference’ wouldn’t accidentally replace their first parameter (the thing that was being subtracted from) by one of subsequent objects which was the part that was supposed to be deleted from the first object. (folks who’ve coded OpenSCAD files will appreciate why that’s important.)
Currently I’m still developing the code so it’s still a slightly manual process, but the things I’m doing are all actions that can be automated and the eventual implementation will be a 1-liner (or maybe a drag&drop) conversion from the single export from OpenSCAD in .csg format to a single .3mf file that Bambu Studio can import and print multicoloured without any manual tweaking. It may take me a few weeks to bring it all together because there’s a lot about 3mf files that I still need to learn…
For now I do have to convert those separate .csg files into .3mf files manually, using OpenSCAD (because Bambu Studio can’t read .csg files), and unfortunately the separate component files don’t automatically position themselves correctly within Bambu Studio, so I have to align them manually - but both of those actions should eventually be done by my code.
There’s a work-in-progress snapshot at http://gtoal.com/OpenSCAD/bicolor-test/ - some of the comments in the source files are wrong or out of date, just ignore them.
The little test file is actually an interesting experiment in its own right. I was looking at two different ways of putting white text on a black surface like a user did on a box I created ( Vectrex Superbox by gtoal MakerWorld: Download Free 3D Models ) - the first test part was made the traditional way with an all-black surface with 3 or 4 layers of white text embedded at the top of the surface. The second one was an all-white piece with a single layer of black on top with the complement of the text. This version turned out to be better since the white text was white all the way through and was not darkened by having a black substrate beneath it, and has the major advantage of only one layer requiring filament switching rather than the 4 layers with both colours that the embedded white on black text version required. The only downside of this negative mask technique is that the sides of any objects with white text on a black surface will also be in white, but for the items I’m making, that’s OK.
Anyway, this is an experiment I’m reporting, but if it turns into a utility that other people can use, I’ll post the final code here.