struct M3VertexBlock
{
D3DXVECTOR3 position;
short value[12]; // array of unknown values. I try cast it's to normal and texture coordinates, but does't work. 6,7 - are texture coordinates /2048.
};
struct M3Header
{
char id[4];// id for file format.
uint32 tagsOffset;// offset to array of the tags.
uint32 nTags;// number of tags.
uint32 unknownValue_01;
uint32 unknownValue_02;
};
struct M3Tag
{
char tagName[4];// name ot the current tag.
uint32 blockOffset;// offset reference to the block with some data.
uint32 blockSize; // count of the block.
uint32 version;
};
void ReadFile(char* name)
{
char *fileData;
ifstream inStream;
inStream.open(name,ios::in | ios::binary);
inStream.seekg (0, std::ios::end);
int fileSize = inStream.tellg();
inStream.seekg (0, std::ios::beg);
fileData= new char[fileSize];
inStream.read(fileData,fileSize);
inStream.close();
M3Header headed;
memcpy(&header, fileData, sizeof(M3Header));
tags = (M3Tag *)(fileData+ header.tagsOffset);
M3VertexBlock* vertexBlock;
unsigned int nVertecesM3 = 0;
unsigned int nIndicesM3 = 0;
unsigned short * indexBlock;
bool firstIndexTag = false;
for(int i = 0; i < header.nTags; ++i)
{
if( tags[i].tagName[2] == '8') && (tags[i].tagName[3] == 'U') // __8U - reference to vertex data.
{
nVertecesM3 = (tags[i].blockSize)/sizeof(M3VertexBlock);
vertexBlock= (M3VertexBlock*)(fileData+ tags[i].blockOffset);
}
if((tags[i].tagName[1] == '6') && (tags[i].tagName[2] == '1') && (tags[i].tagName[3] == 'U')) // _61U - reference to index data.
{
if(firstIndexTag) continue;
firstIndexTag = true;
nIndicesM3 = tags[i].blockSize;
indexBlock = (short*)(fileData+ tags[i].blockOffset);
}
}
}
No comments:
Post a Comment