load 3ds max models into opengl program

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Jan 21, 2006 at 19:05

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…

54 Replies

Please log in or register to post a reply.

4b382c8236c08850d8931f7e1fabf5d5
0
Vandervecken 101 Jan 21, 2006 at 19:11

http://lib3ds.sourceforge.net/

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

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Jan 22, 2006 at 03:37

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!!

A9102969e779768e6f0b8cb87e864c94
0
dave_ 101 Jan 22, 2006 at 09:04

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.

4e70f904a74bd2aa8773733b25b77d41
0
SigKILL 101 Jan 22, 2006 at 17:16

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

-si

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 18, 2006 at 06:10

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

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

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Feb 18, 2006 at 07:12

GameTutorials.com apparently charges money for their tutorials now.

Have you looked at lib3ds, suggested by Vandervecken?

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 18, 2006 at 13:11

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.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Feb 19, 2006 at 03:03

Maybe the sample program linked from the lib3ds site would be helpful? ;)

D6b42023a43d8fcb41122ddca1bf7eeb
0
Bee 101 Feb 20, 2006 at 02:03

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

:)

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 20, 2006 at 02:10

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.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Feb 20, 2006 at 05:15

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.)

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 20, 2006 at 13:11

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

Thanks.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Feb 20, 2006 at 17:18

#include <config.h>

/* #include <config.h> */

That’s called commenting out.

B861fc0599f14928b4b8ac70501aaec1
0
Anudhyan 101 Feb 21, 2006 at 10:33
0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 21, 2006 at 15:52

@Reedbeta

#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.

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 21, 2006 at 15:58

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.

B861fc0599f14928b4b8ac70501aaec1
0
Anudhyan 101 Feb 21, 2006 at 17:05

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.

B861fc0599f14928b4b8ac70501aaec1
0
Anudhyan 101 Feb 21, 2006 at 17:11

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.

6f0a333c785da81d479a0f58c2ccb203
0
monjardin 102 Feb 21, 2006 at 18:11

@Anudhyan: Try using code tags to keep to proper formatting when posting source code.

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 22, 2006 at 00:57

Anudhyan, really thanks you a lot!! I’ll send my email address to you via email.
Hope that can help me a lot…:yes:

A lot of thanks.:worthy: Your kindness is appreciated.

B861fc0599f14928b4b8ac70501aaec1
0
Anudhyan 101 Feb 22, 2006 at 04:13

chingching,
I have sent the sample.
I hope you have recieved it…

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 22, 2006 at 07:05

Hie all,
Regarding to the lib3ds, I had tried, but I blurrr with this

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
if (argc!=2) {
puts(“***ERROR*** No 3DS file specified”);
exit(1);
}
filename=argv[1];

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

And I blurrr with where to put the argument to load model.:sad:
Can someone kindly tell me about these? I’m so stuck.
Thanks a lot.

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 22, 2006 at 07:08

Anudhyan, I already got your sample via email.Thanks a lot again.:worthy:
Any other information are appreciated.

B861fc0599f14928b4b8ac70501aaec1
0
Anudhyan 101 Feb 22, 2006 at 08:44

To calculate the normals of the loaded object:

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

//-----------------------------------------------------------------------------
// Name: DotProduct(vertex,vertex)
// Desc: Returns the dot product of two vertices
//-----------------------------------------------------------------------------
vertex DotProduct(vertex v1,vertex v2)
{
    vertex final;

    final.x=(v1.y*v2.z)-(v1.z*v2.y);
    final.y=(v1.z*v2.x)-(v1.x*v2.z);
    final.z=(v1.x*v2.y)-(v1.y*v2.x);

    return final;
}

//-----------------------------------------------------------------------------
// Name: Normalize(vertex)
// Desc: Normalizes a vertex
//-----------------------------------------------------------------------------
vertex Normalize(vertex v)
{
    vertex result=v;
    float l;
    l=(sqrt(v.x*v.x +v.y*v.y +v.z*v.z));;
    if(l==0)l=1;
    result.x/=l;
    result.y/=l;
    result.z/=l;

    return result;
}

