Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Game Exchange 2 File Loader GE2

0.00/5 (No votes)
2 Nov 2002 1  
Loads a 3D scene from Maya exported GE2 file/files.

Introduction

First of all, a little background on the code within.

What is it:

It's a neat little class that loads the GE2 file format as exported with Maya.

What can it be used for:

You can use it to load a scene or object exported by Maya GE2 file format. And then, you can modify further the structures and data / and or render it. Summing it up, use it in your 3D engine if you want to load Maya objects.

How does it work:

The intended way to use it is like:

  1. Simply include the ge2loader.cpp and hpp into your project.
  2. Proceed to make an instance of the object.
  3. Call the loadGroup method with a file name (sample object supplied).

Please note, if you really don't have any idea as to what GE2 is, then please do a bit of research. Or at least have a look at the file structure in the sample object, creatively called Dork.

  1. #include "..\MODULES\objGameExchange2\ge2loader.hpp"
  2. class ge gameExchange;
    void main ( void ) 
    {
  3.   int ret = gameExchange.loadGroup("dork\\dork.grp");
      if ( ret==-1) cout << "error\n\n";
    }

I don't feel that this class can be very useful to anyone at all unless they intend to plug it into a 3D rendering environment. In my opinion, GE2 export is probably the most useful of all the available exporters that you get with Maya. Future plans are to code an editor that utilizes this GE2; the editor being an intermediate tool that fine tunes the scene for game dev. purposes such as texturing, BSP generation etc... I know it's a big dream but I have had big dreams before, just have a look at my homepage.

At this time, I won't go into a detailed description on the file format or the loader code itself. But rest assured that it does work. Please visit my homepage for more information on my little coding projects.

I have had a few people asking me how to use the data structure for rendering, I have included this email where I explain how to use the data structure.

My reply to Mondi's query:

Sorry for the late reply, I have not been enthusiastic to look up the info to help you, primarily because I know I lost my source code to this long ago :( Anyway I'm bored today and decided to download the ge2loader.zip from my homepage and have a quick look and attempt to explain things to you :). So referring to ge2loader.zip. The object is called a, within my demo code.

a.obj.cout tells me there are 6 objects to render. The objects exists at a.obj.o[0] to a.obj.o.[5].

An object is made up of:

  • name
  • vertList
  • normList
  • uvList
  • faceParts
  • triCount
  • tri

OK, let's do a theoretical example. What you want to do is render the first triangle. If you debug the demo code and have a look at the structure, you will see that the first Tri of the first object named "InsideFaceShape" expands to:

  • v[0] = 454
  • v[1] = 455
  • v[2] = 1

This is telling me to look up those vertices:

So, to render the first tri of the first object:

Beginrender() {

// this demonstrates access to the first vertex

// a. : the entire ge2 structure with all the various files

// a.obj : a pointer to an array with count and another pointer o

// a.obj.o: another pointer to an array of objects


// ok, the first object a.obj.o[0]

// is made up of many triangles a.obj.o[0].tricount

// a.obj.o[0].tri is a pointer to indexes to the real float values

// the idea is to grab an idex a.obj.o[o].tri[0].v[0]

// this is actually the number 454 according to my demo

// this means you want vertex number 454 from the vertex array


// for example, a.obj.o[0].vertList.v[0].x

// this is the first vertex float value for the x-coordinate

// BUT! this is not the X coord for the first point of the first triangle

// it is simply a list of vertecies , and the idea is to access them

// with indexes

// in the same way, you can access the UV's and normals 


// whew.. I hope this helps somewhat.. 


glvertex3f (
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[0]].x,
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[0]].y,
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[0]].z,
)

glvertex3f (
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[1]].x,
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[1]].y,
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[1]].z,
)

glvertex3f (
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[2]].x,
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[2]].y,
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[2]].z,
)
}

OK, now I know it seems terribly complex, and when I did this code, I was rushing and didn't think out the structures well. One of the things that is probably confusing you is Obj and o... Instead, I should have named:

  • Obj as ObjList
  • and o as Obj

Another thing is faceParts, I cant remember exactly.. but what it is that each triangle has a material description.. best way to analyze it is to start debug mode and expand the structure in a Watch list.

As far as this goes for use in a big project, it probably isn't good enough, but it's fairly useful to load all the text files into a structure, and hopefully is quite usable for testing.

> "mondi"  "RJ++" <robertj@nettaxi.com> [CodeProject] 
> Game Exchange 2 File LoaderDate: Sun, 27 Oct 2002 05:32:17 -0500
>
>Hi there,
>
>I've been experimenting with the ge2 format for awhile now, 
>your code helped me clear up a few issues i was having.
>
>question though, being not a terribly good programmer 
>could you point me in the right direction for
>accessing the vertex/face/normal lists so that 
>I could get my app to render the objects?
>
>it would be incredibly helpful :)
>
>thanks
>
>mondi

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here