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

    [Code] orient_faces.rb v1.2

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 3 Posters 4.4k Views 3 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.
    • TIGT Offline
      TIG Moderator
      last edited by TIG

      Does what its name says:

      It matches the orientation of a face to any connected 'co-edged' faces.
      It mimics SketchUp's "Orient Faces" Tool.
      It can sometimes produce slightly different results when more than two
      connected faces share a common edge. Its results are equally logical,
      and who's to say how they should orient anyway ?
      You can call it from other scripts thus: face.orient_faces

      Feedback please...

      EDIT:
      v1.1 20090808 Algorithms improved - much faster.
      v1.2 20120204 Checks of existing method!

      orient_faces.rb

      TIG

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

        @tig said:

        Feedback please...

        Here's some timely feedback ๐Ÿ˜„

        Hey, great script. Can I include it in a little plugin package for a game exporter (free, using other pre-made plugins that are all licensed to distribute freely). I just thought I'd ask though.

        And, I am having some issues where if does not quite reverse all faces. My test model is a very messy triangluated mound of faces, but it is a clean model. I've attached it if you want to play with it.

        I hope to comprehend how it works some day. It is completely different than my face.normal vector comparison approach (which was too mathematically intense for me right now). So if you don't mind sharing the trick to what its doing .... I'd be happy ๐Ÿ˜„

        Thanks TIG!

        Chris

        Chris


        mound.skp

        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

          I have just updated the script to v1.1 http://forums.sketchucation.com/viewtopic.php?p=15273#p15273 - which has slightly different algorithms and is much faster and more reliable... Please try it... ๐Ÿค“

          Feel free to use the ideas in other scripts - an 'acknowledgement' would be nice... ๐Ÿ˜‰

          Basically it takes the face (self) and makes an array of 'all_connected' faces.
          It then makes other arrays of 'awaiting', 'processed' and 'done' faces. Some are initially empty, whilst others =[self]
          It then goes through those faces 'awaiting'.
          It has a subfunc 'flip_face' which compares if a face is 'reversed in the edge' with that of a neighbor-face - if match it reverses the neighbor-face; and moves faces between arrays.
          Then that face is 'done' and no longer 'awaiting'.
          It moves faces between the various arrays to reduce the lists to be processed or so as not to reprocess a face that's been already 'done'.
          It looks at the next face that's 'processed' but not 'done' etc etc.
          'Done' faces are removed from the 'awaiting' array until it's empty - when it's done...

          Clear as mud... ๐Ÿ˜•

          TIG

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

            Awesome TIG!, it now works much more reliably and much faster, as advertised!

            And I will definitely give acknowledgements for your script ๐Ÿ˜„ I still don't understand what that "reversed_in" method does though. I'll try to play more with it to understand it. But for now, I'm just happy it works ๐Ÿ˜„

            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 'reversed_in' function looks to see if a face's edge direction is equal to its normal. Like drawing edges clockwise and anticlockwise give different face normals. If both of an edge's faces have equal "reversed-ness" [doesn't matter whether they are 'reversed_in' the edge or not - it's their equality that we test for...] then one of the faces is reversed in it's normal compared to the other... since we know that the first face we have is already the way round we want it to be, we reverse! the second one... The algorithm takes face1 that we are orient-matching and finds all of its connected_faces and also its immediate_neighbor_faces and it reverses those if needed, then it finds those neighbor_faces' neighbor_faces and so on... until all of the connected_faces are oriented to match face1.

              TIG

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

                Thats great TIG, I had no idea what the reversed_in method was for. I was trying to figure that all out using face.normal, angle_between, linear_combination, on and on. It was not working out.

                But reversed_in, I like how that works. Thanks for having put this together and thanks for the update on it, it will be most useful in cleaning up models for game export!

                Chris

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

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  This code extends API base class **Sketchup::Face** ...

                  • without checking to see if the methods exist first,

                  • despite that fact that TIG always tells others not to do this.

                  This script is going my API doghouse list. ๐Ÿ˜ 

                  I'm not here much anymore.

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

                    Thanks for pointing this out...
                    In may defense, it was written a long time ago "before I 'saw the light'" [> 4 years!] ...
                    I'd all but forgotten about it; when I do use the basis of this code's ideas I have cannibalized bits of it into new methods anyway...
                    At the moment there isn't a native face.orient or face.orient_faces method [or anyone else's that I know of]... so we are safe ! ๐Ÿ˜ฎ
                    BUT it was easy enough to add the simple existing-method check...
                    I've now adjusted the code in v1.2, so it only adds to the base class IF the method face.orient_faces doesn't already exist.
                    Again any developer's can use the 'code' ideas in any way they see fit...
                    See here http://forums.sketchucation.com/viewtopic.php?p=15273#p15273 for v1.2...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      @dan rathbun said:

                      This code extends API base class **Sketchup::Face** ...

                      There should be warning, in the OP, and probably the file header doc. ๐Ÿ’ญ

                      @dan rathbun said:

                      • without checking to see if the methods exist first,

                      I knew you'd fix it promptly. ๐Ÿ‘

                      @dan rathbun said:

                      • despite that fact that TIG always tells others not to do this.

                      Couldn't resist teasing. ๐Ÿ˜› (I DID notice it was 4 years old.)

                      I still believe that adding methods like this, belong in a community project, like SKX. (I still have hopes of reviving that project, or starting a similar one.)

                      @dan rathbun said:

                      This script is going my API doghouse list.

                      I really do not have a "script dog house" list. (Have thought of doing one though.) ๐Ÿ’š

                      I'm not here much anymore.

                      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