Create Coloured Parts with OpenScad and 3DToLD


Create Coloured Parts with OpenScad and 3DToLD
#1
The latest release of 3DToLD added support for coloured 3mf files. This opens up the possibility to create coloured parts with OpenScad.
OpenScad is a script based CAD software. This post will describe the basics of how to create coloured models with OpenScad.
This is not a full tutorial on OpenScad itself. At the point this is written a development version of OpenScad is required, wich can be found on OpenScad website.

The Settings
First you should check some settings: 
  • Under Edit>Preferences>Features>lazy-union
    • check if your model includes multiple components, that will be subparts
    • uncheck overwise
  • Under Edit>Preferences>Advanced>3D Rendering>Backend choose Manifold

Add Colour to models
You can colour a model using the color() module.
Here is an example how it is used:
Code:
color("red")cylinder(10,5);
And this is the result:

.png   Red Cylinder.png (Size: 13.5 KB / Downloads: 28)
You can find the documentation for the color() module here.

If you use multiple shapes that overlap you should union them:
Code:
union(){
color("blue")cube([10,10,10]);
color("red")cylinder(h=10,r=5);
}

.png   Red Cylinder + Blue Cube.png (Size: 7.09 KB / Downloads: 26)

Changing the order of objects changes the result.
Code:
union(){
color("red")cylinder(h=10,r=5);
color("blue")cube([10,10,10]);
}

.png   Blue Cube + Red Cylinder.png (Size: 8.19 KB / Downloads: 25)

If you cut objects with difference() the surface has the colour of the cutting object.
Code:
difference(){
color("blue")cube([10,10,10]);
color("red")cylinder(h=10,r=5);
}

.png   Blue Cube - Red Cylinder.png (Size: 6.89 KB / Downloads: 24)

The intersection() module is also affected by colour.
Code:
intersection(){
color("red")cylinder(h=10,r=5);
color("blue")cube([10,10,10]);
}

.png   Red Cylinder u Blue Cube.png (Size: 15.05 KB / Downloads: 23)

Like for union() the order also matters here.
Code:
intersection(){
color("blue")cube([10,10,10]);
color("red")cylinder(h=10,r=5);
}

.png   Blue Cube u Red Cylinder.png (Size: 14.4 KB / Downloads: 22)

LDraw Colours
To use LDraw colours in OpenScad you can use my LDraw Colors for OpenScad Library

Export as 3mf file
When your done with your model you can export it through File>Export>Export as 3MF...
You will now see this dialog:
   
Choose "Use colors from model and color scheme". Under Unit choose the one you used, if you used LDraw Units leave it on Millimeter. The Metadata is optional and the following field will be read by 3DToLD:
  • Title will be used for the "Descriptive Part Name"
  • Designer will be used for the Author
  • License will be used for "Part License"
Next you choose where to save the 3mf file.

Import into 3DToLD
Now open 3DToLD. If you designed your model in LDraw units change the unit from Auto to LDraw. If your model is designed with -Y as the up axis(LDraw) uncheck "Use LDraw Axis". Doing both of these also removes any transformative processing on the model. Now press the "Load File" button and select your 3mf file. The metadata fields should be populated with the ones you choose in the previous step. The colours are initially direct colours, if you used my LDraw Colour Library you can convert them easily to proper LDraw colours. For that click on "Convert direct/html colours to LDraw colours". Then select the colour categories from wich you used colours and click ok. Your model should now only have LDraw colours. Colours are mapped by their rgb values if two colours have the same values the first in the list is used. Optionally you can also generate outlines(no conditional lines). You can now select your output file and convert/save the model.
Now you have coloured part, that can be used or processed further with other LDraw tools(e.g. LDPE):

.png   Converted Model.png (Size: 9.41 KB / Downloads: 16)
Reply
« Next Oldest | Next Newest »



Messages In This Thread
Create Coloured Parts with OpenScad and 3DToLD - by Hageta - 8 hours ago

Forum Jump:


Users browsing this thread: 2 Guest(s)