sketchucation logo sketchucation
    • 登入
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Transforming an array of points

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    27 貼文 7 Posters 773 瀏覽 7 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • jolranJ 離線
      jolran
      最後由 編輯

      Ah you mean put result in Hash ?

      start = Time.now
      newHash = {}
      10000.times {
      for i in 0...polygonials.length
        newHash[i] = polygonials[i].collect{|p| p.transform(tr) }
      end
      }
      puts "HASH Transforms And Collect; #{Time.now - start}"
      

      =>2.381

      1 條回覆 最後回覆 回覆 引用 0
      • G 離線
        Garry K
        最後由 編輯

        You could render the mesh after the timers to maintain benchmark validity.

        Have you tried traversing your polygons?
        mesh.polygon_points_at( index )
        Shouldn't this give you the same results as an outer_loop on a face?
        The question I would have is although you can get the points for each polygon - Is there a way to tie in a reference to the faces in the model once you have rendered the mesh?
        I would hope that the entities in the group immediately after a fill_from_mesh would be in mesh polygon index order. So there should be a 1 to 1 relationship.

        I haven't played with hashes yet - so my question is probably confusing to you. Although I've programmed for many years and also played with CAD for many years I've only logged 3 or so months with Sketchup since I got serious about it (guess I caught the Sketchup virus).

        1 條回覆 最後回覆 回覆 引用 0
        • jolranJ 離線
          jolran
          最後由 編輯

          @unknownuser said:

          You could render the mesh after the timers to maintain benchmark validity.

          Yeah, for those tests that edit in Place. Otherwise it would be too intense for Sketchup.

          @unknownuser said:

          The question I would have is although you can get the points for each polygon - Is there a way to tie in a reference to the faces in the model once you have rendered the mesh?

          I'm just moving Points in this code. I reckon you'd have to recollect faces afterwards
          and do some boolean tests. There's normal_at which could be used for ex.
          It all depends on (referring to your other question) if face order == polygon index order. I should test that as well unless someone else already knows..

          I'm pretty new to programming, so there can be lots of holes in the logic of my tests.
          But what better way to learn than trying to solve a problem, right?

          Hashes in Ruby are supposed to have much faster lookup than arrays. I think that's what Thomthom tried to point out earlier.

          1 條回覆 最後回覆 回覆 引用 0
          • tt_suT 離線
            tt_su
            最後由 編輯

            @garry k said:

            I think that we gain performance in the actual transform but may loose it accessing the points in the mesh.

            Geom::PolygonMesh.points? http://www.sketchup.com/intl/en/developer/docs/ourdoc/polygonmesh.php#points

            1 條回覆 最後回覆 回覆 引用 0
            • G 離線
              Garry K
              最後由 編輯

              Sorry - bad terminology. I was talking read and write access.
              the only write access we have is mesh.add_point.
              I'm still thinking as a C / C++ programmer.

              1 條回覆 最後回覆 回覆 引用 0
              • tt_suT 離線
                tt_su
                最後由 編輯

                @garry k said:

                Sorry - bad terminology. I was talking read and write access.
                the only write access we have is mesh.add_point.

                PolygonMesh.set_point
                http://www.sketchup.com/intl/en/developer/docs/ourdoc/polygonmesh.php#set_point

                1 條回覆 最後回覆 回覆 引用 0
                • jolranJ 離線
                  jolran
                  最後由 編輯

                  Yet Another test 👊

                  Don't know how reliable this test is but it appears face get appended in the same order as indexed in Polygonmesh. But Polygonmesh Count indexes starting at 1.

                  Edit: Updated for adding c_point in polygonmesh index as well. But wonder how hidden edges affect the Index ordering..

                  The API says:

                  @unknownuser said:

                  The negative values should not be used as an index for point_at, take the positive value of the index value in the polygon array

                  Perhaps hidden edges will only happend if mesh is constructed from a collection of Sketchup::Face's. Not relevant in this case.
                  In that case maybe use index.abs or perhaps double negation: index = index<0 ? -index : index

                  ents = Sketchup.active_model.active_entities
                  
                  def centerpoints(f)
                    cx = (f[0].x + f[1].x + f[2].x + f[3].x)/4
                    cy = (f[0].y + f[1].y + f[2].y + f[3].y)/4
                    cz = (f[0].z + f[1].z + f[2].z + f[3].z)/4
                    return Geom;;Point3d.new(cx, cy, cz)
                  end
                  
                  
                  face1 = [ 
                    Geom;;Point3d.new(-5,-5,0), Geom;;Point3d.new(5,-5,0),
                    Geom;;Point3d.new(5,5,0), Geom;;Point3d.new(-5,5,0) 
                  ]
                  
                  #create points for 4 faces
                  faceHash = {}
                  for i in (0...4) 
                     faceHash[i] = face1
                     face1 = face1.collect{|pt| pt.offset([20,0,0])}
                  end
                  
                  #get refference to the center of "face"#3 Before appending to mesh.
                  
                  fC = centerpoints(faceHash[2])
                  ents.add_cpoint(fC)
                  
                  # Bit strange to loop hash this way, but they get ordered.
                  msh = Geom;;PolygonMesh.new
                  for n in (0...faceHash.length)
                    msh.add_polygon(faceHash[n])
                  end
                  
                  #Test PolygonMesh index. How does hidden edges affect indexes for this ?
                  # +1 index for polygons in Mesh. 2 c_points should get added at same spot
                  meshface3 = msh.polygon_points_at(2+1)
                  mc = centerpoints(meshface3)
                  ents.add_cpoint(mc)
                  
                  
                  group = ents.add_group
                  group.entities.add_faces_from_mesh(msh)
                  faces = group.entities.grep(Sketchup;;Face)
                  
                  #Red material to face 3
                  faces[2].material = "red"
                  
                  
                  
                  1 條回覆 最後回覆 回覆 引用 0
                  • 1
                  • 2
                  • 2 / 2
                  • 第一個貼文
                    最後的貼文
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement