Author Topic: Problem with rotating a box.  (Read 1779 times)

Offline Azzy Elvul

  • byte
  • *
  • Posts: 2
    • View Profile
Problem with rotating a box.
« on: September 11, 2012, 03:57:24 pm »
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:
Code: [Select]
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:
Code: [Select]
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]

Offline tomoroho

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Problem with rotating a box.
« Reply #1 on: September 11, 2012, 06:23:42 pm »
1. u should add texture to manager before loadobj,that means the code below should places before loading obj file.
Code: [Select]
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Problem with rotating a box.
« Reply #2 on: September 11, 2012, 09:21:45 pm »
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.

Offline Azzy Elvul

  • byte
  • *
  • Posts: 2
    • View Profile
Re: Problem with rotating a box.
« Reply #3 on: September 12, 2012, 08:42:45 am »
Thank you. The emulator was the problem.

Offline hamedf_hamedf

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Problem with rotating a box.
« Reply #4 on: November 25, 2012, 02:38:22 pm »
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]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Problem with rotating a box.
« Reply #5 on: November 25, 2012, 09:16:29 pm »
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:

Code: [Select]
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.

Offline hamedf_hamedf

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Problem with rotating a box.
« Reply #6 on: November 25, 2012, 09:55:43 pm »
may i have your exmaple code or project that load with my obj file?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Problem with rotating a box.
« Reply #7 on: November 25, 2012, 10:01:51 pm »
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):

Code: [Select]
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();

Offline hamedf_hamedf

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Problem with rotating a box.
« Reply #8 on: November 25, 2012, 10:41:25 pm »
Excuse me dear,
this is my project in attachment
 :-\
is there any problem?
my wood.png file is 1024*512

[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Problem with rotating a box.
« Reply #9 on: November 25, 2012, 10:54:21 pm »
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).

Offline hamedf_hamedf

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Problem with rotating a box.
« Reply #10 on: November 25, 2012, 11:05:45 pm »
That's good
yes, i changed to 512*512 and work well.
 :) :) :)
Thanks So Much

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Problem with rotating a box.
« Reply #11 on: November 25, 2012, 11:09:39 pm »
No problem. Just keep in mind that looking at the log output from time to time may help in such cases.