Author Topic: How can I serialize a mesh?  (Read 28389 times)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How can I serialize a mesh?
« Reply #30 on: August 08, 2011, 12:19:54 pm »
You haven't read my mail, have you?

Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: How can I serialize a mesh?
« Reply #31 on: August 08, 2011, 02:02:39 pm »
yes i have read your mail, thanks
sorry but i don't know how i serialize the file, when i delete  [ 0 ], i have an error in my line?
« Last Edit: August 08, 2011, 02:08:18 pm by nico_r_a »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How can I serialize a mesh?
« Reply #32 on: August 08, 2011, 02:21:51 pm »

Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: How can I serialize a mesh?
« Reply #33 on: August 08, 2011, 02:37:04 pm »
Code: [Select]
    public static void main(String[ ] args)  throws FileNotFoundException {
        Object3D[] sc = null;


        DeSerializer de;
        sc = Loader.load3DS("C:/workspace/file/res/raw/sc.3ds",20);

        //sc.build;
        de = new DeSerializer();
        de.serializeArray(sc, new FileOutputStream("C:/workspace/file/res/raw/sersc.ser"), true);
    }
}
i write this, i have modified the serialize by the serializeArray, but i have still an object which is loaded
i am sorry, but i read and i read your doc deserialize, but i have big problem to understand (in english it's not easy to me so i ask you lots of questions)

so how do i serialize a file (lots of object) please? ? ?


in more when i try to compil my program  java with texture to create a file ser
the console says me :
"[ Mon Aug 08 17:23:19 CEST 2011 ] - ERROR: Tried to set an undefined texture as default!"
while i have given the good name associated between the object and the texture

Code: [Select]
    TextureManager.getInstance().flush();
TextureManager tm = TextureManager.getInstance();
   Texture textureai= new Texture("C:/workspace/file/res/drawable/ai.jpg");
        tm.addTexture("ai", textureai);
        scene.setTexture("textureai");

it's correct, is'nt it??
and how do i serialize a file (lots of object) please? ? ? ?
« Last Edit: August 08, 2011, 05:41:07 pm by nico_r_a »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How can I serialize a mesh?
« Reply #34 on: August 08, 2011, 07:43:08 pm »
Your serialization code is fine. If it doesn't load it correctly, your loading code is wrong. Make sure to use the array-version of the loader-method too.

Wrong:
Code: [Select]
   tm.addTexture("ai", textureai);
   scene.setTexture("textureai");


Right:
Code: [Select]
 
   tm.addTexture("ai", textureai);
   scene.setTexture("ai");


Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: How can I serialize a mesh?
« Reply #35 on: August 08, 2011, 11:21:47 pm »
thank you for the reply by the mail. I listen your advice. But you have said i load the object in the array and i work with but i don't see.
Because in my file .3ds i have 80  objects how do i to load all this object in minimum of line code?
because i don't ssee how do i load the 3ds with all this object same after i have read your doc on the deserialize.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How can I serialize a mesh?
« Reply #36 on: August 08, 2011, 11:28:11 pm »
load3DS() already loads all objects from the file. serializeArray() serializes all these objects and Loader.loadSerializedObjectArray() loads them all into jPCT-AE. If they still doesn't appear in your app, you are doing something wrong with the loaded objects that i can't possibly guess.

Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: How can I serialize a mesh?
« Reply #37 on: August 09, 2011, 09:39:32 am »
so in my jpct (to create the ser)
i have writen this
Code: [Select]

Object3D[] sce = null;

TextureManager.getInstance().flush();
TextureManager tm = TextureManager.getInstance();

Texture textureai = new Texture("C:/workspace/file/res/drawable/ai.jpg");


 DeSerializer de;
       
       
        sce = Loader.load3DS("C:/workspace/file/res/raw/sce.3ds",20);

        tm.addTexture("ai", textureai);
        sce.setTexture("ai");

  //  sce.build();


 de = new DeSerializer();
       
       
        de.serializeArray(sce, new FileOutputStream("C:/workspace/file/res/raw/sersc.ser"), true);



When i have changed the "serialize" by the "serializeArray", eclipse has asked to change "object3d" by "object3d[]" and since i have lots of mistakes
but i have an error on the line         
sce.setTexture("ai");
sce.build()


and i writte this in my application android

Code: [Select]
Scee = Loader.loadSerializedObjectArray(getResources().openRawResource(R.raw.sersc));
and i have the same problem that in my jpct i have changed the
Scee = Loader.loadSerializedObject(getResources().openRawResource(R.raw.sersc));
by
Scee = Loader.loadSerializedObjectArray(getResources().openRawResource(R.raw.sersc));

So eclipse says me that i must to change the objkect 3d in object3[] what create lots of mistakes
example : world.addObject(Scee);


« Last Edit: August 09, 2011, 09:43:02 am by nico_r_a »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How can I serialize a mesh?
« Reply #38 on: August 09, 2011, 09:48:47 am »
Sorry, but the only real advise i can give you is: Learn how to code! You obviously haven't much clue about what you are doing. That's not a problem, everybody has to start somewhere...but 3D graphics doesn't seem to be the right project for a beginner to me.

Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: How can I serialize a mesh?
« Reply #39 on: August 09, 2011, 03:08:37 pm »
I have changed my code, but now i have "n" file ser (about 30ko each) with "n" the number of object in my 3ds.
It' better than before, but the problem is to load each ser.
i have tried to use the array but there is an error then i use it,
the code in my jpct to create ser is this

Code: [Select]
        for(int i = 0; i < scee.length; i++) {
             System.out.println("serializing object: " + i + "/" + scee.length);
            scee[i].build();
            de.serialize(scee[i], new FileOutputStream("C:/workspace/file/res/raw/serscee"+i+".ser"), true);
        }
How do i do to not load  each ser one per one, i try , i try to load by array but i don't arrive, there is possibility that you help me same if i am bad in java
because i would like to introduce the "de.serializearray" but it's incompatible with the "scee[ i ]"


and i always have the problem with the texture because like my scee is in "object3D[]", this line of code is specified with error in eclipse, so i have written this
Code: [Select]
tm.addTexture("ai", textureai);
        scee[i].setTexture("ai");

but now in the console after the compilation, there are written to each texture

[ Tue Aug 09 ] - ERROR: A texture with the name 'ai' has been declared twice!



« Last Edit: August 09, 2011, 05:48:58 pm by nico_r_a »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How can I serialize a mesh?
« Reply #40 on: August 09, 2011, 08:53:41 pm »
Just serialize all objects in one array like you did before. Then load the whole array at once from one file. Then iterator over the array and do everything that you would normally do on one object only on each. Like (pseudo-code):

On the desktop:
Code: [Select]
Object3D[] objs=Loader.load3DS(....);

for (Object3D obj:objs) {
     obj.build();
}

new DeSerializer().serializeArray(objs....);

On Android:

Code: [Select]
tm.addTexture("ai", textureai);
...

Object3D objs=Loader.loadSerializedObjectArray(....);
world.addObjects(objs);

There's no need serialize each object on its own. There's also no need to assign the textures by using setTexture()...the Loader will do this based on the names (as i've explained multiple times). Just make sure that you've added the textures to the manager BEFORE loading the serialized model.

Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: How can I serialize a mesh?
« Reply #41 on: August 10, 2011, 10:46:52 am »
thank you very much  ;D ;D ;D ;D ;D ;D ;D ;D
 i have loaded the 3ds thantks to file ser. but i have loaded without texture
now the scene load in 1minute, it's great
i am going to try to load with texture now, thank you

Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: How can I serialize a mesh?
« Reply #42 on: August 10, 2011, 11:58:30 am »
i don't arrive to load the texture, actually i think to load in my code several texture but the application load only one texture on the all object of the scene.
in my jpct to create the ser i write nothing on the texture, don't you?*
in my application android, (my textures are 256*256 or 512*512) it's not a problem?

Code: [Select]
TextureManager.getInstance().flush();
TextureManager tm = TextureManager.getInstance();

Texture textureai1 = new Texture(getResources().getDrawable(R.drawable.ai1));
Texture textureai2 = new Texture(getResources().getDrawable(R.drawable.ai2));

tm.addTexture("ai1", textureai1);
tm.addTexture("ai2", textureai2);

    Object3D[] scee = Loader.loadSerializedObjectArray(getResources().openRawResource(R.raw.sersce));

world.addObjects(scee);

for(int i = 0; i < scee.length; i++) {
            System.out.println("serializing object: " + i + "/" + scee.length);

SimpleVector Sv = new SimpleVector();
Sv.x = 0;
Sv.y = 0;
Sv.z = 0;
scee[i].strip();
scee[i].build();




so i have tried this second code too, because i have said me that the size of texture is too much, but it's more long and sometimes there is a bug (i have to load 32 textures)

Code: [Select]
TextureManager.getInstance().flush();
TextureManager tm = TextureManager.getInstance();

     Texture textureai1 = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.ai1)), 256, 256));
     Texture textureai2 = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.ai2)), 256, 256));
     
