3d object from .obj file doesn't apply texture

Started by thrysyuk, May 20, 2012, 01:46:43 PM

Previous topic - Next topic

thrysyuk

Hello,

First of all i would like to thank jPCT team for the great work they do. I'm new to jPCT and 3d modeling for android so please do not blame me for my incompetence in possibly obvious things :)
i have a problem with loading my 3d .obj file. Actually it loads just fine, but the main texture is not applied at all.
i've already read the article about correct loading of objects with textures -  http://www.jpct.net/wiki/index.php/Loading_models

Here is a code snippet how i'm loading the object with textures:

Texture texture = new Texture(BitmapHelper.convert(getResources().getDrawable(com.threed.jpct.example.R.raw.front)));
TextureManager.getInstance().addTexture("Layer 0.JPG", texture);
Texture texture1 = new Texture(BitmapHelper.convert(getResources().getDrawable(com.threed.jpct.example.R.raw.edge)));
TextureManager.getInstance().addTexture("Layer 0 Extrusion Material - Default Texture.JPG", texture1);

obj = Object3D.mergeAll(Loader.loadOBJ(getResources().openRawResource(R.raw.jbcut), getResources().openRawResource(R.raw.jbcut_conf), 20));
obj.strip();
obj.build();

world.addObject(obj);



  • jbcut - .obj file
  • jbcut_conf - .mtl file
  • front - front texture of the 3d object. .mtl file maps the texture by name "Layer 0.JPG"
  • edge - back texture. .mtl file maps the texture by name "Layer 0 Extrusion Material - Default Texture.JPG"

texture "edge" (Layer 0 Extrusion Material - Default Texture.JPG) is applied well, but the "front" (Layer 0.JPG) is not applied.
I would really appreciate if you could give me some suggestions how to fix this. Please let me know if you need any other info (files from me to examinate the issue).

Thanks for the help beforehand.
Taras.

EgonOlsen

If it doesn't apply the texture, it's name in the file most likely isn't "Layer 0.JPG"...or this is another crazy anomaly of the OBJ-format. Have a look at the log output. It should actually say which names it has found and which texture it adds to the manager in case that none with that name exists.

thrysyuk

Thanks for the reply.
the object was created using Photoshop Repousse. Please find attached .mtl file of my object that contains references to textures.
i also checked logs and found one interesting thing:
05-20 21:03:30.427: I/jPCT-AE(386): Texture named -s 0.465376 0.988734 1.0 -o 0.238287 -0.002412 1.0 Layer 0.JPG added to TextureManager!
Looks like jPCT doesn't recognize coordinates of vertixes from textures or something like this.
Also the next log record
05-20 21:03:52.697: I/dalvikvm(386): Jit: resizing JitTable from 512 to 1024
looks strange. the size of the Layer 0 texture is 512 and according to that record we are trying to stretch the texture to 1024. Could this cause the issue with not applying texture?

Here's the full log of loading of the object:

