Enhanced show_anchors() to handle 2d.

This commit is contained in:
Garth Minette 2020-12-27 21:52:13 -08:00
parent b518763d6f
commit f30e46e3ac
2 changed files with 19 additions and 9 deletions

View File

@ -274,7 +274,7 @@ function standard_anchors(two_d=false) = [
// Module: anchor_arrow() // Module: anchor_arrow()
// Usage: // Usage:
// anchor_arrow([s], [color], [flag]); // anchor_arrow(<s>, <color>, <flag>);
// Description: // Description:
// Show an anchor orientation arrow. // Show an anchor orientation arrow.
// Arguments: // Arguments:
@ -303,7 +303,7 @@ module anchor_arrow(s=10, color=[0.333,0.333,1], flag=true, $tags="anchor-arrow"
// Module: anchor_arrow2d() // Module: anchor_arrow2d()
// Usage: // Usage:
// anchor_arrow2d([s], [color], [flag]); // anchor_arrow2d(<s>, <color>, <flag>);
// Description: // Description:
// Show an anchor orientation arrow. // Show an anchor orientation arrow.
// Arguments: // Arguments:
@ -312,7 +312,7 @@ module anchor_arrow(s=10, color=[0.333,0.333,1], flag=true, $tags="anchor-arrow"
// Example: // Example:
// anchor_arrow2d(s=20); // anchor_arrow2d(s=20);
module anchor_arrow2d(s=15, color=[0.333,0.333,1], $tags="anchor-arrow") { module anchor_arrow2d(s=15, color=[0.333,0.333,1], $tags="anchor-arrow") {
noop() stroke([[0,0],[0,s]], width=s/10, endcap1="butt", endcap2="arrow2"); noop() color(color) stroke([[0,0],[0,s]], width=s/10, endcap1="butt", endcap2="arrow2");
} }
@ -341,18 +341,28 @@ module show_internal_anchors(opacity=0.2) {
// Example(FlatSpin): // Example(FlatSpin):
// cube(50, center=true) show_anchors(); // cube(50, center=true) show_anchors();
module show_anchors(s=10, std=true, custom=true) { module show_anchors(s=10, std=true, custom=true) {
check = assert($parent_geom != undef) 1;
two_d = attach_geom_2d($parent_geom);
if (std) { if (std) {
for (anchor=standard_anchors()) { for (anchor=standard_anchors(two_d=two_d)) {
attach(anchor) anchor_arrow(s); if(two_d) {
attach(anchor) anchor_arrow2d(s);
} else {
attach(anchor) anchor_arrow(s);
}
} }
} }
if (custom) { if (custom) {
for (anchor=select($parent_geom,-1)) { for (anchor=select($parent_geom,-1)) {
attach(anchor[0]) { attach(anchor[0]) {
anchor_arrow(s, color="cyan"); if(two_d) {
recolor("black") anchor_arrow2d(s, color="cyan");
} else {
anchor_arrow(s, color="cyan");
}
color("black")
noop($tags="anchor-arrow") { noop($tags="anchor-arrow") {
xrot(90) { xrot(two_d? 0 : 90) {
up(s/10) { up(s/10) {
linear_extrude(height=0.01, convexity=12, center=true) { linear_extrude(height=0.01, convexity=12, center=true) {
text(text=anchor[0], size=s/4, halign="center", valign="center"); text(text=anchor[0], size=s/4, halign="center", valign="center");

View File

@ -8,7 +8,7 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,483]; BOSL_VERSION = [2,0,484];
// Section: BOSL Library Version Functions // Section: BOSL Library Version Functions