The texture on sphere appeared not properly

Started by hisong, August 09, 2011, 11:59:10 AM

Previous topic - Next topic

hisong

     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

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]

Nemetz

Please, show your texture cutting....
I think problem in this point.

EgonOlsen

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

hisong

Quote from: EgonOlsen 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

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.

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();




EgonOlsen

Remove that line. You shouldn't create texture coordinates on objects that already have some: cube.calcTextureWrapSpherical();

hisong

#5
Quote from: EgonOlsen on August 10, 2011, 07:14:39 AM
Remove that line. You shouldn't create texture coordinates on objects that already have some: 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: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 ??

EgonOlsen

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.