How to bind the Texture to a serialized Object3D loaded from JPCT into JPCT-AE

Started by Sheshmoshen, June 04, 2020, 03:32:45 AM

Previous topic - Next topic

Sheshmoshen

Thank you for the reply.

I'm going to elaborate on my question.

I have a java server side script that converts the obj file into a java serialized object.

Instead of serializing the whole Object3D[] array that is returned from loading.

I do something like this:

Object3D[] objects = Loader.loadOBJ(objFileName, mtlFileName, 1.0f);

Object3D resultObj = Object3D.mergeAll(objects)
resultObj.build();

DeSerializer serializer = new DeSerializer();
serializer.serialize(resultObj, outStream, true);


The texture in the MTL file is named map.jpg, and JPCT outputs this name as well.

Now on the android side of things:

I need to map the texture to different faces of the Object3D model.

How can I achieve this once I merged everything into one Object3D and serialized it?

Here is what I have and it's not quite working.



Object3D modelObj = Loader.loadSerializedObject(objInputStream);

  String texFile = "root/map.jpg";

Texture texture = new Texture(BitmapHelper.rescale(
   BitmapFactory.decodeFile(texFile),
        256,
        256
));

texture.setMipmap(true);

TextureManager.getInstance().addTexture("map.jpg", texture);

modelObj.setTexture("map.jpg");


It does show something but not quite what I see in MeshLab or Blender.

I think my issue is that I'm mapping the textures improperly.

Hope I clarified my issue, thanks for helping!

EgonOlsen

I'm not sure if I got the question correctly, but the basic idea with all loaders (that includes loading of serialized objects) is, that you assign a texture with the matching name to the TextureManager before loading, so that the loader can pick it and assign it in the loading process. If there is no such texture in the manager at load time, a dummy texture with that name will be created and you can swap it out after the loading is done. Or, if the object in question uses only one texture anyway, you should be able to set the new texture with setTexture(). Which of these ways are you using and what exactly doesn't work? Can you post some example code?

Sheshmoshen

I updated my question for clarity.

The actual image is one file.

But in that file there is a bunch of different textures that will be applied to different polygons in the Object3D.

Thanks again!

EgonOlsen

Actually, the setting of the texture should be done automatically, if you swap the order like so:


  String texFile = "root/map.jpg";

Texture texture = new Texture(BitmapHelper.rescale(
   BitmapFactory.decodeFile(texFile),
        256,
        256
));

texture.setMipmap(true);

TextureManager.getInstance().addTexture("map.jpg", texture);


Object3D modelObj = Loader.loadSerializedObject(objInputStream);


and omit the setTexture call. The loader should handle this (the log output should indicate if that had worked or not). I'm not sure if that solves the problem, though. Have you checked that loading the object directly into Android produces the correct texturing? Maybe it's a format issue...

EgonOlsen

BTW: A screen shot might help to get an idea of what the actual problem looks like...