Author Topic: Load 3DS with texture  (Read 4423 times)

Offline bayee

  • byte
  • *
  • Posts: 3
    • View Profile
Load 3DS with texture
« on: September 27, 2010, 11:29:02 am »
Hi,

I have download a 3DS file from the net and I try to load it into AE.

I have use the DeSerializer from PC. Here is my code:

Code: [Select]
                Config.oldStyle3DSLoader = true;
                Object3D[] obj = Loader.load3DS(args[0], 1f);
                System.out.println("Object loaded!");
                DeSerializer ds = new DeSerializer();
                for(int i = 0; i < obj.length; i++) {
                        System.out.println("serializing object: " + i + "/" + obj.length);
                        obj[i].build();
                        ds.serialize(obj[i], new FileOutputStream("out"+i+".ser"), true);
                }


When I run the above program, I got this in console (my 3DS file is called 23moon.3DS)


Loading file 23moon.3DS
File 23moon.3DS loaded...243558 bytes
Processing new material Material #1!
Texture named MOONMAP.JPG added to TextureManager!
Processing object from 3DS-file: Sphere01
Object 'Omni04_jPCT-2' created using 9800 polygons and 4902 vertices.
Object loaded!
serializing object: 0/1



Now I have out0.ser which I can load into AE, but I am not sure how I can apply texture to it.

Please advice. Thx.




Offline JKumar

  • byte
  • *
  • Posts: 33
    • View Profile
Re: Load 3DS with texture
« Reply #1 on: September 27, 2010, 11:59:36 am »
HI,

        Follow the steps below.

TextureManager.getInstance().addTexture("<Name of texture>", new Texture(getResources().openRawResource(R.raw.mytexture)));


model.setTexture("<Name of texture>);
         

Offline bayee

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Load 3DS with texture
« Reply #2 on: September 27, 2010, 12:14:20 pm »
 :-\
HI,

        Follow the steps below.

TextureManager.getInstance().addTexture("<Name of texture>", new Texture(getResources().openRawResource(R.raw.mytexture)));


model.setTexture("<Name of texture>);
         

thx for the quick reply, but where do i get the mytexture file ? it is in the 3ds file right ? sorry if this sound stupid, but I am really new with all these...
« Last Edit: September 27, 2010, 03:25:05 pm by bayee »

Offline JKumar

  • byte
  • *
  • Posts: 33
    • View Profile
Re: Load 3DS with texture
« Reply #3 on: September 28, 2010, 09:46:19 am »
Hi,

          Its an image file which u might have as an additional with the 3ds.You can put the file in any of the resource folders and can access the same using the above code.


Offline bayee

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Load 3DS with texture
« Reply #4 on: September 28, 2010, 12:02:35 pm »
Hi,

          Its an image file which u might have as an additional with the 3ds.You can put the file in any of the resource folders and can access the same using the above code.



hi JKumar, thx once again... does this mean the texture image file is not embed in the 3ds file which i download from the net ? but most of the free 3ds file in the net does not come with an image texture file, though many of their preview have texture....

Offline kamax

  • byte
  • *
  • Posts: 2
    • View Profile
Re: Load 3DS with texture
« Reply #5 on: January 16, 2011, 01:18:10 pm »
I have the same "problem", i have download a free palm tree  (.3ds) and i have just this file.
When i open it with blender i can see it colored but with the script in this topic to transform it into .ser file i have just .ser file.
The palm tree is white in the game engine.

Any help ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Load 3DS with texture
« Reply #6 on: January 16, 2011, 09:00:05 pm »
That's a weakness of the serialization idea: jPCT loads the diffuse color information but doesn't store it in the model. It just creates colored textures from them and add them to the TextureManager and the model. In the serialization step, the actual coloring information is gone. However, the names of the textures created will be serialized. One (rather clumsy) way, is to get the list of texture names from the TextureManager after loading the model and before serializing it and creating texture with the same names in jPCT-AE "by hand" before loading the model. That will give you the correct names...the only problem left are the actual color values. But luckily, the names contain them. You can simply derive them from the names...or create the names from the values. As said, this is clumsy, but it's the only way to get the coloring information back for deserialized models.