A render function that returns geometries would also be handy
On Thu, 3 Oct 2019, 10:53 Torsten Paul, Torsten.Paul@gmx.de wrote:
On 03.10.19 15:08, shadowwynd wrote:
name = "Fred";
linear_extrude(2) text(name);
Specifically this and also all the other imports are
the most often asked candidates for querying geometry.
The thing is those are the most easy ones that can live
without as the data already exists and does not depend
on calculated geometry.
However to get the data out we need some more basic
ground work to be done in the language that allows the
data to be presented without ugly hacks that can never
be fixed.
I believe the changes to the parser that are currently
in progress plus the "objects" proposal from Doug should
allow import and text (and maybe others) to be used in
a function context returning an object that has both
the geometry as right now and also the additional raw
data about the glyphs.
While that is not a fully general solution, it should
cover quite a number of use cases while still fitting
into the OpenSCAD language without awkward and strange
workarounds.
If that all works out as I think remains to be seen
and also depends on the time that can be dedicated to
this.
ciao,
Torsten.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
On 2019-10-03 15:08, shadowwynd wrote:
Here's a simple example of why querying geometry would be useful.
Imagine a
rectangular key fob with the person's name extruded above the
rectangular
backing, and a 5mm margin on every side between the text and the
rectangle.
This is very much a "hello world" problem, and I see many kids doing
this as
a "my first 3d print" introduction.
That example is a close match to my sign generator with AngelCAD:
https://gist.github.com/arnholm/23c482530fd1882c615f5e6e3c9eedca
The train-derailing starts with this simple question: what are the
dimensions of the rectangle?
In the above example it is done by first computing the bounding box of
the resulting text and position and size the rectangle based on that.
Carsten Arnholm
shadowwynd wrote
Or you can size/scale it to fit a standard size fob, which distorts the
font.
Might it not make more sense to say "that's all Openscad is capable of".
Would a more perfect solution be used sufficiently often to justify the time
that would be required to implement it?
To my mind the attraction of Openscad is the ease with which it can be
learned. I am perfectly happy to live with some limitations on its
capability.
The important thing is to list the limitations up-front so that someone does
not waste time learning it and then run into a brick wall when they should
have given their time to learning a more traditional CAD program.
...R
--
Sent from: http://forum.openscad.org/
@nophead
I read but did not totally follow your plan for how you would do the 'robot
arm, ring example'
I am re-reading also studying-up on some points of OpenSCAD, now....
I am mostly a casual user and I am sure the issue is my inexperience with
the language. I have not really used OpenSCAD functions and I am only now
learning how the 'children' process works and as for using 'multmatrix' I
have never felt the need to use it, or maybe I did but didn't know it.
Do you have some simple code you could post that would show how you use
functions and positioning modules to achieve this? Obviously it doesn't
have to actually contain complex objects even simple rectangular cubes as
place holders would suffice. What I want to see is how you would nest these
positioning modules and use functions to feed position modules and return
positions to other modules needing the position information.
I would still like some ability to query objects, especially those that form
hard to compute (for me) angles or positions where I need to insert items.
Using the method you outline might suffice for many things that are done
100% OpenSCAD.
TIA
--
Sent from: http://forum.openscad.org/
There is a real world example here:
https://github.com/nophead/NopSCADlib/blob/master/printed/fixing_block.scad#L49
I have parametric fixing blocks with three screws positions.
I have functions that return the transformation matrices to get from the
block's origin to the screw positions.
function fixing_block_h_hole(screw = def_screw) =
translate(fixing_block_depth(screw) / 2) * rotate([90, 0, 0]); //!
Returns transform to position the horizontal screw
function fixing_block_v_holes(screw = def_screw) = //! Returns a list
of transforms to position the vertical screws
let(pitch = 2 * insert_outer_d(screw_insert(screw)) + 2 * wall,
offset = fixing_block_depth(screw) / 2)
[for(end = [-1, 1]) translate([end * pitch / 2, offset]) *
rotate([180, 0, 0])];
function fixing_block_holes(screw) =
concat([fixing_block_h_hole(screw)], fixing_block_v_holes(screw)); //!
Returns a list of transforms to position all the screws
Those functions are normally called by modules to place children at those
positions.
module fixing_block_h_hole(screw = def_screw) //! Position children on
the horizontal hole
multmatrix(fixing_block_h_hole(screw))
children();
module fixing_block_v_holes(screw = def_screw) //! Position children
on the vertical holes
for(p = fixing_block_v_holes(screw))
multmatrix(p)
children();
module fixing_block_holes(screw = def_screw) //! Position children on
all the holes
for(p = fixing_block_holes(screw))
multmatrix(p)
children();
These positioning modules are used to drill the holes in the block, place
the inserts in the holes and place the screws.
module fixing_block_assembly(screw = def_screw) //! Printed part with
the inserts inserted
assembly(str("fixing_block_M", 20 * screw_radius(screw))) {
translate_z(fixing_block_height(screw))
rotate([0, 180, 0])
color(pp1_colour) render() fixing_block(screw);
insert = screw_insert(screw);
fixing_block_v_holes(screw)
insert(insert);
fixing_block_h_hole(screw)
insert(insert);
}
They can also be used to drill holes in the panels they fasten to but there
is a problem: the positioning is 3D, but for speed I design my sheets in
2D. Originally I projected the holes to 2D but that is also slow.
My final solution was to factor out the position to functions that return
transformation matrices. Then when I design a box I build lists of these
transformation for all the fixing blocks in the box. For each panel I then
run through the list to see if they place a drill on the surface of the
sheet and if so position a circle to subtract from the sheet. I.e. I do the
projection myself because CGAL is too slow.
Here I build a list transforms to position all the blocks:
https://github.com/nophead/NopSCADlib/blob/master/printed/butt_box.scad#L74
With this function I multiply all the block positions by the screw
positions to get a list of all the block holes positions for the box:
function side_holes(type) = [for(p = fixing_block_positions(type), q =
fixing_block_holes(bbox_screw(type))) p * q];
Here, given the position of the sheet as a transform, I check if hole is
on the sheet, and if so drill it.
module drill_holes(type, t)
for(list = [corner_holes(type), side_holes(type)], p = list)
let(q = t * p)
if(abs(transform([0, 0, 0], q).z) < eps)
multmatrix(q)
drill(screw_clearance_radius(bbox_screw(type)), 0);
For each sheet I make a 2D object with the holes drilled in it.
module bbox_base_blank(type) { //! 2D template for the base
dxf(str(bbox_name(type), "_base"));
difference() {
sheet_2D(bbox_base_sheet(type), bbox_width(type), bbox_depth(type), 1);
drill_holes(type, translate(bbox_height(type) / 2));
}
}
Most of my objects are not this complicated though. They mostly just have
have modules to position their children with translate and rotate. If an
object only has screws in the Z plane then the positioning modules work for
both 2D and 3D. E.g.
module iec_screw_positions(type) //! Position children at the screw holes
for(side = [-1, 1])
translate([side * iec_pitch(type) / 2, 0])
children();
module iec_inserts(type) { //! Place the inserts
insert = screw_insert(iec_screw(type));
iec_screw_positions(type)
insert(insert);
}
On Thu, 3 Oct 2019 at 21:30, macdarren via Discuss <
discuss@lists.openscad.org> wrote:
@nophead
I read but did not totally follow your plan for how you would do the 'robot
arm, ring example'
I am re-reading also studying-up on some points of OpenSCAD, now....
I am mostly a casual user and I am sure the issue is my inexperience with
the language. I have not really used OpenSCAD functions and I am only now
learning how the 'children' process works and as for using 'multmatrix' I
have never felt the need to use it, or maybe I did but didn't know it.
Do you have some simple code you could post that would show how you use
functions and positioning modules to achieve this? Obviously it doesn't
have to actually contain complex objects even simple rectangular cubes as
place holders would suffice. What I want to see is how you would nest
these
positioning modules and use functions to feed position modules and return
positions to other modules needing the position information.
I would still like some ability to query objects, especially those that
form
hard to compute (for me) angles or positions where I need to insert items.
Using the method you outline might suffice for many things that are done
100% OpenSCAD.
TIA
--
Sent from: http://forum.openscad.org/
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
[ dimensions of text ]
Text is kind of a special case, in that its dimensions do not
straightforwardly depend on the inputs. (The same is true of the
boolean operations, but text metrics don't exactly depend on geometry.)
The "text metrics" problem would be solved by a function that accepted
the same parameters as text() and returned a vector of metrics.
I think the "query geometry" problem would probably be almost
completely solved with the bounding box of the output from render, or
something similar, especially if you can apply a rotation matrix to
the bounding box or to the object first.
This still doesn't help me snap to a tangent of a curve at an
intersection, but small steps...
On Thu, Oct 3, 2019 at 7:48 PM Jordan Brown
openscad@jordan.maileater.net wrote:
[ dimensions of text ]
Text is kind of a special case, in that its dimensions do not straightforwardly depend on the inputs. (The same is true of the boolean operations, but text metrics don't exactly depend on geometry.)
The "text metrics" problem would be solved by a function that accepted the same parameters as text() and returned a vector of metrics.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
In a recent design, I found that "text" can be usefully managed using
"resize". And its capability is useful (for the same reason) to imported STL
of unknown size (or size that has to be precisely assigned in openscad).
For example "resize" allows to explicitly resize an object on X axis,
proportionally auto-resize on Y axis, and not resize on Z axis.
resize([10,0,0], auto=[true,true,false]) cube([5,4,1]);
--
Sent from: http://forum.openscad.org/
Oh, I know resize, which is why I gave the example of:
name="Ro"
name="Pippinpaddleopsicopolis"
For instance, if I take a cube and rotate it 42° about the X axis, I can,
with trig, calculate the position of the top vertex. While this would be
much easier with some sort of [xmin,xmax,ymin,ymax,zmin,zmax] = bounds()
rotate([45,0,0]) cube(10); construction, it is perfectly doable via
(reasonably) simple math.
The problem is that OpenSCAD has operations that can not be calculated this
way (text(), surface(), import(), rands() (depending on usage), etc.) and
boolean/offset/minkowski operations in which the bounding box calculation
get downright freakish.
module tag(name, multiplier=7)
{
size = (len(name)*multiplier);
linear_extrude(2) resize ([size, 10, 0], auto=true) text(name,
valign="center");
difference()
{
color("yellow") translate ([-10, -10, 0]) cube ([10+size+5, 20, 1]);
translate ([-6, 0, -1]) cylinder (d=4, h=10, $fn=20, center=true);
}
}
tag("ro");
translate ([0, 25, 0]) tag("Pippinpaddleopsicopolis", 5);
http://forum.openscad.org/file/t486/pippinpaddle.png
--
Sent from: http://forum.openscad.org/