Merge pull request #1522 from adrianVmariano/master

highlight
This commit is contained in:
Revar Desmera 2024-12-11 20:49:10 -08:00 committed by GitHub
commit a351fae9a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 99 additions and 24 deletions

View file

@ -43,6 +43,9 @@ $ghost_this=false;
$ghost=false; $ghost=false;
$ghosting=false; // Ghosting is in effect, so don't apply it again $ghosting=false; // Ghosting is in effect, so don't apply it again
$highlight_this=false;
$highlight=false;
_ANCHOR_TYPES = ["intersect","hull"]; _ANCHOR_TYPES = ["intersect","hull"];
@ -1154,8 +1157,8 @@ module tag_this(tag)
// that don't use {{attachable()}} or built in modules such as // that don't use {{attachable()}} or built in modules such as
// - `polygon()` // - `polygon()`
// - `projection()` // - `projection()`
// - `polyhedron()` (or use [`vnf_polyhedron()`](vnf.scad#vnf_polyhedron)) // - `polyhedron()` (or use {{vnf_polyhedron()}})
// - `linear_extrude()` (or use [`linear_sweep()`](regions.scad#linear_sweep)) // - `linear_extrude()` (or use {{linear_sweep()}})
// - `rotate_extrude()` // - `rotate_extrude()`
// - `surface()` // - `surface()`
// - `import()` // - `import()`
@ -3107,24 +3110,15 @@ module attachable(
if (expose_tags || _is_shown()){ if (expose_tags || _is_shown()){
if (!keep_color) if (!keep_color)
_color($color) _color($color)
if (($ghost || $ghost_this) && !$ghosting) _show_ghost() children(0);
%union(){
$ghosting=true;
children(0);
}
else children(0);
else { else {
$save_color=undef; // Force color_this() color in effect to persist for the entire object $save_color=undef; // Force color_this() color in effect to persist for the entire object
if (($ghost || $ghost_this) && !$ghosting) _show_ghost() children(0);
%union(){
$ghosting=true;
children(0);
}
else children(0);
} }
} }
let( let(
$ghost_this=false, $ghost_this=false,
$highlight_this=false,
$tag=default($save_tag,$tag), $tag=default($save_tag,$tag),
$save_tag=undef, $save_tag=undef,
$color=default($save_color,$color), $color=default($save_color,$color),
@ -3134,6 +3128,26 @@ module attachable(
} }
} }
module _show_highlight()
{
if ($highlight || $highlight_this)
#children();
else
children();
}
module _show_ghost()
{
if (($ghost || $ghost_this) && !$ghosting)
%union(){
$ghosting=true;
_show_highlight()children();
}
else _show_highlight()children();
}
// Function: reorient() // Function: reorient()
// Synopsis: Calculates the transformation matrix needed to reorient an object. // Synopsis: Calculates the transformation matrix needed to reorient an object.
// SynTags: Trans, Path, VNF // SynTags: Trans, Path, VNF

View file

@ -161,21 +161,74 @@ module color_overlaps(color="red") {
%children(); %children();
} }
// Section: Setting Object Transparency // Section: Setting Object Modifiers
// Module: highlight()
// Synopsis: Sets # modifier for attachable children and their descendents.
// SynTags: Trans
// Topics: Attachments, Modifiers
// See Also: highlight_this(), ghost(), ghost_this(), recolor(), color_this()
// Usage:
// highlight([highlight]) CHILDREN;
// Description:
// Sets the `#` modifier for the attachable children and their descendents until another {{highlight()}} or {{highlight_this()}}.
// By default, turns `#` on, which makes the children transparent pink and displays them even if they are subtracted from the model.
// Give the `false` parameter to disable the modifier and restore children to normal.
// Do not mix this with user supplied `#` modifiers anywhere in the geometry tree.
// Arguments:
// highlight = If true set the descendents to use `#`; if false, disable `#` for descendents. Default: true
// Example(3D):
// highlight() cuboid(10)
// highlight(false) attach(RIGHT,BOT)cuboid(5);
function highlight(highlight) = no_function("highlight");
module highlight(highlight=true)
{
$highlight=highlight;
children();
}
// Module: highlight_this()
// Synopsis: Apply # modifier to children at a single level.
// SynTags: Trans
// Topics: Attachments, Modifiers
// See Also: highlight(), ghost(), ghost_this(), recolor(), color_this()
// Usage:
// highlight_this() CHILDREN;
// Description:
// Applies the `#` modifier to the children at a single level, reverting to the previous highlight state for further descendents.
// This works only with attachables and you cannot give the `#` operator anywhere in the geometry tree.
// Example(3D):
// highlight_this()
// cuboid(10)
// attach(TOP,BOT)cuboid(5);
function highlight_this() = no_function("highlight_this");
module highlight_this()
{
$highlight_this=true;
children();
}
// Module: ghost() // Module: ghost()
// Synopsis: Sets transparency for attachable children and their descendents. // Synopsis: Sets % modifier for attachable children and their descendents.
// SynTags: Trans // SynTags: Trans
// Topics: Attachments // Topics: Attachments, Modifiers
// See Also: ghost_this(), recolor(), color_this() // See Also: ghost_this(), recolor(), color_this()
// Usage: // Usage:
// ghost([ghost]) CHILDREN; // ghost([ghost]) CHILDREN;
// Description: // Description:
// Sets the transparency for the attachable children and their descendents until another {{ghost()}} or {{ghost_this()}}. // Sets the `%` modifier 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. // By default, turns `%` on, which makes the children gray and also removes them from interaction with the model.
// Do not mix this with user supplied `%` operators anywhere in the geometry tree. // Give the `false` parameter to disable the modifier and restore children to normal.
// Do not mix this with user supplied `%` modifiers anywhere in the geometry tree.
// Arguments: // Arguments:
// ghost = If true set the descendents to be transparent; if false, disable transparency. Default: true // ghost = If true set the descendents to use `%`; if false, disable `%` for descendents. Default: true
// Example(3D): // Example(3D):
// ghost() cuboid(10) // ghost() cuboid(10)
// ghost(false) cuboid(5); // ghost(false) cuboid(5);
@ -188,14 +241,14 @@ module ghost(ghost=true)
// Module: ghost_this() // Module: ghost_this()
// Synopsis: Makes the children at a single level transparent. // Synopsis: Apply % modifier to children at a single level.
// SynTags: Trans // SynTags: Trans
// Topics: Attachments // Topics: Attachments, Modifiers
// See Also: ghost(), recolor(), color_this() // See Also: ghost(), recolor(), color_this()
// Usage: // Usage:
// ghost_this() CHILDREN; // ghost_this() CHILDREN;
// Description: // Description:
// Makes the children transparent for one level, reverting to the previous transparency state for further descendents. // Applies the `%` modifier to the children at a single level, reverting to the previous ghost state for further descendents.
// This works only with attachables and you cannot give the `%` operator anywhere in the geometry tree. // This works only with attachables and you cannot give the `%` operator anywhere in the geometry tree.
// Example(3D): // Example(3D):
// ghost_this() cuboid(10) // ghost_this() cuboid(10)

View file

@ -1609,6 +1609,14 @@ function real_roots(p,eps=undef,tol=1e-14) =
// x0 = endpoint of interval to search for root // x0 = endpoint of interval to search for root
// x1 = second endpoint of interval to search for root // x1 = second endpoint of interval to search for root
// tol = tolerance for solution. Default: 1e-15 // tol = tolerance for solution. Default: 1e-15
// Example(2D): Solve x*sin(x)=4
// f = function (x) x*sin(x)-4;
// root=root_find(f, 0,25); // root = 15.2284
// // Graphical verification
// stroke([for(x=[0:25]) [x,f(x)]],width=.2);
// color("red")move([root,f(root)])
// circle(r=.25,$fn=16);
// The algorithm is based on Brent's method and is a combination of // The algorithm is based on Brent's method and is a combination of
// bisection and inverse quadratic approximation, where bisection occurs // bisection and inverse quadratic approximation, where bisection occurs