//-----------------------------------------------------------------------------
// Name: CalculateNormals(object *)
// Desc: Calculates the normals of an object
//-----------------------------------------------------------------------------
void CalculateNormals(object *o)
{
    int i;
    vertex v1,v2,v3,b1,b2,normal;
    int con[3000];

    for(i=0;i<o->numPolys;i++)
    {
        v1.x=o->v[o->p[i].a].x;
        v1.y=o->v[o->p[i].a].y;
        v1.z=o->v[o->p[i].a].z;

        v2.x=o->v[o->p[i].b].x;
        v2.y=o->v[o->p[i].b].y;
        v2.z=o->v[o->p[i].b].z;

        v3.x=o->v[o->p[i].c].x;
        v3.y=o->v[o->p[i].c].y;
        v3.z=o->v[o->p[i].c].z;
    
        b1.x=v2.x-v1.x;
        b1.y=v2.y-v1.y;
        b1.z=v2.z-v1.z;

        b2.x=v3.x-v1.x;
        b2.y=v3.y-v1.y;
        b2.z=v3.z-v1.z;

        normal = DotProduct(b1,b2);
        normal = Normalize(normal);

        con[o->p[i].a]+=1;
        con[o->p[i].b]+=1;
        con[o->p[i].c]+=1;

        o->n[o->p[i].a].x+=normal.x;
        o->n[o->p[i].a].y+=normal.y;
        o->n[o->p[i].a].z+=normal.z;
        o->n[o->p[i].b].x+=normal.x;
        o->n[o->p[i].b].y+=normal.y;
        o->n[o->p[i].b].z+=normal.z;
        o->n[o->p[i].c].x+=normal.x;
        o->n[o->p[i].c].y+=normal.y;
        o->n[o->p[i].c].z+=normal.z;
    }
    
    for (i=0;i<o->numVerts;i++)
    {
        if(con[i]>0)
        {
            o->n[i].x/=con[i];
            o->n[i].y/=con[i];
            o->n[i].z/=con[i];
        }
    }
}
0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 22, 2006 at 15:29

Anudhyan, I’d tried your sample code, there is no compile error, but there are linking errors:

LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Trial.exe : fatal error LNK1120: 1 unresolved externals

Is there any problem with lib?

Since I haven’t put any texture in my model, thus I comment the segments of loading texture.

Well, my model is a house, and the house is build up with a number of polygons plus furnitures inside, will that a problem when loading it? And I’ll have more houses in my project.

Thanks a lot for helping me.:worthy:

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 22, 2006 at 15:32

Well, Monjardin, thanks for providing me those info…

B861fc0599f14928b4b8ac70501aaec1
0
Anudhyan 101 Feb 22, 2006 at 17:01

chingching,
I forgot to tell you that all the geometry should be attached together.
As for the link error…I have never seen it. I use MVC++ 6. Did you use the .dsp file I provided? I had it linked to only these libs:
opengl32.lib glu32.lib glaux.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
And if your model has more than 3000 polys,increase the array sizes in the object class.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Feb 22, 2006 at 18:27

The link error means the main() function is missing…chingching, did you compile the code Anudhyan posted all by itself? It’s just a couple of functions, so you need to have your own application around it…

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 23, 2006 at 10:32

Anudhyan, I’d already solve those linking errors, erm…too sad that no model displayed. Well, I’ll try to change the coding to win32 console application style, coz I always used to that. But, your sample code really helps me a lot. Thanks. I’ll trial and trial to check why the model didn’t displayed as there is no error. If you got any idea, kindly give me ya\~\~:lol:
Thanks.

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 23, 2006 at 10:36

Yes, Reedbeta, I got run whole sample coding given by Anudhyan. Anyway, thanks for telling me that.
Well, can you tell me what’re these about?

glutInit(&argc, argv);
if (argc!=2) {
puts(“***ERROR*** No 3DS file specified”);
exit(1);
}
filename=argv[1];

Thanks!!

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 23, 2006 at 10:46

Hi all,
I’m here really appreciate the warmer hands from all of you.
As the time goes by, I really nervous and scare that I can’t complete my project on time, as I can’t even load a model into my openGL program. Well, I got 4 house models to be loaded, plus some furnitures inside the houses. :sad:
After loading models, I have to do navigation somemore, and the hardest part for me – Collision Detection.:wacko:
So, really thanks you all for lending me your warmest hands. Hope to get more info or idea from you all during my project going on.
Really thanks a lot.:worthy:

B861fc0599f14928b4b8ac70501aaec1
0
Anudhyan 101 Feb 23, 2006 at 12:49

