Author Topic: The texture on sphere appeared not properly  (Read 2336 times)

Offline hisong

  • byte
  • *
  • Posts: 16
    • View Profile
The texture on sphere appeared not properly
« on: August 09, 2011, 11:59:10 am »
     Hi,I'm a newbie for jpct-ae.  I used the getSphere(float scale) Function of Primitives Class.  and then map a earth on it.   I found that the sphere appeared not properly.  I also use the opengl es of android to draw a sphere and map a texture on it.  It showed correctly.

this is the code sample
Code: [Select]
Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(context.getResources().getDrawable(R.drawable.earth)),1024,512));
TextureManager.getInstance().addTexture("texture", texture);


// cube = Primitives.getCube(20);
cube = Primitives.getSphere(25, 25);
cube.calcTextureWrapSpherical();
cube.setTexture("texture");
cube.build();

world.addObject(cube);
com.threed.jpct.Camera cam = world.getCamera();
cam.moveCamera(com.threed.jpct.Camera.CAMERA_MOVEOUT,50);
cam.lookAt(cube.getTransformedCenter());
I also found that  it is slow when the project is generating the sphere!!

anyone met this problem??  thanks

[attachment deleted by admin]
« Last Edit: August 09, 2011, 12:59:17 pm by hisong »

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: The texture on sphere appeared not properly
« Reply #1 on: August 09, 2011, 02:45:15 pm »
Please, show your texture cutting....
I think problem in this point.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: The texture on sphere appeared not properly
« Reply #2 on: August 09, 2011, 03:05:05 pm »
Objects genearted by Primitives have no proper uv-mapping. If you want that, you have to load a "real" model. For a sphere, you might want to try this one: http://www.jpct.net/download/misc/terra.asc

Offline hisong

  • byte
  • *
  • Posts: 16
    • View Profile
Re: The texture on sphere appeared not properly
« Reply #3 on: August 10, 2011, 07:01:34 am »
Objects genearted by Primitives have no proper uv-mapping. If you want that, you have to load a "real" model. For a sphere, you might want to try this one: http://www.jpct.net/download/misc/terra.asc

Thank you for replying so quickly.

You mean that the ASC file carry the "u v" information??
I use the Loader to load the ASC file you give. but the texture remain appear not properly.
This is the code sample I had modify.
Code: [Select]
try {
cube = Loader.loadASC(new FileInputStream("/sdcard/terra.asc"), 4, true);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cube.calcTextureWrapSpherical();
cube.strip();
cube.build();



Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: The texture on sphere appeared not properly
« Reply #4 on: August 10, 2011, 07:14:39 am »
Remove that line. You shouldn't create texture coordinates on objects that already have some:
Code: [Select]
cube.calcTextureWrapSpherical();

Offline hisong

  • byte
  • *
  • Posts: 16
    • View Profile
Re: The texture on sphere appeared not properly
« Reply #5 on: August 10, 2011, 11:43:27 am »
Remove that line. You shouldn't create texture coordinates on objects that already have some:
Code: [Select]
cube.calcTextureWrapSpherical();

Thank you very much. I had got it for I remove the code line that you suggest.

But I also found the other issue: The first time I had build the app, the app work.  And then I restart the app or rebuild the app, it calls an error.
I checked the error:
Code: [Select]
ERROR/AndroidRuntime(13590): java.lang.RuntimeException: [ 1312968646623 ] - ERROR: A texture with the name 'texture' has been declared twice!
The error made me confuse. How to solved it ??
« Last Edit: August 10, 2011, 11:46:19 am by hisong »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: The texture on sphere appeared not properly
« Reply #6 on: August 10, 2011, 12:28:29 pm »
That's because you don't really start it twice. You are just bringing it in front again, which creates a new Activity instance (and gl context...) but in the same VM instance. Try to learn more about Android's Activity management to understand what's going on here.


Actually, you don't have to reload textures, objects or anything. You can reuse everything that you've loaded at the very first startup of the Activity in that VM. That means that you can simply continue exactly where you have left. Have a look at the example(s) that come with jPCT-AE for a possible solution and http://www.jpct.net/forum2/index.php/topic,1657.0.html for some more discussion about this issue. Please note that the thread is one year old, so not everything that is said there is still valid for the current example code, because it includes some of the working that the thread mentions now.