• Login
sketchucation logo sketchucation
  • Login
๐Ÿค‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

[Plugin] Voxelize - Updated 2011-04-04

Scheduled Pinned Locked Moved Plugins
48 Posts 21 Posters 61.2k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    solo
    last edited by 22 Mar 2011, 16:06

    Cool, fun plugin.

    One problem it reverses faces on blue axis.

    http://www.solos-art.com

    If you see a toilet in your dreams do not use it.

    1 Reply Last reply Reply Quote 0
    • T Offline
      TheDro
      last edited by 22 Mar 2011, 16:22

      What do you mean by reverse faces? The cube faces? If you're talking about the image, it's not just a sphere, it's a sphere with a cylinder pushed into the top of it.

      1 Reply Last reply Reply Quote 0
      • S Offline
        solo
        last edited by 22 Mar 2011, 16:33

        No, see image, up faces are revered after operation.


        faces reversed.jpg

        http://www.solos-art.com

        If you see a toilet in your dreams do not use it.

        1 Reply Last reply Reply Quote 0
        • K Offline
          kdasilva
          last edited by 22 Mar 2011, 16:37

          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?

          1 Reply Last reply Reply Quote 0
          • S Offline
            solo
            last edited by 22 Mar 2011, 17:24

            Real fun to play with.

            Voxel turtle.


            voxel turtle.jpg

            http://www.solos-art.com

            If you see a toilet in your dreams do not use it.

            1 Reply Last reply Reply Quote 0
            • T Offline
              TheDro
              last edited by 22 Mar 2011, 17:27

              @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!

              1 Reply Last reply Reply Quote 0
              • D Offline
                Dan Rathbun
                last edited by 22 Mar 2011, 18:03

                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.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TheDro
                  last edited by 22 Mar 2011, 18:17

                  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.

                  1 Reply Last reply Reply Quote 0
                  • R Offline
                    Rich O Brien Moderator
                    last edited by 22 Mar 2011, 18:38

                    This screams out for Sketchy Physics to drop all those cubes.

                    Download the free D'oh Book for SketchUp ๐Ÿ“–

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      TheDro
                      last edited by 22 Mar 2011, 20:11

                      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?

                      1 Reply Last reply Reply Quote 0
                      • K Offline
                        Khai
                        last edited by 22 Mar 2011, 20:18

                        guys...

                        Minecraft!?!?!

                        if you can get this to save out to the Minecraft format...

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          Dan Rathbun
                          last edited by 22 Mar 2011, 20:33

                          @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

                          I'm not here much anymore.

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            Dan Rathbun
                            last edited by 22 Mar 2011, 20:39

                            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.)

                            I'm not here much anymore.

                            1 Reply Last reply Reply Quote 0
                            • D Offline
                              Dan Rathbun
                              last edited by 22 Mar 2011, 20:51

                              @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.

                              I'm not here much anymore.

                              1 Reply Last reply Reply Quote 0
                              • T Offline
                                TheDro
                                last edited by 23 Mar 2011, 04:10

                                @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.

                                1 Reply Last reply Reply Quote 0
                                • 2 Offline
                                  22curious
                                  last edited by 24 Mar 2011, 13:46

                                  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?

                                  1 Reply Last reply Reply Quote 0
                                  • T Offline
                                    TheDro
                                    last edited by 24 Mar 2011, 14:59

                                    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.

                                    1 Reply Last reply Reply Quote 0
                                    • D Offline
                                      Dan Rathbun
                                      last edited by 24 Mar 2011, 15:08

                                      @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.

                                      I'm not here much anymore.

                                      1 Reply Last reply Reply Quote 0
                                      • 2 Offline
                                        22curious
                                        last edited by 24 Mar 2011, 18:31

                                        @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.

                                        1 Reply Last reply Reply Quote 0
                                        • D Offline
                                          Dan Rathbun
                                          last edited by 25 Mar 2011, 21:16

                                          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

                                          I'm not here much anymore.

                                          1 Reply Last reply Reply Quote 0
                                          • 1
                                          • 2
                                          • 3
                                          • 1 / 3
                                          1 / 3
                                          • First post
                                            11/48
                                            Last post
                                          Buy SketchPlus
                                          Buy SUbD
                                          Buy WrapR
                                          Buy eBook
                                          Buy Modelur
                                          Buy Vertex Tools
                                          Buy SketchCuisine
                                          Buy FormFonts

                                          Advertisement