www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: zammbi on March 04, 2012, 08:08:07 am

Title: Tile texture on a SkyBox
Post by: zammbi on March 04, 2012, 08:08:07 am
I might be missing something but I can't see how to tile a texture on a SkyBox.
Is it possible?
Title: Re: Tile texture on a SkyBox
Post by: EgonOlsen on March 04, 2012, 08:33:55 pm
Yes, but it's a little complicated. You can get the world instance that the skybox is using. From that world, you can get the actual skybox object (simple the only object in that world). And then, you can get the PolygonManager from that object and set new texture coordinates for it. You'll find code in the forum that does the tiling calculations on an object using the PolygonManager.

The remaining question is: Why would you want to? A tiled sky isn't a real sky anymore, isn't it?
Title: Re: Tile texture on a SkyBox
Post by: zammbi on March 04, 2012, 09:12:37 pm
Is this the code you talking about?

Code: [Select]
private void tileTexture(Object3D obj, float tileFactor) {
PolygonManager pm = obj.getPolygonManager();

int end = pm.getMaxPolygonID();
for (int i = 0; i < end; i++) {
SimpleVector uv0 = pm.getTextureUV(i, 0);
SimpleVector uv1 = pm.getTextureUV(i, 1);
SimpleVector uv2 = pm.getTextureUV(i, 2);

uv0.scalarMul(tileFactor);
uv1.scalarMul(tileFactor);
uv2.scalarMul(tileFactor);

int id = pm.getPolygonTexture(i);

TextureInfo ti = new TextureInfo(id, uv0.x, uv0.y, uv1.x, uv1.y,
uv2.x, uv2.y);
pm.setPolygonTexture(i, ti);
}
}


Quote
The remaining question is: Why would you want to? A tiled sky isn't a real sky anymore, isn't it?
Since some devices are very low in memory this is one way to save memory. Get a tileable texture and it will look perfect(stretching small images are ugly). For example my spaceship game, space can tile easy :)
I'm surprised no one has done it before.
Title: Re: Tile texture on a SkyBox
Post by: EgonOlsen on March 04, 2012, 09:29:41 pm
Yes, that's the code.
Title: Re: Tile texture on a SkyBox
Post by: zammbi on March 05, 2012, 12:48:00 pm
Seems I'm doing something wrong, it doesn't want to tile.

Code: [Select]
skyBox = new SkyBox("stars", "stars", "stars", "stars","stars", "stars", 200);
Object3D skybox3DObj = skyBox.getWorld().getObjects().nextElement();
tileTexture(skybox3DObj, 2);
Title: Re: Tile texture on a SkyBox
Post by: EgonOlsen on March 05, 2012, 01:24:11 pm
Look fine so far. Maybe the SkyBox-class does something that prevents this from working...i'll look into it.
Title: Re: Tile texture on a SkyBox
Post by: zammbi on March 05, 2012, 01:31:50 pm
Quote
Maybe the SkyBox-class does something that prevents this from working...i'll look into it.
Ok thanks.

The texture only shows once and then repeats the edge, doesn't matter what do.
Btw I'm not clamping the texture.
Title: Re: Tile texture on a SkyBox
Post by: EgonOlsen on March 05, 2012, 02:14:12 pm
I see...the SkyBox-class enables this. The stupid thing is, that Texture has an enableClamping()-method only but no way to disable it again. No idea what i was thinking when doing it that way. You can work around this by extending Texture, override enableClamping() with an empty implementation and create your SkyBox-textures using that class instance...
Title: Re: Tile texture on a SkyBox
Post by: zammbi on March 05, 2012, 09:18:01 pm
Ah thanks I'll give it a try later.
Are you going to disable clamping from skyboxing (or give a option) into JPCT? or/and add a disableClamping method?
Title: Re: Tile texture on a SkyBox
Post by: EgonOlsen on March 05, 2012, 09:33:41 pm
I'll most likely deprecate it and replace it with a setClamping(<boolean>)-method.
Title: Re: Tile texture on a SkyBox
Post by: zammbi on March 06, 2012, 01:26:11 am
Works great.

Code: [Select]
I'll most likely deprecate it and replace it with a setClamping(<boolean>)-method.
Awesome. Then I just can disable clamping once I setup the skybox instead of overriding?
Title: Re: Tile texture on a SkyBox
Post by: EgonOlsen on March 06, 2012, 06:59:57 am
Awesome. Then I just can disable clamping once I setup the skybox instead of overriding?
Yes.