Chingching,
Do you want another sample made by me – its all about collision detection and response ?
I am happy to know that you could compile it. But 90% of the times you won’t
be able to see the models - if you randomly just send in a model with no planning. First, there is the scale factor. Your model could either be too small or too big. Second, your model could be far away from the origin. Make sure
its centres around 0,0,0.
My advice is to use the model I provided and use the exact gluLookAt coordinates in my original code.
Next, go to 3ds max and centre and scale your model so it resembles my box.
And then use your model in place of the box.
Didn’t you see the box when you first compile and run the unaltered code ?
First use a simple model.Then move on to better things.
Note that everything should be attached together and be 1 object.
If you model has more than 3000 verts/polys increase the values in the object
class.

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 23, 2006 at 15:06

Anudhyan, a lot of thanks here if you can send me the sample code via email.:yes:
And I’ll check my model’s coord and its centre.
Ya, the box is displayed while I compile your original code.
Somemore,you said that all geometry must be attached together become one object, but my model is house with some furniture inside, is it possible to do? Or maybe I can’t what you mean…coz I more on coding part, and my partner is more on modeling.:wacko:
Thanks for your advices. I really appreciate it.

B861fc0599f14928b4b8ac70501aaec1
0
Anudhyan 101 Feb 23, 2006 at 16:54

Um… It is of course possible to attach all the geometry together (why not ?) The only problem is that you have to use only one texture for one object.
There is nothing preventing you from exporting every object as a different file using export selected. Then importing every object differently. If the furniture are similar then you should load only the chair/table and scatter them around the house…
Remember that without any view transformations in opengl, the eye position will be at 3ds max’s 0,0,0 and will be looking towards the z- axis. i.e. downward in 3ds max.
If you keep having trouble displaying your model, you could mail me your house model and I will transform it as required.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Feb 23, 2006 at 16:54

@chingching

Yes, Reedbeta, I got run whole sample coding given by Anudhyan. Anyway, thanks for telling me that.
Well, can you tell me what’re these about?

glutInit(&argc, argv);
if (argc!=2) {
puts(“***ERROR*** No 3DS file specified”);
exit(1);
}
filename=argv[1];

Thanks!!

Chingching, there have already been several links posted in this thread that should enable you to figure out what the above does. argc and argv are references to the command-line arguments provided to the program. You have to execute the program from a command line like this (suppose the program is called 3dsview): 3dsview my3dsfile.3ds. This provides the filename “my3dsfile.3ds” as a command-line argument.

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 24, 2006 at 05:44

Anudhyan, thanks you. I’d already mail to you.

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 24, 2006 at 05:44

Reedbeta, thanks for telling me that. I’ll try again.

820ce9018b365a6aeba6e23847f17eda
0
geon 101 Feb 24, 2006 at 11:47

@chingching

(…) And I blurrr with where to put the argument to load model.:sad:
Can someone kindly tell me about these? I’m so stuck.
Thanks a lot.

when you succuessfully compiled your model, open up a console and tyupe in the name of your executable, followed by your .3DS-file.

Alternatively, on windows, just drag-n-drop your 3DS-file onto the executable.

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 25, 2006 at 05:56

@geon

when you succuessfully compiled your model, open up a console and tyupe in the name of your executable, followed by your .3DS-file. Alternatively, on windows, just drag-n-drop your 3DS-file onto the executable.

Geon, mind to explain in detail?
Thanks.

820ce9018b365a6aeba6e23847f17eda
0
geon 101 Feb 25, 2006 at 14:06

In windows you can drag-and-drop a file onto an executable, or double-click a file that has an association. This will start the executable with the dragged/doubleclicked file as a commandline argument.

That means doublecklicking a *.txt-file is equivalent to typing this in the Run-field on your start-menu:

notepad the_file_I_just_doubleclicked.txt

Now seriously, start using google! You ask many questions that are allready answered, or has the answer in the supplied links, or that you could easily have found the answer to if you just googled around a little.

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Feb 25, 2006 at 15:00

Well, Geon, thank you. I’ll google around. So sorry that I always asked silly questions as I always get stuck. I’m so regret that I didn’t grasp time to gain more knowledge and preparation. Then now I just like a fly without head, fly here and there but don’t know where to go.
Anyway, a lot of thanks to you, hope you still willing to provide me some information if I get stuck.
Thanks.

