Original Post
Okay, so lately I've been rewriting my MS3D class to fit itself nicely for vertex arrays, I'm having a few issues in doing this, let me post some code.. This is the structure I will be holding the vertex information, I want to hold the xyz vertices, the xyz normals, the st tex coords, the rgba colors, and the BoneID for skeletal animation... The MS3D file structure is setup like this Right now I'm just worried about getting vertex info, normal info, and tex coord info.. I've managed to copy the vertex information successfully.. The normals and texture coordinates are a little more iffy, they are set up per triangle, not per vertex, I've thought of how I could throw everything into that one vertex loop, but somehow I'm not sure if that will be able to happen, here is how ms3d converts the information, (using identical structures).. How am I supposed to break these things down to being copied per vertex instead of copying them per triangle? Can anyone gimme a push in the right direction?
struct Vertex
{
float vx;
float vy;
float vz;
float nx;
float ny;
float nz;
float s;
float t;
unsigned char r,g,b,a;
int BoneID;
};
int NumVertices;
Vertex * Vertices;
// File header
struct MS3DHeader
{
char m_ID[10];
int m_version;
} PACK_STRUCT;
// Vertex information
struct MS3DVertex
{
byte m_flags;
float m_vertex[3];
char m_boneID;
byte m_refCount;
} PACK_STRUCT;
// Triangle information
struct MS3DTriangle
{
word m_flags;
word m_vertexIndices[3];
float m_vertexNormals[3][3];
float m_s[3], m_t[3];
byte m_smoothingGroup;
byte m_groupIndex;
} PACK_STRUCT;
// Material information
struct MS3DMaterial
{
char m_name[32];
float m_ambient[4];
float m_diffuse[4];
float m_specular[4];
float m_emissive[4];
float m_shininess; // 0.0f - 128.0f
float m_transparency; // 0.0f - 1.0f
byte m_mode; // 0, 1, 2 is unused now
char m_texture[128];
char m_alphamap[128];
} PACK_STRUCT;
// Joint information
struct MS3DJoint
{
byte m_flags;
char m_name[32];
char m_parentName[32];
float m_rotation[3];
float m_translation[3];
word m_numRotationKeyframes;
word m_numTranslationKeyframes;
} PACK_STRUCT;
// Keyframe data
struct MS3DKeyframe
{
float m_time;
float m_parameter[3];
} PACK_STRUCT;
int nVertices = *( word* )pPtr;
NumVertices = nVertices;
Vertices = new Vertex[nVertices];
pPtr += sizeof( word );
int i;
for ( i = 0; i < nVertices; i++ )
{
MS3DVertex * pVertex = ( MS3DVertex* )pPtr;
MS3DTriangle *pTriangle = ( MS3DTriangle* )pPtr;
Vertices.BoneID = pVertex->m_boneID;
Vertices.vx = pVertex->m_vertex[0];
Vertices.vy = pVertex->m_vertex[1];
Vertices.vz = pVertex->m_vertex[2];
pPtr += sizeof( MS3DVertex );
}
int nTriangles = *( word* )pPtr;
NumTriangles = nTriangles;
Triangles = new Triangle[nTriangles];
pPtr += sizeof( word );
for ( i = 0; i < nTriangles; i++ )
{
MS3DTriangle *pTriangle = ( MS3DTriangle* )pPtr;
int vertexIndices[3] = { pTriangle->m_vertexIndices[0], pTriangle->m_vertexIndices[1], pTriangle->m_vertexIndices[2] };
float t[3] = { 1.0f-pTriangle->m_t[0], 1.0f-pTriangle->m_t[1], 1.0f-pTriangle->m_t[2] };
memcpy( Triangles.Textures1, pTriangle->m_s, sizeof( float )*3 );
memcpy( Triangles.Textures2, t, sizeof( float )*3 );
memcpy( Triangles.VertexIndices, vertexIndices, sizeof( int )*3 );
pPtr += sizeof( MS3DTriangle );
}