Exporting solids & reversed faces
-
I'm using a third party library that takes triangulated manifold polyhedra as input. I have a SketchUp plugin that iterates through a solid's Faces, creates PolygonMeshes from them and then does a bit of cleaning up to link these PolygonMeshes together. No big deal.
Problem is when I reverse one of the faces inside SketchUp. Sketchup still considers this to be a solid but the PolygonMesh my script creates is also reversed and my thrird party library throws an error.
I know of two possible solutions to this but they are both heavy duty and a but ugly. I was hoping someone might have a better suggestion. The two I am aware of are:
- Draw lines along the normals of each face (From the face, outwards). Count the number of faces it intersects. Reverse if even, do nothing if odd.
2)Take one face as a reference. Make sure all adjacent faces are aligned similarly by checking the order of it's vertices. Iterate through the structure until all faces have been checked. If construction of polyhedron fails, reverse all faces.
-
I wrote a face.orient_faces method that is in a [Code] post, from over 6 years ago - learn to SCF search...
http://sketchucation.com/forums/viewtopic.php?p=15273#p15273
This mimics the native 'orient'.
Seems to me that since you will need to open these SKP files to see if they are OK [?] why not skip the awkward coding solution, use a style with a distinctly color back-face material, View>Monochrome mode and simply pick a right oriented face and use the native context-menu 'Orient' [you should have already set shortcut keys to 'Reverse' and 'Orient' !]... -
Cheers TIG. I did do a bit of SKF ploghing but obviously not enough.
This is all part of a plugin I've been developing (http://www.vistii.com) which relies on users supplying the solids. It seems a little cumbersome to keep telling users that their solids are not valid for some reason or another. It would be much nicer to clean up after them.
So, if you don't mind, I'll be mimicking your code. I don't want to take it "as is" since I don't want to monkey patch the Face class. Thanks for the help.
-
@noelwarr said:
- Draw lines along the normals of each face (From the face, outwards). Count the number of faces it intersects. Reverse if even, do nothing if odd.
You don't mean making actual edges, right?
-
No, just lines and using methods like Geom::intersect_line_plane and then checking weather the intersection lies withing the face itself. It's complicated and error prone (When lines intersect edges instead of faces) but can be made to work.
Advertisement