• Advertisement


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

need help with ms3d files

This topic is 5464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ooook, I used the code from nehe''s game tutorials for loading MS3D files, this is my MS3D header:
typedef struct MS3D_HEADER_TYP
   	char id[10];
	int  version;

typedef struct MS3D_VERTEX_TYP
	unsigned char flags;
	unsigned char refCount;
	char boneID;
	float vertex[3];

typedef struct MS3D_TRIANGLE_TYP
	unsigned short flags;
	unsigned short vertexIndices[3];
	float vertexNormals[3][3];
	float u[3];
	float v[3];
	unsigned char smoothingGroup;
	unsigned char groupIndex;

typedef struct MS3D_GROUP_TYP
   	unsigned char	flags;
   	char name[32];
   	unsigned short	numTriangles;
	unsigned short*	triangleIndices;
	char materialIndex;

class MS3D
	unsigned short	numVertices;
	MS3D_VERTEX*	vertices;
	unsigned short	numTriangles;
	MS3D_TRIANGLE*	triangles;
	unsigned short	numGroups;
	MS3D_GROUP*	groups;
	bool Load(char* filename);
	void Render();
			delete vertices;		
			delete triangles;
			delete groups;

bool MS3D::Load(char* filename)
	FILE* file;
	MS3D_HEADER header;
	int loop;
	if((file= fopen(filename, "rb"))==NULL)
		// error message goes here

		return false;
	fread(&header.id, sizeof(char), 10, file);
	fread(&header.version, 1, sizeof(int), file);
	if(strncmp(header.id, "MS3D000000", 10)!=0)
		// error message goes here

		return false;
	if(header.version!=3 && header.version!=4)
		// error message goes here

		return false;
	fread(&numVertices, sizeof(unsigned short), 1, file);
	vertices= new MS3D_VERTEX [numVertices];
	for(loop=0; loop<numVertices; loop++)
		fread(&vertices[loop].flags,	sizeof(BYTE),  1, file);
		fread( vertices[loop].vertex,	sizeof(float), 3, file);
		fread(&vertices[loop].boneID,	sizeof(char),  1, file);
		fread(&vertices[loop].refCount, sizeof(BYTE),  1, file);
	fread(&numTriangles, sizeof(unsigned short), 1, file);
	triangles= new MS3D_TRIANGLE [numTriangles];
	for(loop=0; loop<numTriangles; loop++)
		fread(&triangles[loop].flags,		sizeof(unsigned short), 1, file);
		fread( triangles[loop].vertexIndices,	sizeof(unsigned short), 3, file);
		fread( triangles[loop].vertexNormals[0],sizeof(float),		3, file);
		fread( triangles[loop].vertexNormals[1],sizeof(float),	 	3, file);
		fread( triangles[loop].vertexNormals[2],sizeof(float),		3, file);
		fread( triangles[loop].u,		sizeof(float),		3, file);
		fread( triangles[loop].v,		sizeof(float),		3, file);
		fread(&triangles[loop].smoothingGroup,	sizeof(unsigned char),	1, file);
		fread(&triangles[loop].groupIndex,	sizeof(unsigned char),	1, file);
	fread(&numGroups, sizeof(unsigned short), 1, file);
	groups= new MS3D_GROUP [numGroups];
	for(loop=0; loop<numGroups; loop++)
		fread(&groups[loop].flags,	 sizeof(unsigned char),	1,  file);
		fread( groups[loop].name,	 sizeof(char),		32, file);
		fread(&groups[loop].numTriangles,sizeof(unsigned short),1,  file);
		groups[loop].triangleIndices=new unsigned short [groups[loop].numTriangles];
		fread( groups[loop].triangleIndices, sizeof(unsigned short), groups[loop].numTriangles,file);
		fread(&groups[loop].materialIndex,   sizeof(char), 1, file);

	// error message goes here

	return true;

void MS3D::Render()
	// Draw By Group

	for(int loop1=0; loop1<numGroups; loop1++ )
		// Draw As Regular Triangles, Since .MS3D''s Aren''t Optimized Like .MD2''s

		for(int loop2=0; loop2<groups[loop1].numTriangles; loop2++)
			int triangleIndex       =  groups[loop1].triangleIndices[loop2];
			const MS3D_TRIANGLE* tri= &triangles[triangleIndex];
			// Loop Through The Triangle''s Vertices, And Output Them!

			for(int loop3=0; loop3<3; loop3++)
				int index= tri->vertexIndices[loop3];
				glNormal3fv( tri->vertexNormals[loop3]);
				glTexCoord2f(tri->u[loop3], tri->v[loop3]);
and that code successfully loads up an ms3d file, and displays it, by creating each object, ex: MS3D ship; and etc.... now, what I need to be able to do, is load the ms3d file, but then allow the program to automatically load the bmps....but I don''t know how to look at the bmps that are saved to it, so I can''t exactly do that..... I don''t want to have to preload everything, because that wont'' give any functionality to my 3d artists, because I want them to be able to develop a file in ms3d, save it, and load it right in to the exe and not have to recompile anything........ what I need is some easy code and a decent walkthrough of where to put everything that I''d need. the rest of my code for the program uses nehe.gamedev.net''s bmp loader and that''s pretty much it, so what I have is a function that loads the textures, but I could create another bmp texture loader for the ms3d header file, if it won''t work any other way....... soo, in essense, i need to be able to load an ms3d, and its textures and be able to display it without having to recompile.... really all i need is what the header files look like that have the file names..because I evidently have the wrong type of header file..... bloodright.150m.com //For the latest on all of the IVGDA projects!

Share this post

Link to post
Share on other sites

  • Advertisement