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

    Urgent - Is there a script to reset/zero all transformation?

    Scheduled Pinned Locked Moved Plugins
    23 Posts 5 Posters 1.7k 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

      Yeah, that would be my guess. I suppose a script could be written to go through and reset all scaling transformations to a more universal translation, instead of the SU shortcut of just adjusting the last element in the transofmration array to act as a global scale modifier. I had considered writing this plugin previously but I decided not to bother since it seems so rare to come by. But perhaps it would have its uses. This might be a good model to test it on.

      Chris

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

      1 Reply Last reply Reply Quote 0
      • PixeroP Offline
        Pixero
        last edited by

        Please do write it.

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

          I've alsmost got something ready for you to test. Does anyone know (I know you do!) what classes get listed in the model.definitions? I am planning on iterating through all definitions and then instances to straighten out their transformation. But I need to know what to weed out. I am guessing I would only include groups and components, is there anything else whose transformation might need to be reset?

          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

            The model.definitions returns a list of 'component_definitions' which includes all components, groups and images... you can test for the last two with .group? and .image?
            http://code.google.com/apis/sketchup/docs/ourdoc/componentdefinition.html

            TIG

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

              Well, I don't know if this is perfect. It should reset the scaling of all groups and components. Just enter this all as a single line of code into the ruby console.

              ins = [];Sketchup.active_model.definitions.each { |e| e.instances.to_a.each { |x| ins << x } };ins.each do |e| if (e.class == Sketchup;;ComponentInstance) || (e.class == Sketchup;;Group);old_t = e.transformation.to_a;old_t[15] = 1.0;ngsm = (1)/(e.transformation.to_a[15]);e.transformation = Geom;;Transformation.new(old_t);e.transform! Geom;;Transformation.scaling(ngsm,ngsm,ngsm);end;end
              
              

              Then try to re-export. I'll be interested to see if this changes anything. Thanks!

              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

                ok thanks TIG! I couldn't remember if it was more than just those 3 classes. In the end, I just filtered out anything that was not a group or componentinstance. I think that works out safely.

                And the theory behind what my code is fixing is simple. SU uses a cheap trick to sometimes adjust the global scale of objects. It just changes the 16 element of the transformation matrix from "1.0" to a global multiplier (0.5 if the component is scale 2x larger, for example). And then it multiplies the rest of the transformation object by that 16th element. BUT, the 16th element of the transformation array is ignored by most other apps. So when exporting to renderers, they often do not take into account that a component might have a global scale modifier applied to it, hiding in that 16th element. Thus they ignore the global scale entirely, causing problems.

                So this snippet will go through and determine what the global multiplier is, and apply it to the transformation matrix and reset the 16th element to 1.0. Thus the components should export correctly because all their scale data should be contained in the regular location inside the transformation matrix.

                We'll see if it really helps though.

                Chris

                PS. This snippet WILL fix face me components that rotate all crazy in SU 7.1, as that is also a side effect of SU's own cheap global scaling trick, if anyone is having problems with that.

                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

                  Did you get a chance to test this Jan?

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

                  1 Reply Last reply Reply Quote 0
                  • PixeroP Offline
                    Pixero
                    last edited by

                    @chris fullmer said:

                    Did you get a chance to test this Jan?

                    Sorry for not getting back.
                    I managed to export the scene in smaller chunks and am currently finishing it up in time for my deadline.
                    I will try it when things calm down later this week.
                    Thank you very much, I'm sure I will use this in the future.

                    1 Reply Last reply Reply Quote 0
                    • PixeroP Offline
                      Pixero
                      last edited by

                      @unknownuser said:

                      The best way to tackle this issue is to explode EVERYTHING. It takes a while, especially with larger models, but it's nearly full-proof. Same thing happens when exporting to certain other formats. The Group/Comps structure of SketchUp isn't translated properly. Exploding the model puts everything in one context.

                      You might want to have a look a TBD's Bomb script. It explodes everything without having to do it manually. It takes the same amount of time, but you can 'set-it-and-forget-it' and wait till it's done. Might be hours though.

                      HTH

                      The thing is I don't want to explode everything, since that removes any control over how lightmapping is applied on certain objects.
                      Anyway you can watch the result here:
                      http://forums.sketchucation.com/viewtopic.php?f=81&t=28907

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

                        Please oh pretty please try my code snippet? Just to see if it helps, or if it even just doesn't crash. I'd love to see if that little bit of code could fix it all.

                        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

                          Oh and maybe I didn't explain it well enough. It does not change anything visually in the model. It will all look exactly the same. Nothing gets exploded. So just run it, then re-export and see if it helps sort out the issues. Thanks!

                          Chris

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

                          1 Reply Last reply Reply Quote 0
                          • PixeroP Offline
                            Pixero
                            last edited by

                            @chris fullmer said:

                            Please oh pretty please try my code snippet? Just to see if it helps, or if it even just doesn't crash. I'd love to see if that little bit of code could fix it all.

                            Chris

                            I will I will. Next week I'll have to make some modifications so I'll have to re export at least parts of the scen. I will try it then if not before.

                            1 Reply Last reply Reply Quote 0
                            • PixeroP Offline
                              Pixero
                              last edited by

                              Chris, I tried the script but it didnt work. Same mess as before. 😕
                              Will try again later.

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

                                Bummer, I was very hopeful. Any chance you could forward me a copy of your model to test a few things on?

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

                                1 Reply Last reply Reply Quote 0
                                • PixeroP Offline
                                  Pixero
                                  last edited by

                                  I'll do that tomorrow.

                                  1 Reply Last reply Reply Quote 0
                                  • 1
                                  • 2
                                  • 1 / 2
                                  • First post
                                    Last post
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement