MaLoader. .ma Maya Ascii Scegegraph parser for jME loading and other uses

As soon as I've finished it you will be able to buy it :slight_smile:

Ha-ha, for how much?

If you post a 2009 .ma file into pastebin I could make it compatible. I however dont have a 2009 wares.



MaLoader is updatated.



1:  Texture coordinates and experimental texture loading are implemented.

2:  Currently no normal loading, however normals get built from jme's normalbuilder.

3:  Large models are supported, but jme's minimizeVerts may take a while. if youre looking at more than 50 000 tris.

4:  Faces larger than triangles are also supported. No more triangulate on export neccesary.

5:  Material setup is halfway there, doesnt set up materials but makes the proper data structures.

6:  Code a lot cleaner.

7:  Parsing now more stable.

9:  Changed the data structures to arrays, buffers were good but it involved duplicating them to arrays now and then.



What needs to be done:



1: transform capabilaties.

2: support for maya's 'shorthand for attributes' as of yet, the difference is under maya's export options you have to click 'use full names for attributes on nodes' right in the bottomā€¦

3: normal setup (I need help with this one, I have edge info that says wich ones are hard and soft but know nothing about building normals)

4: material preferences loading

5: transparency texture loading



To load a maya scene heres what I do:



1: make sure all your material nodes are simple. Materials that are used must all be blinn and have one texture connection to color.

2: freeze all transformations

3: edit->delete all by type->history (of course)

4: select the objects to export (its easier if theyre all in one group or transform node)

5: file->export selection. (make sure that youre not exporting truncated attribute names)



Do note that if you have a large polyginal object with lots of seperate surfaces a edit mesh->seperate should help with loading speeds, but hinder jME's displaying speeds since you get more trimeshes to cull and draw.



Get it from the mapspinner source on google code.


Hi lanmower,



I post 2 files ma of Maya 2009:



http://pastebin.com/f26133c56 ā€“ sphere without texture.

http://pastebin.com/f3b0d8ef9 ā€“ A trunk of a tree very simple with texture, only color.



The models are triangulate.



Thanks.

Regards.

here's a pretty ineffecient and hacky normal creation thingyā€¦



final   static   public   void   recalculateNormals(TriMesh cl_mesh, boolean b_invert) {
      final   FloatBuffer      lcla_vertices = cl_mesh.getVertexBuffer();
      final   IntBuffer      lcla_indices = cl_mesh.getIndexBuffer();
      
      final   TriStruct      lcla_tris[] = buildTriStructArrayFromMesh(cl_mesh);
               
      FloatBuffer      lcla_normals = cl_mesh.getNormalBuffer();

      if(lcla_normals == null) {
         lcla_normals = BufferUtils.createFloatBuffer(lcla_vertices.capacity());
         cl_mesh.setNormalBuffer(lcla_normals);
      } else if(lcla_normals.capacity() < lcla_vertices.capacity()){
         lcla_normals = BufferUtils.createFloatBuffer(lcla_vertices.capacity());
         cl_mesh.setNormalBuffer(lcla_normals);
      }

      Vector3f      lcl_n = new Vector3f(0, 0, 0);
      int      li_temp2;
      int      li_count = 0;

      for(int li_index = 0; li_index < lcla_indices.capacity(); li_index++) {
         li_temp2 = lcla_indices.get(li_index) * 3;
         li_count = 0;
         lcl_n.set(0, 0, 0);

         for(TriStruct lcl_tri : lcla_tris) {
            if(lcl_tri.vertexIndexInTri(li_temp2) != -1) {
               lcl_n.addLocal(lcl_tri.mcl_tri.getNormal());
               li_count++;
            }
         }

         if(li_count > 0) {
            lcl_n.divideLocal((float)li_count);
            lcl_n.normalizeLocal();
         }

         if(b_invert) {
            lcla_normals.put(li_temp2, -lcl_n.x);
            lcla_normals.put(li_temp2 + 1, -lcl_n.y);
            lcla_normals.put(li_temp2 + 2, -lcl_n.z);
         } else {
            lcla_normals.put(li_temp2, lcl_n.x);
            lcla_normals.put(li_temp2 + 1, lcl_n.y);
            lcla_normals.put(li_temp2 + 2, lcl_n.z);
         }
         
      }
   }



