sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Clone PolygonMesh

    Scheduled Pinned Locked Moved Developers' Forum
    23 Posts 4 Posters 919 Views 4 Watching
    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.
    • jolranJ Offline
      jolran
      last edited by

      Thanks a lot for the code Dan, I will definately test it!

      Doing mostly JS for the past 6 months, is the good old for loop abandoned in Ruby ? πŸ˜„

      The code:

      @unknownuser said:

      You need to "absolutify" each index, in case any edges are hidden

      Yeah, I noticed that. But it was a hard lesson learned.

      I'm revisiting old code and I see some comments regarding abs performance issues. ❓
      So for some reason I used this. However you abs method looks slicker.

      def self.positivVal(a)
          a = a < 0 ? -a ; a
      end
      

      To further clarify, this concerns my parametric node modeler( long going project unfortunately )
      It displays temporary geometry via the view draw class.

      So I have to build compatible arrays or hashes not only for the PolygonMesh but also for the view draw methods in the update methods.
      I've decided to build a solution for each node. So next node in "chain" that takes this polygonMesh as an input will have to be clone it.

      I'm using this code for that

      #Clone 1 mesh
      def self.clone_polyMesh(mesh) 
      	#Counts
      	npolys = mesh.count_polygons
      	#mesh
      	meshclone = Geom;;PolygonMesh.new( mesh.count_points, npolys )
      	for i in (1..npolys)
      		plps = mesh.polygon_points_at( i )
      		meshclone.add_polygon( plps )
      	end
      	meshclone
      end
      

      But your code looks more compact, so I might try that instead.

      ❓ The question is if I have to build the polygons until the mesh is baked ?
      Like the first code you posted Dan. For just adding points might be sufficient.
      Keep the polygonMeshes with points only. And when it's time to bake build the polygons.
      I might be overlooking something that must be done in the right context/scope....

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        Well this would be the simplest and avoid any abs issue:

        def self.clone_polyMesh(mesh) 
          meshclone = Geom;;PolygonMesh.new()
          for i in (1..mesh.count_polygons)
            meshclone.add_polygon( mesh.polygon_points_at(i) )
          end
          meshclone
        end
        

        P.S.: Ruby 2.0 has been optimized much more than the old Ruby 1.8 trunk.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          @jolran said:

          To further clarify, this concerns my parametric node modeler( long going project unfortunately )
          It displays temporary geometry via the view draw class.

          Have you seen:http://www.thomthom.net/software/vertex_tools/

          ❓

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • jolranJ Offline
            jolran
            last edited by

            That code looks compact enough. πŸ‘
            Does it matter for performance not providing arguments in PolygonMesh.new(), or is the docks wrong(again) ?

            @unknownuser said:

            P.S.: Ruby 2.0 has been optimized much more than the old Ruby 1.8 trunk.

            I know 😳 Still klingin on to SU8.. Poor old sod.

            And regarding that, I was looking for a way to iterate by 3 (for converting a quadpoints-array
            to tri-points-array that I can push to GL_TRIANGLES.)

            so each_slice(3) looked suitable. Turned out was only compatible with ranges for ruby 1.8.

            Edit: removed code that wasent working...

            @unknownuser said:

            Have you seen:http://www.thomthom.net/software/vertex_tools/

            Yeah! Amazing tool. He's draw class is an inspiration. I do have peeked inside there πŸ˜„

            updates:
            I forgot Polygonmesh removes duplicates. (It seams so anyway.)
            So it may be hard to recreate polygons later in another context without adding in the polygons..
            It's also peculiar to update the mesh points.
            Assuming the only way to edit/replace points is use of set_point(index, point) ?
            PolygonMesh.points.clear! would be good to have..

            1 Reply Last reply Reply Quote 0
            • jolranJ Offline
              jolran
              last edited by

              I'm toast.

              One cannot refresh the Polygonsmesh. Polygons keeps getting added even if updating points with setpoint(which make sense though). I presume there is no way to delete polygons ?
              I noticed cpu worked hard. So I counted polygons. + + + ++++ 😞

              I guess only way is to use PolygonMesh.new() at every update ?
              Not so funny since a sliderhandle may update values 100+ times in milliseconds..
              I'm not sure about best practices here, sounds expensive to create new objects frequently.

              Update: Polygonmesh.new() works.
              Don't know if there is any sideeffects appart form heavy GC lifting..
              Considering one often creates and dispose Point3d objects quite frequently I can't see why it couldent be done with a PolygonMesh πŸ˜•

              1 Reply Last reply Reply Quote 0
              • jolranJ Offline
                jolran
                last edited by

                Yey! It works! At least at Cube level πŸ˜›


                createcubemin1.gif

                1 Reply Last reply Reply Quote 0
                • jiminy-billy-bobJ Offline
                  jiminy-billy-bob
                  last edited by

                  Holy sheet!
                  I wanna play with this!! πŸ˜„

                  So how did you do the UI in the end? Is it a webdialog or external?

                  25% off Skatter for SketchUcation Premium Members

                  1 Reply Last reply Reply Quote 0
                  • jolranJ Offline
                    jolran
                    last edited by

                    Hi. Jiminy πŸ˜„ wasent expecting any response..

                    It's a standard webdialog. Pure JS and HTML.
                    The canvas and nodes are all SVG. Then the rest are plain html elements. like Tooltips, contextmenus etc.

                    I switched to D3.js. Not a compability layer, but have some nice selectors and methods.
                    It has such nice zooming and panning. Also very fast!
                    You should check it out! People think one can only use it with SVG, but that is not true.

                    It needed quite a bit of Javascript code to get the interaction working, since d3 is quite lowlevel. There are no solution for handling multiproperty nodes. There's layouts, but I'm basically only using the selectors and the zoom/pan functions.
                    Everything is programmed from scratch. Connections, nodes etc.. So I am expecting hickups here and there..

                    1 Reply Last reply Reply Quote 0
                    • jiminy-billy-bobJ Offline
                      jiminy-billy-bob
                      last edited by

                      Would you be willing to upload your project on github? I would love to take a look at how you did that. And maybe help if I can. πŸ˜„

                      If that's ok with you of course.

                      25% off Skatter for SketchUcation Premium Members

                      1 Reply Last reply Reply Quote 0
                      • jolranJ Offline
                        jolran
                        last edited by

                        No sorry.

                        I havent decided the future for this plugin yet. 😐

                        Was thinking a free version and then if things progress well maybe a more advanced Pro version. That will keep everyone happy.

                        That also means restrictions on the license, so Github will not fit.

                        I hope you understand. 😳

                        This may change. Plugin's status isent release ready anyway.
                        I did not post the gif to show off. Just was so god damn happy it worked I needed to share my joy.

                        BTW I appreciate you offering help. PM me for questions regarding code. No Problem.

                        1 Reply Last reply Reply Quote 0
                        • jiminy-billy-bobJ Offline
                          jiminy-billy-bob
                          last edited by

                          @jolran said:

                          I hope you understand. 😳

                          I completely understand! If you're going to monetize your work, don't make it public πŸ˜‰

                          I asked because I was thinking about a plugin using a similar node-based UI (A material editor for render engines). But I haven't found any convincing JS framework (You told me about JSplumb a while back, but it doesn't seem really strong and stable).
                          I guess I'll have to make my own, like you did πŸ˜„

                          As for the help I can provide, I'm curently working on a scattering plugin. So let me know if you have any question regarding this topic.

                          25% off Skatter for SketchUcation Premium Members

                          1 Reply Last reply Reply Quote 0
                          • jolranJ Offline
                            jolran
                            last edited by

                            πŸ˜„ Thanks for the understanding! It's a touchy subject.

                            A material editor! Is it possible to hook up to thoose from within Sketchup ? I thought they kept their code closed. The Render-engines that is.

                            Then, I shouldent rule out Jsplumb completely, if I was you.
                            It wasent an easy decision to restart from scratch and change library.
                            For the record I had no stability problems with Jsplumb. It was more a matter of performance in combination with JQ UI, and a few features I did not manage to implement.

                            A few things have changed since then for Jsplumb. It's not dependent of Jquery UI draggable for one. = faster.
                            It has Jquery style syntax, so you would feel at home directly, don't need to learn about SVG, if you don't know it already that is. Also more compatible with browsers than d3.
                            Has inbuilt events for connections, so it's MUCH easier to set up. But it's quite a large library. 10K +

                            So if you are not 100% dependent on zooming/multidragging go for jsplumb. At least give it a go. You will get going in a couple of days, Ive seen your layerspanel. No prob.

                            That said. You would have a lot of fun learning d3, when you passed the init threshold.
                            My goal was to learn as little as possible, cause it's easy to get stuck with experiments πŸ˜„ Amazing stuff they do..

                            Scattering plugin, you say. Sounds very interesting indeed. Can be as complex as you like it, I presume.

                            @unknownuser said:

                            So let me know if you have any question regarding this topic.

                            I sure will! And the same goes for you. Can PM snippets and shiat.. πŸ˜„

                            1 Reply Last reply Reply Quote 0
                            • jiminy-billy-bobJ Offline
                              jiminy-billy-bob
                              last edited by

                              @jolran said:

                              A material editor! Is it possible to hook up to thoose from within Sketchup ? I thought they kept their code closed. The Render-engines that is.

                              The data has to be stored somewhere. At least for Vray, the properties are stored as an XML structure in the material's attributes.

                              @jolran said:

                              So if you are not 100% dependent on zooming/multidragging go for jsplumb.

                              Well I think I would be. I mean, this king of UI without zooming is kind of cumbersome, don't you think?

                              Anyway, thanks a lot for all the tips πŸ˜‰

                              25% off Skatter for SketchUcation Premium Members

                              1 Reply Last reply Reply Quote 0
                              • jolranJ Offline
                                jolran
                                last edited by

                                @unknownuser said:

                                The data has to be stored somewhere. At least for Vray, the properties are stored as an XML structure in the material's attributes.

                                Allright!
                                Can't say I havent thought about the idea to include this functionality into the plugin,
                                to be honest.
                                But the risk of feature freenzy and bloat is to big, so I probably stick to only a design/modeling tool.

                                @unknownuser said:

                                Well I think I would be. I mean, this king of UI without zooming is kind of cumbersome, don't you think?

                                Yeah, I guess you are right. Come to think of it, you might be even more dependent of "special-nodes", displaying textures and stuff.

                                1 Reply Last reply Reply Quote 0
                                • tt_suT Offline
                                  tt_su
                                  last edited by

                                  For fastest performance of "copying" a PolygonMesh use the number of points and polygons in the new argument. Then populate the points and finally add the polygons with indices.

                                  I agree that it'd be nice to have .dup and .clone make a fresh copy.

                                  1 Reply Last reply Reply Quote 0
                                  • jolranJ Offline
                                    jolran
                                    last edited by

                                    Yes, Thanks. I used that and noticed some increase in performance.
                                    But I have kind of abandoned the PolygonMesh for now. At least during the previewing state.

                                    I experimented building my own meshclass with indexing of points. Instead of using PolygonMesh class as a Point container.

                                    Keep arrays of indexes and a Hash containing Points. And the Transformation only deals with the uniq points(Hash) then. Quite a lot of speed improvements!

                                    The advantage here is that I can reuse the objects somewhat, while I can't purge/clear(?) a PolygonMesh. So the GC should work a little less.

                                    I'm sure you guys have/are doing something similar or more advanced...

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

                                    Advertisement