Skip to main content
GameDev.net gamedev.net
🔒 Locked

Need help with importing ASCII Mikshape 3-D

Started by last-bastardo Sep 7, 2000 at 12:14 PM 1 replies 1.2k views
Original Post
last-bastardo
last-bastardo
Ok here is a dumb questions I have started quickly working on a importer for Milkshape 3D ASCII format files into OpenGL. Yes I am a newbie (been programming for a while but new to OGL) so I have a problem (wouldn''t be writing if I didn''t DAMN should really stop typing to myself) anyway here is the code. Below now everythign works dandy EXCEPT for the NORMALS. Anbybody out there please help. I put everything into arrays for OGL to process. Anybody got any idea why my normals are messing up, the lighting look very weird and I know it''s the normals. Any help would be appreciated. Last Bastardo -= Find me a word that rhymes with orange ? =- // This reads a string from a file void readstr(FILE *f,char *string) { do { fgets(string, 255, f); } while ((string[0] == ''/'') || (string[0] == ''\n'')); return; } // This is the defenition for a mesh typedef struct Mesh_t { GLfloat *tlist, *vlist, *nlist, *normals; int *plist, *nindex; Mesh_t::~Mesh_t() { delete vlist, plist, tlist, nlist, nindex, normals; } } Mesh_t; // This is the model class class Model_t { private: GLfloat x, y, z, u, v; int tmp, i, flags, bone_id, pcount, vcount, nx, ny, nz, v1, v2, v3;; public: FILE *file; char line[255]; Mesh_t *meshes; int num_meshes; int num_verts, num_polys, num_normals; void Model_t::Open(char *path) { file = fopen(path, "rt"); } Model_t::~Model_t() { fclose(file); } void Model_t:arse() { // This locates the number of meshes while (num_meshes == 0) { readstr(file,line); sscanf(line, "Meshes: %d", #_meshes); } meshes = new Mesh_t[num_meshes]; pcount = 0; vcount = 0; for (i = 0; i < num_meshes; i++) { // This locates the number of verticies while (num_verts == 0) { readstr(file,line); sscanf(line, " %d", #_verts); } meshes.vlist = new GLfloat[num_verts * 3]; meshes[i].tlist = new GLfloat[num_verts * 2]; for (vcount = 0; vcount < num_verts; vcount++) { readstr(file,line); sscanf(line, " %d %f %f %f %f %f %d ", &flags, &x, &y, &z, &u, &v, &bone_id); meshes[i].vlist[(vcount*3)] = x; meshes[i].vlist[(vcount*3) + 1] = y; meshes[i].vlist[(vcount*3) + 2] = z; meshes[i].tlist[(vcount*2)] = u; meshes[i].tlist[(vcount*2) + 1] = v; } readstr(file,line); sscanf(line, "%d", #_normals); meshes[i].nlist = new GLfloat[num_normals * 3]; for (vcount = 0; vcount < num_normals; vcount++) { readstr(file,line); sscanf(line, " %f %f %f", &x, &y, &z); meshes[i].nlist[(vcount*3)] = x; meshes[i].nlist[(vcount*3) + 1] = y; meshes[i].nlist[(vcount*3) + 2] = z; } readstr(file,line); sscanf(line, "%d", #_polys); meshes[i].plist = new GLint[num_polys * 3]; meshes[i].nindex = new GLint[num_polys * 3]; meshes[i].normals = new GLfloat[num_verts * 3]; for (vcount = 0; vcount < num_polys; vcount++) { readstr(file,line); sscanf(line, "%f %d %d %d %d %d %d", &flags, &v1, &v2, &v3, &nx, &ny, &nz); meshes[i].plist[(vcount*3)] = v1; meshes[i].plist[(vcount*3) + 1] = v2; meshes[i].plist[(vcount*3) + 2] = v3; meshes[i].nindex[(vcount*3)] = nx; meshes[i].nindex[(vcount*3) + 1] = ny; meshes[i].nindex[(vcount*3) + 2] = nz; printf("%d %d %d\n", v1, v2, v3); meshes[i].normals[(v1*3)] = meshes[i].nlist[(v1*3)]; meshes[i].normals[(v1*3) + 1] = meshes[i].nlist[(v1*3) + 1]; meshes[i].normals[(v1*3) + 2] = meshes[i].nlist[(v1*3) + 2]; meshes[i].normals[(v2*3)] = meshes[i].nlist[(v2*3)]; meshes[i].normals[(v2*3) + 1] = meshes[i].nlist[(v2*3)+1]; meshes[i].normals[(v2*3) + 2] = meshes[i].nlist[(v2*3)+2]; meshes[i].normals[(v3*3)] = meshes[i].nlist[(v3*3)]; meshes[i].normals[(v3*3) + 1] = meshes[i].nlist[(v3*3) + 1]; meshes[i].normals[(v3*3) + 2] = meshes[i].nlist[(v3*3) + 2]; } } } };
-=Last Bastardo=-
Pauly
Pauly
Yeah, I know what you mean. Milkshape uses a very weird way of representing normals. I could never figure it out, so I generated my own:

http://home.clara.net/paulyg/objects.htm

Paul.
Wayfarer
Wayfarer
Why are you trying to read a Milkshape 3D ASCII text file directly?
It is much simplier to use the MilkShape SDK and write an exporter
plugin to your 3D format specification. That way, you don''t have to
interpret how a ASCII file is written, you can simply write your own
format to a binary file within your exporter.

And I also had a hard time with Milkshape normals. I wrote a plugin
exporter for D3D. For example, the function DrawIndexedPrimitive() can
take in a list of vertices and a list of indices to those vertices.
And every normal for each vertex is stored within the vertex structure.

However, MilkShape3D also creates an index of nomals. Which means that
it can use an index to a vertex and an index to a normal to describe
a point. This isn''t compatible with DrawIndexedPrimitive() since it
requires that every vertex should have its own normal, not be referenced
as an index.

So, in order to get it to work with DrawIndexedPrimitive(), I had to
create a new vertex whenever the same normal index was repeated for a
different vertex. My code is now a mess, but it works.

Topic Locked

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

Sign in to reply to this topic.