Problem with rotating a box.

Started by Azzy Elvul, September 11, 2012, 03:57:24 PM

Previous topic - Next topic

Azzy Elvul

Hello,
I have box with removed one face with applied texture. I use blender to create the box and export it into obj file  ( see  box_obj and box_mtl files)
I import the box file with this code:
InputStream objStream1 = getResources().openRawResource( getResources().getIdentifier( "com.threed.jpct.example:raw/box_obj", null, null ) );
InputStream mtlStream1 = getResources().openRawResource( getResources().getIdentifier( "com.threed.jpct.example:raw/box_mtl", null, null ) );

box = com.threed.jpct.Loader.loadOBJ( objStream1, mtlStream1, 3.0f )[0];
if ( null != box )
{
//box.invert();
box.setCulling( Object3D.CULLING_DISABLED );
box.setEnvmapped( Object3D.ENVMAP_DISABLED );

box.setTexture( "texture" );
//box.calcNormals();
box.rotateX( 90 );
box.build();
box.compile();
world.addObject(box);
box.translate( 0.f, 0.f, 0.f );
}


There are 2 problems:
1. The applied texture from mtl file not shown. The texture exist in drawable and
I can apply it on object using this code:
InputStream is = getResources().openRawResource(R.drawable.grid);
Bitmap bitmap  = BitmapFactory.decodeStream(is);
Texture texture = new Texture(bitmap);
TextureManager.getInstance().addTexture("texture", texture);
and set it with box.setTexture( "texture" );
Maybe the file is ok because I see the correct object using 3D Model Viewer (  http://www.janbirsa.com/tools/ModelViewer/ )

2. With applied texture when I rotate the box ( with rotateXXX or rotateAxis ) the result is something like box.jpg

Maybe I miss something.


[attachment deleted by admin]

tomoroho

1. u should add texture to manager before loadobj,that means the code below should places before loading obj file.
InputStream is = getResources().openRawResource(R.drawable.grid);
Bitmap bitmap  = BitmapFactory.decodeStream(is);
Texture texture = new Texture(bitmap);
TextureManager.getInstance().addTexture("texture", texture);

for detail,see to http://www.jpct.net/wiki/index.php/Loading_models

2. what u expect to be right?

EgonOlsen

The emulator renders crap most of the time. Give it a try on a real device to if that looks more like you want it to.

Azzy Elvul

Thank you. The emulator was the problem.

hamedf_hamedf

Hi,
i use blender to create a cylinder with texture. export obj file and mtl file. that is attached.

but when i load it in jPCT-AE it shows the cylinder without texture, i'm consider the last post but answer isn't changed.
do you have any suggestion? can you test my obj file?

Thanks


[attachment deleted by admin]

EgonOlsen

The other model that you've send me via PM loads fine and texture works too. No idea what's wrong with your approach. Try to leave out that Bitmap/decode-step and load the texture directly from the input stream like so:


Texture woody = new Texture(res.openRawResource(R.raw.wood));


Also double check that there's no other texture assignment and especially (as i've already written in the PM) no call to any calcTextureWrap-method.

hamedf_hamedf

may i have your exmaple code or project that load with my obj file?

EgonOlsen

I hacked into my demo Activity, which is a cluttered mess that i'm using for internal testings of all kind. So i can't post the complete Activity here, but all i added was this (it's called rock because it replaced an object that was already there):


Texture woody = new Texture(res.openRawResource(R.raw.wood));
TextureManager.getInstance().addTexture("wood", woody);
Object3D rock = Object3D.mergeAll(Loader.loadOBJ(res.openRawResource(R.raw.boxobj), res.openRawResource(R.raw.boxmtl), 0.1f));
rock.setTexture("wood");
world.addObject(rock);
...
world.buildAllObjects();

hamedf_hamedf

Excuse me dear,
this is my project in attachment
:-\
is there any problem?
my wood.png file is 1024*512

[attachment deleted by admin]

EgonOlsen

Works fine:



Try with a square texture (i.e. 512*512) instead. Some OpenGL ES 2.0 implementations are having problem with non-square textures (which is why the log outputs a warning in that case).

hamedf_hamedf

That's good
yes, i changed to 512*512 and work well.
:) :) :)
Thanks So Much

EgonOlsen

No problem. Just keep in mind that looking at the log output from time to time may help in such cases.