textureai1.compress();
textureai2.compress();

tm.addTexture("ai1", textureai1);
tm.addTexture("ai2", textureai2);

    Object3D[] scee = Loader.loadSerializedObjectArray(getResources().openRawResource(R.raw.sersce));

world.addObjects(scee);

for(int i = 0; i < scee.length; i++) {
            System.out.println("serializing object: " + i + "/" + scee.length);

SimpleVector Sv = new SimpleVector();
Sv.x = 0;
Sv.y = 0;
Sv.z = 0;
scee[i].strip();
scee[i].build();



Do you have a solution??
and another question, if i put color on object in my 3ds ,and i put a spotlight (near camera) in my 3ds or with the application android, will i have the shape effect on the object??
« Last Edit: August 10, 2011, 12:01:22 pm by nico_r_a »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How can I serialize a mesh?
« Reply #43 on: August 10, 2011, 12:38:37 pm »
I'm not sure what you are tyring to say here...the object has no texture? Or the it has only one texture? Or you don't know how to load 32 textures? It's actually really simple and i tried to explain it multiple times before: The names in the file and the names in the manager have to match exactly. And the textures have to be added to the manager BEFORE loading the mesh. This is needed for deserializing them only, it's not needed for serializing. On the desktop (i.e. where you serialize your object), you can check for all the names that the Android version has to know by calling getNames(); on your instance of the TextureManager. Do these names match your names in the Android code?

Or do you have some setTexture() left in your code from former versions? If so, remove it.

Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: How can I serialize a mesh?
« Reply #44 on: August 10, 2011, 01:09:52 pm »
actually, on the emulator i have only one texture which is load on all objects. whereas i should have 32 textures loaded on each object with each object a texture different.
and is there shape effect with the jpct if i put a spotlight in my 3ds or in the code android ?
so the second code is not good? i should rather use a texture 512*512
« Last Edit: August 10, 2011, 01:16:38 pm by nico_r_a »