sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Intersect_with question/problem

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 439 Views 3 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.
    • T Offline
      th3lurker
      last edited by

      So after another long deliberation i chose to use the add_faces_from_mesh or fill_from_mesh for that export i keep blabbering about. Sadly this creates a few problems, one of which is that i can't position textures directly, i have to go through the whole newly created faces list and position the texture on each of them. For that i have to keep track of the order in which the faces are added, cause there is no way to associate the polygon created for the mesh object with the face object generated when i create the mesh, except to remember the order in which they were created.
      The second problem i have, and the one i have questions about is cutting a hole. Seems easy, doesn't it? Well the mesh object google provides doesn't allow us to specify the "inner loops", unlike the unsupported C++ SDK. One option would be to use the usual add_face method, folled by add_face + erase for the holes. That slows down the export, so i have to try and find a different way. One way would be to add the faces from the mesh and then delete the holes. Thing is, if i add 2 polygons, let's say 2 squares, one smaller, inside the other one, no common points, when i create the mesh the two faces created overlap, but do not intersect, so deleting the smaller one makes no difference. Here i get to the intersect_with problem. I can't get it to work. Since i can't post from work (our ISP's IPs are all banned for some reason) i'll try and write the code from memory.

      model = Sketchup.active_model
      entities = model.active_entities
      
      pt1 = Geom;;Point3d.new 0,0,0
      pt2 = Geom;;Point3d.new 10,0,0
      pt3 = Geom;;Point3d.new 10,10,0
      pt4 = Geom;;Point3d.new 0,10,0
      pt5 = Geom;;Point3d.new 1,1,0
      pt6 = Geom;;Point3d.new 9,1,0
      pt7 = Geom;;Point3d.new 9,9,0
      pt8 = Geom;;Point3d.new 1,9,0
      
      mesh = Geom;;PolygonMesh.new
      mesh.add_polygon pt1,pt2,pt3,pt4
      mesh.add_polygon pt5,pt6,pt7,pt8
      
      group = entities.add_group
      group.entities.add_faces_from_mesh mesh,0
      #now i have to try and intersect the faces, actually i have to #intersect the 4 lines that make up the smaller square with the #face that is the larger square
      transformation = group.transform! #i forgot the exclamation #point at work....hmmmm
      #now if i provide the last parameter as an array of entities i #extract from group.entities, it crashes if i provide one or more #line objects in the list. if i only provide face object it #doesn't crash, but doesn't do anything either
      entityArray = Array.new
      entityArray.push group.entities[i] #with i i can select the lines 0-3,5-8 or the faces 4,9, i won't write that code
      entities.intersect_with true, transformation, group.entities, transformation, true, entityArray
      

      What am i doing wrong?

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

        transformation = group.transformation
        ...
        entityArray=group.entities.to_a
        ...

        TIG

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

          Let's assume that 'world' and 'holeface' intersect each other...
          Then you still need to do a 'intersect_with' the 'world' and 'holeface' meshes.
          Then the 'holeface' deletion would still leave the edges of the faces.
          You can get a references to these as say...
          togos=[]
          holeface.each{|face|
          face.edges.each{|e|
          togos << e if e.faces.length==1
          }
          }
          then use ...entities_erase(togos)
          AND worse it leaves extra faces if some are split... you can collect these by making an array of faces before the intersect_with and then an array afterwards.
          You then need to test this list to see it any of the 'new' faces need deleting - e.g. if they share planartity with those in the 'world' mesh maybe not???

          I see this as a flawed approach 😞

          TIG

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

            TIG may know the answer to this...

            What if you create 2 mesh objects .. "the world" and another for "the hole" ...

            Then:
            gents = group.entities gents.add_faces_from_mesh( mesh1 ) holeface = gents.add_faces_from_mesh( mesh2 ) gents.erase_entities( holeface )

            ??

            EDIT: Wont work because the dang API docs are wrong! .. again.
            add_faces_from_mesh() returns a Fixnum integer, not an array of the faces added.

            I'm not here much anymore.

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

              Success

              I let the explode do the intersect ...

              model = Sketchup.active_model
              ents = model.active_entities
               
              pt1 = Geom;;Point3d.new 0,0,0
              pt2 = Geom;;Point3d.new 10,0,0
              pt3 = Geom;;Point3d.new 10,10,0
              pt4 = Geom;;Point3d.new 0,10,0
              pt5 = Geom;;Point3d.new 1,1,0
              pt6 = Geom;;Point3d.new 9,1,0
              pt7 = Geom;;Point3d.new 9,9,0
              pt8 = Geom;;Point3d.new 1,9,0
               
              mesh1 = Geom;;PolygonMesh.new
              mesh1.add_polygon pt1,pt2,pt3,pt4
              
              mesh2 = Geom;;PolygonMesh.new
              mesh2.add_polygon pt5,pt6,pt7,pt8
              
              grp = ents.add_group
              gents = grp.entities
              gents.add_faces_from_mesh( mesh1 )
              
              grp2 = gents.add_group # nested group
              grp2.entities.add_faces_from_mesh( mesh2 )
              #
              holeface = grp2.entities.to_a.find_all{|e| e.is_a?(Sketchup;;Face)}
              grp2.entities.erase_entities( holeface )
              holeface = nil # so it's not pointing at a deleted entity
              holeloop = grp2.entities.to_a
              
              grp2.explode # merge with parent group
              togo = []
              grp.entities.to_a.each{|e|
                if e.is_a?(Sketchup;;Face) &&
                       e.edges == holeloop
                  togo << e
                end
              }
              grp.entities.erase_entities( togo )
              grp2 = togo = nil # GC
              

              I'm not here much anymore.

              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