Home Technical Talk

[Extend Programming] To create you own 3D exporter

polycounter lvl 14
Offline / Send Message
sama.van polycounter lvl 14
This a little difficult subject to me...

I would like to understand how to create exporter of 3D data.
To export material infos of this kind of information is really easy... but 3D data...

I do not speak about the programming language but what kind of data I need to export 3D information.

Final output will be an ASCII file. I do not know yet if XML or another kind.
This is first to understand how it works.

I would like to understand what I need to create polygons, to connect edge, etc...
And what is the order O_o...

when I give a look in a Collada file there are the following data :
- position
- normal
- geotangent
- geobinormal
- map1 (probably the Uvs)


I do not know where to go, my research on google is not the best because I maybe do not have the right key word, etc...


Does someone already create this kind of stuff?
Is there a tutorial or technical documentation speaking about polygon structure on a full model?

Replies

  • Eric Chadwick
    Options
    Offline / Send Message
    Export from what? The data is wholly dependent on the software you're exporting from, since each stores the 3D data in a different manner.

    For example, the 3ds Max SDK is the best place to learn Max data export. They also have an older export framework called iGame that's free to d/l.
  • Lamont
    Options
    Offline / Send Message
    Lamont polycounter lvl 15
    I wrote one a few years ago, slow as hell now (was for a Quake Engine editor). I remember I did it by getting all the faces, triangulating and printing out to file. You don't have to triangulate, just made the math easier.

    Like to get the faces I'd do something like:


    string TheFaces[] = `polyInfo -fv ($YourMesh + ".f[" + $YourFace + "]")`; // gets the vert NUMBER not LOCATION on each face

    So the output from that would be what maya is looking for YourMesh.f[XX].

    Then for each face I'd get the verts and turn that into an array. And get the point info use pointposition on each one. I'd get the vert normal from getAttr.

    For normals, you can use Polyinfo, but you gotta freeze the mesh first. But you can get each vert normal in getAttr as well. Hell you can do a lot with getAttr.
  • rollin
    Options
    Offline / Send Message
    rollin polycounter
    it depends on what the other part, the format-user (e.g the engine) needs

    the basics are vertex positions, face-to-vertex data, face-normals data

    for texture support you additionally need vertex or face -to-uv data and maybe texture name (imo its better to don't store it in here but it depends)
    you have to decide here if you want t allow a vertex to have only one ore more uv-coordinates

    all other stuff is additional:
    smoothing groups
    skin weights
    ...
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    for just a model with triangle faces and a UV map (what most formats carry) all you need:
    1. vertex array (3 elements: each holding x,y,z positions)
    2. face array (3 elements: each pointing to the index of the vertex array of that vertex)
    3. uvVertex array (same as vertex, holds U & V coordinates of the UV verts)
    4. uvFace array (same amount and order as the face array but points to uvVertex indexes)
    thats it :)

    The important thing to remember is that the face and UVface array have the same length and each index represents the same face. Vertex and UVvertex arrays though can be completely different this is because UV verts can be merged and stacked for example.

    pseudo example code:
    var vtx:Array = [{x:0,y:64,z:128},{x:256,y:32,z:0},{x:512,y:0,z:128},...];
    var fcs:Array = [[0,1,2],[2,1,3],[3,2,4],...];
    var uvVtx:Array = [{u:0.5,v:0.5},{u:0.25,v:0.1},{u:0.15,v:0.22},...];
    var uvFcs:Array = [[2,3,0],[2,1,0],[5,4,1],...];
    

    you are probably doing this in maya which I don't know well - in max I could give you an example on how to read out this data.
  • akramparvez
    Options
    Offline / Send Message
    akramparvez polycounter lvl 8
    as renderhjs mentioned those are the basic things you need for exporting a model. But majority of code actually depends on the engine or app you are exporting to and how it reads in the data. If you are writing both exporter from 3d app and importer for engine, then it depends on you.
    If you are using 3ds max as the app then you have a very good example in the Maxscript Help on How to Read and Write Geometry Data to an ASCII file.
  • sama.van
    Options
    Offline / Send Message
    sama.van polycounter lvl 14
    wow thanks guys!!

    Very interesting stuff!!

    Guyomu also gave to me this url : http://nehe.gamedev.net/

    It look very interesting and will try the first lesson on the left.

    I do not want to create crazy stuff, just would like to understand a little more some technical point about 3D...


    Anyway, I will keep updated this thread about my progression!

    @EricChadwick : first I only would like to understand what you need to save 3D info.

    @Lamont : yeah I will try Python this time. Melscript make me sleepy... I need new and fresh stuff :D and melscript is very slow... for that reason I would like to switch on Python.. But you already know it! :D

    @ rollin ; Yup I understand! About skinning etc... I will wait to export&import my first cube... and after level.... hahah! but yeah I realloy would like to learn more about it once I will start!

    @renderhjs : your exemple is very interesting! About UvVtx and UvFcs, what is the difference?
    Once seems to be 2D and the other one 3D?

    @ akramparvez I am using maya to export, but for the import I do not know yet. maybe the openGl thing but this is first to understand how it work. and with time I will think about the structure. I do not have any experience in this kind of stuff then... I will do.. again.. one more time... and again... and then I will do it fior real. hahaha.


    Really thank you guys!
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    @renderhjs : your exemple is very interesting! About UvVtx and UvFcs, what is the difference?
    Once seems to be 2D and the other one 3D?
    no the vertex data (booth UV vertex and geometry vertex) is stored as X,Y,Z positions.

    The face arrays booth UV and Geometry Face arrays point with index numbers to the corresponding verts. 0 for example means the 1st vertex in that array, 1 means the 2nd array because arrays usually start at the index 0.
    For every face however you need to assign 3 vertex points because all 3d models consist in the end of triangles. So that face array describes which 3 vertex id's are used to construct this face.


    Here is a example of how the ASE format works:
    ase_format_blocks.gif
  • Lamont
    Options
    Offline / Send Message
    Lamont polycounter lvl 15
    Yeah, go Python. Much faster and can extend to other applications with a little elbow grease.
  • sama.van
    Options
    Offline / Send Message
    sama.van polycounter lvl 14
    Plop plop!

    Here is the progression : http://a.samavan.com/openGL/SamaTest_A.exe
    (file size : 120ko, do not need to install, double click on it)


    Exporter is done with Python from Maya.
    *.exe file built with Visual C++ express 2008 and openGL Library.

    To explain quickly, my python script creates the C++ code I need to create the model with OpenGL and then I copy&past it in the main code as closed function for yet. (I didn't learn to load that kind of thing dynamically with C++ yet T_T...)

    It Look like that :
    void DrawType_AA_Type_AA ()
    {
    	glBegin(polyMethod);
    
    	// Object name :Type_AA_Type_AA
    	// Triangle count :475
    	// Vertex count :475
    
    			glColor3f(0.94f, 0.0f, 0.86f);	glVertex3f(-0.0839508914948f, 1.57715454102f, -0.0987513923645f); //0:Type_AA_Type_AA.vtx[1]
    			glColor3f(0.94f, 0.0f, 0.86f);	glVertex3f(-0.116539840698f, 1.60792755127f, -0.112678594589f); //0:Type_AA_Type_AA.vtx[3]
    			glColor3f(0.94f, 0.0f, 0.86f);	glVertex3f(-0.0791381502151f, 1.57816146851f, -0.120917186737f); //0:Type_AA_Type_AA.vtx[0]
    
    ............................. etc ..............................
    
    			glColor3f(1.0f, 0.82f, 0.82f);	glVertex3f(-1.19209289551e-009f, 1.18689689636f, 0.115272331238f); //474:Type_AA_Type_AA.vtx[225]
    			glColor3f(1.0f, 0.82f, 0.81f);	glVertex3f(-0.0321928310394f, 1.25121589661f, 0.123057403564f); //474:Type_AA_Type_AA.vtx[267]
    			glColor3f(1.0f, 0.58f, 0.55f);	glVertex3f(-0.108060331345f, 1.25121589661f, 0.0735828113556f); //474:Type_AA_Type_AA.vtx[238]
    	
    	glEnd();
    }
    

    I currently create all polygons one per one using the GL_POLYGONS method.
    I tried the GL_POLYGON_STRIP but nothing in Maya is done for helping in this way...
    Then very difficult part, I didn't success to writte a right structure for it... :(

    I also added the vertex color.

    I will try the Uvs + texture part...

    If someone has a model without texture for yet with cool vertex color on it I will be happy to create a *.exe file especially for it!
    The link I give on the top is a 475 poly model and the file size is about 120ko....
  • sama.van
    Options
    Offline / Send Message
    sama.van polycounter lvl 14
    Exporter work with the Uvs! (yeah I know this not so exciting to read).

    The exporter will also add extra C++ line to make ready the model for instancing in Open GL!
    Once the openGL read the data it stocks it and I can call the model as an intense during the simulation.

    I also found a way to insert texture data in the *.exe when compiling.
    Finally only one exe file with 3D + texture data and do not need to install for trying it.

    Now the exported data look something like that :
    GLvoid BuildCH_PC_AList ()
    {
    	instanceA=glGenLists(1);
    	glNewList(instanceA,GL_COMPILE);
    	glBegin(GL_TRIANGLES);
    	
    	// Object name :	CH_PC_A
    	// Triangle count :	1157
    	// Vertex count :	655
    
    			glTexCoord2f(0.498550236225f, 0.881278157234f);	glVertex3f(25.36561203f, 42.4318466187f, -0.389068484306f);
    			glTexCoord2f(0.533483743668f, 0.882003545761f);	glVertex3f(34.8576507568f, 37.9554977417f, -18.9861679077f);
    			glTexCoord2f(0.532193601131f, 0.892431139946f);	glVertex3f(41.2289924622f, 42.5101928711f, -18.9861679077f);
    
    ...................... etc ..................
    
    			glTexCoord2f(0.336829423904f, 0.834408462048f);	glVertex3f(-24.5715827942f, 520.895263672f, -10.8179721832f);
    			glTexCoord2f(0.343480736017f, 0.798385560513f);	glVertex3f(-22.2391300201f, 527.248352051f, -1.47946739197f);
    
    	glEnd();
    	
    	glEndList();
    }
    
    

    Here is the demo : http://a.samavan.com/openGL/SamaTest_B.exe
    I instance a model of 1157 triangle 80x100 time.
    800 instances = 925 600 poly

    I would be glad if someone could try it and let me know if this is slow or run fine on his computer.
    Image name is SamaTest.exe in the TaskManager.


    Now I will try out bones + skin data...
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    This is REALLY cool, I have been wanting to try something like this for a long time. Will be following this :)
  • giyomu
    Options
    Offline / Send Message
    Ganbatte Sama , I wait my Iphone Game engine in Maya now !! ...^^

    good progress by the way ;)
  • jfyelle
    Options
    Offline / Send Message
    If your game pipeline is based on Autodesk DCCs (max, Maya, Softimage), I'd close my eyes and go directly with FBX and the FBX SDK.
  • sama.van
    Options
    Offline / Send Message
    sama.van polycounter lvl 14
    @jocose : uh uh uh... Try it too!!!

    - how to install all the shit :
    http://www.mrmoen.com/2008/03/30/opengl-with-visual-c-express-edition/
    - Cool tutorial to start openGL :
    http://nehe.gamedev.net/lesson.asp?index=01
    http://nehe.gamedev.net/lesson.asp?index=02
    - And then python for Maya if you want to create your exporter, hoping you already know melscript :) :
    http://www.chadvernon.com/blog/tutorials/python-scripting-for-maya-artists/


    @giyomu : lol, yeah in one year not before!

    @jfyelle : Oh no no but the main idea is how to create his own exporter and then to understand how will be used the data.

    I choose to start with C++ in OpenGL (thing I never touched 10 days ago....) and then try to understand how to build a model + uvs + texture with gl.h and glu.h library.

    There is no wish to create something new etc... just wishing to understand!

    I am on the bones system + skin now...
    This is... not cute to read, I have for one week to understand all this shit in openGL before updating my python script >_<


    About FBX exporter, when you give a look inside, you finally understand you need one more script to import it in openGL.
    With my script, if a programmer wanted to get my 3D from Maya for openGL use, he do not need a reader.
    I export directly the 3D model ready for openGL use with C++ synthax.
    Then when the engine read my file, it use it directly. There is not conversion.


    But anyway I do not plan to create a game, just would like to progress in learning with practice and then want to share if someone want to try the experience too!
  • sama.van
    Options
    Offline / Send Message
    sama.van polycounter lvl 14
    Plop!

    Does someone has a good tutorial about bone structure and skinning method in openGL C++?
    I do not success to find a good "easy" one with Google. :(
  • arrangemonk
Sign In or Register to comment.