05-20 21:03:30.407: I/jPCT-AE(386): Loading file from InputStream
05-20 21:03:30.407: I/jPCT-AE(386): Text file from InputStream loaded...1185 bytes
05-20 21:03:30.417: I/jPCT-AE(386): Processing new material Layer 0 Front Inflation Material!
05-20 21:03:30.427: I/jPCT-AE(386): Texture named -s 0.465376 0.988734 1.0 -o 0.238287 -0.002412 1.0 Layer 0.JPG added to TextureManager!
05-20 21:03:30.437: I/jPCT-AE(386): Processing new material Layer 0 Front Bevel Material!
05-20 21:03:30.467: I/jPCT-AE(386): Processing new material Layer 0 Extrusion Material!
05-20 21:03:30.497: I/jPCT-AE(386): Processing new material Layer 0 Back Bevel Material!
05-20 21:03:30.507: I/jPCT-AE(386): Processing new material Layer 0 Back Inflation Material!
05-20 21:03:30.517: I/jPCT-AE(386): Loading file from InputStream
05-20 21:03:30.527: D/szipinf(386): Initializing zlib to inflate
05-20 21:03:30.717: D/dalvikvm(386): GC_CONCURRENT freed 1641K, 35% free 8230K/12487K, external 4812K/8908K, paused 6ms+5ms
05-20 21:03:30.817: D/dalvikvm(386): GC_FOR_MALLOC freed 1296K, 33% free 8380K/12487K, external 716K/4812K, paused 48ms
05-20 21:03:30.817: I/dalvikvm-heap(386): Grow heap (frag case) to 12.228MB for 840004-byte allocation
05-20 21:03:30.887: D/dalvikvm(386): GC_FOR_MALLOC freed 2K, 31% free 9198K/13319K, external 716K/4812K, paused 54ms
05-20 21:03:30.997: D/dalvikvm(386): GC_FOR_MALLOC freed 1460K, 36% free 8653K/13319K, external 716K/4812K, paused 52ms
05-20 21:03:31.157: D/dalvikvm(386): GC_CONCURRENT freed 1563K, 32% free 9117K/13319K, external 716K/4812K, paused 5ms+4ms
05-20 21:03:31.257: D/dalvikvm(386): GC_FOR_MALLOC freed 603K, 32% free 9063K/13319K, external 716K/4812K, paused 39ms
05-20 21:03:31.267: I/dalvikvm-heap(386): Grow heap (frag case) to 13.896MB for 1889998-byte allocation
05-20 21:03:31.357: D/dalvikvm(386): GC_FOR_MALLOC freed 1K, 29% free 10907K/15175K, external 716K/4812K, paused 78ms
05-20 21:03:31.477: D/SntpClient(60): request time failed: java.net.SocketException: Address family not supported by protocol
05-20 21:03:31.637: D/dalvikvm(386): GC_CONCURRENT freed 3261K, 38% free 9714K/15623K, external 716K/4812K, paused 7ms+5ms
05-20 21:03:31.707: D/dalvikvm(386): GC_FOR_MALLOC freed 69K, 39% free 9677K/15623K, external 716K/4812K, paused 60ms
05-20 21:03:31.747: I/dalvikvm-heap(386): Grow heap (frag case) to 15.397MB for 2834992-byte allocation
05-20 21:03:31.868: D/dalvikvm(386): GC_FOR_MALLOC freed 0K, 33% free 12445K/18439K, external 716K/4812K, paused 107ms
05-20 21:03:32.067: D/dalvikvm(386): GC_CONCURRENT freed 3532K, 41% free 10911K/18439K, external 716K/4812K, paused 4ms+6ms
05-20 21:03:32.177: D/dalvikvm(386): GC_FOR_MALLOC freed 1433K, 43% free 10603K/18439K, external 716K/4812K, paused 49ms
05-20 21:03:32.227: I/dalvikvm-heap(386): Grow heap (frag case) to 17.653MB for 4252484-byte allocation
05-20 21:03:32.317: D/dalvikvm(386): GC_FOR_MALLOC freed 2K, 35% free 14753K/22599K, external 716K/4812K, paused 75ms
05-20 21:03:32.487: D/dalvikvm(386): GC_CONCURRENT freed 4360K, 48% free 11967K/22599K, external 716K/4812K, paused 5ms+7ms
05-20 21:03:32.537: D/dalvikvm(386): GC_FOR_MALLOC freed 4K, 48% free 11962K/22599K, external 716K/4812K, paused 51ms
05-20 21:03:32.547: I/dalvikvm-heap(386): Grow heap (frag case) to 18.101MB for 3329602-byte allocation
05-20 21:03:32.647: D/dalvikvm(386): GC_FOR_MALLOC freed 0K, 33% free 15214K/22599K, external 716K/4812K, paused 69ms
05-20 21:03:32.687: I/jPCT-AE(386): Text file from InputStream loaded...1664793 bytes
05-20 21:03:33.027: D/dalvikvm(386): GC_CONCURRENT freed <1K, 33% free 15214K/22599K, external 716K/4812K, paused 22ms+6ms
05-20 21:03:33.189: D/dalvikvm(386): GC_FOR_MALLOC freed 4160K, 52% free 11053K/22599K, external 716K/4812K, paused 58ms
05-20 21:03:33.198: I/dalvikvm-heap(386): Grow heap (frag case) to 17.213MB for 3329636-byte allocation
05-20 21:03:33.277: D/dalvikvm(386): GC_FOR_MALLOC freed 0K, 37% free 14305K/22599K, external 716K/4812K, paused 58ms
05-20 21:03:33.477: D/dalvikvm(386): GC_CONCURRENT freed <1K, 37% free 14305K/22599K, external 716K/4812K, paused 5ms+5ms
05-20 21:03:34.097: D/dalvikvm(386): GC_CONCURRENT freed 3251K, 43% free 13101K/22599K, external 716K/4812K, paused 4ms+13ms
05-20 21:03:34.207: I/jPCT-AE(386): Processing object from OBJ-file: jPCT_generated
05-20 21:03:36.338: D/dalvikvm(386): GC_CONCURRENT freed 1370K, 39% free 13810K/22599K, external 716K/4812K, paused 4ms+8ms
05-20 21:03:37.588: D/dalvikvm(125): GC_EXPLICIT freed 100K, 50% free 2930K/5831K, external 2075K/2294K, paused 1339ms
05-20 21:03:38.688: D/dalvikvm(386): GC_CONCURRENT freed 2081K, 39% free 13831K/22599K, external 716K/4812K, paused 4ms+6ms
05-20 21:03:40.677: D/dalvikvm(386): GC_CONCURRENT freed 2106K, 39% free 13838K/22599K, external 716K/4812K, paused 5ms+7ms
05-20 21:03:42.507: D/dalvikvm(225): GC_EXPLICIT freed 491K, 55% free 2598K/5703K, external 716K/1038K, paused 1228ms
05-20 21:03:42.737: D/dalvikvm(386): GC_CONCURRENT freed 2133K, 40% free 13752K/22599K, external 716K/4812K, paused 5ms+7ms
05-20 21:03:44.767: D/dalvikvm(386): GC_CONCURRENT freed 2020K, 39% free 13817K/22599K, external 716K/4812K, paused 4ms+6ms
05-20 21:03:46.547: D/dalvikvm(386): GC_CONCURRENT freed 2116K, 40% free 13749K/22599K, external 716K/4812K, paused 4ms+6ms
05-20 21:03:47.927: D/dalvikvm(386): GC_CONCURRENT freed 2048K, 40% free 13749K/22599K, external 716K/4812K, paused 4ms+7ms
05-20 21:03:49.387: D/dalvikvm(386): GC_CONCURRENT freed 2048K, 40% free 13749K/22599K, external 716K/4812K, paused 4ms+5ms
05-20 21:03:50.647: D/dalvikvm(386): GC_CONCURRENT freed 2047K, 40% free 13749K/22599K, external 716K/4812K, paused 4ms+6ms
05-20 21:03:52.417: D/dalvikvm(386): GC_CONCURRENT freed 2002K, 39% free 13809K/22599K, external 716K/4812K, paused 4ms+5ms
05-20 21:03:52.697: I/dalvikvm(386): Jit: resizing JitTable from 512 to 1024
05-20 21:03:54.147: D/dalvikvm(386): GC_CONCURRENT freed 2108K, 40% free 13749K/22599K, external 716K/4812K, paused 4ms+7ms
05-20 21:03:55.497: D/dalvikvm(386): GC_CONCURRENT freed 2047K, 40% free 13749K/22599K, external 716K/4812K, paused 5ms+6ms
05-20 21:03:56.597: D/dalvikvm(386): GC_CONCURRENT freed 1316K, 37% free 14368K/22599K, external 716K/4812K, paused 4ms+10ms
05-20 21:04:04.637: I/jPCT-AE(386): Object 'jPCT_generated_jPCT0' created using 6362 polygons and 3183 vertices.
05-20 21:04:04.897: D/dalvikvm(386): GC_CONCURRENT freed 6688K, 58% free 9647K/22599K, external 716K/4812K, paused 4ms+5ms
05-20 21:04:05.677: D/dalvikvm(386): GC_CONCURRENT freed 1662K, 56% free 10032K/22599K, external 716K/4812K, paused 5ms+9ms
05-20 21:04:05.797: I/dalvikvm(386): Total arena pages for JIT: 11
05-20 21:04:05.797: I/dalvikvm(386): Total arena pages for JIT: 12
05-20 21:04:06.057: I/jPCT-AE(386): Normal vectors calculated in 1087ms!
05-20 21:04:06.067: I/jPCT-AE(386): Memory usage before compacting: 10541 KB used out of 22599 KB
05-20 21:04:06.187: D/dalvikvm(386): GC_EXPLICIT freed 1216K, 59% free 9325K/22599K, external 716K/4812K, paused 118ms
05-20 21:04:06.257: D/dalvikvm(386): GC_EXPLICIT freed <1K, 59% free 9325K/22599K, external 716K/4812K, paused 77ms


Here is a test object i'm trying to import to Android http://sharesend.com/fno4v so you can see what type of the object i'm working with.

Thank you a lot of your help!
Taras

[attachment deleted by admin]

thrysyuk

Well, when i applied next changes to code:

Texture texture = new Texture(BitmapHelper.convert(getResources().getDrawable(com.threed.jpct.example.R.raw.front)));
TextureManager.getInstance().addTexture("-s 0.465376 0.988734 1.0 -o 0.238287 -0.002412 1.0 Layer 0.JPG", texture);

here's what i got: http://sharesend.com/07p54. The texture was applied, but incorrectly.

EgonOlsen

Yepp...looks like a OBJ-format-anomaly...one of many. Can you provide me with that model to adjust the loader?

thrysyuk

Here is a model http://sharesend.com/6c24n. Please let me know if you need any assistance from my side.

Thank you a lot.
Taras

EgonOlsen

I see...it's a weird variant of the mtl-file-format. I've never seen this and at least DeepExploration loads it in the same way as jPCT does, i.e. it includes these strange -s and -o data in the texture name. I think that this is a flaw in the exporter. These additional data isn't supposed to be there IMHO. However, i'll make the loader ignore it, because i've no idea what to make of it.

thrysyuk

Thank you a lot.
Do you know maybe some different tools that might do the same thing without those -s and -o?
The idea is to have an object like this one: http://sharesend.com/fno4v.

