karl- / pb_Stl

STL import/export for Unity, supporting both ASCII and Binary.
MIT License
179 stars 43 forks source link

The Mesh direction is probably reversed. #9

Open rich-wan opened 6 years ago

rich-wan commented 6 years ago

The Mesh direction is probably reversed.

karl- commented 6 years ago

What app are you importing from?

rich-wan commented 6 years ago

@karl- OpenSCAD this is my test file Untitled.zip

rawnsley commented 5 years ago

@hsc0der is correct. The triangles in the example file have counter-clockwise winding order as required by the STL "standard". Here's the first facet:

solid OpenSCAD_Model
  facet normal 0 0 -1
    outer loop
      vertex 10 0 0
      vertex 15 0 0
      vertex 14.6722 -3.11868 0
    endloop
  endfacet
  ...

Looking back from the normal (sitting on the negative z axis) we can see a vertex that travels left (positive x), then down-right (negative x, negative y), which is in a counter-clockwise direction.

The binary importer is fine because you reverse the counter-clockwise points to be clockwise in order to match the Unity convention, but in the ASCII importer it looks like you reverse the direction, but actually you only reverse the lines of code (it's a classic error).

Happy make a pull request if it would make it clearer, but you may be looking at this area anyway for other reasons.