3DS Texture loading advice...

Started by Darkflame, August 11, 2010, 05:22:19 PM

Previous topic - Next topic

Darkflame

I'm wishing to load a textured 3ds model from a remote url.

Jpct does have this neat system, as I understand, that when the 3ds model is loaded it will automatically assign matching textures already in its memory. (that is, if the 3ds refers to a filename "text1.jpg" for the texture, and a texture with that name is in memory, it will add it).
Thats pretty cool.
The problem is, with my app the textures also have to be loaded dynamically, and their names wont be known in advance. So I cant easily preload them all in, then call to load the 3ds.

Ideally, I'd like to be able to point the app at a url, say;
http://www.darkflame.co.uk/building1/building.3ds
And the app looks at the 3ds file, see's what texture-names it has assigned, then looks in the same url directory for them
http://www.darkflame.co.uk/building1/texture1.jpg
http://www.darkflame.co.uk/building1/texture2.jpg

Is this possible?

The only other solution I see for my app is I point it at a file on the server that lists both the 3ds file and all its textures. Then it looks at that list and downloads the textures listed and then the 3ds file.


EgonOlsen

If jPCT can't find textures with the names that the file indicates, it creates new ones with that name. You can obtain the name list from the TextureManager afterwards and query the server for these textures. If a texture can be found, you can load it and replace the one created by jPCT with the loaded one in the TextureManager (see the replaceTexture(<String>, <Texture>)-method.

Darkflame

Ah, so I use
TextureManager.getInstance().getNames(); ?

That seems a good solution, but how would I isolate the names just added?
Would I have to count the number of names before hand, the number after, and then count backwards over the number of new ones added? Or is there a better way?
(And am I using too many question marks? or not?)
               

EgonOlsen

I think that's the way. Another option is use Loader.readTextureNames3DS(...). But that one loads the whole file, so you would end up with loading the file twice from the server, which doesn't sound very smart.

raft

java.util package greatly simplifies these kind of things


Set<String> oldNames = textureManager.getNames();
// download and load your model here

Set<String> newNames = textureManager.getNames();
newNames.removeAll(oldNames);
// now newNames contains the new texture names


i'm assuming textureManager.getNames() returns a new Set evertime. otherwise you need to create your set with the returned set.


Set<String> oldNames = new HashSet<String>(textureManager.getNames());
// download and load your model here

Set<String> newNames = new HashSet<String>(textureManager.getNames());
newNames.removeAll(oldNames);

Darkflame

Quote from: raft on August 12, 2010, 01:24:46 AM
java.util package greatly simplifies these kind of things


Set<String> oldNames = textureManager.getNames();
// download and load your model here

Set<String> newNames = textureManager.getNames();
newNames.removeAll(oldNames);
// now newNames contains the new texture names


Bingo.
Very elegant, worked a charm :)

Thanks for the help :)