EgonOlsen

Please give this version a try: http://jpct.de/download/beta/jpct_ae.jar. At least it should ignore this data when loading the file.

thrysyuk

#9
Thanks for helping me :)

i applied new jar, set name of the texture:

TextureManager.getInstance().addTexture("Layer 0.JPG", texture);

The texture is shown now, but not applied onto the object.
It looks like this: http://sharesend.com/07p54

It seems those -s and -o and coordinates near them: "-s 0.465376 0.988734 1.0 -o 0.238287 -0.002412 1.0" are the coordinates/instructions how texture should be applied.

Does it make sense?

BTW, maybe there is another way for creating such type of objects without using Photoshop Repousse? are you aware of any?
Is there any possibility in jPCT to make such objects in runtime?

Thank you.
Taras

EgonOlsen

Quote from: thrysyuk on May 21, 2012, 09:20:09 PM
It seems those -s and -o and coordinates near them: "-s 0.465376 0.988734 1.0 -o 0.238287 -0.002412 1.0" are the coordinates/instructions how texture should be applied.
Maybe yes, but i've no idea about what these values actually mean. The texture obviously has to be stretched in x-direction by ~2 and in y-direction by some much smaller value...and nothing that i see in -s or -o resembles this. I can't find anything on the net either. When i load the model in DeepExploration and set the texture manually, the result looks exactly as what jPCT renders. I guess the key is to find something that can read this variant correctly and export it again in a way that it doesn't contain this weird data anymore. Usually, DeepExploration does this trick for me, but not here...
I also tried to load it in Blender (but i was too stupid to make it visible in this abomination of a GUI) and in Deled3D (which invented a new plane but didn't load any material information at all)...

thrysyuk

Yeah, this is really specific for the Photoshop. This feature is too limited.
Thanks a lot for the help. I really appreciate your efforts.

Best regards,
Taras