JPCT-AE Serialization issue

Started by Msali, July 15, 2016, 12:59:21 PM

Previous topic - Next topic

Msali

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

EgonOlsen

#1
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.

Msali

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.

EgonOlsen

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.

Msali

ok, I'm waiting to hear from you  ;)

thanks

EgonOlsen


Msali

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

EgonOlsen

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?

Msali

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



Msali

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