final  static  private     TriStruct[]     buildTriStructArrayFromMesh(TriMesh cl_mesh) {
       FloatBuffer     lcla_vertices = cl_mesh.getVertexBuffer();
        IntBuffer       lcla_indices = cl_mesh.getIndexBuffer();
       
        lcla_vertices.rewind();
        lcla_indices.rewind();
       
       TriStruct       lcla_tris[] = new TriStruct[lcla_indices.capacity() / 3];
       
        Vector3f        lcl_a = new Vector3f();
        Vector3f        lcl_b = new Vector3f();
        Vector3f        lcl_c = new Vector3f();
       
        float           lf_temp;
        int             li_temp;
        float           lf_dot = -1;
        int             li_triCnt = 0;
       
        for(int li_index = 0; li_index < lcla_indices.capacity(); li_index += 3, li_triCnt++) {
            lcla_tris[li_triCnt] = new TriStruct();
            lcla_tris[li_triCnt].mcl_tri = new Triangle(new Vector3f(), new Vector3f(), new Vector3f());
           
            li_temp = lcla_indices.get(li_index) * 3;
            lcla_tris[li_triCnt].mia_indices[0] = li_temp;
           
            lcl_a.x = lcla_vertices.get(li_temp);
            lcl_a.y = lcla_vertices.get(li_temp + 1);
            lcl_a.z = lcla_vertices.get(li_temp + 2);
           
            li_temp = lcla_indices.get(li_index + 1) * 3;
            lcla_tris[li_triCnt].mia_indices[1] = li_temp;
           
            lcl_b.x = lcla_vertices.get(li_temp);
            lcl_b.y = lcla_vertices.get(li_temp + 1);
            lcl_b.z = lcla_vertices.get(li_temp + 2);
           
            li_temp = lcla_indices.get(li_index + 2) * 3;
            lcla_tris[li_triCnt].mia_indices[2] = li_temp;
           
            lcl_c.x = lcla_vertices.get(li_temp);
            lcl_c.y = lcla_vertices.get(li_temp + 1);
            lcl_c.z = lcla_vertices.get(li_temp + 2);
           
            lcla_tris[li_triCnt].mcl_tri.set(0, lcl_a);
            lcla_tris[li_triCnt].mcl_tri.set(1, lcl_b);
            lcla_tris[li_triCnt].mcl_tri.set(2, lcl_c);
            lcla_tris[li_triCnt].mcl_tri.calculateNormal();
        }
       
        return lcla_tris;
   }



import com.jme.math.Triangle;

public class TriStruct {
   // indices into the float buffer for the triangle points...divide by 3 to get the indices into the index buffer...
   public   int         mia_indices[] = new int[3];
   public   Triangle   mcl_tri;
   
   public   TriStruct() {
      
   }
   
   final   public   int      vertexIndexInTri(int i_index) {
      if(mia_indices[0] == i_index) {
         return 0;
      }
      
      if(mia_indices[1] == i_index) {
         return 1;
      }
      
      if(mia_indices[2] == i_index) {
         return 2;
      }
      
      return -1;
   }

}

Youre files were in shorthand attributes mode, my first iterations of the code didnt support that, get a new copy now since I have a full rewrite uploaded.



Thats right guys. FULL REWRITE. Muwhahahahahaaaaa!



I'm never going to sleep, NEVER!



Oh well, I still need someone to help me with normal creation since I'm a complete bozo.

Where are all the real coders, we need help! I can only do the easy stuff.

Lol the 2009 files work nicely!



Never expected that to happen :slight_smile:



I am a god!



(Scurries back to eclipse and maya)

Hi,



I download the code and there are little errors.



In MaToJme.java


node = MaMesh.createIfType(type, line);



cannot find the method and incompatible types
found: "MaMesh.createIfType" required: "MaNode"

And in MapStreamer.java some methods are duplicate.


I run the MaLoaderTest and seems that the model is loaded, no throws errors in runtime but I can't see the model.

What can be happening??

Thanks
Regards

That could be a sync problem with the google code svn, I have a real hard time getting my svn uploads in properly.

Deleted/uploaded it again, tortoisesvn seems to merge some of my commits instead of replacing the uploaded files.

Hi,



Wonderful!!!



I can see the models, great work!!



The model of tree has a texture, only color. When the model is loaded the color don't see.



I test a model with a texture file and I can see the model perfect! with the texture.



In JME the objects support only color???



Thanks

Regards

Is it possible to provide this code again? Pastbin is just for a short duration! Would be nice if we would have something about thisā€¦even it is not(?) stableā€¦

iā€™ve still got the code, though i couldnā€™t get it to workā€¦



will put it here in a few minutes



http://www.jmonkeyengine.com/jme/files/ma.zip

I still have it, it works afaikā€¦



You can also find it (a bit hard) on google code at previous revisions in the code browser, I think the last copy with maloader was in the forties.



I plan on taking up this project in conjunction with extending it for building portal systems when I have some more free time again, so its not a dead idea :slight_smile:



The code works, and is quite stable, I could for instance import even paint effects trees converted into polygons with all the leafs and everything.



Try not to push the polycount too high on a single mesh since that will make the normal building take very longā€¦

FYI, it seems to be r41 that has the ma loaderā€¦ i'm not entirely sure what revision I had pulled my copy from.