3DS loading. Yet again......
I've restarted with loading 3ds files and has written a new 3DS loader. The problem is that the loader can find the objects, but not the objects' TriMesh chunk. (or any of its sub-chunks)
If I try to find EDIT_OBJ subchunks, it only loads the first object, but then stops the program since it seems to have reached end of the file.
Any ideas?
Heres the code:
///////////////////////////////////////////
ProcessChunks(FILE *file)
{
CModel_3DS_Chunk chunk;
int read = 0;
while (fread(&chunk,sizeof(CModel_3DS_Chunk),1,file))
{
switch(chunk.id)
{
case MAIN3DS:
{
printf("Main3DS\n");
}
break;
case EDIT3DS:
{
printf("\tEdit3DS\n");
}
break;
case 0x3D3E: // Mesh Version;
{
fseek(file, (chunk.size - sizeof(CModel_3DS_Chunk)), SEEK_CUR);
}
break;
case EDIT_OBJ:
{
printf("\t\tObject name: '%s'\n",ReadString(file,&read));
}
break;
case OBJ_TRIMESH:
{
printf("\t\tTriangular Polygon List\n");
}
break;
default:
{
fseek(file,(chunk.size - sizeof(CModel_3DS_Chunk)),SEEK_CUR);
}
break;
}
}
return(1);
}
///////////////////////////////////////////
End Code.
Js
Heres the code nicely formatted :)
I think the problem is that when you do hit a tri mesh chunk or any other chunk that actually contains data beyond the standard sizeof(CModel_3DS_Chunk) you aren't reading that data and then you're hitting junk data from that point forth. every chunk that you hit can be a different size. i don't remember offhand but aren't the things in the tri-mesh chunk something like:
int (number of vertices)
data (sizeof(int) * number of vertices)
in your code, you're not reading in that variable sized "data" part anywhere before you move on to reading the next "chunk". so when you do that, your file pointer is in the wrong place to read the next chunk.
-me
///////////////////////////////////////////ProcessChunks(FILE *file){ CModel_3DS_Chunk chunk; int read = 0; while (fread(&chunk,sizeof(CModel_3DS_Chunk),1,file)) { switch(chunk.id) { case MAIN3DS: { printf("Main3DS\n"); } break; case EDIT3DS: { printf("\tEdit3DS\n"); } break; case 0x3D3E: // Mesh Version; { fseek(file, (chunk.size - sizeof(CModel_3DS_Chunk)), SEEK_CUR); } break; case EDIT_OBJ: { printf("\t\tObject name: '%s'\n",ReadString(file,&read)); } break; case OBJ_TRIMESH: { printf("\t\tTriangular Polygon List\n"); } break; default: { fseek(file,(chunk.size - sizeof(CModel_3DS_Chunk)),SEEK_CUR); } break; } } return(1);}///////////////////////////////////////////
I think the problem is that when you do hit a tri mesh chunk or any other chunk that actually contains data beyond the standard sizeof(CModel_3DS_Chunk) you aren't reading that data and then you're hitting junk data from that point forth. every chunk that you hit can be a different size. i don't remember offhand but aren't the things in the tri-mesh chunk something like:
int (number of vertices)
data (sizeof(int) * number of vertices)
in your code, you're not reading in that variable sized "data" part anywhere before you move on to reading the next "chunk". so when you do that, your file pointer is in the wrong place to read the next chunk.
-me
True, but the thing is that it skips the chunks I haven't identified. So the vertex list and the face list AND the texture coordinate list are all skipped. (or should be skipped)
check the default case. =)
check the default case. =)
Js
But you arent reading(or skiping) data of those "IDENTIFIED" chunks (
case EDIT_OBJ:
{
printf("\t\tObject name: '%s'\n",ReadString(file,&read));
//*YOU ARENT READING DATA HERE!!!!
}
break;
case OBJ_TRIMESH:
{
printf("\t\tTriangular Polygon List\n");
//*YOU ARENT READING DATA HERE!!!!
}
break;
)
So when you're starting to read another chunk in your loop ,you're reading EDIT_OBJ or OBJ_TRIMESH data ,not a chunk!!!
case EDIT_OBJ:
{
printf("\t\tObject name: '%s'\n",ReadString(file,&read));
//*YOU ARENT READING DATA HERE!!!!
}
break;
case OBJ_TRIMESH:
{
printf("\t\tTriangular Polygon List\n");
//*YOU ARENT READING DATA HERE!!!!
}
break;
)
So when you're starting to read another chunk in your loop ,you're reading EDIT_OBJ or OBJ_TRIMESH data ,not a chunk!!!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement