• Advertisement
Sign in to follow this  

3d models (maya)

This topic is 4598 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

i need some help now with loading 3d models in opengl. i can't find very much info on the web. i would mostly like to use maya, but if you know of another language that would be good, say so. i went to nehe's tutorial on importing milkshape models, but i still don't get it. i need something a little more clear, does anybody know of any tutorials or books that would be helpfull?

Share this post


Link to post
Share on other sites
Advertisement
try loading wavefront files. They are textbased and easy to parse. most 3d package will be able to export to .obj. As for tutorials... google is you friend.

Share this post


Link to post
Share on other sites
ok, i still have a little problem. i just don't know how to load models, i can export them and everything. i don't know how to import them into my c++ project. i searched on google for a long time, and i just can't find any good tutorials, actaully, i can't find any at all on how to get them into my project. do you know of a good tutorial or book or something?

Share this post


Link to post
Share on other sites
For a tutorial on loading Obj files, I *think* there is one here at UltimateGameProgramming. You will have to go to Tutorials->OpenGL then look though the pages. Note that you will need a flash enabled browser to use that site (which I don't). See if one is there, if not I may have another site that you can find stuff.

Share this post


Link to post
Share on other sites
thaaaaank you, this site is awsome, and it does have one, but what it the other site you were talking about?

crap, it doesn't really explain anything though, do you know of another site that might help?

Share this post


Link to post
Share on other sites
The format is realy simple. it goes like this:

a vertex is a line that starts with the letter v followed by 3 floating point numbers. i.e
v 3.01213 -1.2345 1.000

a vertex normal starts with vn followed by 3 floatig point numbers
vn 1.000 2.345 3.1415

a texture coordinat starts with vt followed by 2 numbers
vt 0.123 0.567

a triangle looks like this

f 1/1/1 10/3/5 15/4/6

meaning that
- the 1st point of the triangle uses the first vertex, the first normal and the first texture coordinate in the file
- the 2nd point uses the 10th vertex, 3rd normal and 5th texture coordinate
- the 3rd point uses the 15th vertex, 4th normal and 6th texture coordinate

you can ignore the rest of the lines (if any).

(there is a bit more but this will do for a start.)

now you have to do 2 passes on the file. in the first pass you count the number of vertex, normals texture coordinates, then you allocate memory to hold the date and in the second pass you you read in the data.

Share this post


Link to post
Share on other sites
I would look at the FBX exporter that comes with Maya. Handles multiple animations, materials, textures, skinning etc

The FBX SDK can be downloaded from the Alias website which is all you need to load the files.....

Share this post


Link to post
Share on other sites
but not every 3d package can export that format...

Share this post


Link to post
Share on other sites
dude, thanks nefthy, but my only problem is i don't know how to export them so i can count the triangle stuff, and i don't really know how to load it up, but that will help, cause i get it alot better now. and if i experiment enough, i will get it. and, i know this is a newby question, but is there like a step by step or really in depth tutorial on how to export models from any modeling program and then load it up in c++ and opengl.

[Edited by - iedoc on June 10, 2005 8:44:58 PM]

Share this post


Link to post
Share on other sites
this just SUCKS. i can't find anything good on exporting models from maya, then loading them in c++ and opengl. can anybody please help me?

Share this post


Link to post
Share on other sites
I don't know how you kann export the in maya (haven't ever used maya), but any 3d package I have seen can do it. It should be somthing like File -> Export -> wavefront .obj

For testing your code you can find one here

As for loading it...


#include <stdio.h>

char* line = NULL;
unsigned int vertexc, normalc, texturec, facec; /* we use this to count the vertexes etc. */
size_t len = 0; /* the size of line */
size_t read = 0; /* how many chars read */
File* f = fopen(filename);

if (f == NULL) {
/* couldn't open the file */
return; /* probably want to report it to) */
}

