Hi,
I'm wondering if it's possible to obtain any kind of data on an imported STL model? I'm thinking specifically of coordinates and dimensions. There's this script I'm working on that builds a simple structure around an imported STL. Right now it only works with models that lay flat on the z axis and centered on point (0,0) but I'd love to be able to automatically re-position and re-scale the added/subtracted volumes based on data from the imported model.
Thanks, Catarina
|
Hi Catarina, Hi Mailing list,
On Sun, Dec 06, 2009 at 12:44:23PM +0000, Catarina Mota wrote: > I'm wondering if it's possible to obtain any kind of data on an > imported STL model? I'm thinking specifically of coordinates and > dimensions. > > There's this script I'm working on that builds a simple structure > around an imported STL. Right now it only works with models that lay > flat on the z axis and centered on point (0,0) but I'd love to be able > to automatically re-position and re-scale the added/subtracted volumes > based on data from the imported model. unfortunately there is no support for something like that in openscad atm. it would be rather easy to add functions to read such data from stl files and return the data as vectors or numbers. But I would like it more to have a generic feature in openscad to extract such data from any 3d object. the biggest problem with implementing something like that is that it doesn't fit into the openscad syntax as it is in the moment. suggestions are very welcome! I'll start by outlining the first solution that I came up with: one idea would be to add a special operator that creates a value from an object tree. Example given with '@[ ... ]' as this operator: module obj1() { difference() { sphere(r = r1); cylinder(h = r1*2 + 1, r = r2, center = true); } } var r1 = 100, r2 = 20; var vol = volume(@[ obj1() ]); // Create a cube with the same volume as obj1() cube(pow(vol, 1/3)); The problem with this approach would be that it would make it much harder to find the corret evaluation order. At the moment, first all variables are evaluated and then the object tree is created. In this example obj1 depends on the variables r1 and r2 but the variable vol depends on obj1. one possible solution would be to switch the variables to be evaluated once they are accessed. this would 'unroll' the dependency chain automaticaly and still be compatible with the current behavior. however - I'm not quite sure if this is the right way to do it. I'm not sure how I would document this feature so everyone would understand it in its full extend. And that is always a bad sign.. ;-) as said: suggestions are very welcome! what do you think? yours, - clifford -- Reality corrupted. Reboot universe? (Y/N). |
that looks good, but would it be possible to have the syntax be this instead:
var vol = volume(obj1()); it would be really nice if modules and such could be treated as variables. of course i don't have to implement it, so whatever way you do will be best! Zach On Mon, Dec 7, 2009 at 6:41 AM, Clifford Wolf <[hidden email]> wrote: > Hi Catarina, Hi Mailing list, > > On Sun, Dec 06, 2009 at 12:44:23PM +0000, Catarina Mota wrote: >> I'm wondering if it's possible to obtain any kind of data on an >> imported STL model? I'm thinking specifically of coordinates and >> dimensions. >> >> There's this script I'm working on that builds a simple structure >> around an imported STL. Right now it only works with models that lay >> flat on the z axis and centered on point (0,0) but I'd love to be able >> to automatically re-position and re-scale the added/subtracted volumes >> based on data from the imported model. > > unfortunately there is no support for something like that in openscad atm. > it would be rather easy to add functions to read such data from stl files > and return the data as vectors or numbers. But I would like it more to have > a generic feature in openscad to extract such data from any 3d object. > > the biggest problem with implementing something like that is that it > doesn't fit into the openscad syntax as it is in the moment. suggestions > are very welcome! > > I'll start by outlining the first solution that I came up with: > > one idea would be to add a special operator that creates a value from an > object tree. Example given with '@[ ... ]' as this operator: > > module obj1() { > difference() { > sphere(r = r1); > cylinder(h = r1*2 + 1, r = r2, center = true); > } > } > > var r1 = 100, r2 = 20; > var vol = volume(@[ obj1() ]); > > // Create a cube with the same volume as obj1() > cube(pow(vol, 1/3)); > > The problem with this approach would be that it would make it much harder > to find the corret evaluation order. At the moment, first all variables are > evaluated and then the object tree is created. In this example obj1 > depends on the variables r1 and r2 but the variable vol depends on obj1. > > one possible solution would be to switch the variables to be evaluated once > they are accessed. this would 'unroll' the dependency chain automaticaly > and still be compatible with the current behavior. > > however - I'm not quite sure if this is the right way to do it. I'm not > sure how I would document this feature so everyone would understand it in > its full extend. And that is always a bad sign.. ;-) > > as said: suggestions are very welcome! > what do you think? > > yours, > - clifford > > -- > Reality corrupted. Reboot universe? (Y/N). > _______________________________________________ > OpenSCAD mailing list > [hidden email] > http://rocklinux.net/mailman/listinfo/openscad > |
In reply to this post by Clifford Wolf
Thanks Clifford. Being able to extract and use data from any 3D object would really rock. I'm not the right person to give you feedback on the best way to implement this, but I'm sure others more knowledgeable than me will chime in with good suggestions.
Catarina
On Mon, Dec 7, 2009 at 11:41 AM, Clifford Wolf <[hidden email]> wrote: Hi Catarina, Hi Mailing list, |
In reply to this post by Zach Smith
Hello,
On Mon, Dec 07, 2009 at 11:43:05AM -0500, Zach Smith wrote: > that looks good, but would it be possible to have the syntax be this instead: > > var vol = volume(obj1()); > > it would be really nice if modules and such could be treated as > variables. of course i don't have to implement it, so whatever way > you do will be best! like that is complicated because the system can't know at parse time if obj1() is a module instanciation or function call. but since value expressions have a very different syntax than object trees it should know it at evaluation time. but I just had this idea: it would be easy parse it with '{' ... '}' as convert-object-tree-to-value operator and since {...} is already used to group module instances in the object tree it maybe wouldn't feel like a new syntax but instead feel like an old well known syntax that is now also allowed in yet another place. So the statement would read: var vol = volume( { obj1(); } ); yours, - clifford -- +++>+>++++++[<+++++++>-]<..>++>++++++[<+++++>-]<.>>++++++[<+++++++++++>-]<. >++>>++++[<++++[<+++++++>-]>-]<<.>+>>++++[<++++[<++++++>-]>-]<<.++++++++.<- ---.>---.<<<<-.>>>>---.<---.<<.<+..>.>>---.>>++++>>++++[<++++[<+++++++>-]>- ]<<..----.<<<--------.<<++++..>>>>>+++++++...<<<<<-.>>>>.<++++.---.>+++..<+ +++++.+++.>--.<<<<.>>>>---.<++.<<<+.>>>>+.++++.---.<----.>>--.<<<<<.>.<---- ..>.>+++++++++.>>>>>>++++[<++++[<+++++>-]>-]<<.+++++.<<<<<<+.>.>.>-.--.+++. >++++++.+++.-------.<++.<<<.>.>>>.>-.<--.<<<<++..>.<---..>>>>>>>++++++++++. |
Free forum by Nabble | Edit this page |