How can I serialize a mesh?

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

Previous topic - Next topic

Xyvab

Hello
I saw that into the res.zip example package there are some files with the ".ser" extension.
How can I create some like them?
Thanks in advance,
Xyvab

_______
I'm not english so I'm sorry for any orthographic error  :-\

EgonOlsen

You'll need the desktop version of jPCT for this: http://www.jpct.net/jpct-ae/download/alpha/jpctapi_121a.zip
It contains a DeSerializer class that creates serialized data that jPCT-AE can load at maximum speed.

Xyvab

Thanks for the fast answer, man !
Now I have another problem: which code have I to type to work the "serialize" method?
I've looked to the API page on DeSerializer, but I didn't understand a lot ... can you help me?

EgonOlsen

Opps, forgot to document that class...actually it's pretty easy. All you have to do is this:


new DeSerializer().serialize(yourObject3D, someOutputStream, true);


yourObject3D is...your Object3D. Just load it and set it up by assigning textures and calling build() on it. Just like you would do it, if you were about to render it. someOutputStream is most likely a FileOutputStream, reduced can always be true if you serialize for jPCT-AE only.
Textures aren't serialized, but their names are. So if you set up and serialize your object in desktop jPCT with two texture assigned called "hurz" and "gurz", just make sure that your Android version adds textures with the same names "hurz" and "gurz" to the TextureManager prior to loading the serialized object.

Xyvab

Thanks again for the fast answer  ;D
Now, I wrote this:
new DeSerializer().serialize(Loader.load3DS("C:/file.3ds", 1), new FileOutputStream("C:/file.ser"), true);

but it gives this error:
"The method serialize(Object3D, OutputStream, boolean) in the type DeSerializer is not applicable for the arguments (Object3D[], FileOutputStream, boolean)"

How can I fix it?

P.S.:
I imported these packages:
import java.io.FileOutputStream;
import java.io.OutputStream;

import com.threed.jpct.DeSerializer;
import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;

EgonOlsen

The 3ds loader returns an array of Object3Ds, not a single one. There a mergeAll-method in Object3D that you use to combine them or you serialize them as single objects. However, its not the best idea to serialize what comes right from the Loader. Its better to call build() on each object before serializing it because that reduces setup time on Android.

Xyvab


pritom057

hi EgonOlsen

I am not getting you...can you please explain it or show me some code which you are talking about

EgonOlsen

You have to use the desktop version of jPCT to serialize an Object3D. Unfortunatly, there's no tool present ATM that eases this serialization task, so it's up to you to code some small application that does it.

These are the steps to follow:

  • load the Object3D in your desktop jPCT application, assign textures and call build() on it.
  • serialize it by using the DeSerializer.serialize()-method. Make sure to serialize it in reduced mode
  • copy the file created into your Android project's resources
  • use the appropriate method in Loader on jPCT-AE to load the serialized file (watch the size...raw resources are limited to 1mb, you can zip them to bypass this is needed)

Note that textures themselves are not part of the file, but their names are. I.e. if you assign textures with the same names to the TextureManager on Android as you do on desktop jPCT before loading the serialized object, jPCT-AE will automagically assign them to your loaded object.

pritom057


pritom057

Sir I fave got another problem.....and that is how do i add texture into Serialize file
I have done flowing.....whats wrong with this
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package javaapplication2;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.threed.jpct.DeSerializer;
import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import java.awt.Color;

/**
*
* @author sarwar.siddique
*/
public class Main {

    /**
     * @param args the command line arguments
     */


    public static void main(String[] args) throws FileNotFoundException {
        // TODO code application logic here
        Object3D grass = null;
        TextureManager.getInstance().flush();


TextureManager tm = TextureManager.getInstance();
Texture grass2 = new Texture("C:/Worksapce/SaveMe/res/raw/f15e.jpg");
        DeSerializer de;
        grass = Loader.load3DS("C:/Worksapce/SaveMe/res/raw/f15.3ds",5)[0];
        tm.addTexture("grass2", grass2);
        grass.setTexture("grass2");
        //grass.setAdditionalColor(Color.yellow);
        grass.build();
        de = new DeSerializer();
        de.serialize(grass, new FileOutputStream("C:/Worksapce/SaveMe/res/raw/sf15.ser"), true);
                //.serialize(Loader.load3DS("C:/file.3ds", 1), new FileOutputStream("C:/file.ser"), true);
    }

}


Thanks In Advance

EgonOlsen

Nothing is wrong with that at first glance. But you are just showing the serializing code, not how you load it. And you are not telling what the actual problem is. Regarding textures, i can only repeat myself from the post above:

QuoteNote that textures themselves are not part of the file, but their names are. I.e. if you assign textures with the same names to the TextureManager on Android as you do on desktop jPCT before loading the serialized object, jPCT-AE will automagically assign them to your loaded object.

pritom057

Sir
I am not rendering the texture over the object..
after serialize I am getting only white object...
And I load the object as you show in your demo code.....

I just want to know how to texture over the object..

thanks in advance

EgonOlsen


nico_r_a

#14
i have downloaded the "jpctapi" but i don't know what i have to open to serialize an object.
so what is the procedure?
how do you use the "jpct api"? with "eclipse jee"? because eclipse don't find a project in "jpctapi"
where do you write this sentence "new DeSerializer().serialize(yourObject3D, someOutputStream, true);"??
thank you