[Code] orient_faces.rb v1.2
-
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_facesFeedback please...
EDIT:
v1.1 20090808 Algorithms improved - much faster.
v1.2 20120204 Checks of existing method!
orient_faces.rb -
@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
-
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...
-
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
-
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.
-
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
-
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.
-
-
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 nativeface.orient
orface.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 methodface.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... -
@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.)
Advertisement