EDIT: SOLUTION ONE POST FURTHER!!!!
Hello everybody..
for my 3d engine i've written a loader for 3ds models based on some tutorial i found on the net called spacesimulator or s.th. like this .-). It works perfectly fine when i import a model which consists out of one mesh.. texture and model will be displayed correctly. But when i load in an object which consists of multiple meshes, lets say a car.. which consists out of the main part and 4 weels, only one wheel gets rendered and the rest of the 4 parts not. i probably think that this is because i need to read out the other meshes as well and displaying them.
the 3ds file looks like this:
[size=2]| +--EDIT_OBJECT (0x4000)
[size=2] | | |
[size=2] | | +--OBJ_TRIMESH (0x4100)
[size=2] | | | |
[size=2] | | | +--TRI_VERTEXL (0x4110)
[size=2] | | | +--TRI_VERTEXOPTIONS (0x4111)
[size=2] | | | +--TRI_MAPPINGCOORS (0x4140)
[size=2]
[font="Courier New"]and i read out 4110 to 4140 like this:[/font]
It wonders me that i skip through the different vertices, polygons and tex coordinates but not through the object. where in the 3ds files are they defined then? so where is the point where the next objects begins...
[/font][font="Courier New"] Hope someone can help me.. it would really like to understand the concept ..
For completeness: Thats how i draw them:
[/font]
[font="Courier New"]
glBegin(GL_TRIANGLES);
for (unsigned int i = 0; i < this->polygons_qty; i++)
{
glTexCoord2f(this->mapcoord[this->polygon.a].u,
this->mapcoord[this->polygon.a].v);
glVertex3f(this->vertex[this->polygon.a].x,
this->vertex[this->polygon.a].y,
this->vertex[this->polygon.a].z);
now everytime when i am in 0x4000 i increase my object counter and write all the future information in Objects[object_counter]..
Objects is a struct which containts vertices, polygons & tex coordinates..
by drawing i do the same!!
here is part of the code:
case 0x4000: // Edit_Object
i = 0;
do
{
fread(&l_char, 1, 1, l_file);
this->object[offset].name=l_char;
i++;
} while(l_char != '\0' && i < 20);
break;
case 0x4100: // Object Trimesh
offset = this->objects_qty;
this->objects_qty+=1; // by car we go in here 5 times
break;
case 0x4110: // Tri Vertex (Vertices List)
fread(&l_qty, sizeof(unsigned short), 1, l_file);
for (i = 0; i < l_qty; i++)
{
fread(&this->object[offset].vertex.x, sizeof(float), 1, l_file);
fread(&this->object[offset].vertex.y, sizeof(float), 1, l_file);
fread(&this->object[offset].vertex.z, sizeof(float), 1, l_file);
}
this->object[offset].vertices_qty = l_qty;
and for drawing:
glBegin(GL_TRIANGLES);
for (unsigned int j = 0; j < this->objects_qty; j++)
{
for (unsigned int i = 0; i < this->object[j].polygons_qty; i++)
{
glTexCoord2f(this->object[j].mapcoord[this->object[j].polygon.a].u,
this->object[j].mapcoord[this->object[j].polygon.a].v);
glVertex3f(this->object[j].vertex[this->object[j].polygon.a].x,
this->object[j].vertex[this->object[j].polygon.a].y,
this->object[j].vertex[this->object[j].polygon.a].z);
I can successfully read and load the objects like ur code. But I am unable to read Color info.. means color of objects that we reading from the file.
actually there are many ways to read 3DS chunks on the internet but in our way how can we read color info ?
U can see my code here..
//OBJ_TRIMESH
//TRI_VERTEXL
//TRI_FACEL1
//TRI_MAPPINGCOORS
case 0xa020: // diffuse color
if(1)
{
case 0×0010: // Color F
fread (&red, sizeof(float), 1, l_file);
fread (&green, sizeof(float), 1, l_file);
fread (&blue, sizeof(float), 1, l_file);
//if (!ReadFloat(fp, red)) return FALSE;
//if (!ReadFloat(fp, green)) return FALSE;
//if (!ReadFloat(fp, blue)) return FALSE;
break;
case 0×0011: // Color 24
fread (&red, sizeof(float), 1, l_file);
fread (&green, sizeof(float), 1, l_file);
fread (&blue, sizeof(float), 1, l_file);
//if (!ReadUByte(fp, tmp)) return FALSE;
//red = (float) tmp / (float) 255.0;
//if (!ReadUByte(fp, tmp)) return FALSE;
//green = (float) tmp / (float) 255.0;
//if (!ReadUByte(fp, tmp)) return FALSE;
//blue = (float) tmp / (float) 255.0;
break;
}
break;
Think of Design with Dimensions
http://real3d.pk
[/quote]