Author Topic: JPCT-AE Serialization issue  (Read 3167 times)

Offline Msali

  • byte
  • *
  • Posts: 9
    • View Profile
JPCT-AE Serialization issue
« on: July 15, 2016, 12:59:21 pm »
Hello everybody,

I need to transfer object3D through a websocket from an android device to another. I was evaluating some options. One of them would be to serialize the Object3D and send it, but as far as I understood, the only way to serialize an object3D would be to do it through JPCT for Java.

Is it possible to install JPCT (not JPCT-AE) on the android device just to use the DeSerializer class on object3Ds instanciated with JPCT-AE?

Thanks for your help

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: JPCT-AE Serialization issue
« Reply #1 on: July 15, 2016, 01:49:11 pm »
I don't think that it will work. The Object3Ds of desktop and Android jPCT aren't compatible, so the DeSerializer of the desktop version can't work on instances from jPCT-AE and vice versa.
Can't you use Java's normal object serialization process instead? Object3D implements Serializable and as long as you don't add the Object3D to be transfered to a world instance on the sender side (or remove it before sending it), this should actually work.
« Last Edit: July 15, 2016, 01:54:05 pm by EgonOlsen »

Offline Msali

  • byte
  • *
  • Posts: 9
    • View Profile
Re: JPCT-AE Serialization issue
« Reply #2 on: July 15, 2016, 02:29:38 pm »
Yes, I think it would be the only solution left. I just thought about handling the serialization from the client side thus improving the loading performance to the server side without adding the complexity of a separate java tool using JPCT to serialize the objects. 


I'm actually writing an Android framework for Augmented Reality that I'm willing to share with JPCT-AE users however.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: JPCT-AE Serialization issue
« Reply #3 on: July 15, 2016, 02:39:08 pm »
I could provide you with the sources of the DeSerializer class for desktop jPCT. It shouldn't be too hard to modify them in a way so that you can use them to serialize stuff on Android. But I'm not sure, if I manage to do that today and after that, I'm on holiday for two weeks.

Offline Msali

  • byte
  • *
  • Posts: 9
    • View Profile
Re: JPCT-AE Serialization issue
« Reply #4 on: July 15, 2016, 03:01:13 pm »
ok, I'm waiting to hear from you  ;)

thanks

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: JPCT-AE Serialization issue
« Reply #5 on: July 15, 2016, 09:27:47 pm »
You have mail.

Offline Msali

  • byte
  • *
  • Posts: 9
    • View Profile
Re: JPCT-AE Serialization issue
« Reply #6 on: July 22, 2016, 04:35:31 pm »
I am actually experiencing a new issue.

My attempt is to transfer the object3d in a JSon enconding by serializing the object3d and the texture which I learned from the docs to be Serializable as well.

The result is that the model is rendered, but it is not textured. This is basically what I'm doing in a separate thread that than adds the object to a thread safe queue that the ondraw method polls to look for new objects:

public  void run(){

            JSONObject job = new JSONObject(message);

            Boolean successful = (Boolean) job.get("successful");
            if(successful){
                String basename = job.getString("basename");
                byte[] txtr =(org.apache.commons.codec.binary.Base64.decodeBase64(job.getString("file").getBytes()));
                Texture texture = Object3DManager.deserializeTexture(txtr);

                Log.e(TAG, "textured!");
                if(texture==null)
                    Log.e(TAG,"texture==null");

                TextureManager.getInstance().addTexture(basename, texture);

                    byte[] obj3Ddata =  (org.apache.commons.codec.binary.Base64.decodeBase64(job.getString("obj3d").getBytes()));
                    Log.e(TAG,"obj3Ddata len:"+obj3Ddata.length);
                    Object3D o3d = Object3DManager.deserializeObject3D(/*blob.array()*/obj3Ddata);

                    jpctWorldManager.addObjectToCreationQueue(o3d,loc);

            }
            else {
                Log.e(TAG, job.getString("message"));
                return;
            }

    }

Is it better to call build() on the sender or the receiver side?
Also the untextured model moves in a bursty way, as I rotate the camera.

Any help would be great.

Thanks

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: JPCT-AE Serialization issue
« Reply #7 on: July 23, 2016, 11:45:20 am »
You serialized object contains a reference to an ID in the TextureManager, not to the texture directly. Try to do an additional obj.setTexture(...) after transfering both. I'm not sure about the camera thing though... Have you tried to clear rotation and translation?

Offline Msali

  • byte
  • *
  • Posts: 9
    • View Profile
Re: JPCT-AE Serialization issue
« Reply #8 on: July 25, 2016, 01:43:34 pm »
that's actually what I already do. That's the method I call inside the onDrawFrame method:

private void addObject3DToWorld(Object3D object3D,float x, float y, float z){
        //Log.e("object:"+object3D.getName(), "CREATED at:"+x+" y:"+y+" z:"+z);


        object3D.setTexture(object3D.getName());
        object3D.translate(x, y, z);
     

        world.addObject(object3D);
        objectPositions.put(object3D.getID(),object3D.getCenter());
     
    }



Offline Msali

  • byte
  • *
  • Posts: 9
    • View Profile
Re: JPCT-AE Serialization issue
« Reply #9 on: July 25, 2016, 05:54:13 pm »
if it could help someone, I solved the issue not serializing the texture anymore but simply transferring the bitmap like this:

ByteArrayOutputStream stream = new ByteArrayOutputStream();
            BitmapFactory.decodeResource(act.getResources(), textureID).compress(Bitmap.CompressFormat.JPEG, 100, stream);
           
JSONObject jsonObject = new JSONObject();
jsonObject.put("file", org.apache.commons.codec.binary.
                StringUtils.newStringUtf8(org.apache.commons.codec.binary.Base64.encodeBase64(stream.toByteArray())));