Skip to main content
gamedev.net
🔒 Locked

Lib3DS question

Started by immuner Mar 12, 2007 at 7:21 PM 11 replies 3.7k views
Original Post
immuner
immuner
Okay, I have looked through the forums and even though this might have been asked before, i would be grateful if you could take a look. As I don't have the time to create my own, I am using lib3ds to try and load a 3ds model (mostly because I would like to use animation models). No matter what, I find the lib3ds code so far very very bad even for a free lib (some basic documentation...nothing). Anyways, I can't get access to the material maps of my model apart from the first one (through materials->texture1_map). how do i get to the other diffuse maps? P.S. If someone has found a loader that I can use to do animation with models created in max, feel free to mention it. Thank you
Keyboard not found. Press F1 to Continue.
Dancin_Fool
Dancin_Fool
You may want to look into using a different format like .x or something. I've written a parser for the 3ds format before and it's not the greatest format to be using for a game.

As for documentation, I can't remember any sources exactly but if you google 3ds chunk format, I'm sure you can find some documentation on how it works which should help in learning how the library works.
immuner
immuner
yes, i know it's not the best format available but .x does not suit me as i am using opengl for my application. thank you.
Keyboard not found. Press F1 to Continue.
Kestrel
Kestrel
raw3dsData=lib3ds_file_load(fileName);

for(Lib3dsMaterial* Index=raw3dsData->materials;Index!=0;Index=Index->next)
{
Index->;texture1_map;
}

lib3ds stores its material data in a link list.
knobby67
knobby67
:) I've just asked exactly the same question over on the openGL forum, can someone point me and now it appears us in the direction of some documentation or tutorials on this lib? Thanks
Kestrel
Kestrel
lib3ds isn't well documented. But all you need is the the 'examples' folder.

player.c does most of what you'ld want to do, loading mesh data, loading materials and playing animations.

knobby67
knobby67
Kestrel thanks for that. Perhaps you or someone else who has used the lib could point me in the right direction. I've tried to run both player and 3ds2rib from the example code with half a dozen models from turbo squid but I always get a camera error? That is

./player "obelisk.3ds"
***ERROR*** No Camera found.

This appears for any .3ds or .3DS model, can anyone advise on this, do I need I certain kind of model? Thanks.

Kestrel
Kestrel
The problem is that player.c were designed to play anmations with cameras. If the 3ds file had a camera in it you'ld be able to view the animation from the camera.

You can try taking the camera code out or you can look for 3ds files that have cameras in then.

Check out 3dsViewer. The 3dsViewer.zip file has a few models in it. The canyonRun1.3DS animation has a camera in it. It might work.
immuner
immuner
Quote:
Original post by Kestrel
raw3dsData=lib3ds_file_load(fileName);

for(Lib3dsMaterial* Index=raw3dsData->materials;Index!=0;Index=Index->next)
{
Index->;texture1_map;
}

lib3ds stores its material data in a link list.


of course! you're right! thanks...coding should stop when the brain is malfunctioning...
Keyboard not found. Press F1 to Continue.
knobby67
knobby67
Hi all,
my big question for today is there some change in the way 3ds handles textures or does it not load some image formats. I wrote my own loader and couldn't get any of the models I downloaded to show textures, I thought it was me so tried to use lib3ds still no textures. Kestrel kindly pointed me in the direction of his 3dsviewer, this works with his example models. However when I try to load any models I've gotten of the net, they are like my code untextured. :s

I have used Blender to load the files and it works fine, fully textured. I'm rather at a loss. The images use .JPEG file extentions, don't work with my model loader, don't work with my 3ds code, don't work with Kestrels 3dsloader but do load on Blender. Any advise please! I'm at a loss.
Kestrel
Kestrel
The problem with my 3dsviewer is that it doesn’t load JPEG’s. It only does .bmp and .tga files.

I don't know what the problem is with the other stuff. The max length of a texture name in a 3ds file is 8 characters + a 3 character extension. If a texture name is longer than 8 characters it will truncate the name. 3ds also doesn't store path names.

Are you loading the texture correctly?
Are you loading the UV coords?
knobby67
knobby67
Hi Kestrel, thankyou for helping us understand this lib :)
Am I correct in pesuming
file=lib3ds_file_load(filename);
loads all the data including the texture names from the .3ds, and generates an openGL texture number for each texture? Or do I have to do this the normal openGL way?
I have pretty much copied the code from player.c and can see nowhere where a texture is bound to the object? But perhaps I'm misunderstanding the libary. Can you give me a pointer in the right direction? Here's what I've done based on the player.c code, but I can see no glBindTexture for binding the textures to the objects. Thankyou.
(Sorry can't see any button to put code in box?)


GLuint displayId;
Lib3dsRgba ambiant={0.2f, 0.2f, 0.2f, 1.0f};
Lib3dsRgba diffuse={0.8f, 0.8f, 0.8f, 1.0f};
Lib3dsRgba spectal={0.0f, 0.0f, 0.0f, 1.0f};
static GLfloat a[4]={0.0f, 0.0f, 0.0f, 1.0f};

void LoadModel(char *filename)
{
Lib3dsFile* file = 0;
Lib3dsMesh *mesh;
Lib3dsFace *f;
Lib3dsMaterial *material;

unsigned int p;
float s;
unsigned int i;

file=lib3ds_file_load(filename);

if ( ! file )
{
printf(" Loading 3DS file failed.\n");
exit(1);
}

displayId = glGenLists(1); /* assign display list */
glNewList(displayId, GL_COMPILE);

glBegin(GL_TRIANGLES);
for (mesh = file->meshes; mesh; mesh = mesh->next)
{
for (p = 0; p < mesh->faces; p++) /* step through mesh list */
{
f = &mesh->faceL

;
material = 0;
if (f->material[0]) /* does it have a material? */
{
material = lib3ds_file_material_by_name(file, f->material);
}

if (material) /*if it does use it's values not sure why a?*/
{

glMaterialfv(GL_FRONT, GL_AMBIENT, a);
glMaterialfv(GL_FRONT, GL_DIFFUSE, material->diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, material->specular);
s = pow(2.0f, 10.0f*material->shininess); /* make shininess an openGL value */
if (s>128.0f)
{
s=128.0f;
}
glMaterialf(GL_FRONT, GL_SHININESS, s);
}
else /*assign default material values */
{
glMaterialfv(GL_FRONT, GL_AMBIENT, ambiant);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, spectal);
}





glNormal3fv(f->normal); /*use normals */



for ( i = 0; i < 3; i++)
{

glVertex3fv(mesh->pointL[f->points].pos); /*draw the triangle*/

}
}
}

glEnd(); /* end GL_TRIANGLES */
glEndList(); /* end display list */
lib3ds_file_free(file);



}


Kestrel
Kestrel
No lib3ds doesn't load the texture. You'ld have to load them your self. You'ld also have to read the UV coordinates from the file and pass them to opengl.

Topic Locked

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

Sign in to reply to this topic.