Jump to content


load 3ds max models into opengl program


54 replies to this topic

#1 chingching

    Member

  • Members
  • PipPip
  • 38 posts

Posted 21 January 2006 - 07:05 PM

i'm facing problem of loading 3ds max models into opengl program...do u guys got any idea?or any website can give me a help?thanks...

#2 Vandervecken

    Member

  • Members
  • PipPip
  • 32 posts

Posted 21 January 2006 - 07:11 PM

http://lib3ds.sourceforge.net/

I used this just recently. It was very easy to use.

#3 chingching

    Member

  • Members
  • PipPip
  • 38 posts

Posted 22 January 2006 - 03:37 AM

thanks a lot!!! I'll try that...if got any others way for loading the 3ds max model into opengl program, kindly give me a reply...thanks a lot!!

#4 dave_

    Senior Member

  • Members
  • PipPipPipPip
  • 584 posts

Posted 22 January 2006 - 09:04 AM

Write an exporter to export the data into your file format.
Search for 3d studio max exporter in google. Theres plenty of results on the first page.

#5 SigKILL

    Valued Member

  • Members
  • PipPipPip
  • 200 posts

Posted 22 January 2006 - 05:16 PM

www.wotsit.org, if you're anything like me ;)

-si

#6 chingching

    Member

  • Members
  • PipPip
  • 38 posts

Posted 18 February 2006 - 06:10 AM

I read from forum that this website provides good tutorials, but I failed to open the page http://www.gametutor.../OpenGL_Pg4.htm

Any others way that can get know about loading 3ds model into openGL program?

#7 Reedbeta

    DevMaster Staff

  • Administrators
  • 5308 posts
  • LocationSanta Clara, CA

Posted 18 February 2006 - 07:12 AM

GameTutorials.com apparently charges money for their tutorials now.

Have you looked at lib3ds, suggested by Vandervecken?
reedbeta.com - developer blog, OpenGL demos, and other projects

#8 chingching

    Member

  • Members
  • PipPip
  • 38 posts

Posted 18 February 2006 - 01:11 PM

Hi,
I had looked at lib3ds, and even downloaded, but I don't know how to make it useful for me. I'm so stuck. Kindly give me some directions?

Thanks.

#9 Reedbeta

    DevMaster Staff

  • Administrators
  • 5308 posts
  • LocationSanta Clara, CA

Posted 19 February 2006 - 03:03 AM

Maybe the sample program linked from the lib3ds site would be helpful? ;)
reedbeta.com - developer blog, OpenGL demos, and other projects

#10 Bee

    New Member

  • Members
  • Pip
  • 3 posts

Posted 20 February 2006 - 02:03 AM

I'm new in 3ds, also got some told me about the lib3ds is useful, but i haven't try it.

:)

#11 chingching

    Member

  • Members
  • PipPip
  • 38 posts

Posted 20 February 2006 - 02:10 AM

Ya, I already tried to run that sample program, and tried to fix the errors, but too sad that it displayed a message -- "No 3DS file specified."

I already trial and trial to load model, but still fail. Anyone can tell me what to do??:wallbash: I'm really so stuck.

Thanks to those suggestions provided.
Any information are still welcome.
Thanks.

#12 Reedbeta

    DevMaster Staff

  • Administrators
  • 5308 posts
  • LocationSanta Clara, CA

Posted 20 February 2006 - 05:15 AM

