• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

## Recommended Posts

I'm having some problems with this. Before, for each vertex I had a struct as such type vertex { float x, y, z, u, v; } type normal { float x, y, z; } type face { short i1, i2, i3; } and for each vertex and normal in the file I'd allocate sizeof(normal) * n_normals and likewise for the verts, and it worked just fine, but I decided to use vertex arrays and at someones suggestion I did this float *vertex; float *normal; float *texcoords short *face Allocated each as vertex = sizeof(vertex) * n_vertex * 3, likewise for normals, and * 2 for the texcoords. Milkshapes ascii files are structured like this: vertices: 2 1 0.3547, 3.3475, -1.4623, 1.346, 0.3467 -1 Where the 5 floats are x, y, z, u, v and the normals are normal: 5 0.57433, 0.45873, 0.2366 the faces are face: 15 0 1 2 0 1 2 where the first 3 are the indices to the verts, the second 3 are the indices to the normals, but theyre always the same as the verts so I ignore them. Here are the loops that read from the file
		for (ii = 0; ii < Model->Mesh.VertexCount; ii++)
{
fgets(LineBuffer, 256, File);
sscanf(LineBuffer, "%hd %f %f %f %f %f %hd", &Temp, &Model->Mesh[i].Vertex[ii * 3], &Model->Mesh[i].Vertex[ii * 3 + 1], &Model->Mesh[i].Vertex[ii * 3 + 2], &Model->Mesh[i].TexCoord[ii * 2], &Model->Mesh[i].TexCoord[ii * 2 + 1], &Temp);
}

for (ii = 0; ii < Model->Mesh[i].NormalCount; ii++)
{
fgets(LineBuffer, 256, File);
sscanf(LineBuffer, "%f %f %f", &Model->Mesh[i].Normal[ii * 3], &Model->Mesh[i].Normal[ii * 3 + 1], &Model->Mesh[i].Normal[ii * 3 + 2]);
}

for (ii = 0; ii < Model->Mesh[i].FaceCount; ii++)
{
fgets(LineBuffer, 256, File);
sscanf(LineBuffer, "%hd %hd %hd %hd %hd", &Temp, &Model->Mesh[i].Face[ii * 3], &Model->Mesh[i].Face[ii * 3 + 1], &Model->Mesh[i].Face[ii * 3 + 2], &Temp);
}

If anyone can spot the problem I'd very much appreciate it, I can't seem to get it working. ------------ - outRider - Edited by - outRider on June 8, 2001 12:10:26 AM

##### Share on other sites
quote:

Allocated each as vertex = sizeof(vertex) * n_vertex * 3, likewise for normals, and * 2 for the texcoords

That should be "sizeof(float)" if each vertex-component is represented as a float (sizeof(vertex) would equal sizeof(float)*3 since your ''vertex''-structs are declared as containing 3 floats (x, y, z)).

For the tex-coords it should be "sizeof(short) * n_texcoords * 2".

If the file containing the vertex data (etc.) contains commas between the elements shouldn''t the sscanf call also have them?

ex.

0.57433, 0.45873, 0.2366

sscanf should be called as:
  sscanf(LineBuffer, "%f, %f, %f", &Model->Mesh[i].Normal[ii * 3], &Model->Mesh[i].Normal[ii * 3 + 1], &Model->Mesh[i].Normal[ii * 3 + 2]);

##### Share on other sites
Sorry, those are both typos in the post, that's not the case in my actual source, I was just lazy.

There are no commas in the text file, and there is no type vertex anymore (when I did use the vertex struct everything worked fine, but then it wouldnt be a usable array for glVertexPointer()) and sizeof() is passed float.

I can post the drawing code if it would help, maybe theres a prob there.

------------
- outRider -

Edited by - outRider on June 9, 2001 1:27:32 AM

• ### Forum Statistics

• Total Topics
627711
• Total Posts
2978744

• 21
• 14
• 12
• 36
• 30