sketchucation logo sketchucation
    • Login
    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!
    ⚠️ Update | Sketchucation Tools 5.0.8 released with licensing improvements and bugfixes Download

    Global vertex position fails, when I pull a face

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 2 Posters 452 Views 2 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.
    • N
      niccah
      last edited by

      Hi!

      I have a problem with the global vertex positions....

      Initial situation:

      • a group with different faces inside
      • to get the global positions of the single verticies: group.transformation + vertex.position

      up till now: everything is fine...

      now I pull a face - the group gets larger - group.transformation changes.... AND the moved verticies get a NEGATIV value.

      Is there an easy possibility to "rearrange" the verticies? If not, I have to go over all verticies - get the smallest value and rearrange each value.

      Thanks a lot for your help!

      1 Reply Last reply
      Reply Quote 0
      • thomthomT
        thomthom
        last edited by

        Hard to tell what is going on here without seeing any code.

        But you are aware that then you open a group of component its coordinated are transformed into world coordinates automatically by SU?

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply
        Reply Quote 0
        • N
          niccah
          last edited by

          @thomthom said:

          Hard to tell what is going on here without seeing any code.

          But you are aware that then you open a group of component its coordinated are transformed into world coordinates automatically by SU?

          Okay, sorry, here more explanations with code:

          
          model = Sketchup.active_model
          groups = model.entities
          result = groups[0]
          
          UI.messagebox result.transformation
          
          entities = result.entities
          face = Array.new
          		
          # read all faces
          i=0
          entities.each do |tmp|
          if tmp.typename == "Face"
          	if tmp.normal[2] != 0
          		face[i]=Face.new(tmp)
          		i+=1
          	end
          end
          end
          
          

          And the class for faces:

          
          class Face
          	def initialize(face)
          		
          		vertices = face.vertices
          		
          UI.messagebox vertices[0].position
          	end
          end
          
          

          Now I start the code... everything is okay....
          then I pull a face manually in Sketchup and start the code again... every verticies has a different NOT GLOBAL position.

          I hope I could help you to understand my problem πŸ˜„

          Thanks a lot for your help!

          1 Reply Last reply
          Reply Quote 0
          • thomthomT
            thomthom
            last edited by

            hm... I'm not reading your code flow... I don't see anywhere where you apply any transformation to the vertex positions...

            Mind you, how are you comparing that the positions changed? There is nothing that guaranties that the entities and vertices will be returned in the same order after the model has been modified.

            btw, on a side note - .typename is a terrible performance killer. For more information: http://www.thomthom.net/thoughts/2011/12/never-ever-use-typename/

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply
            Reply Quote 0
            • N
              niccah
              last edited by

              @thomthom said:

              There is nothing that guaranties that the entities and vertices will be returned in the same order after the model has been modified.

              Yes, you're right and I know that - I just compared the minimum of (for example) y values.... at the beginning it should be 0 for some verticies. I pull a face and then the minimum of y is (for example) -10.

              @thomthom said:

              btw, on a side note - .typename is a terrible performance killer. For more information: http://www.thomthom.net/thoughts/2011/12/never-ever-use-typename/

              Oh, thanks a lot! I didn't know that! That's a great info! I will adjust my code.

              1 Reply Last reply
              Reply Quote 0
              • thomthomT
                thomthom
                last edited by

                @niccah said:

                @thomthom said:

                btw, on a side note - .typename is a terrible performance killer. For more information: http://www.thomthom.net/thoughts/2011/12/never-ever-use-typename/

                Oh, thanks a lot! I didn't know that! That's a great info! I will adjust my code.

                There's a whole lot more optimization tips in this thread: http://forums.sketchucation.com/viewtopic.php?f=180&t=25305
                And a nice list of other resources here: http://forums.sketchucation.com/viewtopic.php?f=180&t=10142

                Both are stickies in the Developer section.

                As for your original topic, I'm still not sure what we are dealing with. I think there's something in what you do which is an important clue to what you experience.

                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply
                Reply Quote 0
                • thomthomT
                  thomthom
                  last edited by

                  Hang on....

                  I think I might see what causes what you describe... you're not obtaining global coordinates at all. You're just looking at the local coordinates. You need to apply the transformation of the parent entities to the Point3d object.

                  When you then change the geometry in your group, you then offset it bounding box, affecting the coordinates. (If I understand this all right)

                  global_position = vertex.position.transform( parent_transformations )

                  Thomas Thomassen β€” SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply
                  Reply Quote 0
                  • N
                    niccah
                    last edited by

                    @thomthom said:

                    Hang on....

                    I think I might see what causes what you describe... you're not obtaining global coordinates at all. You're just looking at the local coordinates. You need to apply the transformation of the parent entities to the Point3d object.

                    When you then change the geometry in your group, you then offset it bounding box, affecting the coordinates. (If I understand this all right)

                    global_position = vertex.position.transform( parent_transformations )

                    Uhh jeah - I think that's the point I looked for! I didn't know that I can transform the position it self - but that's exactly that I want!

                    Thanks a lot!

                    And thanks for all your tips for optimizations!

                    1 Reply Last reply
                    Reply Quote 0
                    • thomthomT
                      thomthom
                      last edited by

                      Note that the method doesn't transform the point itself - but returns a copy.

                      Thomas Thomassen β€” SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply
                      Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better πŸ’—

                      Register Login
                      • 1 / 1
                      • First post
                        Last post
                      Buy SketchPlus
                      Buy SUbD
                      Buy WrapR
                      Buy eBook
                      Buy Modelur
                      Buy Vertex Tools
                      Buy SketchCuisine
                      Buy FormFonts

                      Advertisement