add ghosting

This commit is contained in:
Adrian Mariano 2024-11-27 20:20:41 -05:00
parent f982b96d12
commit 1930d5deee
2 changed files with 71 additions and 24 deletions

View file

@ -39,7 +39,9 @@ $edge_length = undef;
$tags_shown = "ALL"; $tags_shown = "ALL";
$tags_hidden = []; $tags_hidden = [];
$ghost_this=false;
$ghost=false;
$ghosting=false; // Ghosting is in effect, so don't apply it again
_ANCHOR_TYPES = ["intersect","hull"]; _ANCHOR_TYPES = ["intersect","hull"];
@ -3104,31 +3106,32 @@ module attachable(
$attach_alignment=undef; $attach_alignment=undef;
if (expose_tags || _is_shown()){ if (expose_tags || _is_shown()){
if (!keep_color) if (!keep_color)
_color($color) children(0); _color($color)
else { if (($ghost || $ghost_this) && !$ghosting)
$save_color=undef; // Force color_this() color in effect to persist for the entire object %union(){
$ghosting=true;
children(0); children(0);
} }
else children(0);
else {
$save_color=undef; // Force color_this() color in effect to persist for the entire object
if (($ghost || $ghost_this) && !$ghosting)
%union(){
$ghosting=true;
children(0);
} }
if (is_def($save_tag) && is_def($save_color)){ else children(0);
$tag=$save_tag; }
$save_tag=undef; }
$color=$save_color; // Revert to the color before color_this() call let(
$save_color=undef; $ghost_this=false,
$tag=default($save_tag,$tag),
$save_tag=undef,
$color=default($save_color,$color),
$save_color=undef
)
children(1); children(1);
} }
else if (is_def($save_color)) {
$color=$save_color; // Revert to the color before color_this() call
$save_color=undef;
children(1);
}
else if (is_def($save_tag)) {
$tag=$save_tag;
$save_tag=undef;
children(1);
}
else children(1);
}
} }
// Function: reorient() // Function: reorient()
@ -3926,7 +3929,7 @@ function _find_anchor(anchor, geom)=
: oang // face anchors point UP/BACK : oang // face anchors point UP/BACK
) [anchor, final_pos, final_dir, default(override[2],spin), ) [anchor, final_pos, final_dir, default(override[2],spin),
if (is_def(edgeang)) [["edge_angle",edgeang],["edge_length",edgelen], ["vec", endvecs]]] if (is_def(edgeang)) [["edge_angle",edgeang],["edge_length",edgelen], ["vec", endvecs]]]
) : type == "conoid"? ( //r1, r2, l, shift ) : type == "conoid"? ( //r1, r2, l, shift, axis
let( let(
rr1=geom[1], rr1=geom[1],
rr2=geom[2], rr2=geom[2],

View file

@ -161,6 +161,50 @@ module color_overlaps(color="red") {
%children(); %children();
} }
// Module: ghost()
// Synopsis: Sets transparency for attachable children and their descendents.
// SynTags: Trans
// Topics: Attachments
// See Also: ghost_this(), recolor(), color_this()
// Usage:
// ghost([ghost]) CHILDREN;
// Description:
// Sets the transparency for the attachable children and their descendents until another {{ghost()}} or {{ghost_this()}}.
// By default, turns transparency on. Give the `false` parameter to disable transparency.
// Do not mix this with user supplied `%` operators anywhere in the geometry tree.
// Arguments:
// ghost = If true set the descendents to be transparent; if false, disable transparency. Default: true
// Example(3D):
// ghost() cuboid(10)
// ghost(false) cuboid(5);
function ghost(ghost) = no_function("ghost");
module ghost(ghost=true)
{
$ghost=ghost;
children();
}
// Module: ghost_this()
// Synopsis: Makes the children at a single level transparent.
// SynTags: Trans
// Topics: Attachments
// See Also: ghost(), recolor(), color_this()
// Usage:
// ghost_this() CHILDREN;
// Description:
// Makes the children transparent for one level, reverting to the previous transparency state for further descendents.
// This works only with attachables and you cannot give the `%` operator anywhere in the geometry tree.
// Example(3D):
// ghost_this() cuboid(10)
// cuboid(5);
function ghost_this() = no_function("ghost_this");
module ghost_this()
{
$ghost_this=true;
children();
}
// Section: Colorspace Conversion // Section: Colorspace Conversion