Dd7f1397929790ff4b05ed9bec2d37d3
0
kennyurge 101 Mar 06, 2006 at 16:33

im havin the same prob as chingching….have you solve the problem yet?

C5d125dc492efd1b3a1d8d076d39fa1b
0
Spessotto 101 Mar 06, 2006 at 19:52

hello guys..im new here..and i want to know if someone can help me, because i have a 3ds loader…works well…but i want to put the 3ds file(a gun) in the middle of screen (like in the fps)..someone can help? thanks and sorry about the bad english!!!

Rafael S.

820ce9018b365a6aeba6e23847f17eda
0
geon 101 Mar 06, 2006 at 20:54

First of all, make your own thread for a new subject.

Anyway…

Just find out how to move the camera around. (I’. shure you can find it if you just fiddle around with the code for a while.) Then put the camera where the eyes of a charakter would have been. Simple.

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Mar 07, 2006 at 06:45

@kennyurge

im havin the same prob as chingching….have you solve the problem yet?

You can try the part coding of loading model that provided by Anudhyan (in the first page).

Dd7f1397929790ff4b05ed9bec2d37d3
0
kennyurge 101 Mar 07, 2006 at 08:20

@chingching

You can try the part coding of loading model that provided by Anudhyan (in the first page).

I not really good in programming and I don’t understand the incomplete program from Anudhyan :wallbash: :surrender and not sure where to use it…Do you have the complete program? Can you send me the code to my email? kennyurge@yahoo.com

Looking forward to your reply and thanks to your help..I appreaciate it.:worthy:

Dd7f1397929790ff4b05ed9bec2d37d3
0
kennyurge 101 Mar 07, 2006 at 08:23

@Anudhyan

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.

Hi, Anudhyan..Do you mind send me a copy of the file too? It will helps a lot in my project too. Thanks very much.:yes: :worthy:

Dd7f1397929790ff4b05ed9bec2d37d3
0
kennyurge 101 Mar 07, 2006 at 09:23

@kennyurge

Hi, Anudhyan..Do you mind send me a copy of the file too? It will helps a lot in my project too. Thanks very much.:yes: :worthy:

:yes: Thanks man\~I got it!:lol:

0131e0cf2bd46d8a2c4774ab3f1d476a
0
chingching 101 Mar 08, 2006 at 05:14

Kennyurge,
Sorry that now only saw your post…but it’s good to hear that Anudhyan had sent you the code…really sorry to you and thanks to Anudhyan ya\~\~

46462f88a1670d7e9cbbfa360aa20134
0
juhnu 101 Mar 08, 2006 at 07:39

“And if your model has more than 3000 polys,increase the array sizes in the object class.”

How about using a dynamic array like std::vector<>?

E7a408293454588084c3f3d5ee57925a
0
nexusssz 101 Aug 22, 2006 at 18:30

Hi guys
i’ve a problem here…hope u can help..
i’ve the following data extracted from a 3d model.
how do i display the model in opengl???

Vertex 1 -0.00423 0.78933 4.45589 {normal=(-0.00266 0.267 0.966)}
Vertex 2 -0.4276 1.862 3.8984 {normal=(-0.01221 0.4969 0.8681)}
Vertex 3 -0.81184 2.1162 3.12242 {normal=(-0.0444 0.6719 0.74012)}
Vertex 4 -1.13479 3.3543 2.4625 {normal=(-0.09215 0.7945 0.60084)}
Face 1 - vertex 1 vertex 7 and vertex 2
Face 2 - vertex 2 vertex 8 and vertex 3
Face 3 - vertex 3 vertex 9 and vertex 4

nex

F15803027d6731513ea907371c9308eb
0
ghadaShams 101 May 06, 2009 at 02:10

@kennyurge

I not really good in programming and I don’t understand the incomplete program from Anudhyan :wallbash: :surrender and not sure where to use it…Do you have the complete program? Can you send me the code to my email? kennyurge@yahoo.com Looking forward to your reply and thanks to your help..I appreaciate it.:worthy:

Me too in dead for this code .Any help please.
kennyurge , can you send it to me via mail ?

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 May 06, 2009 at 02:23

ghadaShams, this is a two-year-old thread…most of the original posters are probably long gone. If you have a specific question about 3ds model loading, you should post a new thread to ask it.