kev 3ds loaders setBounds

dudes what version of xith3d are u using? and where did u upload the new loader?

loader i would guess is on yer site kev?

i dont mind rolling back my xith version. just wondered what versions u chaps are using? i updated from the CVS. it didnt work in the older version i had.

i get this error:

java.lang.NoSuchMethodError: com.xith3d.scenegraph.Shape3D.updateBounds(Z)V
at org.newdawn.xith3d.threeds.SmoothGroupProcessor.process(SmoothGroupProcessor.java:157)
at org.newdawn.xith3d.threeds.TDSLoader.processChunk(TDSLoader.java:125)
at org.newdawn.xith3d.threeds.TDSLoader.load(TDSLoader.java:92)
at ant.xith3d.mod.Building.loadBuildingData(Building.java:58)
at ant.xith3d.RenderWindow.init(RenderWindow.java:146)
at ant.xith3d.RenderWindow.(RenderWindow.java:40)
at ant.xith3d.Main.main(Main.java:8)

my load code is:


TDSLoader tload = new TDSLoader();
System.out.println("innited the 3ds file: " + tload);
model = tload.load("model/", new FileInputStream(new File(bFileName)), true);
// model.setIsOccluder(true);
// model.setShowBounds(true, true);
System.out.println("loaded the 3ds file: " + tload);

Well everything works fine when loading, but you screwed something up BIG time (/me shoots kev for making him waste over 4 hours debugging and doubting his own code, f**** homework)… ;D

new IndexedTriangleArray(context.numberOfFaces * 3,vertexFormat,context.numberOfFaces * 3);

That’s totally wrong, the first argument takes the exact number of non-duplicated vertices, and the last one takes the size of the array holding the vertices’ indices
corrected
if (context.indexedGeometryUsed) {
context.indexedGeometry = new IndexedTriangleArray(context.numberOfVerts ,vertexFormat,context.numberOfFaces * 3);

:sad panda:

Thank you KevGlass :stuck_out_tongue:

http://www.users.xith.org/JavaCoolDude/Pictures/3dsloaded.jpg

Notice the nice bumping on the model :wink:


  private void proccessShape3D(Shape3D shape){
    IndexedTriangleArray geometry = (IndexedTriangleArray)shape.getGeometry();

    int[]        indices     = geometry.getIndex();
    float[]      texcoords   = new float     [geometry.getValidVertexCount()*2];
    Point3f[]    vertices    = new Point3f   [geometry.getValidVertexCount()];
    Vector3f[]   normals     = new Vector3f  [vertices.length  ];
    TexCoord3f[] tangents    = new TexCoord3f[vertices.length  ],
                 binormals   = new TexCoord3f[vertices.length  ],
                 texcoords3f = new TexCoord3f[vertices.length  ];

    geometry.getTextureCoordinates(0,0,texcoords);

    for(int i = 0; i< vertices.length; i++){
      texcoords3f[i] = new TexCoord3f(texcoords[i*2 + 0],
                                      texcoords[i*2 + 1],0);
      geometry.getCoordinate(i, vertices   [i] = new Point3f ());
      geometry.getNormal    (i, normals    [i] = new Vector3f());
    }

    OjectStructure.generateTBN(indices , vertices , normals,
                               tangents, binormals, texcoords3f);

    TriangleArray newGeometry = new TriangleArray(indices.length,
                                                  GeometryArray.TEXTURE_COORDINATE_3 |
                                                  GeometryArray.COORDINATES          |
                                                  GeometryArray.NORMALS,
                                                  3,
                                                  new int[]{0,1,2});

    for(int i=0; i<indices.length; i++){
      newGeometry.setNormal           (  i, normals    [indices[i]]);
      newGeometry.setCoordinate       (  i, vertices   [indices[i]]);
      newGeometry.setTextureCoordinate(0,i, texcoords3f[indices[i]]);
      newGeometry.setTextureCoordinate(1,i, tangents   [indices[i]]);
      newGeometry.setTextureCoordinate(2,i, binormals  [indices[i]]);
    }
    parent.addChild(ShapeFactory.getTexturedShape(newGeometry,
                                                  "Data/chalicebase.png",
                                                  "Data/chalicedot3.png",
                                                  "Data/torusgloss.png",
                                                  .1f,.1f,.1f, 1, 1, 1, 32));
  }

Loading the chalice took 2.422 S
Loading the torus took 1.016 S
Loading the angel took 43.5 S

Man you gotta work on dat speed

http://www.users.xith.org/JavaCoolDude/Pictures/speed.jpg

Erg, sorry about that, I actually had the right code in originally, but while debugging I ended up changing it to that.

Doh!

New version uploaded…

Speed:

Have to say its not something I tend to worry about too much, these loaders are only convienience. However, if you could send me the “angel” model I’ll see if I can use it as a benchmark…

Sorry guys, seems to have caused you more trouble than its worth. See… this is why I don’t do fixes :wink:

Not sure when I’m going to get my next free patch… shouldn’t really be posting now… should be off to werk… man JGOF is addictive.

Kev

sent :slight_smile:

Ant,

I try to be using the latest version from CVS, but I do jar it up, so I might be up to a week behind…

Are you up and working with the new code now, or do I need to check the latest stuff out again?

Kev

i get the same error. and i am now testing againt the jeep model. the loader finds and starts loading the model ok. but then hits that exception.

i am also puting my models in my jar so to test it the same way u seem to be- and get the same error.

going to try and roll back xith3d a few weeks and try again.

Na, no worries, I’ll get the latest source from CVS tonight and find out what the problem is…

Also noticed that I don’t bother reading the contents in the file into memory before processing it, man I was in a rush, this should help the speed a fair bit…

More time tonight, assuming I don’t get obsessed over my newly arrived IPOD :wink:

Kev

sod the iPod! will take a few hours to charge up anyways dude :).

