Jump to content


Triangle Face Problem


  • You cannot reply to this topic
6 replies to this topic

#1 idreamlovey

    Member

  • Members
  • PipPip
  • 91 posts

Posted 08 July 2007 - 03:42 PM

I have a mesh of home exported from 3d max. I am using DrawIndexPrimitive to render the mesh. My problem is that some of the walls of home are visible and some are not. So i rendered with D3DCULL_NONE and here i see all of them are visible. As the vertices defined in clockwised can be only visible in my engine, so i figured out that some of vertices are not in clockwise order.
So i calculated in following way to detect whether the triangles are in clockwise or not:-
Here v1,v2 and v3 vectors are vertices of the triangle
e1 = v1-v3 and e2 = v2-v3
then i calculated the dot product of the e1 and e2 vertices that is
say dAngle = e1.e2
now i reversed the position of v1 and v3 of those whose dAngle found<0 in above calculation.
Now after that i see that those which are not visible becomes visible but then some of other becomes invisible(not all). Any solution for it to make all visible.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 08 July 2007 - 05:05 PM

The calculation you've done doesn't detect wrong winding, it just detects triangles where the angle at v3 happens to be > 90 degrees. There isn't any simple way to "detect" wrong winding since every triangle is wound counter-clockwise when you look at it from one side and clockwise when you look at it from the other.

To fix the problem you should go into 3DS Max, turn on the display of normals, and make sure all normals are pointing in a consistent direction (most likely outward). Reverse any faces that have a normal pointing in the wrong direction.

If the mesh is sufficiently well behaved (all in a single piece), you can do this automatically by crawling the mesh, starting from a single triangle that is known to have correct winding, and deducing the correct winding for each triangle adjacent to it, then all triangles adjacent to those, and so forth. But it's probably simpler just to do it by hand unless you have a LOT of data that needs to have its winding standardized.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 idreamlovey

    Member

  • Members
  • PipPip
  • 91 posts

Posted 10 July 2007 - 11:02 AM

In 3d max i unify the all normals and also checked out for the normals whether they are showing inwards or not. And there is no problem at all found. Also one more thing when i export them as xfile and i see that the mesh is visible with D3DCULL_CCW but when i rotate the mesh with 180 degree it is visible with D3DCULL_CW not D3DCULL_CCW. What can be the possible cause for this.

#4 idreamlovey

    Member

  • Members
  • PipPip
  • 91 posts

Posted 10 July 2007 - 11:03 AM

All normals in 3d max is showing outwards

#5 Nautilus

    Senior Member

  • Members
  • PipPipPipPip
  • 326 posts

Posted 10 July 2007 - 02:53 PM

Have you tried, then, to reverse them all (so to point INward), export the model as usual and load it in your renderer?

If that works, be sure you are using the right flags to convert the model from .3ds to .x ... IIRC there is a flag to ensure the correct normals' orientation.

Ciao ciao : )
-Nautilus

(readin' this? perhaps you should get out more -- give it a thought)


#6 idreamlovey

    Member

  • Members
  • PipPip
  • 91 posts

Posted 10 July 2007 - 03:02 PM

I tried to export only vertices of the data not indices and when i render the mesh by drawprimitive (no index as i was doing previosly) it appears working. But i want to use DrawIndexPrimitive.Previosly, In exporting the data first i was expoting the whole mesh vertices and then the face indices. In second attempt i am exporting the whole mesh faces vertices not indices just by replacing the indices of face directly by vertices. So i don't think that there could be any flaw in my ways of exporting the data. If it still there please tell where it could be.

#7 idreamlovey

    Member

  • Members
  • PipPip
  • 91 posts

Posted 19 July 2007 - 03:52 AM

You All are genious...

Yes it is correct that problem stands on exporting the data. I figured out that it occurs only in complex mesh data as i was taking the face normal to vertex. And by my algorithm, it was exporting lots of vertices unnessarily. Now i simply take out each vertex normal and everything is working fine. I get that previously i exported 5436 vertices and now it is 3544...

Thank u all for your such a hounable replies to my questions...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users