jPCT-AE - a 3d engine for Android > Support

Adding / modifying textures on a plane primitive on the fly.

(1/3) > >>

davec64:
Hi
I Have manged to get most of my visual effects working. However I have once again become stuck on changing textures based on the deformed plane height. spent over 2 days trying to work this one out.
If I change them to different incremental textures at the retexture stage. I see similar to what I expect see image each polygon clearly visible. Although I am not 100% on the output except that there are 2 polys per square.
 
When I try to get a polygon and apply a new texture. all the textures go back to my default texture and no polygons are visible any more.
I am sure this is just a misunderstanding of how to change the texture.
Any help greatly appreciated.
this is from my vertexcontroller that sets the z value that is done in a loop outside of this snippet.
When this code is applied it seems to apply to all the the polygons ( as if  there is one poly per column).


--- Code: --- if (polyindex < maxPolygonID) {
            int depthiD = TextureManager.getInstance().getTextureID("depth" + (int) data % 29);
            if (depthiD == -1) {
             depthiD =  TextureManager.getInstance().getTextureID("depth0");

            }
            Logger.log("texture id = " + depthiD + "data = " + (int) data + "polyindex ="
                + polyindex);
            int t1 = pm.getPolygonTexture(polyindex);
            uv0 = pm.getTextureUV(polyindex, 0);
            uv1 = pm.getTextureUV(polyindex, 1);
            uv2 = pm.getTextureUV(polyindex, 2);
            TextureInfo ti = new TextureInfo(t1, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
            ti.add(depthiD, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y, TextureInfo.MODE_MODULATE);
            pm.setPolygonTexture(polyindex++, ti);

            t1 = pm.getPolygonTexture(polyindex);
            uv0 = pm.getTextureUV(polyindex, 0);
            uv1 = pm.getTextureUV(polyindex, 1);
            uv2 = pm.getTextureUV(polyindex, 2);
            ti = new TextureInfo(t1, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
           ti.add(depthiD, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y, TextureInfo.MODE_MODULATE);
            pm.setPolygonTexture(polyindex++, ti);
          }

--- End code ---
Second attachment is with this code. It seems to upset the whole texture.
https://www.dropbox.com/sh/0epa1c6jved3dxu/XGq4d9ItAu

EgonOlsen:
When does this re-texturing happen? At runtime, i.e. after the plane has been build() and/or rendered at least once? In that case, you can't do it that way. An object's mesh gets compiled to be processed by the GPU. During that step, it will be split into groups of polygons that share a common render state. That means that all polygons with the same texture will be grouped into one structure which will then be transfered to and rendered by the GPU.
If you are changing textures after this process, you can change them only per group and not individually anymore.
What you could do is to use one texture that contains all others instead and only change the texture coordinates for each polygon. If you are going this way, you have to add an explicit call of Object3D.compile(true, false); and you have to call Object3D.touch(); after setting the new coordinates.

davec64:
Hi Yes this is at run time.
So it will have to be by group.
So you are saying create a master texture that has in my case.
30 textures of different shades.
Then change the coords of each polygon to point to the correct shade.
can you give me a brief example of this.
ie i have a texture map of 1024*1024 and 4 shades in this map
so 0,0,512,512 would be one next would be 0,512,512,1024 not sure if thats correct but you know what I mean.
Thanks
Dave 

EgonOlsen:
Yes, similar to that. However, i don't understand why a simple colored texture has to be 512 pixels in size each. Something like 16*16 or 32*32 should be sufficient IMHO. Maybe we should take one step back: What are you actually trying to achieve? To assign a different color based on the height?

davec64:
Yes a different colored texture based on height. It does not have to be so large that was just so that I could visualize the texture tile as it where. this is to show the depth of a channel like a topography. 16 *16 could work.
no problems I think.

Navigation

[0] Message Index

[#] Next page

Go to full version