• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Using Polygon Mesh

Scheduled Pinned Locked Moved Developers' Forum
11 Posts 6 Posters 2.0k 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.
  • A Offline
    ArjunaMeridian
    last edited by 9 Sept 2011, 20:01

    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
    • A Offline
      AdamB
      last edited by 12 Sept 2011, 08:48

      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 12 Sept 2011, 12:42

        @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
        • T Online
          TIG Moderator
          last edited by 12 Sept 2011, 13:08

          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
          • F Offline
            fredo6
            last edited by 12 Sept 2011, 13:34

            @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
            • T Offline
              thomthom
              last edited by 12 Sept 2011, 14:04

              @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
              • A Offline
                AdamB
                last edited by 12 Sept 2011, 14:45

                @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
                • T Offline
                  thomthom
                  last edited by 12 Sept 2011, 15:26

                  @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
                  • A Offline
                    AdamB
                    last edited by 12 Sept 2011, 19:30

                    @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
                    • T Offline
                      thomthom
                      last edited by 12 Sept 2011, 21:55

                      😆

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

                      1 Reply Last reply Reply Quote 0
                      • C Offline
                        Chris Fullmer
                        last edited by 13 Sept 2011, 00:26

                        @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
                        1 / 1
                        • First post
                          7/11
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement