How can I serialize a mesh?

Started by Xyvab, April 23, 2010, 08:34:24 PM

Previous topic - Next topic

EgonOlsen

You haven't read my mail, have you?

nico_r_a

#31
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?


nico_r_a

#33

    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

    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? ? ? ?

EgonOlsen

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:

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



Right:
 
   tm.addTexture("ai", textureai);
   scene.setTexture("ai");



nico_r_a

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.

EgonOlsen

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.

nico_r_a

#37
so in my jpct (to create the ser)
i have writen this


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


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);



EgonOlsen

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.

nico_r_a

#39
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


        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

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!




EgonOlsen

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:

Object3D[] objs=Loader.load3DS(....);

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

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


On Android:


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.

nico_r_a

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

nico_r_a

#42
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?


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)


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??

EgonOlsen

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.

nico_r_a

#44
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