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

    [Ruby] Surface

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 4 Posters 2.1k 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.
    • H Offline
      Hackbard_C
      last edited by

      Hello,

      i have a plenty of points and want to create a surface with the sketchup ruby api. How do i do this? I dont get a "nice version"..

      # points will be read from a file... pts = [] pts.push([0,0,0]) pts.push([0,9,0]) pts.push([9,9,10]) my_face = Sketchup.active_model.entities.add_face pts f_material = Sketchup.active_model.materials[0] f_material.color = "green" f_material.alpha = 0.5 my_face.material = f_material

      Of Course, this works, but how do i appendd another polygon? I have to loop, but creating evertime a new face? Actually... faces, polygons, entities.. where are the differences? What about hierachy?

      Programming in general is no problem, but i dont get the way of thinking in sketchup in my brain.. maybe there is a good tutorial? (I just found ruby-tutorials (i dont need) or sketchup tutorials (helpfully, but i want to use ruby with it!) and [0] is quite poor...)

      Regards,
      Hackbard_C

      [0] http://code.google.com/intl/de/apis/sketchup/docs/tutorial_geometry.html

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

        This might be better in the Ruby Forum...

        Without knowing what you want to end up with it's difficult to see what you want to do...

        Let's assume that you want lots of similar shaped faces, then make one and group it, copy the group and 'transform' it to where you want it/them etc...

        If you want to colour them do it now and then if appropriate explode the groups into one lump...

        What are you trying to do ?

        TIG

        1 Reply Last reply Reply Quote 0
        • H Offline
          Hackbard_C
          last edited by

          Ok, I'll start a thread at the ruby Forum, just thought of beeing a newbee in sketchp πŸ˜‰

          What I want to do? Making a Hull.. mhm.. maybe comparing with a terrain... there is a grid and each point has a specific height... and i have to triangulate this grid, but the grid I have is not a regular one, the points aren't equally distributed.

          i have points p1, p2, p3,... pN... and I know (p1,p2,p3) has to be a triangle, (p2,p3,p4) has to be a triangle.. and so on. I dont know how to do this with the Sketchup Api

          edit
          Ah, someone moved this topic - thanks!
          /edit

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

            Do you have to create your own ruby? Is there any reason you can't use an existing script?

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

            1 Reply Last reply Reply Quote 0
            • H Offline
              Hackbard_C
              last edited by

              Doing it myself is the better way... because maybe I need this for my master-thesis, however ouf course an existing script (with reference/author) is possible.

              But I need the source code too, so that I can adjust it to my needs.

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

                well, Didier made a script called "cloud.rb" - named because it takes a point cloud and turns it into a mesh. I have no idea what algorithm he uses to decide how to order his 3d points. It can be found on this page:

                404 Not Found

                favicon

                (www.crai.archi.fr)

                and scroll down looking for cloud v6.zip. I think he scrambled his script so you can't see the source code, but he might share it with you if you PM him and ask.

                Your code looks good though. The idea is right. Find 3 points and add a face. The tricky part is figuring out how to decide what 3 points to add - how to determine their proximity to each other so that you daont have a very messy TIN. But I bet there are published papers out there on this topic if you do need to write it all on your own.

                Hope that begins to help,

                Chris

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

                1 Reply Last reply Reply Quote 0
                • Didier BurD Offline
                  Didier Bur
                  last edited by

                  Hi Chris,
                  This is the Delaunay 2D triangulation algorithm that I used here.
                  Cheers,

                  DB

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

                    Oh great, thanks Didier! For more info on delaunay's method, check out the wikipedia page:

                    Link Preview Image
                    Delaunay triangulation - Wikipedia

                    favicon

                    (en.wikipedia.org)

                    So the idea would be to implement that process to determine what order to add the points to make faces. Probably add a face normal check to help make all faces point in the same direction.

                    Or just Didier's if you can get away with it πŸ˜„ It's pretty darn good,

                    Chris

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

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      Hackbard_C
                      last edited by

                      Thanks for your Replies πŸ˜„ But the "tricky part", the algorithm (Delaunay or something like this) is no problem for me.

                      In SketchUp is there something like GL_TRIANGLE_FAN or T_LINE_STRIP? Do I just have to loop the code I wrote in the first post? Or are there possibilities to do it a simpler way? To reduce code? Do it faster?

                      Hackbard_C

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

                        I think you are stuck with having to loop through the points to find the triangles you want to make faces from. You might be interested in the PolygonMesh class. It looks like it might be able to handle the mesh creation faster than just adding the faces directly.

                        http://code.google.com/apis/sketchup/docs/ourdoc/polygonmesh.html

                        @unknownuser said:

                        The PolygonMesh class contains methods to create polygon mesh structures. This is useful if you need to write a custom importer/exporter in Ruby that works at the level of triangulated polygons. For example, you can determine the triangles that make up a 15-sided SketchUp face by using this class, or write a SketchupImporter that reads a data file, creates a mesh from it, and draws faces based on the mesh.

                        IT also mentions in al old version of the API that you can pre-specify the amount of points and faces that are going to be added to the mesh to speed up the creation process.

                        Glad you can work out the delauney bit, I'm sure you'll get the SketchUp API under control in no time,

                        Chris

                        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