Help me with my attempted shared TDSModel

Ok. Without really reading all the 3DS loader code (it’s rather difficult to follow and uncommented), I tried to “brute force” the creation of a sharedCopy TDSModel. I’m using a slightly modified 3ds loader library, the changes being:

  1. When you use the loader to load a 3DS file, now you have to put the calling class (this) into the constructor, like this:
TDSLoader(this).load(file, true);
  1. Various changes such as the changing of private varibles to public, and the creation of a Point3f object inside the TimedTransforms to allow me to copy them into the new TDSModel.
  2. Creation of an Iterator in TDSModel.

The source is here.
The library is here. You can just drag the library into one of your universal library folders (the java.ext.dirs property will show you where this is).
The library source with my modifications is here.
And an example animated model you could use is here.

I didn’t sign the library, i hope that doesn’t cause any problems…

The TDSModel has two things that need to be copied I think. One is an ArrayList that contains all the transforms, and is used with the setTime() function, and the other are the actual children of the model. That is why traverseTree() is called twice, and that is the reason for the arraylist parameter. traverseTree() will go through either the ArrayList or the actual TDSModel, and add TransformGroups, Transform3D’s, frames, and finally the Shape3D objects at the end to the model variable (the model that I’m trying to make into a sharedcopy).

Currently, the Ship class will make an identical looking copy of the TDSModel, but it WILL NOT ANIMATE!! ARG!! :slight_smile:

My guess is that I’m forgetting to copy something else…

Somebody please help me out.

Since I have no computer to actually build this on at the moment I’m afraid this is from visual inspection:

The assumption that you only ever have one group inside another may be wrong…

The copying code would probably make more sense and need less public variables if you added copy() to TimedTransform and made it return a copy of itself. Then you could just have one special case for TimedTransforms (using an instanceof?)

I’m not 100%, but I think the reason it doesn’t work is because your argument “arraylist” passed to “traverseTree” is never set to true? This means that while the TDSModel has the transforms added beneath it in the scenegraph they’re not added to its internal list which is used to control the animation. The flag “arraylist” is actually redunant anyway since any TimedTransform you create should be added to the TDSModel with addTransform().

Kev

PS. Its still a really bad idea to be sticking libraries for stuff like this in your “universal library folders”. Its not realistic to your eventual deployment.

[quote]Since I have no computer to actually build this on at the moment I’m afraid this is from visual inspection:

The assumption that you only ever have one group inside another may be wrong…
[/quote]
No, I’m used a modified version of the traverseTree function to print out the entire tree of the TDSModel, and it seems like the TDSModel itself has say, 4 children. Then each of these will have only one child, which will only have one child, untill you have 4 children for the TDSModel, and each of these children will have one child totalling for a line of 4 children (if that makes sense). Then the array list is a bit different, it has about 12 children (depending on the model), and each of these has a line ranging from like 4 to 2 children… but like the others, only one child per transform.

[quote]The copying code would probably make more sense and need less public variables if you added copy() to TimedTransform and made it return a copy of itself. Then you could just have one special case for TimedTransforms (using an instanceof?)
[/quote]
Probably, but this should still work, and I when I get this working, I might go the extra mile to add that to the library.

[quote]I’m not 100%, but I think the reason it doesn’t work is because your argument “arraylist” passed to “traverseTree” is never set to true? This means that while the TDSModel has the transforms added beneath it in the scenegraph they’re not added to its internal list which is used to control the animation. The flag “arraylist” is actually redunant anyway since any TimedTransform you create should be added to the TDSModel with addTransform().
[/quote]
No, it is set to true here:

while(i.hasNext()) {
                  numtransforms++;
                  Object a = i.next();
                  traverseTree(a, temp, null, true);
            }

And they are added using with addTransform if it’s from the arraylist.

[quote]Kev

PS. Its still a really bad idea to be sticking libraries for stuff like this in your “universal library folders”. Its not realistic to your eventual deployment.
[/quote]
Meh, I prefer it this way while I’m developing, because it makes it much easier to compile things, and what if I end up not using this or that? Then I can easily change it without any problems. Also, I could end up using this system on other systems buy using an installer.