I’ve just tried it against the latest stuff pulled out of CVS, seems to work fine…

Are you perchance using the xith3d.jar out of CVS which appears to be completely out of date?

Kev

gurrrr- indeed i am- would have thought it would be the the jar with the build (dont no why) :).

bugger- ok me build the new cvs version and give it a wing.

Well, hopefully this will make JCD happy… the bad news is, I’m not sure the normal calcualtion is right anymore… however, I’m told the C++ version takes about 2 seconds to load the angel model, now the java version takes about 0.2 seconds on my laptop to load the model. Wahay! :slight_smile:

New version of the xith-3ds.jar is on the website, hopefully the normal generation is still correct… let me know if people start seeing oddities…

Now, my ipod is calling me… “come play with me…”

Kev

Damn man just when I created the JCD format that basically converts a 3Ds model into an idexed vertex, normal, texcoord3f, tangent, binormal indices form…
The angel model took a little less than 1 sec to load in my format.
Lemmie check your new loader…

Dude the speed issue is completely solved, two thumbs up :slight_smile:
The normals on the other hand…hmmm I think they might be screwed up a bit, let me dig into that a little more

Cheers, I couldn’t quite decide if they were right or not… hard to tell with visual inspection… let me know what you find out…

Cheers for spending time on this,

Kev

Check out how fast the JCD is loaded
Reading file angel took 0.078 S :o
Simple question before I go and check your code again: Are you using NIO buffers by any chance?

Nope, no NIO for me… didn’t even get round to buffering it actually, didn’t realise performance was that critical to you… probably best you stick to your own format if you need that much performance…

Kev

No no man maybe I should have expressed myself a bit better;
What I’m trying to say here is using NIO buffers will seriously speed up your loader.
As a matter of fact, your 3DS loader is a critical part in creating a model with my format specifications.
A better thing would be explaining how I create the JCD format:
First of all I load a 3DS model using your loader, which is a magnificent piece of code.
Second I retrieve the IndexedGeometry as well as the normals, textureCoordinates, indices and the number of unique vertices.
After that, I generate the TBN matricies which require over 5 normalizations per vertex, and yet is done at a litte over 0.01 s for a > 5000 vertex model.
Finally I save the newly created model using the following function:


  public static void saveJCDModel(Tuple3f[] ve  , Tuple3f[] no,
                                  Tuple3f[] ta  , Tuple3f[] bi,
                                  Tuple3f[] te  , int[]     indices ,
                                  int validVertexCount, String    name){
    ByteBuffer modelInfo = ByteBuffer.allocateDirect(ve.length*60       +
                                                     indices.length *4  + 8);

    modelInfo.putInt(indices.length).putInt(validVertexCount);

    for(int i = 0; i < validVertexCount; i++){
      modelInfo.putFloat(ve[i].x).putFloat(ve[i].y).putFloat(ve[i].z);
      modelInfo.putFloat(no[i].x).putFloat(no[i].y).putFloat(no[i].z);
      modelInfo.putFloat(ta[i].x).putFloat(ta[i].y).putFloat(ta[i].z);
      modelInfo.putFloat(bi[i].x).putFloat(bi[i].y).putFloat(bi[i].z);
      modelInfo.putFloat(te[i].x).putFloat(te[i].y).putFloat(te[i].z);
    }

    int size = indices.length/3;

    for(int i = 0; i < size; i++)
      modelInfo.putInt(indices[i*3 + 0]).
                putInt(indices[i*3 + 1]).
                putInt(indices[i*3 + 2]);
      modelInfo.flip();

    try{
      new FileOutputStream(name + "JCD.jcd").getChannel().write(modelInfo);
    }
    catch(Exception e){}
  }

