Author Topic: 3DS Texture loading advice...  (Read 5501 times)

Offline Darkflame

  • int
  • **
  • Posts: 55
    • View Profile
3DS Texture loading advice...
« on: August 11, 2010, 05:22:19 pm »
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.


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 3DS Texture loading advice...
« Reply #1 on: August 11, 2010, 09:28:04 pm »
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.

Offline Darkflame

  • int
  • **
  • Posts: 55
    • View Profile
Re: 3DS Texture loading advice...
« Reply #2 on: August 11, 2010, 11:10:05 pm »
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?)
               

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 3DS Texture loading advice...
« Reply #3 on: August 11, 2010, 11:24:47 pm »
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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: 3DS Texture loading advice...
« Reply #4 on: August 12, 2010, 01:24:46 am »
java.util package greatly simplifies these kind of things

Code: [Select]
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.

Code: [Select]
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);

Offline Darkflame

  • int
  • **
  • Posts: 55
    • View Profile
Re: 3DS Texture loading advice...
« Reply #5 on: August 12, 2010, 01:52:30 pm »
java.util package greatly simplifies these kind of things

Code: [Select]
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 :)