I enjoyed this tutorial. I actually modified the 'explode' module while watching it to make it cleaner. This one also centers perfectly for any number of objects except for 1, in which case it seems to do nothing. Here is the code: gist.github.com/damccull/1a1df5e785e56daf53e0d7b7d8ff219e module explode(distance = [10, 0, 0], center = false, enable = true) { if(enable){ offset = center ? (($children * distance) / 2 - distance / 2) * -1 : [0, 0 , 0]; for(i = [0 : 1 : $children - 1]) { translate(i * distance + offset) { children(i); } } } else { children(); } } A little vector math enables the use of a single 'offset' variable. Sane defaults prevent a user from unwittingly breaking the module, and I used an if/else rather than two if's.
Paul Randall thanks. I love sharing my way of coding something with people because I find it interesting to see how others code things, so I assume they're interested too.
Fantastic Video !. Thanks a lot for sharing with us your knowledge on this program. Every time I see a new feature of OpenSCAD *I like it MORE and MORE* Thanks again, and many greetings from Santiago de Chile, South America. I´m John.
3:00 - the reason you use $children-1 as the upper end of your loop is that you number children starting at 0. So, if you have five children, they are numbered 0,1,2,3, and 4. There is no child 5.
In your explode module, rather than duplicating the `for` loop, you could do a realDistance = enable ? distance : 0; Then translate by `realDistance`. If it is 0, then no translation happens.
Great stuff. I was going to make a couple comments that were already made (if/else, the ternary operation blah ? true : false, and arrays start at index 0, therefore len is always count - 1). The only thing left might be functionality that was added to openSCAD after u made this video (I have no idea), u can access a vector's first 3 elements with vector.x vector.y and vector.z
I enjoyed this tutorial. I actually modified the 'explode' module while watching it to make it cleaner. This one also centers perfectly for any number of objects except for 1, in which case it seems to do nothing. Here is the code:
gist.github.com/damccull/1a1df5e785e56daf53e0d7b7d8ff219e
module explode(distance = [10, 0, 0], center = false, enable = true) {
if(enable){
offset = center ? (($children * distance) / 2 - distance / 2) * -1 : [0, 0 , 0];
for(i = [0 : 1 : $children - 1]) {
translate(i * distance + offset) {
children(i);
}
}
} else {
children();
}
}
A little vector math enables the use of a single 'offset' variable. Sane defaults prevent a user from unwittingly breaking the module, and I used an if/else rather than two if's.
Paul Randall thanks. I love sharing my way of coding something with people because I find it interesting to see how others code things, so I assume they're interested too.
Fantastic Video !. Thanks a lot for sharing with us your knowledge on this program.
Every time I see a new feature of OpenSCAD *I like it MORE and MORE*
Thanks again, and many greetings from Santiago de Chile, South America. I´m John.
really nice tutorial, helped a lot
3:00 - the reason you use $children-1 as the upper end of your loop is that you number children starting at 0. So, if you have five children, they are numbered 0,1,2,3, and 4. There is no child 5.
Nice how you separate the explode module from the parts.
Great content but I can't see the code clearly. Perhaps with future videos increasing font size? Just a suggestion.
Put it in 720p and use glasses. Issue solved !.
The link to damccull at github is not working anymore
In your explode module, rather than duplicating the `for` loop, you could do a
realDistance = enable ? distance : 0;
Then translate by `realDistance`. If it is 0, then no translation happens.
Jeremy Starcher I had the same idea while watching this tutorial and Incorporated it into my modified example.
Great stuff. I was going to make a couple comments that were already made (if/else, the ternary operation blah ? true : false, and arrays start at index 0, therefore len is always count - 1). The only thing left might be functionality that was added to openSCAD after u made this video (I have no idea), u can access a vector's first 3 elements with vector.x vector.y and vector.z