All those steps take a little over 1 s with the new version of your loader.
Now if you were to load your meshes with an NIO buffer, the speed of all the mentioned operations will definitely fall below 1 s, I’m positive.

PS: Here’s how I load my format, it might help you out tweaking your loader


  public static GeometryArray readJCDModel(String name){

    FileInputStream fileStream     = null;
    ByteBuffer      modelInfo      = null;
    byte            fileContents[] = null;

    try{
      fileStream = new FileInputStream(name + "JCD.jcd");
      fileContents = new byte[fileStream.available()];
      fileStream.read(fileContents);
      modelInfo = ByteBuffer.wrap(fileContents);
    }
    catch(Exception e){}

    int[]        indices     = new int       [modelInfo.getInt()];
    Point3f[]    vertices    = new Point3f   [modelInfo.getInt()];
    Vector3f[]   normals     = new Vector3f  [vertices.length  ];
    TexCoord3f[] tangents    = new TexCoord3f[vertices.length  ],
                 binormals   = new TexCoord3f[vertices.length  ],
                 texcoords3f = new TexCoord3f[vertices.length  ];

   for(int i = 0; i< vertices.length; i++){
      vertices   [i]= new Point3f   (modelInfo.getFloat(),
                                     modelInfo.getFloat(),
                                     modelInfo.getFloat());
      normals    [i]= new Vector3f  (modelInfo.getFloat(),
                                     modelInfo.getFloat(),
                                     modelInfo.getFloat());
      tangents   [i]= new TexCoord3f(modelInfo.getFloat(),
                                     modelInfo.getFloat(),
                                     modelInfo.getFloat());
      binormals  [i]= new TexCoord3f(modelInfo.getFloat(),
                                     modelInfo.getFloat(),
                                     modelInfo.getFloat());
      texcoords3f[i]= new TexCoord3f(modelInfo.getFloat(),
                                     modelInfo.getFloat(),
                                     modelInfo.getFloat());
    }
    for(int i = 0; i< indices.length; i++)
      indices[i] = modelInfo.getInt();

    TriangleArray newGeometry = new TriangleArray(indices.length,
                                                  GeometryArray.TEXTURE_COORDINATE_3 |
                                                  GeometryArray.COORDINATES          |
                                                  GeometryArray.NORMALS,
                                                  3,
                                                  new int[]{0,1,2});

    for(int i=0; i<indices.length; i++){
      newGeometry.setNormal           (  i, normals    [indices[i]]);
      newGeometry.setCoordinate       (  i, vertices   [indices[i]]);
      newGeometry.setTextureCoordinate(0,i, texcoords3f[indices[i]]);
      newGeometry.setTextureCoordinate(1,i, tangents   [indices[i]]);
      newGeometry.setTextureCoordinate(2,i, binormals  [indices[i]]);
    }
    return newGeometry;
  }

PS2: I convert IndexedGeometry into non-Indexed because of a bug in the shadow generation. I will try to look into that and maybe fix it.
Thanks again for the help :slight_smile:

happy happy fellas :slight_smile: all it tops. it works here- seems the shadows are atad buggered mind :(.

nice speedy here by the way- but more is always good no? if the shadows are abit strange is that to do with normals?

i going to do some model tests to see the best way to make a model for the loader. mine seem not to work. maybe i need to group um… will keep u posted :)- top work the both of u. its has become a tip top loader!

normals anyone :wink: shadows?

hehhehe- push push.