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

    Absolute vs. Relative Meshes/Groups

    Scheduled Pinned Locked Moved Developers' Forum
    2 Posts 1 Posters 9.5k Views 1 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.
    • K Offline
      kevd
      last edited by

      Me again, though with a completely different issue this time.

      I'm trying to write a script that computes a triangulation of the active model (using Face.Mesh), then outputs the vertices of the triangulation to a file. The script works perfectly fine for "simple" models -- that is to say, "models without any 'groups'." However, I discovered that if the model contains groups, the output is bizarre: all the geometries do get output to the file, but in a very distorted form. What seems to be happening is that the mesh that SketchUp outputs is relative to the group's coordinates, not the absolute coordinates of the world frame.

      I'm going to try doing it the "correct" way, i.e. store the transformation information of each group and apply this transformation to all vertices before writing to the file. However, I'm worried that this might be a little painful, especially because groups can be nested arbitrarily deep and my recursive programming skills are a little rusty. So, in the meantime, I was wondering if anyone knew of a way to force SketchUp to output absolute vertex information (or "relative to the global coordinate system") instead of relative to the group.

      Thanks a bunch again!

      Kevin

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

        Huh. Well. As it happens, it was much less painful adding in the transformation information than I thought: it works perfectly now.

        For anyone interested, just as an fyi, if you want to recapture the correct geometry, you have to transform the mesh according to the value returned by Group.transform, not the inverse of Group.transform. In other words, you want something like:

        
        t_matrix = Geom;;Tranformation.new
        def output_entity(entity, t_matrix)
          if entity.typename == "Group"
            t_matrix = t_matrix * entity.transformation  # <== *NOT* t_matrix * entity.transformation.inverse
            entity.entities.each{|sub_entity| output_entity(sub_entity, t_matrix) }
          elsif entity.typename == "Face"
            mesh = entity.mesh 0
            mesh = mesh.tranform! t_matrix
            # [Add output code here]
          end
        end
        
        

        Anyway, I'd still be curious if there's a more "internal" solution, but it seems like everything's working perfectly, and much less painfully than I'd expected.

        Kevin

        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