When modeling, you always have to combine many submodels, and OpenSCAD shows the result of calculating in the preview. Sometimes, however, the submodels overlap. No matter how you flip them over, you still cannot see some specific details. It might cause trouble for debugging. When it happens, what can we do for that?
Highlight modifier #
To illustrate, let's take the heart listed in Boolean operations and hull for example.
radius = 10;
module heart(radius) {
rotated_angle = 45;
diameter = radius * 2;
$fn = 48;
rotate(-rotated_angle) union() {
circle(radius);
translate([0, -radius, 0])
square(diameter);
}
translate([cos(rotated_angle) * diameter, 0, 0])
circle(radius);
}
heart(radius);
The heart consists of one square and two circles. You can type a #
character in front of the models to inspect respectively. The rendering process will be as usual but also draw the submodels modified by #
in pink.
radius = 10;
module heart(radius) {
rotated_angle = 45;
diameter = radius * 2;
$fn = 48;
rotate(-rotated_angle) union() {
#circle(radius);
#translate([0, -radius, 0])
square(diameter);
}
#translate([cos(rotated_angle) * diameter, 0, 0])
circle(radius);
}
heart(radius);
Now, you can see the submodels respectively.
Transparent modifier %
I also talked about how to make a hollow sphere in Boolean operations and hull.
radius = 10;
thickness = 1;
module hollow_sphere(radius, thickness) {
$fn = 48;
inner_radius = radius - thickness;
difference() {
sphere(radius);
sphere(inner_radius);
}
}
hollow_sphere(radius, thickness);
However, you cannot see if there's a sphere inside a sphere.
That is because the bigger sphere wraps the smaller sphere. If you want to see these two spheres at the same time, you can use %
to modify the outer sphere. The modified object will draw in transparent gray.
...
difference() {
%sphere(radius);
sphere(inner_radius);
}
...
Then, you can see both of them.
Show only modifier !
Sometimes, you might want to see a particular sub-model without showing others. An alphabet on a sphere demonstrated in Boolean operations and hull could be an example. Here is the code again.
character = "A";
font_size = 10;
thickness = 1;
module hollow_sphere(radius, thickness) {
$fn = 48;
inner_radius = radius - thickness;
difference() {
sphere(radius);
sphere(inner_radius);
}
}
module sphere_character(ch, font_size, thickness) {
font_offset = font_size / 2;
intersection() {
hollow_sphere(font_size, thickness);
linear_extrude(font_size * 2)
translate([-font_offset, -font_offset, 0])
text(ch, size = font_size);
}
}
sphere_character(character[0], font_size, thickness);
sphere(font_size - thickness, $fn = 48);
What if you just want to see the model created by the code below?
...
linear_extrude(font_size * 2)
translate([-font_offset, -font_offset, 0])
text(ch, size = font_size);
...
You might want to comment other lines of the code. It's surely a way to do that but troublesome. One convenient way is just putting a !
in front of the sub model.
...
!linear_extrude(font_size * 2)
translate([-font_offset, -font_offset, 0])
text(ch, size = font_size);
...
It will ignore the rest of the design and show the sub model only.
Disable modifier *
Often, you want to disable a sub model to figure out what's the problem of your design. For instance, the sphere_character
module shown above has a sub-model and you want to disable it.
...
linear_extrude(font_size * 2)
translate([-font_offset, -font_offset, 0])
text(ch, size = font_size);
...
Comment them? Sure! You have to, however, comment all its lines, such as:
...
// linear_extrude(font_size * 2)
// translate([-font_offset, -font_offset, 0])
// text(ch, size = font_size);
...
Or:
...
/*
linear_extrude(font_size * 2)
translate([-font_offset, -font_offset, 0])
text(ch, size = font_size);
*/
...
Both are troublesome. An easy way is using *
.
...
*linear_extrude(font_size * 2)
translate([-font_offset, -font_offset, 0])
text(ch, size = font_size);
...
The *
modifier just ignores this entire sub-model for the rendering process.
Forcing the generation of a mesh
Occasionally, the preview will have a broken result. Putting an alphabet on a sphere, for example, might generate a broken preview.
For generating the mesh of all design, you may press the F6 function key to do the Render command. It solves the problem but is slow because the broken preview might only come from a sub model. Rendering all design in this situation is wasting time, and you may render
the sub model only. For example.
...
#render() sphere_character(character[0], font_size, thickness);
sphere(font_size - thickness, $fn = 48);
You can combine other modifiers, such as the example shown above. As you can see, the alphabet doesn't break now.
While you are modeling, try to incorporate these modifiers. They are helpful tools when you are debugging your design.