sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Transforming multiple vertices simultaneously?

    Scheduled Pinned Locked Moved Developers' Forum
    15 Posts 5 Posters 406 Views 5 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.
    • Chris FullmerC Offline
      Chris Fullmer
      last edited by

      Hi, I'm having a problem with transformation (ahhaha, why do I even attempt transformations....).

      Essentially, this snippet is doing most of the work, where verts is an array of vertices.

      verts.each do |e| x = e.position.x.to_f first_weight = x/120.0 second_weight = 1.0 - first_weight y_vec = Geom::Vector3d.linear_combination( first_weight, vec1, second_weight, vec2 ) t = Geom::Transformation.axes [60, 120, 0], [96.3726463410442, 71.5004408183896, 0.0], yvec, [0,0,1] ents.transform_entities(t, e) end

      Overall it is working pretty good except that I have a feeling I can't do the transformations one by one like I am doing. However, each transformation uses a different y-axis. I've attached pics of what is happening. All the vertices are moving to the right locations (I think), but its the bad triangulation and leftover faces that is telling me that I'm doing it wrong.

      before trans.jpg

      after trans.jpg
      (hmm, if you can't tell whats happening, the boxy shape thing is being transformed to fit into the lines at the top.)

      So my guess was that somehow I needed to apply the transformation to all vertices, with a different transformation for each, all at the same time. Am I headed in the right direction? Any help would be greatly appreciated.

      Chris

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

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        You should only call it once after the loop.

        
        end # of each loop, than call..
        ents.transform_entities(t, verts)
        

        Hi

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

          Yes, except that I am applying a differet transformation to each vertex. The y tranformation axis changes depending on the x position of the original vertex. So I was thinking I need to apply the transformation one by one to the vertices. Unless I could put the y-axis finding function inside a {proc} block inside the yaxis slot in the transformation. does that make any sense?

          Chris

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

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

            Hey Hey!, I founf that instead of running the transformation on the vertices directly, I could run it on point3d objects, and put the vector between the original vertex to the new vertes into an array. Then use:

            entities = entities.transform_by_vectors sub_entities, vector_array

            as a way to apply it to my vertex array, using the vector array, all in one shot, and my geometry comes out very clean! I think this is the approach I will take, unless someone has a better suggestion?

            Chris

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

            1 Reply Last reply Reply Quote 0
            • X Offline
              xrok1
              last edited by

              you wouldn't be trying soft selection transformations would you? ๐Ÿ˜›

              โ€œThere are three classes of people: those who see. Those who see when they are shown. Those who do not see.โ€

              http://www.Twilightrender.com try it!

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

                Sorry to disappoint, not soft selection at this point. The problem with soft selection is that the native SU tools won't recognize a soft selection. So that means that you have to rebuild the move, copy, scale, rotate, etc tools to work with the soft selection. And currently, I am sooo bad with the UI. Fredo has it down pat, but it will take some learning for me. So maybe in time, but for now I am working on a top secret project that is not soft selection. But its still cool.

                Chris

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

                1 Reply Last reply Reply Quote 0
                • X Offline
                  xrok1
                  last edited by

                  ๐Ÿ˜† can't blame me for trying.

                  anyway i'm sure what you're working on will keep me distracted for a good while while i wait ๐Ÿ˜‰

                  โ€œThere are three classes of people: those who see. Those who see when they are shown. Those who do not see.โ€

                  http://www.Twilightrender.com try it!

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by

                    @chris fullmer said:

                    Hey Hey!, I founf that instead of running the transformation on the vertices directly, I could run it on point3d objects, and put the vector between the original vertex to the new vertes into an array. Then use:

                    entities = entities.transform_by_vectors sub_entities, vector_array

                    as a way to apply it to my vertex array, using the vector array, all in one shot, and my geometry comes out very clean! I think this is the approach I will take, unless someone has a better suggestion?

                    Chris

                    So I understand, transform_by_vectors matches a each entity to a corresponding transformation by the index of the arrays? So that each entity is transformed one time?

                    I never thought of it like this. I had thought it applied each transformation to all entities so each entity would get transformed N time (assuming the transformation array had N elements.)

                    Another Aha! moment for me. Thanks.

                    Hi

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

                      That's very interesting.

                      And now I'm very curious to what Chris is cooking. Can I bribe you with a cookie?

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

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

                        @jim said:

                        So I understand, transform_by_vectors matches a each entity to a corresponding transformation by the index of the arrays? So that each entity is transformed one time?

                        Unfortunately (I think), it doesn't accept an array of entities and an array of transformations. It accepts an array of entities and an array of vectors.

                        So what I did was instead of running each transformation on each vertex one by one (which messes up the model), I created a new array of the vertex positions, then transformed all those point3d objects one by one (since that doesn't mess up anything in the model), and each time I wrote their vector change to an array:
                        positions_array.each do |e| original_position = e t = Geom::Transformation.axes point, xaxis, yaxis, zaxis new_position = e.transformation t vector = original_position.vector_to new_position transformation_vectors << vector

                        That gives me a corresponding vector for each vertex. So then I have my array of vertices, and their corresponding vector to move them by for the method:

                        entities.transform_by_vectors sub_entities, vector_array

                        And as a note, I left out a few lines of code that calculate the yaxis change for each transofrmation which is why I'm going through this process of finding the vectors. And at this point it looks like it works well. But its possible that I'll have to make tweaks (well, a massive overhaul is more likely for me really).

                        Hope that made sense,

                        Chris

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

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

                          I forgot to mention that since I have 3d positions for all the new vertices before I actually transform them, I think I should be able to add temporary .draw_line's or something to show the user where the geometry is planning on going before they commit to the operation.

                          I just need to figure out how on earth to implement the stupid .draw method....... ๐Ÿ˜•

                          Chris

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

                          1 Reply Last reply Reply Quote 0
                          • J Offline
                            Jim
                            last edited by

                            @chris fullmer said:

                            Unfortunately (I think), it doesn't accept an array of entities and an array of transformations. It accepts an array of entities and an array of vectors.

                            Yes, of course. I meantan array of vectors. Vectors are transformations in a way - they can be seen as directions from getting from point A to point B.

                            @chris fullmer said:

                            I just need to figure out how on earth to implement the stupid .draw method.....

                            If you mean the view.draw method - that only works from a Tool class.

                            Hi

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

                              yes, the view.draw method. I get confused with how it decides to execute or not. Or maybe I'm seeing things that are not really happening, or something like that. I don't have any great examples right now that I'm confused with, but I'm sure when I try to implement it, I'll come across some stuff that I'll need help with ๐Ÿ˜„

                              Chris

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

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

                                Isn't an easier way to find the required transformation of one vertex then group the vertices (by their edges ?) and rhen move the group by that transformation, finally then explode the group ?

                                TIG

                                1 Reply Last reply Reply Quote 0
                                • J Offline
                                  Jim
                                  last edited by

                                  Normally yes, but he wants to apply a different transformation to each vertex.

                                  Hi

                                  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