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

    [Plugin] triangulateFaces.rb v1.2 20101120

    Scheduled Pinned Locked Moved Plugins
    97 Posts 21 Posters 109.1k Views 21 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      Here's v2.0, now new improved - 'triangulates' [almost] everything...
      http://forums.sketchucation.com/viewtopic.php?p=169956#p169956

      TIG

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

        Thanks TIG, this is great!!!

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

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

          Here's v2.1, I've renamed the command triangulatefaces(array_of_faces) as 'triangulate' was already a defined command inside delauney/cloud scripts etc, used to triangulate points...
          http://forums.sketchucation.com/viewtopic.php?p=169956#p169956
          Please replace earlier versions with this new file to avoid clashes...

          TIG

          1 Reply Last reply Reply Quote 0
          • S Offline
            sepo
            last edited by

            Cheers Tig...nice one.

            1 Reply Last reply Reply Quote 0
            • C Offline
              CPhillips
              last edited by

              Here is the method I use:

              
              def triangulateFace(face)
                  ents=Sketchup.active_model.active_entities
                  faces=face.mesh.polygons
                  verts=face.mesh.points
                  faces.each{|f|
                      ents.add_line(verts[f[0].abs-1],verts[f[1].abs-1])
                      ents.add_line(verts[f[1].abs-1],verts[f[2].abs-1])
                      ents.add_line(verts[f[2].abs-1],verts[f[0].abs-1])
                  }       
              end
              
              

              The nice thing is it cant fail to triangulate regardless of the shape or number of holes. But it unfortunately adds faces to the "holes". Or rather Sketchup does. Does anyone a way to add an edge without Sketchup attempting the "heal" the face?

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

                I thought of that approach but abandoned it because of that facing hole problem...

                TIG

                1 Reply Last reply Reply Quote 0
                • K Offline
                  kwistenbiebel
                  last edited by

                  Thank you TIG for this plugin. 👍

                  Do we still need to add those extra lines in the ruby console to get the plugin in a menu?
                  I couldn't find it in the Plugins/Tools menu, thus my question...

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

                    @kwistenbiebel said:

                    Thank you TIG for this plugin. 👍

                    Do we still need to add those extra lines in the ruby console to get a menu?
                    I couldn't find it in the Plugins/Tools menu, thus my question...

                    'Triangulate Faces in Selection' should be in the Plugins menu...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • K Offline
                      kwistenbiebel
                      last edited by

                      Strange, I can't find it anywhere in my long long plugin list 😳 .
                      Maybe it clashes with some other plugin? (I do have WxSU installed which caused me trouble with other plugins in the past).
                      By the way, I am on SU6 Pro.

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

                        @kwistenbiebel said:

                        Strange, I can't find it anywhere in my long long plugin list 😳 .
                        Maybe it clashes with some other plugin? (I do have WxSU installed which caused me trouble with other plugins in the past).
                        By the way, I am on SU6 Pro.

                        If you have 2.1 open it in a text editor and read the last bit it should define the menu...

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • C Offline
                          CPhillips
                          last edited by

                          I finally figured out how to triangulate any face without the side effect of filling holes.

                          def triangulateFace(face)
                              mesh=face.mesh(1)
                              faces=mesh.polygons
                              verts=mesh.points
                              uvs=mesh.uvs(true)
                              outmesh = Geom;;PolygonMesh.new
                              faces.each{|f|
                                  outmesh.add_polygon(verts[f[0].abs-1],verts[f[1].abs-1],verts[f[2].abs-1])
                              }
                              ents=Sketchup.active_model.active_entities
                              mat=face.material
                              face.erase!
                              grp = ents.add_group
                              grp.entities.add_faces_from_mesh(outmesh)
                              grp.entities.each{|e|
                                  if(e.class==Sketchup;;Edge)
                                      e.smooth=false
                                      e.soft=false            
                                  elsif(e.class==Sketchup;;Face && mat!=nil)
                                         #handle materials and uvs.
                                      uva=verts.index(e.vertices[0].position)
                                      uvb=verts.index(e.vertices[1].position)
                                      uvc=verts.index(e.vertices[2].position)
                                      e.material=mat
                                      e.position_material(mat,[verts[uva],uvs[uva],verts[uvb],uvs[uvb],verts[uvc],uvs[uvc]],true)
                                  end
                              }
                              grp.explode
                          end
                          
                          1 Reply Last reply Reply Quote 0
                          • C Offline
                            Coronel
                            last edited by

                            Could you please clarify for a 3D newie the purpose of triangulation in this case?
                            Does it means the model will be correct or will work better or is merely a way of get more detail?

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

                              @coronel said:

                              Could you please clarify for a 3D newie the purpose of triangulation in this case?
                              Does it means the model will be correct or will work better or is merely a way of get more detail?

                              If you have a mesh that's rectangular it won't deform consistently. If you triangulate the faces they will... etc.

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • C Offline
                                CPhillips
                                last edited by

                                I needed the triangulation to prepare a model for export.

                                Thanks for incorporating it into your script TIG! Why is it that back facing UV's didn't work?

                                1 Reply Last reply Reply Quote 0
                                • C Offline
                                  CPhillips
                                  last edited by

                                  @tig said:

                                  @cphillips said:

                                  I needed the triangulation to prepare a model for export.

                                  Thanks for incorporating it into your script TIG! Why is it that back facing UV's didn't work?

                                  There is only a method to 'place material textures on a face' - and that assumes a 'front_face' - there's no 'back_face' method...

                                  Do you mean position_material? It takes a bool for front or back material

                                  http://code.google.com/apis/sketchup/docs/ourdoc/face.html#position_material

                                  1 Reply Last reply Reply Quote 0
                                  • I Offline
                                    ideas_arte
                                    last edited by

                                    Thanx really useful!

                                    where download? 😳

                                    1 Reply Last reply Reply Quote 0
                                    • J Offline
                                      Jim
                                      last edited by

                                      @ideas_arte said:

                                      where download?

                                      That's a valid question; it is not clear which version is the latest, and it is harder than necessary to locate the download.

                                      The download is about 5 posts before this one.

                                      Hi

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

                                        @cphillips said:

                                        I needed the triangulation to prepare a model for export.

                                        Thanks for incorporating it into your script TIG! Why is it that back facing UV's didn't work?

                                        There is only a method to 'position material textures on a face' - and that assumes a 'front_face' - there's no 'back_face' method ? ...

                                        TIG

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

                                          @cphillips said:

                                          @tig said:

                                          @cphillips said:

                                          I needed the triangulation to prepare a model for export.

                                          Thanks for incorporating it into your script TIG! Why is it that back facing UV's didn't work?

                                          There is only a method to 'place material textures on a face' - and that assumes a 'front_face' - there's no 'back_face' method...

                                          Do you mean position_material? It takes a bool for front or back material

                                          http://code.google.com/apis/sketchup/docs/ourdoc/face.html#position_material

                                          Duh! 😳 I'll adjust the code and re-post...

                                          TIG

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

                                            There's something afoot... What I posted before worked - on keeping the front face texture mapping but not on the back_face... Now when I try it it fails to map both faces ? Any ideas - CPhillips's idea worked fine in tests but now seems to fail...

                                            TIG

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

                                            Advertisement