Until now, my projects have been are destined for 3D printing and I
didn't care about colour in the 3D model because my printer can't handle
colour anyway.
But now I'm working on developing a model that is intended for viewing
on screen, and I want to have different colours for various parts. So
instead of exporting to STL as I would usually do, I tried using 3MF
format (which supports colour). But I discovered that the colours do not
seem to be carried through into the exported 3MF file, presumably
because of the way the rendering in OpenSCAD works.
So now I'm thinking to create a series of separate object files, one for
each colour, and use some other software to combine them. Ideally, I
want something that doesn't involve a huge amount of disk space and
which and is easy to learn (so not with zillions of features) where I
can do something along the lines of
import file 1, assign colour A by numeric/RGB value
import file 2, assign colour B by numeric/RGB value
..etc ...
Ideally, it would be a scripted process. Oh, and it has to run on
Windows 10.
The question is, what other software to use? (or is there a way in
OpenSCAD itself)
Thanks for any advice,
Steve
If you just want to view it on screen, why not use the color() facility
which works with F5 and be done with it?
On 1/20/2024 8:13 PM, Steve Lelievre via Discuss wrote:
Until now, my projects have been are destined for 3D printing and I
didn't care about colour in the 3D model because my printer can't
handle colour anyway.
But now I'm working on developing a model that is intended for viewing
on screen, and I want to have different colours for various parts. So
instead of exporting to STL as I would usually do, I tried using 3MF
format (which supports colour). But I discovered that the colours do
not seem to be carried through into the exported 3MF file, presumably
because of the way the rendering in OpenSCAD works.
So now I'm thinking to create a series of separate object files, one
for each colour, and use some other softw
I would presume that he doesn't merely want to view it himself, but to
share it with others, possibly py putting it on a web server and letting
other people view and interact with it using a 3D viewer in the browser.
Or sharing it some other way.
On Sat, Jan 20, 2024 at 7:37 PM jon via Discuss discuss@lists.openscad.org
wrote:
If you just want to view it on screen, why not use the color() facility
which works with F5 and be done with it?
On 1/20/2024 8:13 PM, Steve Lelievre via Discuss wrote:
Until now, my projects have been are destined for 3D printing and I
didn't care about colour in the 3D model because my printer can't
handle colour anyway.
But now I'm working on developing a model that is intended for viewing
on screen, and I want to have different colours for various parts. So
instead of exporting to STL as I would usually do, I tried using 3MF
format (which supports colour). But I discovered that the colours do
not seem to be carried through into the exported 3MF file, presumably
because of the way the rendering in OpenSCAD works.
So now I'm thinking to create a series of separate object files, one
for each colour, and use some other softw
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Sorry for being unclear.
Yes, indeed, this is for a model that I would make available to other
people for viewing.
On 2024-01-20 5:45 p.m., Leonard Martin Struttmann via Discuss wrote:
I would presume that he doesn't merely want to view it himself, but to
share it with others, possibly py putting it on a web server and
letting other people view and interact with it using a 3D viewer in
the browser. Or sharing it some other way.
I came across a similar struggle, but here I'm able to script in UNIX shell scripts extensively, learning some sort of scripting capability is central to making any sort of computer animation or the thing you're doing.
In my case I generate parts to STL, but I need to "transfer" certain types of information - in some cases it's only the surface property (which color, is it shiny metallic) and in other cases it also includes information needed for assembly video, e.g. thread pitch and offsets, or various distances.
Because you can't embed this sorts of data in files that are generated (like STL) one approach is to create a lookup registry, which woks off a key that is embedded in your file name. In my scripts for example the first step is I convert "filename.scad" to "filename.stl", and this is done via batch script. Well, if you have your "filename" be something interesting, for example of "filename" is equal to "part-description__surface-description-index" where "surface-description-index" is a number, then you can have a separate file which lists the numbers and gives for each number a "shader" for the surface properties, and other data can be combined in this way.
This is a very important puzzle to solve because when you have many tools generating many models, but not the same tool is generating the model (e.g. OpenSCAD or CadQuery) as is rending the assembly video (e.g. Blender or POV-ray), then you need to transfer these additional properties somehow. I am still working on a best approach, and am just giving some ideas. I think some sort of intricate scripting will be your ticket. Now Windows does run Python, for purposes of scripting something like this.
Sent with Proton Mail secure email.
On Saturday, January 20th, 2024 at 7:50 PM, Steve Lelievre via Discuss discuss@lists.openscad.org wrote:
Sorry for being unclear.
Yes, indeed, this is for a model that I would make available to other people for viewing.
On 2024-01-20 5:45 p.m., Leonard Martin Struttmann via Discuss wrote:
I would presume that he doesn't merely want to view it himself, but to share it with others, possibly py putting it on a web server and letting other people view and interact with it using a 3D viewer in the browser. Or sharing it some other way.
PrusaSlicer allows one to paint colors on a 3D model prior to printing.
If you export that painted model in a file format that preserves color,
that might be another approach.
Jon
On Saturday, January 20th, 2024 at 7:50 PM, Steve Lelievre via Discuss
discuss@lists.openscad.org wrote:
Sorry for being unclear.
Yes, indeed, this is for a model that I would make available to other
people for viewing.
On 2024-01-20 5:45 p.m., Leonard Martin Struttmann via Discuss wrote:
I would presume that he doesn't merely want to view it himself, but
to share it with others, possibly py putting it on a web server and
letting other people view and interact with it using a 3D viewer in
the browser. Or sharing it some other way.
OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org
Thanks for the responses to my question about how to get colors into an
exported model.
I have now been able to do what I wanted, even though I went down a long
and winding road. It's a long and slightly complicated story but, for
the record, this is what I did:
I discovered that FreeCAD has a facility to run OpenSCAD inside it. And
FreeCAD can export to .obj format, which supports color. So I installed
FreeCAD and started playing around.
Using the built-in OpenSCAD facility, I create a couple of cubes of
different colours and exported them to a .obj file. Opening that file
with Windows 3D Viewer showed the cubes in the correct color.
Very promising, I thought.
So then I tried to using FreeCAD to run the OpenSCAD program that
generates my model. It failed completely.
FreeCAD churned away for about 5 minutes and then started telling me it
needed missing files, something to do with processing DXFs. After I gave
it permission to download the missing files it continued to process for
another 5 minutes or so, then it errored out. (My model is complex -
even normal OpenSCAD takes about 8 minute to render it on my PC and it
has a few tens of thousands of edges, facets etc.)
One step forward, two steps back!
Because I couldn't generate my model inside FreeCAD, I decided to go
back to regular OpenSCAD and turn the two main parts of the model into
two STL files. Then in FreeCAD I used a two OpenSCAD commands to import
them:
color("red")import("C:/Users/steve/Desktop/Base.stl");
color("green")import("C:/Users/steve/Desktop/Ring.stl");
It took a while, but this seemed to work - except that in FreeCAD's
preview area the two objects weren't colored as required.
In the Combo View window I saw that the process had generated 4 things.
They were named:
Base (marked with a little green icon that looks like it might be a wave)
Mesh (appeared to be the same shape as Base but the icon was a blue cube)
Ring (green icon again)
Mesh001 (same shape as Ring, and a blue icon again)
Right-clicking on each in turn to examine their Appearance properties, I
found that Base and Mesh were set to a grey color, but Mesh and Mesh001
were set to red and green respectively.
Exporting to .obj failed after several minutes with "list index out of
range". I decided to try again. I deleted Base and Ring (because they
were grey) and found the preview area changed to showing the model in
the correct colors. But exporting to .obj still failed "list index out
of range".
So then I did a test where I kept Base and Ring and deleted Mesh and
Mesh001. Exporting to .obj succeeded and Windows 3D Viewer shows the
model. But it was grey instead of having the desired colours (and
rotated up by 90 degrees for some reason.)
So, it seems to me that if an OpenSCAD script will run inside FreeCAD,
it can be used to generate a model that exports to .obj with colors
correctly assigned. But if you have to use the import command to load
pre-calculated shapes from files, your model has these mesh things
added. And they somehow prevent a subsequent export to .obj from working
properly. But it is the meshes that have the desired colours so if you
get rid of them, you loose the color settings.
All that said, by using Jon's suggestion relating to PrusaSlicer but
applying it to FreeCAD, I can achieve to what I want to do. I import my
two STL files as above, then delete the two meshes, and then set the
colors of the two remaining objects manually. With the meshes gone,
exporting to .obj works fine and the remaining two items, now with the
desired colors, look correct in Windows 3D Viewer.
I just have to figure out how to counteract the unexpected orientation
of the .obj model when seen in Windows 3D Viewer (adding suitable
rotates to my little import script doesn't work - weirdly, FreeCAD
rotates the meshes but not Base or Ring.)
Cheers,
Steve
On 2024-01-21 4:39 a.m., jon wrote:
PrusaSlicer allows one to paint colors on a 3D model prior to
printing. If you export that painted model in a file format that
preserves color, that might be another approach.
Jon
I have played around with the "OpenSCAD Workbench" inside of FreeCAD myself, and I'm running FreeCAD 0.20.1, so slightly outdated perhaps. While I was able to open the .SCAD files in FreeCAD, it did take some modifications, esp. some of the nested boolean operations are not handled correctly in FreeCAD.
If you're already able to export STL from OpenSCAD, then I would stick with that. Why not, export to STL in OpenSCAD, then import the STL into another tool. There are many tools that can import STL, and many of those tools will no doubt be able to apply a "shader" or a color to the STL. You can combine the pieces in this way.
In my case I automated the production of STL files using OpenSCAD command-line scripting. I open every .SCAD file within a specified "parts/" directory, and for each, I convert to .STL by calling OpenSCAD on the command line. Then you can use those STL in other tools as you've started to do.
Sent with Proton Mail secure email.
On Sunday, January 21st, 2024 at 5:06 PM, Steve Lelievre via Discuss discuss@lists.openscad.org wrote:
Thanks for the responses to my question about how to get colors into an
exported model.
I have now been able to do what I wanted, even though I went down a long
and winding road. It's a long and slightly complicated story but, for
the record, this is what I did:
I discovered that FreeCAD has a facility to run OpenSCAD inside it. And
FreeCAD can export to .obj format, which supports color. So I installed
FreeCAD and started playing around.
Using the built-in OpenSCAD facility, I create a couple of cubes of
different colours and exported them to a .obj file. Opening that file
with Windows 3D Viewer showed the cubes in the correct color.
Very promising, I thought.
So then I tried to using FreeCAD to run the OpenSCAD program that
generates my model. It failed completely.
FreeCAD churned away for about 5 minutes and then started telling me it
needed missing files, something to do with processing DXFs. After I gave
it permission to download the missing files it continued to process for
another 5 minutes or so, then it errored out. (My model is complex -
even normal OpenSCAD takes about 8 minute to render it on my PC and it
has a few tens of thousands of edges, facets etc.)
One step forward, two steps back!
Because I couldn't generate my model inside FreeCAD, I decided to go
back to regular OpenSCAD and turn the two main parts of the model into
two STL files. Then in FreeCAD I used a two OpenSCAD commands to import
them:
color("red")import("C:/Users/steve/Desktop/Base.stl");
color("green")import("C:/Users/steve/Desktop/Ring.stl");
It took a while, but this seemed to work - except that in FreeCAD's
preview area the two objects weren't colored as required.
In the Combo View window I saw that the process had generated 4 things.
They were named:
Base (marked with a little green icon that looks like it might be a wave)
Mesh (appeared to be the same shape as Base but the icon was a blue cube)
Ring (green icon again)
Mesh001 (same shape as Ring, and a blue icon again)
Right-clicking on each in turn to examine their Appearance properties, I
found that Base and Mesh were set to a grey color, but Mesh and Mesh001
were set to red and green respectively.
Exporting to .obj failed after several minutes with "list index out of
range". I decided to try again. I deleted Base and Ring (because they
were grey) and found the preview area changed to showing the model in
the correct colors. But exporting to .obj still failed "list index out
of range".
So then I did a test where I kept Base and Ring and deleted Mesh and
Mesh001. Exporting to .obj succeeded and Windows 3D Viewer shows the
model. But it was grey instead of having the desired colours (and
rotated up by 90 degrees for some reason.)
So, it seems to me that if an OpenSCAD script will run inside FreeCAD,
it can be used to generate a model that exports to .obj with colors
correctly assigned. But if you have to use the import command to load
pre-calculated shapes from files, your model has these mesh things
added. And they somehow prevent a subsequent export to .obj from working
properly. But it is the meshes that have the desired colours so if you
get rid of them, you loose the color settings.
All that said, by using Jon's suggestion relating to PrusaSlicer but
applying it to FreeCAD, I can achieve to what I want to do. I import my
two STL files as above, then delete the two meshes, and then set the
colors of the two remaining objects manually. With the meshes gone,
exporting to .obj works fine and the remaining two items, now with the
desired colors, look correct in Windows 3D Viewer.
I just have to figure out how to counteract the unexpected orientation
of the .obj model when seen in Windows 3D Viewer (adding suitable
rotates to my little import script doesn't work - weirdly, FreeCAD
rotates the meshes but not Base or Ring.)
Cheers,
Steve
On 2024-01-21 4:39 a.m., jon wrote:
PrusaSlicer allows one to paint colors on a 3D model prior to
printing. If you export that painted model in a file format that
preserves color, that might be another approach.Jon
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
On 2024-01-21 4:03 p.m., neri-engineering wrote:
Why not, export to STL in OpenSCAD, then import the STL into another tool. There are many tools that can import STL, and many of those tools will no doubt be able to apply a "shader" or a color to the STL.
Right.
My original question asked for advice on which tool to use for colouring
parts of a model and exporting in a colour-capable format, but I got
sidetracked when I found FreeCAD and discovered it's ability to run
OpenSCAD.
But my old brain has finally got back to the real solution - I just
export the parts from OpenSCAD and merge them in another tool, import to
FreeCAD (without using the OpenSCAD extension), recolour and export to obj.
And FreeCAD seem okay for the job now that I've got it figured out.
Steve