PDA

View Full Version : UV Coordinates import from 3DS mesh file



02-25-2004, 08:17 AM
i wrote a loader for obj file(wavwe front) which is not having any texture support(bmp file with UV coordinates) to import into my GAME. i want to load the mesh object with textures from the file by generating the textures using the referenced files in the file. so i opted 3DS file and started writing a 3ds loader. but i cant find enough information on decoding the texture coordinates and the corrosponding BMP(or TGa or ...) from the 3DS file. can any one help me. i am writing a free combat flight simulation game.any one help me if u know any tutorial or 3DS loader available over the net. is there is any other file format that supports textures with UV's ?
-indra

147-2
02-25-2004, 10:14 AM
Hm... I have had no problems with the 3ds loader I grabbed from www.gametutorials.com. (http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg4.htm) I have been using it for quite a while, and have modified it to my tastes... Check it out, it has worked for me since day 1.




[This message has been edited by 147-2 (edited 02-25-2004).]

DJSnow
02-26-2004, 06:15 AM
*Argh*
i advice you honestly NOT TO USE the 3DSLOADER from gametutorials.com - because it's total ****ty: it loads only the first mesh out of the file ! (of course, no problem to extend it by yourself but if i proclaim a loader as "useable" it should be useable, and not only 50% of it!)

yakuza
02-29-2004, 08:42 AM
I've found Lev's 3ds loader to be a helpful resource while working on my own:
http://www.levp.de/3d/index.html

I've also extensively used this reference to decipher the various chunks in the 3ds file:
http://www.cyberloonies.com/3DSFTK4.htm

Hope those links help.

03-01-2004, 12:48 PM
thanku guys but i wrote my own loader that even reads tex coords and loades the textures an dbulds the lists too.the only problem is vertex normals with out them the vertex and every thing else is quiet good except the faces. they are not smmoth at the borders . each face is seperate plane.iwant more smoothed view . is there is any other thing for that thann increasing polygon tessalation(detail)? will vertex normals work? iam still specifying face normals only!
thans for ur time
-indra

yakuza
03-01-2004, 03:25 PM
Generating vertex normals will indeed smooth things out. For each vertex, average the normals of all faces that share that vertex.

enmaniac
03-02-2004, 06:45 AM
Yes, this exactly what 3DSLoader from www.gametutorials.com (http://www.gametutorials.com) does :-p

03-02-2004, 08:33 AM
vertex normals r introducing another problem. the model looks obscurely shaded .what i mean by that is it is having parallel bands in that which are much significant at larger distances and not much problem at less viewing distances from the object.

this is the code for calculating face normals and vertex normals for each individual object in the 3ds file.

void CGLMFC1View::calcAllNormals(MeshObj *p_object)
{ TRACE0("calcAllNormals()");
GLfloat in[3][3],out[3];
int a,b,c;
int i=0,j=0,faces[100],facecounter=0,nfacesV=0;
GLfloat tempNormal[3];
//first lets calculate the face normals
for( i=0;i<p_object->face_qty;i++)
{


//get its vertices indexes
a=p_object->face[i].a;
b=p_object->face[i].b;
c=p_object->face[i].c;
//load the 3 vertices in to the array in[][]
in[0][0]=p_object->vertex[a].x;
in[0][1]=p_object->vertex[a].y;
in[0][2]=p_object->vertex[a].z;
in[1][0]=p_object->vertex[B].x;
in[1][1]=p_object->vertex[B].y;
in[1][2]=p_object->vertex[B].z;
in[2][0]=p_object->vertex[c].x;
in[2][1]=p_object->vertex[c].y;
in[2][2]=p_object->vertex[c].z;

//calculate and specify the normal
calcNormal(in,out);
p_object->facenormal[i].x=out[0];
p_object->facenormal[i].y=out[1];
p_object->facenormal[i].z=out[2];
}
p_object->face_normal_qty=i-1;

// now lets calculate the vertex normals by averaging the face normals
for(i=0;i<p_object->vertices_qty;i++)
{ facecounter=0;
nfacesV=0;
//search the for the shared faces of this ith Vertex
for( j=0;j<p_object->face_qty;j++)
{
int temp1=p_object->face[j].a;
int temp2=p_object->face[j].b;
int temp3=p_object->face[j].c;
int l=i;
if(temp1==l&#0124; &#0124;temp2==l&#0124; &#0124;temp3==l)
{
facecounter++;
faces[nfacesV]=j;
nfacesV++;
}
}
tempNormal[0]=tempNormal[1]=tempNormal[2]=0.0f;
for(int k=0;k<facecounter;k++)
{
tempNormal[0]+=p_object->facenormal[faces[k]].x;
tempNormal[1]+=p_object->facenormal[faces[k]].y;
tempNormal[2]+=p_object->facenormal[faces[k]].z;

}
if(facecounter!=0)
{ p_object->vetrtexnormal[i].x=tempNormal[0]/facecounter;
p_object->vetrtexnormal[i].y=tempNormal[1]/facecounter;
p_object->vetrtexnormal[i].z=tempNormal[2]/facecounter;
}
}


}