Skip to main content
gamedev.net
🔒 Locked

3DS parser

Started by nini 3 replies 500+ views
Original Post
nini
nini
hi all , i'm writting a 3DStudio file parser but i can't figure out a problem with the UV Map. here is pseudo code of what i do (i ommit a large portion for clarity) :

BYTE *data (= all the data of the file)
...
case CHUNK_UVMAP:

WORD numTexCoord = data[0];
data+=2;

for(int i=0;i<numTexCoord;i++)
{
// A Float type is 4 Byte so we get the first four byte of data pointer.
mesh.uvs.u = (*(float*))&data[0];
mesh.uvs.v = (*(float*))&data[4];
data+=8;
}
break;

case CHUNK_FACES:

WORD numFaces = *((WORD*)data);
data+=2;

for(int i=0;i<numFaces;i++)
{
mesh.Faces.a = *((WORD*))&data[0];
mesh.Faces.b = *((WORD*))&data[2];
mesh.Faces.c = *((WORD*))&data[4];
data+=8; // we skip 3*2Byte + 2Byte of flag for the face

}

break;

Finally i render the model with OpenGL immediate mode (glVertex3f and glTexCoord2f) by submitting the vertices and the texcoord according to the face indexes. All go fine for geometry rendering but not for UV Map : here is a link that show the problem : Image Hosted by ImageShack.us Thanx in advance...
godmodder
godmodder
Why are you first reading all of your data into a pointer and then extracting all of the data out of it into other arrays/pointers? That's just asking for trouble. I've written several .3ds loaders and I've never used this kind of mechanism. You should try and read the binary data directly from the file with the fread() function. This way, you'll save yourself alot of trouble if only for the convenient file pointer which is increased every time you read some data, so you can pinpoint your location in the file at every possible moment.
I haven't really looked at your code in detail, but I think it's a pretty weird way to do this kind of thing. I mean, you don't pour your water into 2 different glasses before you drink it! Just the same what you're actually doing here...

PS: This was just a suggestion. If you want to stick to your current code: Last time I checked France was also a free country ;)

Hope I've been able to help,
Jeroen
nini
nini
Quote:
Original post by godmodder
I've written several .3ds loaders

Hope I've been able to help,
Jeroen


I can't figure out why my texcoord aren't good...the way i do it is for limiting disk access , in a multithreaded resource manager i can load multiple object at a time , i agree with you this solution is complex but i don't want to discuss about it for now , i've dumped texcoord and then compared those with the ascii version of the 3DS file and they seem to match...

i'm using devil library for reading image file so i don't have control about how its layout in memory, could be this ?

And yes France is definitely a free country but i don't understand your annotation...
cheers
nini
nini
Quote:
Original post by lauris71
Are you sure you do not have image loaded upside down?
If so,
mesh.uvs.v = 1-(*(float*))&data[4];
could help.
Lauris


Yeahhh Great thank you very much that was it ....


Thanx for all

Topic Locked

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

Sign in to reply to this topic.