Well, the sample program displays that message if you don't provide it with a filename as a command line argument. It's also apparently written with a Unix configure script in mind, so you can just comment out the reference to config.h. Does it give other errors? (I haven't tried compiling it myself.)
reedbeta.com - developer blog, OpenGL demos, and other projects

#13 chingching

    Member

  • Members
  • PipPip
  • 38 posts

Posted 20 February 2006 - 01:11 PM

Erm...what you meant by commend in config.h? I'm so blur now...

Thanks.

#14 Reedbeta

    DevMaster Staff

  • Administrators
  • 5308 posts
  • LocationSanta Clara, CA

Posted 20 February 2006 - 05:18 PM

#include <config.h>

/* #include <config.h> */

That's called commenting out.
reedbeta.com - developer blog, OpenGL demos, and other projects

#15 Anudhyan

    New Member

  • Members
  • PipPip
  • 15 posts

Posted 21 February 2006 - 10:33 AM

There is a tutorial on loading 3ds meshes here -
http://www.spacesimu..._3dsloader.html

And the source code for windows-
http://www.spacesimu...t-tutorial4.zip

#16 chingching

    Member

  • Members
  • PipPip
  • 38 posts

Posted 21 February 2006 - 03:52 PM

Reedbeta said:

#include <config.h>

/* #include <config.h> */

That's called commenting out.

Ya, Reedbeta, I already comment out that.
But, i still can't figure out the problem.
Your kindness are appreciated.
Ideas and suggestions are still welcoming.
Thanks.

#17 chingching

    Member

  • Members
  • PipPip
  • 38 posts

Posted 21 February 2006 - 03:58 PM

Anudhyan,thanks for gave me the source code zip file. Really thanks a lot.
I haven't try it, but I hope it can help me a lot. Coz I have just left a bit time to complete my project. I'm so nervous now. Thus, anyone got any idea about my problem, kindly suggest here or send me via email.

A lots of thanks here.

#18 Anudhyan

    New Member

  • Members
  • PipPip
  • 15 posts

Posted 21 February 2006 - 05:05 PM

chingching,
I have a great little sample on loading 3ds models that i wrote myself. It covers the loading as well as the displaying of the mesh. Its very short and to the point. I wanted to e-mail the full source but i don't have your e-mail id.

#19 Anudhyan

    New Member

  • Members
  • PipPip
  • 15 posts

Posted 21 February 2006 - 05:11 PM

here is part of my code:
----------------------------------------------------
//Basic Classes:
//Required for representing the loaded model
class vertex{
public:
	float x,y,z;
};
//MapCoord - for storing texture mapping coords
class mapcoord{
public:
	float u,v;
};

//The three ints for the polygon
//represent the no.s(or rank) of it's 3 vertices
class polygon{
public:
	int a,b,c;
};

class object{
public:
	char name[20];
	int numVerts,numPolys;
	vertex v[3000];
	polygon p[3000];
	mapcoord m[3000];
};



//-----------------------------------------------------------------------------
// Name: Load3dsObject (object *, char *)
// Desc: Loads a 3ds object given a filename
//-----------------------------------------------------------------------------

void Load3dsObject (object *obj, char *filename)
{
	FILE *file;			//Our file pointer

	char temp;			//Temporary char for reading name of object
	short chunkID;		//Stores ID of current chunk.
	int chunkLength;

	short useless;
	
	//Open our file for reading(r) and in binary mode(b)- "rb"
	file=fopen (filename, "rb");

	int i; 

	//While current position is lesser than the total length
	while (ftell(file) < filelength (fileno (file)))  
	{
		fread (&chunkID, 2, 1, file); 
		fread (&chunkLength, 4, 1,file); 

		switch (chunkID)
        {
			case 0x4d4d:		//Skip these chunks
				break;    
			case 0x3d3d:
				break;
			
			case 0x4000:		//Chunk containing name
				for(i=0;i<20;i++)
				{
					fread (&temp, 1, 1, file);
                    obj->name[i]=temp;
					if(temp == '\0')break;
                }
				break;

			case 0x3f80:		//Skip again
				break;
			case 0x4100:
				break;
	
			case 0x4110:		//Chunk with num of vertices
								//followed by their coordinates
				fread (&obj->numVerts, sizeof (unsigned short), 1, file);
				for (i=0; i<obj->numVerts; i++)
                {
					fread (&obj->v[i].x, sizeof(float), 1, file);
 				
                    fread (&obj->v[i].y, sizeof(float), 1, file);
 					
					fread (&obj->v[i].z, sizeof(float), 1, file);
 				
				}
				break;

			case 0x4120:		 //Chunk with numPolys and
								 //the indices
				fread (&obj->numPolys, sizeof (unsigned short), 1, file);
                for (i=0; i<obj->numPolys; i++)
                {
					fread (&obj->p[i].a, sizeof (unsigned short), 1, file);
				
					fread (&obj->p[i].b, sizeof (unsigned short), 1, file);
				
					fread (&obj->p[i].c, sizeof (unsigned short), 1, file);
					
					fread (&useless, sizeof (unsigned short), 1, file);
					
				}
				break;

		
			case 0x4140:		//Chunk with texture coords
				fread (&useless, sizeof (unsigned short), 1, file);
				for (i=0; i<obj->numVerts; i++)
				{
					fread (&obj->m[i].u, sizeof (float), 1, file);
				
                    fread (&obj->m[i].v, sizeof (float), 1, file);
				}
                break;

			default:
				 fseek(file,chunkLength-6, SEEK_CUR);
        } 
	}
	fclose (file);		
}



//-----------------------------------------------------------------------------
// Name: DrawObject(object *obj)
// Desc: Draws our loaded 3ds object
//-----------------------------------------------------------------------------

void DrawObject(object *obj)
{
	glBegin(GL_TRIANGLES); 
    for (int i=0;i<obj->numPolys;i++)
    {
 		glTexCoord2f( obj->m[ obj->p[i].a ].u,
                      obj->m[ obj->p[i].a ].v);
        glVertex3f( obj->v[ obj->p[i].a ].x,
                    obj->v[ obj->p[i].a ].y,
                    obj->v[ obj->p[i].a ].z); 

		glTexCoord2f( obj->m[ obj->p[i].b ].u,
                      obj->m[ obj->p[i].b ].v);
        glVertex3f( obj->v[ obj->p[i].b ].x,
                    obj->v[ obj->p[i].b ].y,
                    obj->v[ obj->p[i].b ].z);

		glTexCoord2f( obj->m[ obj->p[i].c ].u,
                      obj->m[ obj->p[i].c ].v);
        glVertex3f( obj->v[ obj->p[i].c ].x,
                    obj->v[ obj->p[i].c ].y,
                    obj->v[ obj->p[i].c ].z);
	}
    glEnd();
}

It would be more helpful to you if I could attach the file and e-mail it to you.

#20 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 21 February 2006 - 06:11 PM

@Anudhyan: Try using code tags to keep to proper formatting when posting source code.
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users