Sign in to follow this  
Mercenarey

Problem with Directx, Milkshape and Normals

Recommended Posts

I have been going over Brett Porter's Skeletal Animation demo. I am using DirectX. And this OpenGL snippet puzzled me: glBegin( GL_TRIANGLES ); {   for ( int j = 0; j < m_pMeshes[i].m_numTriangles; j++ )   {     int triangleIndex = m_pMeshes[i].m_pTriangleIndices[j];     const Triangle* pTri = &m_pTriangles[triangleIndex];     for ( int k = 0; k < 3; k++ )     {       int index = pTri->m_vertexIndices[k];       glNormal3fv( pTri->m_vertexNormals[k] );       glTexCoord2f( pTri->m_s[k], pTri->m_t[k] );       glVertex3fv( m_pVertices[index].m_location );     }   } } glEnd(); It seems, that for an indexed vertex you can pick a normal. This is a loose coupling compared to DirectX, where a vertex' normal is locked inside the vertex structure - and then it is cemented down in a locked vertexbuffer. The problem with this is, that shared Milkshape vertices can have different normals in different contexts/indices (for instance a sharp corner would have triangles sharing the same vertex, while having different normals), and this is well supported by OpenGL, while in DirectX, you can't simply unlock the vertexbuffer and alter the stuff constantly. The traffic over the bus would kill performance. So how the heck do I get around this? And how does directx' own .x format get around it? Should I duplicate those vertices that don't share normals? Thanx.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mercenarey
It seems, that for an indexed vertex you can pick a normal. This is a loose coupling compared to DirectX, where a vertex' normal is locked inside the vertex structure - and then it is cemented down in a locked vertexbuffer...

You can do the same thing in D3D by filling a vertex buffer every frame (which is pretty much what "immediate mode" OpenGL code does).

Quote:
Original post by Mercenarey
...The problem with this is, that shared Milkshape vertices can have different normals ... So how the heck do I get around this?


In both OpenGL and D3D, you have to duplicate the vertex if anything is different.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this