Convert Maya model into OpenGL

creater16
Unregistered
 
Post: #1
Hello all, i am doing a project which is needed to create a 3D environment with interactive control. I know it is easier to just draw all the complex images in MAYA(.ma .API or .obj format maybe) and then import to OpenGL. But i am just wondering how to convert it into openGL code(without data lost).


thanks alot !!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
It's quite easy to make a program to read .OBJ files. If you search the forum you'll find plenty of threads about it, including some with example code.
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #3
Other than using the .obj format, which is quite limited, the out-of-the-box plug-ins to export from Maya for games have been deprecated as far as I can tell, but you might still find documentation for them as "Games Translators" in the Maya docs folder in the GamesTransfer directory (click on index.html of course). I don't remember the proper way to get to it through the Maya help menu, but you can find it there too I think. Other than that there are two other practical ways to get data out of Maya and into your own OpenGL program as far as I have discovered. Neither of them are easy by any stretch of the imagination for anything more than just plain mesh data (even that can be tricky with Maya unless you just export .obj). Both of them involve writing your own exporter and importer. One, you can try to export all your data through MEL but it's often slow as mud. Or two, you have to go through Maya API which is super fast but presents many issues and is time-consuming to develop with since linking to it takes about two minutes per build on a dual 867. I have messed with option two for a while and it's not impossible but there are many issues and bugs to overcome.

I don't know how much experience with 3D coding you have, but if you're trying to make an entire complex scene and have it be interactive I would honestly recommend going with something like Blender instead.
Quote this message in a reply
creater16
Unregistered
 
Post: #4
AnotherJake Wrote:if you're trying to make an entire complex scene and have it be interactive I would honestly recommend going with something like Blender instead.


Blender? would you mind explain more about that please.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #6
You could write a plugin for maya that exports the object into a .c and .h file that would just draw all the polygons and stuff individually. So what you would end up with is a .c file with 500 lines of opengl code that needs put into a display list which is what an obj loader would do anyway.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #7
If you're going through Maya API, it's actually much easier and more space efficient to export your objects from Maya as binary data and simply load them into your GL program and feed the data to something like glDrawElements instead. Getting it into your program is not the problem, it's all the hoops you have to jump through to get it *out* of Maya in the first place. Maya API can be a real bear to deal with, and Maya itself will rarely leave a clean data set for you, which means you have to clean up the geometry yourself before you export it. Using MEL you'd probably output a text file or two and you could do as you suggest. I wouldn't export a .c file though. It would be wiser to have generic drawing code in your program which automatically knows what to do with any of your imported Maya data.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #8
What I mean is to export from maya somthing similar to this:

.h: draw()
.c: void draw() { glCircle(0, 0, 10) glLine(-1, 1) }

<fake code>

Then your code would just call that method instead of using a data resource and loader, its a bad method though I just thought thats what creater16 was looking for.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #9
unknown Wrote:What I mean is to export from maya somthing similar to this:
I understood what you suggested. I am trying to communicate to you that it's just plain impractical to do things that way. You shouldn't build complex data into your program. Using a loader is the only practical way to go. 1) It's easier to modify the data without having to re-build your application. 2) A program with all the data built into it will create a large memory footprint when it's launched. There is no need to have all the data for all the levels of your game in memory at the same time; it's better to load them as needed instead. 3) It's a pain in the rear to bother formatting text with GL commands in them. It's much easier to dump floats to disk either binary or text. Text is unecessary for private use since you don't need to explain the format to others. 4) It's easier to read one generic drawing routine that handles all of the data in a few lines rather than seemingly endless lines of custom GL code for each object.

I have an old test program that I wrote to load and draw models from my first Maya exporter. The file that does all of the loading and drawing is a whopping 291 lines with lots of fluff and comments. It's extremely simple to load a chunk of data that is already preformatted for glDrawElements or whatever you wish. If you're writing your own export plugin you quickly figure out that you can format that data on the way out in surprisingly simple ways so that your program on the other side doesn't have to do much work. The way you suggested is not simple, nor is it practical.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #10
I agree completly, I wasnt suggesting its what they should do but explaining how they could do what I thought they were asking.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #11
If you are just looking for end results, you may want to check out Unity.

http://otee.dk/unity/

Adding a Maya scene is two drag and drops. If this doesn't sound like your intentions, ignore me. Smile

-Jon
Quote this message in a reply
creater16
Unregistered
 
Post: #12
AnotherJake Wrote:I have an old test program that I wrote to load and draw models from my first Maya exporter. The file that does all of the loading and drawing is a whopping 291 lines with lots of fluff and comments. It's extremely simple to load a chunk of data that is already preformatted for glDrawElements or whatever you wish.

Thankyou AnotherJake, but i am just wondering wold you mind sending me your maya exporter as my reference please?

many thanks
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #13
Sure I guess. I just sent you an email. I don't want to share my animation code (sorry) but I can send an older hacked-up version that exports the models as materials, triangles, vertices, normals, and texture coordinates. The code was developed partly from the Maya dev docs, partly from Brian Greenstone's book, and partly from my own maniacal concoctions, so don't expect it to make much sense! If you're developing on Windows, then the Cocoa code probably won't make much sense either.
Quote this message in a reply
creater16
Unregistered
 
Post: #14
i have sent you my E-mail already. thanks
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Maya OpenGL export MrLee 10 5,758 Aug 5, 2008 11:26 AM
Last Post: MrLee
  convert NSArray in float[] bonanza 6 6,825 Jun 25, 2007 10:33 AM
Last Post: TomorrowPlusX
  New Member 3D Designer, maya, work? speakerwizard 6 4,139 Nov 13, 2006 02:29 PM
Last Post: sealfin
  Poor quality Maya PLE Render. Marjock 0 2,866 Jan 2, 2006 05:02 PM
Last Post: Marjock
  How to generate a complicated model mesh using OpenGL? huihuisakura 6 9,003 Feb 21, 2005 03:38 PM
Last Post: lightbringer