Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem with triangle winding order:

Started by CodeReaver Jan 25, 2006 at 6:36 AM 1 replies 4.4k views
Original Post
CodeReaver
CodeReaver
I'm creating an exportor that takes data from one type of mesh file and and procuces an x file from that. However, it seems the x, y and z and in a different order in the other file than to x,y and z. It might be right hand coordinate system or something. It shows up fime in my viewer because I can adjust the culling or turn it off altogether, but when I load the produced x files in MeshView they appear inverted and you only see the faces that are pointed away from you. What I did was, at first the character I exported was showing up backwards and lying down, so I swapped the x, y and z coordinates around so he was stood up and facing forward. I'd had problems with the culling and I didn't notice I'd put the camera at x=1 instead of z=1, so when I fixed that, my character was facing backwards again. So I multiplied the y coordinates by -1.0 to fix that, but that caused I noticed the problem with the normals in MeshView. The swapping around and inverting of of the x, y and z coordinates gets done before the normals are calculated and saving to the x file happens last so I don't know what the problem is. Is there an automatic way of setting the images orientation for saving that doesn't cause the normals to invert. I want to save the orientation so it's starting from upright and facing forward before any transformations are applied. EDIT: I managed to get part way by myself. I think I need to reverse the triangle winding order, but I just need to find how to do that. It's in a mesh so I don't know if I'd need to change the indices or the vertices. It's only simple meshes I'm dealing with for now so vertices and indeces are all it has. What would be the fastest way if I want the saved mesh file to include the reversed order. [Edited by - CodeReaver on January 25, 2006 6:59:35 AM]
kovacsp
kovacsp
hi,

if you want to reverse your faces, then simply swap two of the three indices in your index buffer.

just like this:
void ReverseCulling(ID3DXMesh* p_mesh){	int			nFaces = p_mesh->GetNumFaces();	IndexBuffer indices(p_mesh, 0);	for (int i = 0; i < nFaces; i++) {		DWORD	tmp;		tmp = indices[i * 3];		indices[i * 3] = indices[i * 3 + 1];		indices[i * 3 + 1] = tmp;	}}


this code uses my IndexBuffer class, which is not relevant now, but you get the idea.

kp
------------------------------------------------------------Neo, the Matrix should be 16-byte aligned for better performance!
CodeReaver
CodeReaver
Thanks. I think the winding order was probably what was wrong.

EDIT: Yeah, that fixed it. The character is upright and facing forward in both my viewer and in MeshView now. The only thing is, even though I swapped the x, y and z coordinates around and reversed the winding order, I still would have thought I'd need to reflect the model in at least one axis to convert from right hand coordinates to left hand. Maybe the files I was importing from just used a weird format.

[Edited by - CodeReaver on January 26, 2006 7:09:07 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.