• Advertisement
Sign in to follow this  

surface normals

This topic is 2897 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, I have the following problem. I read triangles from a file. The structure of the file is similar to this: vertices: x1,y1,z1 x2,y2,z2 x3,y3,z3 . . . triangle idices: ("pointers" into vertex array) a,b,c d,e,f ... Now i'd like to calculate surface normals for this triangles to have a nicely lit object. But the problem is that some triangles are CW and some CCW. So some normals point in wrong direction. How would i go about fixing this? "Equalizing" normals across the surface of the object? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Where is the data coming from? Is there a particular reason why the triangles are not wound consistently?

Share this post


Link to post
Share on other sites
This is just some file found randomly on the net. I can not get better data, that's all i have. I can only fix this triangles automatically. Any idea how?

Share this post


Link to post
Share on other sites
Oh, one more this. This triangles form "closed" surface. So you will not find a triangle which has no adjacent triangles.

Share this post


Link to post
Share on other sites
Thanks,

i solved the problem by picking one triangle as "correctly oriented triangle" and then jumping to neighbours to check if their normal needed inverting. And then afcourse recurse onward.

Share this post


Link to post
Share on other sites
Another way to do it would be to cast a ray from the center (well, the center isn't particularly important, but it gives you a starting point) of every polygon out to infinity in any direction. Count the number of OTHER polygons it hits. If it hits an even number of polygons, the normal should be in on the same side of the polygon as the ray. This only works for closed surfaces.

Share this post


Link to post
Share on other sites
Yes, i know this approach. But the problem is that some meshes have holes in them so this would not be a good way of calculating normals. And i don't thing it would be faster than what i have now where i calculate normals for 300.000 triangles in ~~1sec.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement