From a13e2a7399e8ee8cc3e96e9f0d968ece5e8fbf75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dante=20Ursini?= Date: Mon, 17 Feb 2025 11:13:15 -0300 Subject: [PATCH] 3d Rendering fix --- titleBlock.scad | 185 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 133 insertions(+), 52 deletions(-) diff --git a/titleBlock.scad b/titleBlock.scad index b99c200..634eb52 100644 --- a/titleBlock.scad +++ b/titleBlock.scad @@ -1,14 +1,18 @@ include +include A4_LANDSCAPE= [297,210]; -debugging = false; +title_block_debugging = false; +experimental = true; module titleBlock( project, + title = undef, + description = "", textSize=6, date="2025-01-01", scale=1, @@ -17,87 +21,164 @@ module titleBlock( inset=10, anchor=CENTER, spin=0, - orient=UP + orient=UP, + color="Black", + strokeWidth = 0.5, + page="A4", + landscape = true, //anchor=CENTER,spin=0,orient=LEFT ) { w = rect[0]; h = rect[1]; _inset = inset> 0 ? inset : h/20; - echo("w",w); - echo("h",h); - echo("inset",_inset); - // Border - path = rect([w,h], chamfer=0 /*, anchor=FRONT*/); - //color("Blue") - - //back(-50/2) - - //square(rect, center=true); - - //attachable( anchor,orient,/*anchor, spin, orient,*/size=[w,h,0] /*,axis=RIGHT*/ ) { + //path = rect([w,h], chamfer=0 /*, anchor=FRONT*/); attachable(anchor,spin,orient, size=[w,h,50]) { - union() { - stroke(path, closed=true); + color(color) union() { + //recolor("Yellow") stroke(path, closed=true,width=strokeWidth); + rect_tube(size=[w,h], wall=0.5, h=0.1); // Title - translate([-w /2+_inset, h/2 - _inset ]) - text(project, size=textSize,halign="left",anchor=TOP); - // Revision - translate([-w /2+_inset, -h/2 + _inset]) - text(str("Revision:",revision), size=textSize*2/3/*,anchor=BOTTOM*/); + l1 = h/2 - _inset; + // ************ Project *************** + translate([-w /2+_inset, l1 ]) + linear_extrude(0.1) text(project, size=textSize,halign="left",anchor=TOP,font="Saira Stencil One"); + + metrics = textmetrics(project, size=textSize, font="Saira Stencil One"); // Scale - translate([w/2-_inset, h/2 - _inset]) - text(str("Scale: 1:",scale), size=textSize*2/3,halign="right",anchor=TOP); - // Date + //translate([w/2-_inset, h/2 - _inset]) + // ************ Scale *************** + translate([w/2-_inset, l1]) + linear_extrude(0.1) text(str("Scale: 1/",scale), size=textSize*2/5,halign="right",anchor=TOP); + + + // ************ Title *************** + l2 = l1 - metrics.size[1]- 2*_inset ; + if ( title ) + translate([-w /2+_inset, l2 ]) + linear_extrude(0.1) text( title, size=textSize*2/3,halign="left",anchor=TOP,font="Arial Black"); + + // ************ Description *************** + echo ("Description",description); + if ( description && false ) { + translate([ -8, l2 - _inset/2 ]) + linear_extrude(0.1) + smartText( + description, + size=textSize*1/4, + halign="left", + font="Arial", + //style="italic", + max_width = 51 + ); + } + + // ********** Horizontal line ********* + h1 = h/2-2*_inset - metrics.size[1]; + + if (false) stroke([ + [-w /2+_inset, h1], + [+w /2-_inset, h1] + ], + width=0.2); + + // Vertical sep + if (false) stroke([ + [-w/2+3*_inset+metrics.size[0] ,h/2-_inset], + [-w/2+3*_inset+metrics.size[0] ,h/2-2*_inset - metrics.size[1]]] + ,width=0.2); + + + // ************ Revision *************** + translate([-w /2+_inset, -h/2 + _inset]) + linear_extrude(0.1) text(str("Revision:",revision), size=textSize*2/5/*,anchor=BOTTOM*/); + + // ************ Date *************** translate([w/2-_inset, -h/2 + _inset]) - text(str("Date:",date), size=textSize*2/3,halign="right"); + linear_extrude(0.1) text(str("Date:",date), size=textSize*2/5,halign="right"); }; + children(); }; } -module A4( margin = 10, landscape = true, onlyMargin = true, anchor=CENTER, spin=0, orient=UP ){ - - //a4= [297,210]; +module A4( margin = 10, landscape = true, onlyMargin = true, anchor=CENTER, spin=0, orient=UP, scale=1, strokeWidth=0.2 ){ w = A4_LANDSCAPE[0]; h = A4_LANDSCAPE[1]; marginW = w-2*margin; marginH = h-2*margin; - contour = rect([w,h]); - //translate([w/2,h/2,0]) - //attachable(size=[100,200,0] ) { -// attachable( /*anchor=anchor, , spin, orient,*/size=[marginW,marginH,0] ) { - attachable(anchor,spin,orient, size=[marginW,marginH,50]) { - - union(){ - - if (!onlyMargin) color("Orange") stroke(contour, closed=true); - marginPath = rect([marginW,marginH]); - color("Red") stroke(marginPath, closed=true); + attachable(anchor,spin, orient, size=[marginW,marginH,50]) { + projection( cut = false ) union(){ + if (!onlyMargin) + color("Orange") + rect_tube(size=[w,h], wall=0.5, h=0.1); + color("Red") + rect_tube(size=[marginW,marginH], wall=0.5, h=0.1); }; - //} - children(); + children(); } } +module plan( + project, + title = undef, + description = "", + textSize = 6, + date = "2025-01-01", + scale = 1, + revision = "1a", + page = "A4" + + ) +{ + //rect=[90,30]; + + A4( onlyMargin = false, anchor=LEFT+FWD, scale=2 ) { + //align(align=TOP+LEFT+FWD,spin=[0, 0, 0],inside=true) + //attach(LEFT+FWD,/*RIGHT,inside=true*/) + //align(LEFT,inside=true) + align(FWD+RIGHT,inside=true) { + titleBlock( + project, + title = title, + description = description, + textSize = 7, + rect = [90,30], + inset = 2 + ); + + }; + align(BACK+LEFT,inside=true) { + children(); + } + + //cuboid([50,20,10],anchor=TOP); + //cube([100,100,100]); + //align(FWD+RIGHT,spin=[0, 0, 1],orient=UP) { + + //} + } +} + -if ( debugging ) { +if ( title_block_debugging ) { //titleBlock("My First Project"); - A4( onlyMargin = false,anchor=LEFT+FWD ) - //align(align=TOP+LEFT+FWD,spin=[0, 0, 0],inside=true) - //attach(LEFT+FWD,/*RIGHT,inside=true*/) - //align(LEFT,inside=true) - align(FWD+RIGHT,inside=true) - titleBlock("Metal Desk",textSize=7,rect=[90,30],inset=2); - //cuboid([50,20,10],anchor=TOP); - + lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at rutrum magna. Donec auctor euismod nulla ut congue."; + plan( + "Title Block", + title="Sub title", + description=lorem, + textSize=7, + //spin = 0 + //rect=[90,30], + //inset=2 + ) { - - + projection( cut = false ) cube([100,100,100]); + } }