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

Offline Xyvab

  • byte
  • *
  • Posts: 4
    • View Profile
How can I serialize a mesh?
« on: April 23, 2010, 08:34:24 pm »
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  :-\

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: How can I serialize a mesh?
« Reply #1 on: April 23, 2010, 08:50:45 pm »
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.

Offline Xyvab

  • byte
  • *
  • Posts: 4
    • View Profile
Re: How can I serialize a mesh?
« Reply #2 on: April 23, 2010, 11:32:08 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: How can I serialize a mesh?
« Reply #3 on: April 23, 2010, 11:50:18 pm »
Opps, forgot to document that class...actually it's pretty easy. All you have to do is this:

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

Offline Xyvab

  • byte
  • *
  • Posts: 4
    • View Profile
Re: How can I serialize a mesh?
« Reply #4 on: April 24, 2010, 02:40:08 pm »
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;

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: How can I serialize a mesh?
« Reply #5 on: April 24, 2010, 03:37:06 pm »
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.

Offline Xyvab

  • byte
  • *
  • Posts: 4
    • View Profile
Re: How can I serialize a mesh?
« Reply #6 on: April 25, 2010, 10:49:11 am »
Thanks a LOT !!
Now it works !!!

Offline pritom057

  • byte
  • *
  • Posts: 27
    • View Profile
Re: How can I serialize a mesh?
« Reply #7 on: July 06, 2010, 11:27:58 am »
hi EgonOlsen

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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: How can I serialize a mesh?
« Reply #8 on: July 06, 2010, 09:03:06 pm »
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.

Offline pritom057

  • byte
  • *
  • Posts: 27
    • View Profile
Re: How can I serialize a mesh?
« Reply #9 on: July 07, 2010, 11:28:34 am »
got it man thanks

Offline pritom057

  • byte
  • *
  • Posts: 27
    • View Profile
Re: How can I serialize a mesh?
« Reply #10 on: July 11, 2010, 03:54:21 pm »
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
Code: [Select]
/*
 * 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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: How can I serialize a mesh?
« Reply #11 on: July 11, 2010, 09:48:21 pm »
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:

Quote
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.

Offline pritom057

  • byte
  • *
  • Posts: 27
    • View Profile
Re: How can I serialize a mesh?
« Reply #12 on: July 15, 2010, 07:40:01 am »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: How can I serialize a mesh?
« Reply #13 on: July 15, 2010, 01:44:29 pm »
Object3D.setTexture(...)...

Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: How can I serialize a mesh?
« Reply #14 on: August 03, 2011, 11:26:29 am »
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
« Last Edit: August 03, 2011, 03:09:38 pm by nico_r_a »