/* firstpass */
while ((read = getline(&line, &len, fp)) != -1) {
if (line[0] == 'v') {
if (line[1] == ' ') { /* line starts with v => vertex */
vertexc++;
} else if (line[1] == 't' { /* vt => texture */
texturec++;
} else if (line[1] == 'n' { /* vn => vertex normal */
normalc++;
}
} else if (line[0] == 'f' && line[1] == ' ') {
facec++;
}
}

rewind(f); /* go to start of file again */

/* now you know how many vertexes, etc you have.
Allocate your data structures that will hold your
model and just do the same thing again this time
yousing sscanf with an apropriate format string
to read the data (i.e. "v %f %f %f" for a vertex).
I leave this as an excercise */



/* second pass ... */

fclose(f); /* close the file */






You may want to also take a look here (don't let the linux in the header scare you, the function are the same):
sscanf
fopen
fclose

A complete .obj loading program can be found in the glut source code under demos smooth or something. But you should try writing your own.

Share this post


Link to post
Share on other sites
Quote:
Original post by iedoc
this just SUCKS. i can't find anything good on exporting models from maya, then loading them in c++ and opengl. can anybody please help me?


yeah, my website is pretty much dedicated to explaining how to do it.

http://www.robthebloke.org

Check out the openGL pages for a few examples, and the Maya API->Maya exporter factfile for some more indepth info.

I'm not sure what 3D package FBX isn't available for, i know that maya, xsi, max, cinema4d, milkshape, houdini support it? It's prolly the best around at the moment for support (unlike the dotXSI where plugins exist for all the packages, but usually in some crippled state).

If you need anything more than what the obj files gives you, then it's definately the one to use....

Share this post


Link to post
Share on other sites
Quote:
Original post by iedoc
dude, thanks nefthy, but my only problem is i don't know how to export them so i can count the triangle stuff, and i don't really know how to load it up, but that will help, cause i get it alot better now. and if i experiment enough, i will get it. and, i know this is a newby question, but is there like a step by step or really in depth tutorial on how to export models from any modeling program and then load it up in c++ and opengl.


make sure you have loaded the obj/fbx plugins for maya, window->settings/preferences->plugin manager

The rtg format is also available with maya, although it pretty much has the same amount of data as a 3DS file, (ie anims, materials etc), the format is not the nicest around.

Share this post


Link to post
Share on other sites
thanks robthebloke, i downloaded some plugins, but couldn't figure out how to use them, that should help alot. and that is a nice site you got there. thanks a ton guys for replying.

Share this post


Link to post
Share on other sites
FINALY if figured out how to export .obj files from maya, thanks so much, but now ill have to find a way to load them up in c++, i think i can get this to work now.

Sorry for bugging you guys, but i cant find a tutorial on how to load obj files in c++ opengl, not that yours is bad robthebloke, but i can't understand them very well when there in the c++ source code, but thanks anyways, i still like your site and i can still learn from your tutorials, but i cant learn very well how to load obj files without cut and paste, please help. i don't think it should be that complicated since its pretty much only points in the file, but i could be wrong. i hate sounding like a newb.

[Edited by - iedoc on June 11, 2005 6:31:22 PM]

Share this post


Link to post
Share on other sites
nefthy, i just read your source code and got it very well, thanks a lot. but now i have the stupid problem of puting it on the screen, how do i do that?

i know this is going to sound like a dumb question, but ive been trying to load obj for a long time, ive experimented and searched for a long time, but, what is the easiest way of learning how to do this, i just can't find a good tutorial. is there a book that might be helpfull?

[Edited by - iedoc on June 11, 2005 10:29:12 PM]

Share this post


Link to post
Share on other sites
C++ source code for an obj loader. It's not 100% finished, but all of the mesh and material stuff works. (it's just the nurbs and curves that are a little flaky, but that shouldn't affect you since maya wont export them).

The obj file format is desceptive, it's actually a bit more complicated than it at first seems - most of this is down to the format not identifying how many data elements there are before you read them. The format does also support nurbs and materials, though not many people handle those.

My loaders are designed to be a bit more complete. They get slightly more complicated because they can optionally calculate normals/tangents and they can convert the data into vertex arrays or vertex buffer objects. (C++ one doesn't calculate tangents).

gametutorials.com used to have an obj loading tutorial as well....

Share this post


Link to post
Share on other sites
all right, i guess ill try it again. actually, ill just keep trying it till i learn how to do it.

isn't there a book or something that will tell me how to do this?

also, is nefthy's code right? will that help me with loading the .obj, cause i tried for like 3 hours to use that and one of nehe's tutorials to get it to work, and i couldn't figure it out.

i don't even care anymore if its .obj files that are loaded, i just want to learn how to load models from maya. and if not that, any modeling program is fine.

[Edited by - iedoc on June 12, 2005 3:53:28 PM]

Share this post


Link to post
Share on other sites
Why don't you post what you've coded so far so we can see what is wrong. Also post the obj file you are trying to load.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement