jPCT-AE - a 3d engine for Android > Support
Adding / modifying textures on a plane primitive on the fly.
davec64:
All Done and it works really well.
I have 64 32*32 sub textures in a single 256*256 texture.
selecting the depth sets up the correct texture based on depth.
I have put the code up as an idiots guide of how to change a texture on an object that has already been built.
You must do this first before you compile. (retexture method from advanced example modified)
--- Code: --- PolygonManager pm = obj.getPolygonManager();
int t2Id = TextureManager.getInstance().getTextureID(t2);
int end = pm.getMaxPolygonID();
Logger.log(end + "num of polygons");
int t1 = pm.getPolygonTexture(0);
for (int i = 0; i < end; i++) {
uv0 = new SimpleVector(0, 0, 0);
uv1 = new SimpleVector(0, SUBTEXTURE, 0);
uv2 = new SimpleVector(SUBTEXTURE, 0, 0);
ti = new TextureInfo(t1, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
ti.add(t2Id, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y, TextureInfo.MODE_REPLACE);
pm.setPolygonTexture(i++, ti);
uv0 = new SimpleVector(0, SUBTEXTURE, 0);
uv1 = new SimpleVector(SUBTEXTURE, SUBTEXTURE, 0);
uv2 = new SimpleVector(SUBTEXTURE, 0, 0);
ti = new TextureInfo(t1, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
ti.add(t2Id, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y, TextureInfo.MODE_REPLACE);
pm.setPolygonTexture(i, ti);
--- End code ---
then in your vertex controller
--- Code: --- if (polyindex < maxPolygonID) {
textureIndexX = VesselRenderer.SUBTEXTURE * (int) ((depth * 2) % 8);
textureIndexY = VesselRenderer.SUBTEXTURE * (int) ((depth * 2) / 8);
uv0 = new SimpleVector(textureIndexX, textureIndexY, 0);
uv1 = new SimpleVector(textureIndexX,
textureIndexY + VesselRenderer.INTERNALSUBTEXTURE, 0);
uv2 = new SimpleVector(textureIndexX + VesselRenderer.INTERNALSUBTEXTURE,
textureIndexY, 0);
ti = new TextureInfo(t1, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
ti.add(t1, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y, TextureInfo.MODE_REPLACE);
pm.setPolygonTexture(polyindex++, ti);
uv0 = new SimpleVector(textureIndexX + VesselRenderer.INTERNALSUBTEXTURE, textureIndexY
+ VesselRenderer.INTERNALSUBTEXTURE, 0);
ti = new TextureInfo(t1, uv1.x, uv1.y, uv0.x, uv0.y, uv2.x, uv2.y);
ti.add(t1, uv1.x, uv1.y, uv0.x, uv0.y, uv2.x, uv2.y, TextureInfo.MODE_REPLACE);
pm.setPolygonTexture(polyindex++, ti);
}
--- End code ---
initialise using these methods
--- Code: --- obj.calcNormals();
// make sure to attach the controller before calling build() or otherwise, the object will be
// compiled to static geometry and won't reflect any changes to the mesh.
obj.getMesh().setVertexController(m_channelController, false);
obj.compile(true, false);
obj.build();
--- End code ---
davec64:
Spoke to soon
I am having an issue with the textures. They are not tiling correctly. If I use a tile 32*32 the top left I set to 0,0 then to get set the texture from my 256*256. I use 1/256 * 32 0 depth tile which should give me the far edge of the first of my depth texture tiles ??.
I am getting part of the next tile or some thing is alias ing the edge of the texture when it is displayed.
I think this may be something that I have not done. I have played around with the far edge but it always does the same thing unless it is a solid color and it covers at least 2 extra pixels around the 1st tile texture.
It basically looks like there are extremely thin lines or a shadow on the edge of each polygon.
Not the hypotenuse. Just the edges.
Dave
EgonOlsen:
That's because the bilinear filtering takes adjacent pixels into account. You have two options: use other texture coordinates. If the sections are uni-color anyway, that shouldn't matter. Or disable bilinear filtering (Texture.setFiltering(false)).
davec64:
I Turned off the filtering and it helped a bit however I still saw the thin lines generated in between the polygon edges as the plane went further into the foreground.
So I called Texture.setClamping(true); and that seems to have had the most beneficial effect.
I then changed the texture coords slightly so as not to get to close to the edge of the next line of pixels.
Now it seems to be working as expected.
I turned the filtering back on as well.
Thanks
Dave
Screek:
Hello, davec64, could you maybe write a bit more about your solution? For example, what are the SUBTEXTURE and depth variables for? And how should the texture look like? Or maybe you could make a simple example if you have time? Sorry for so many questions but I'm trying to do something like that from a week, but I'm not good at 3D stuff.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version