SketchUp / sketchup-stl

A SketchUp Ruby Extension that adds STL (STereoLithography) file format import and export.
http://extensions.sketchup.com/content/sketchup-stl
MIT License
248 stars 68 forks source link

Bug/mirrored instances #141

Closed jimfoltz closed 9 years ago

jimfoltz commented 10 years ago

Correct the exported vertex order (winding) for flipped instances.

thomthom commented 10 years ago

Oops. I've totally forgotten about this! I'll look at it tomorrow.

jimfoltz commented 9 years ago

Is it tomorrow?

thomthom commented 9 years ago

Man - I'm really sorry for dropping the ball on this one! Code looks good, though I think the samedirection change is worth making.

jimfoltz commented 9 years ago

This is ready. Please, if there's just small changes go ahead and make them.

jimfoltz commented 9 years ago

I found a model[1] where the exporter fails to catch some mirrored, nested instances.

In the following image taken from NetFabb Basic. Image 1 is the our current master branch (ceb6dcf). Image 2 is with the 1st attempt at mirroring detection (1bf7ad0), and Image 3 is with this latest pull request (5927099). 2015-01_209

[1] https://3dwarehouse.sketchup.com/model.html?id=fd16cf692a4d8ec7697d7f9718010293

jimfoltz commented 9 years ago

I found this helpful: http://math.stackexchange.com/a/184479

thomthom commented 9 years ago

Hmm... so in the third, is it correct then?

jimfoltz commented 9 years ago

Yes, the third. Netfabb colors back faces red. If you examine the sketchup model, the red areas in the first image correspond to instances in the model. The instances are likely flipped, but I am not sure how to tell that from Sketchup.

thomthom commented 9 years ago

Maybe this helps? http://stackoverflow.com/a/17982272

jimfoltz commented 9 years ago

It does, thanks. Could vertex order be used to find reversed faces in a model?

thomthom commented 9 years ago

Not by themselves AFAIK - you need context. Someone contributed a really nice and fast algorithm to detect internal and reversed faces for Solid Inspector a couple of weeks ago - I've implemented it in SI 2.2. https://bitbucket.org/thomthom/solid-inspector/src/1aeb992d5087b96e8fcc148d40ed728ddb0d066d/src/tt_solid_inspector2/shell.rb?at=2.2

Though I'm not sure if that'll help for mirrored instances when we export - don't have just need to keep track of whether an instance if flipped?