Problem with shadows cast from STL models

Problems building or running the engine, queries about how to use features etc.
Post Reply
andrewc
Gnoblar
Posts: 5
Joined: Tue Aug 18, 2015 11:18 am
x 1

Problem with shadows cast from STL models

Post by andrewc »

All,

I'm working on a mechanical simulation application using Ogre 1.9 in Windows, and have been experimenting with shadows. Since it's just a simulator, I don't need anything sophisticated, so I'm using SHADOWTYPE_STENCIL_ADDITIVE. That's to say, for my scene manager I call:

Code: Select all

m_ogreSceneManager->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
and for each of my entities I call:

Code: Select all

e->setCastShadows(true);
This works a treat for meshes that I have generated algorithmically, including bent and straight cylindrical tubes with thickness, and variously-shaped tooling for working the tubes. The shadows from these are exactly what I want. The problem is that my simulated machine assemblies, which are loaded from STL files (exported from SolidWorks) do not cast good shadows at all. Instead, they look like they've been attacked by giant spiders and had webs woven all over them, like this:
screenshot05232016_082729586.png
Has anybody come across this problem? Any idea how to fix it? My guess is that the problem is related to the way STL files only represent flat facets, with no sharing of vertices, and that means in effect that the meshes are full of tiny holes. On the other hand, I'm not sure how that would explain the effect I'm seeing.

All help much appreciated, thanks.

Andrew
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Problem with shadows cast from STL models

Post by dark_sylinc »

Hi Andrew,

First, 99% of geometry is fit for stencil shadow. Malformed geometry is among that 1%. It seems you're hitting worst case for some reason. Btw. if your model contains too many degenerate triangles, it could explain it.
Stencil shadows need "edge lists" which is a precomputed list of triangles that compose the external silhouette. I suspect this:
andrewc wrote: guess is that the problem is related to the way STL files only represent flat facets, with no sharing of vertices, and that means in effect that the meshes are full of tiny holes.
is confusing our edge list generator.

My best suggestion is to merge the vertices and try again.
I wrote a very simple generic routine to do it in real time; perhaps it's useful to you.
The project uses Ogre 2.1; but as you can see the routine is generic (it accepts pointers with streams of data) so it can be used even without Ogre.

I believe OgreMeshMagick had similar functionality (this is likely the relevant code).

My code only merges exact duplicates whereas Meshmagick's supports tolerance values (i.e. "if they're similar by X threshold, then merge")
andrewc
Gnoblar
Posts: 5
Joined: Tue Aug 18, 2015 11:18 am
x 1

Re: Problem with shadows cast from STL models

Post by andrewc »

Thanks very much for the reply. It's good at least to have my suspicions confirmed—i.e. that it's the STL meshing (or how SolidWorks uses STL) that's at the root of the problem. I'll do some further investigations into what I can do to improve that, with more confidence that I haven't just missed something obvious in Ogre! Thanks for the code, by the way, although I suspect that I don't need a real-time solution to the problem. I've written a bazillion Perl scripts that process STL files in interesting ways, so I will probably stick with that approach for improving the meshes.

Best regards,
Andrew
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Problem with shadows cast from STL models

Post by dark_sylinc »

Just by accident, I run into this term I had forgotten about; which could be related to your problem.

If your meshes contain non-manifold geometry, stencil shadows may not work correctly.
andrewc
Gnoblar
Posts: 5
Joined: Tue Aug 18, 2015 11:18 am
x 1

Re: Problem with shadows cast from STL models

Post by andrewc »

Thanks dark_sylinc for the further link. Looks like a well-informed and hopefully helpful resource.

I've since noticed that I get the same shadow issues (i.e. spidery lines) from loading one of the sample STL files (Laurana50k.stl) that comes with Meshlab, and I would have hoped that that was well-formed. Perhaps not. In any case, I will try to pursue this until I understand exactly what the problem is.

Andrew
andrewc
Gnoblar
Posts: 5
Joined: Tue Aug 18, 2015 11:18 am
x 1

Re: Problem with shadows cast from STL models

Post by andrewc »

This is what I get with the Meshlab sample file Laurana50k.stl.
Laurana50k.png
I've done some analysis on the mesh and I'm confident that it is not non-manifold nor malformed in any other way. No face has more than 3 neighbours and there are just a handful on the bottom edge with two or one. My STL import doesn't do any merging of vertices, so there are three vertices per face (around 50,000 faces, hence the filename) each with its own copy of the face normal. However, I have written a Perl script that traverses the mesh from face to face through connected edges (with no tolerance on vertex position—they must be exactly equal) and there is only a single connected surface that accounts for all faces.

Any further ideas as to what might be going wrong? It's hard to believe I'm the first person to load a mesh from an STL file using Ogre and to try to cast shadows from it using SHADOWTYPE_STENCIL_ADDITIVE. There are two directional lights, by the way, but the same problem occurs with a single one.

Cheers,
Andrew
Post Reply