sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Using Polygon Mesh

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 6 Posters 2.0k Views 6 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.
    • A Offline
      ArjunaMeridian
      last edited by

      I'm a newbie to the terrific Sketchucation site and to ruby programming generally.

      My question:

      I'm writing ruby code where I would like to convert a selected face into a subset of either 1) points or 2) polygons and store them in an array. Then, I would like to iterate through the array and potentially color-code the points or polygons based on some arbitrary criteria.

      I've looked at the documentation for both the face.mesh method and the Polygonmesh class, but it isn't obvious.

      Thanks to anyone in advance for help

      1 Reply Last reply Reply Quote 0
      • AdamBA Offline
        AdamB
        last edited by

        If you just wish to color your model, you can just apply a new material to the Faces.

        Developer of LightUp Click for website

        1 Reply Last reply Reply Quote 0
        • A Offline
          ArjunaMeridian
          last edited by

          @adamb said:

          If you just wish to color your model, you can just apply a new material to the Faces.

          Yes, but if for example i had a landscape with changing lighting conditions and wanted to break up a selected face within the model into an arbitrary number (perhaps user defined) of polygons that I then could store in an array...how could I do this?

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            The polymesh way only triangulates the face - so a rectangle is simply split into two triangles - no more.
            If you want to divide a face into smaller faces there are already several examples - Thomthom has EdgeTools and there's my Quadrilateralizer - for two different approaches...
            To split a face you'll need to draw [looped] edges over it and use entities.intersect_with() - how you decide to divide up the face's edges etc is up to you...

            TIG

            1 Reply Last reply Reply Quote 0
            • fredo6F Offline
              fredo6
              last edited by

              @arjunameridian said:

              I'm writing ruby code where I would like to convert a selected face into a subset of either 1) points or 2) polygons and store them in an array. Then, I would like to iterate through the array and potentially color-code the points or polygons based on some arbitrary criteria.

              PolygonMesh will help you to triangulate any face, including with holes. This is only useful for painting, in particular when the face has concave sides or holes, but not for creating a geometrical mesh, because the triangulation is not well balanced.

              You can take inspiration of the following code. <triangles> will contain the triangles of the face.

              
              def triangles_of_faces(face)
                 mesh = face.mesh
                 pts = mesh.points
                 triangles = []
                 mesh.polygons.each do |p|
                    triangles.push p.collect { |i| pts[i.abs-1] }
                 end	
                 triangles
              end
              
              

              Fredo

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                @unknownuser said:

                but not for creating a geometrical mesh, because the triangulation is not well balanced.

                I've noticed that SketchUp often create less than ideal triangulation. You got an alternative triangulation method?

                Thomas Thomassen โ€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • AdamBA Offline
                  AdamB
                  last edited by

                  @thomthom said:

                  Re: Using Polygon Mesh

                  @thomthom said:

                  @unknownuser said:

                  but not for creating a geometrical mesh, because the triangulation is not well balanced.

                  I've noticed that SketchUp often create less than ideal triangulation. You got an alternative triangulation method?

                  It may not be perfect, but if you've ever written a general purpose, multi-boundary (with holes), arbitrary polygon triangulation function, you might want to walk (run?) away. There are so many nasty little corner cases that the fact that it largely works - with outline fonts too which generate seriously complex paths, is impressive.

                  Conditioning the aspect ratio of generated triangles so as to avoid "shards" with tiny interior angles and therefore very touchy vertex normals is absolutely a good thing. Just a lot of work to do.

                  But if you like, I've got code that handles quads ๐Ÿ˜„

                  Adam

                  Developer of LightUp Click for website

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    @adamb said:

                    But if you like, I've got code that handles quads ๐Ÿ˜„

                    Quads? Whatcha mean?

                    Thomas Thomassen โ€” SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • AdamBA Offline
                      AdamB
                      last edited by

                      @thomthom said:

                      @adamb said:

                      But if you like, I've got code that handles quads ๐Ÿ˜„

                      Quads? Whatcha mean?

                      You give me a four-sided polygon (quadrilateral) , and I'm sure I can stretch to writing code to break it into triangles. ๐Ÿ˜ฎ

                      Developer of LightUp Click for website

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        ๐Ÿ˜†

                        Thomas Thomassen โ€” SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • Chris FullmerC Offline
                          Chris Fullmer
                          last edited by

                          @adamb said:

                          @thomthom said:

                          @adamb said:

                          But if you like, I've got code that handles quads ๐Ÿ˜„

                          Quads? Whatcha mean?

                          You give me a four-sided polygon (quadrilateral) , and I'm sure I can stretch to writing code to break it into triangles. ๐Ÿ˜ฎ

                          ๐Ÿ˜„ Best response ever.

                          Lately you've been tan, suspicious for the winter.
                          All my Plugins I've written

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

                          Advertisement