[Code] orient_faces.rb v1.2

[Code] orient_faces.rb v1.2

Postby TIG » Sat Dec 15, 2007 4:48 pm

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
1
Last edited by TIG on Sat Aug 08, 2009 10:55 am, edited 2 times in total.
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] orient_faces.rb

Postby Chris Fullmer » Sat Aug 08, 2009 8:43 am

TIG wrote: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
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Code] orient_faces.rb

Postby TIG » Sat Aug 08, 2009 10:36 am

I have just updated the script to v1.1 viewtopic.php?p=15273#p15273 - which has slightly different algorithms and is much faster and more reliable... Please try it... :ugeek:

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... :?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Code] orient_faces.rb

Postby Chris Fullmer » Sat Aug 08, 2009 5:34 pm

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
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Code] orient_faces.rb

Postby TIG » Sun Aug 09, 2009 3:25 pm

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.
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Code] orient_faces.rb

Postby Chris Fullmer » Sun Aug 09, 2009 5:03 pm

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
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Code] orient_faces.rb

Postby Dan Rathbun » Sat Feb 04, 2012 5:59 am



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. :x
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: [Code] orient_faces.rb

    Postby TIG » Sat Feb 04, 2012 1:14 pm

    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 ! :o
    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 viewtopic.php?p=15273#p15273 for v1.2...
    0
    TIG
    User avatar
    TIG 
    Global Moderator
     

    Re: [Code] orient_faces.rb

    Postby Dan Rathbun » Sun Feb 05, 2012 1:58 am

      Dan Rathbun wrote:This code extends API base class Sketchup::Face ...

      There should be warning, in the OP, and probably the file header doc. :idea:

      Dan Rathbun wrote:
      • without checking to see if the methods exist first,

      I knew you'd fix it promptly. :thumb:

      Dan Rathbun wrote:
      • despite that fact that TIG always tells others not to do this.

      Couldn't resist teasing. :P (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 wrote:This script is going my API doghouse list.

      I really do not have a "script dog house" list. (Have thought of doing one though.) :mrgreen:
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        SketchUcation One-Liner Adverts

        by Ad Machine » 5 minutes ago



        Ad Machine 
        Robot
         



         

        Return to Developers' Forum

        Who is online

        Users browsing this forum: No registered users and 16 guests