[Plugin] Voxelize - Updated 2011-04-04
-
No, see image, up faces are revered after operation.
-
very cool!, you said each cube is an instance, could you swap out the definition to make an object composed to a bunch of tiny anythings? could auto scale the component to fit in your cube, then make all sorts of crazy things.
also, not that it matters, but it seems like the red face matches the red axis, but the blue face follows the green axis and the green face follows the blue axis. Intentional?
-
Real fun to play with.
Voxel turtle.
-
@kdasilva: I added the colors manually and arbitrarily just to make it easier to see which faces were in which direction. I thought of an autoscale feature but then thought it was better the way it is now although I could add that relatively easily, I think. It also wouldn't be difficult for the user to do the calculation on his own by setting the cube length to the length of the group divided by the number of cubes he wants. Could you suggest what options I should make available on the message box for such a features?
@solo: I was actually unaware that faces had a direction but I'll look into flipping them in the definition of the cubes.
Edit: This has been fixed and will be in the next release.Thanks for the input, guys!
-
I can think of a possible use for this.
If the components were lego blocks... a user could draw a 3D design of what they wanted to build, and then voxelize it in lego blocks.
If it were possible to "layerize" the voxelization, it may be easier for the user to actaully build the real deal using real lego blocks.
-
Well to "layerize", if by that you mean look at the model layer by layer, you can use the Section Plane tool. The plugin produces a 3D matrix of 1s and nils which could easily be manipulated, too. As for the lego blocks, that could be implemented by using this matrix in a clever way.
-
This screams out for Sketchy Physics to drop all those cubes.
-
Thanks for the changes, Dan. It's my first time programming in ruby and I'm still a bit iffy about modules and classes and when to use which. I've looked at some documentation about them but haven't had time to read it thoroughly. I've preceded my method names by td_ based on something I read in a thread around here having to do with name conflicts between plugins. Do I need to do that or can I skip it since my plugin is now in its own module?
-
guys...
Minecraft!?!?!
if you can get this to save out to the Minecraft format...
-
@thedro said:
I've preceded my method names by td_ based on something I read in a thread around here having to do with name conflicts between plugins. Do I need to do that or can I skip it since my plugin is now in its own module?
You can skip it now... since it's within it's own namespace, it cannot clash with any other method outside the namespace (including your other plugin submodules.) So td_voxelize() can become just plain ol' voxelize()
I wrote a couple of topics on using modules:
[info] Using Ruby Modules
[talk] Using Ruby Modules -
Another suggestion for the Undo operation:
(1) Define a module var @@op=0 (or whatever) at the top of the code.
(2) Then in your td_voxelize() method, wrap the operation in a begin .. rescue .. end block:
begin model.start_operation( "Voxelize(#{@@op+=1})" ) # .. voxelize code ... model.commit_operation rescue Exception => e model.abort_operation puts("Voxelize Operation Error; #{e.message}") return nil else # only executes if no errors occur return true # or whatever for success ensure # ALWAYS executes no matter what happens end # operation
(a) If any untrapped errors occur, the rescue clause will abort the operation (hopefully preventing model corruption.) Also if you do trap any errors that you feel should cause an abort, you can raise an exception (of some kind,) within the voxelize code, to cause execution of the rescue clause.
If you don't know which exception to raise, using RuntimeError is fine, and you can set the message to whatever suits your fancy:
raise(RuntimeError,"Some custom Voxelize Error Message here.")(b) The @@op counter gives each operation a unique name on the Undo stack. (Similar to when you open multiple new documents in an application. The first gets a name "untitled.doc", the second "untitled2.doc", etc.)
EDIT: Added the else and ensure clauses to example, so you can see where they'd go (if you use them.)
-
@thedro said:
It's my first time programming in ruby and I'm still a bit iffy about modules and classes and when to use which.
Generally...
If only 1 copy of the code is needed, it should be a module.
If more than one copy (instance,) is needed, it should be a class. (There are exceptions, the so-called "Singleton Classes" like TrueClass, FalseClass, NilClass and in practice, most Sketchup Tools should be written as a Singleton Class. For a Singleton, only 1 instance should be in existance any any given time.
The link in my signature line will lead you to a bunch of Resources. Tutorials and alot of books you can downlaod for free.
-
@Khai Hah! Minecraft is actually what first inspired me to write this plugin since it would be a relatively simple way of creating complicated geometries (building plans). It may have other applications though such as Monte Carlo simulation using Geant4. Geant4 is basically a particle physics toolkit that's used to simulate particles interacting with matter. Making geometry with the toolkit can be quite tedious to do code-wise and is far more difficult than using Sketchup. Making cubes is simple though and the application of my plugin is obvious in this case. Anyways, back to Minecraft . As for exporting to a compatible format, I would first have to figure out what that format is but I'm sure it wouldn't be too difficult since the plugin already creates a 3D "binary" matrix. I'll get to that ... eventually.
@Dan Thanks again. I'll get to reading your links concerning modules either tomorrow or the day after.
-
Thanks TheDro & Dan!
How about adding options for:
- spreading the cubes out, with inputs for x, y, and z separation spaces
- choosing which planes to slice, one, some, or all... x-z, y-z, x-y
?
Are there any existing plugins do these slicing, dicing, and spread-em-out actions?
-
Well it's possible to spread out the cubes just by modifying any one of the cubes since they are all instances of the same component. So you can double click on one of the cubes, then use the scaling tool to shrink it, and they will all shrink while remaining in position, and this will produce spacing between them all. As for the plane slicing, I'm not sure I follow. Could explain in more detail, 22curious?
I'll probably release a new version tonight that calculates the position of the cubes MUCH faster.
-
@thedro said:
I'll probably release a new version tonight that calculates the position of the cubes MUCH faster.
It is customary (here at SCF,) to replace the file in the first post of the topic, with the new version, and then edit the topic title (which only you can do because you "own" the topic,) to reflect the revision date.
Example revised topic title:
"[Plugin] Voxelize - Updated 2011-03-24"*** standard date format for Ruby is YYYY-MM-DD**
Then you can slide all the way down to the bottom of the webpage, and click the "Bump" link to bring the topic to the top of the forum list (without needing to post a new message.)
After you do that, I'll remove my version 1a and put a link back to the first post.
-
@unknownuser said:
spread out the cubes...double click on one...use scaling tool to shrink it.
This is where that Homer [doh] audio plugin button comes in handy. Of course!
'Wearing too many hats, my SKU skills are SKrUsty...@unknownuser said:
As for the plane slicing
My need may be met using asteronimo's SliceModeler.rb "plugin that slices a solid 3d model along 2 axes, f.i. an X- and a Z-axis." SliceModeler.rb is based on Tig's Slicer.rb (that isn't on the plugins list? but found at http://forums.sketchucation.com/viewtopic.php?f=180&t=10413&p=68825&hilit=slicer.rb#p688). I'm checking SliceModeler and Voxelize out now!...another path may be combining a lattice>>cutting component>>Tig's Hole punching Tool.
-
Made a few changes for you Andrew:
-
properly module wrapped the plugin.
-
cube size is remembered during session in var
@@cube_size
-
made it easier to control menu with constants defined at top of file
-
added validation for the menu item
I think the "group test" should fire before the inputbox is displayed.
But otherwise it looks good.
Latest version now in the first post
-
-
Very intesting plug-in, and practical too. I was looking for a quick way to place a repeating element on a sphere (in this case Clint Howard's ship from Star Trek TOS "The Corbomite Manuver"). I edited the cube and replaced it with a pyramid with geodesic spheres at each angle.
It turned what would have been a mind-numbing task into something trivial. Now all I have to do is upload it to the warehouse.
-
@Gillman: I'm glad to hear that it was of use to you.
@Khai: I've been looking at the structure of the .schematic file which is used to import structures into Minecraft using MCEdit. I think I've got it figured out but I still need to write the code and I'm reading the book of ruby to try and figure out the best way to do it.
@Everyone: I've added a new "spiral" algorithm to prevent interpreting sharp edges of solids as "entrances" to the solids. Basically, I improved the algorithm to work with more solids which is good. I'll upload the new version once I'm not too busy with work/school.
Advertisement