The question about setTexture

Started by gamenewer, December 14, 2014, 03:43:46 AM

Previous topic - Next topic

gamenewer

Hello Egon,   I pack some texture images into one large picture, I want to set model texture by each texture image coordinates (I can get the coordinates) , but I don't know how to do this ? I only found setTexture(String) and setTexture(TextureInfo) , I try    setTexture(TextureInfo) method but not work ok for me. Please help me, thank a lot  :)

EgonOlsen

You want to the change uv mapping per vertex? Then you have to use the PolygonManager class for this. And this method in particular: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/PolygonManager.html#setPolygonTexture(int, com.threed.jpct.TextureInfo)

gamenewer

Thanks Egon,My means  I have some 3d models ,i,e  3 models 1.ser 2.ser 3.ser , and each model  have  a textue , i,e  1.png 2.png and 3.png , now I use texturePacker tool pack  1 2 3 .png to  a  single picture  x.png , and I  want to set each model  use this single texture , How can I do this ?

Thanks a lot ! :) 

EgonOlsen

Use the PolygonManager to get the current coordinates for each point, transform them to the match the new coordinates in your texture atlas, create a new TextureInfo with these coordinates and set it via the PolygonManager.
You just have to keep in mind that bilinear filtering might cause bleeding into adjacent textures at the edges. If this is an issue in your case depends on the mapping of the model.

gamenewer

Your great !   I got it , as you say  that bilinear filtering might cause bleeding into adjacent textures at the edges,The road texture by repeat mode,  and  there looks somethings like a black line at the edges , How to resove  this issue?

EgonOlsen

Modify either the texture coordinates at the edges or the texture atlas. There's no solution in code for this, it's an art issue.

gamenewer

#6
Thanks , I  shrink the uv ( 0 changed to 0.001 and 1 changed to 0.009)  , it seems edge is ok , but I think this is not a good solution,  when one model use one texture  everything is ok ,but when one model use part of texture it's not ok , what's the diffrent between this case?

I found  when Object3D use transparent mode , there is a black border around the model.  If use a texture , setClamping(true) can resovle this issue , but when use part of  texture , it's no effect .

EgonOlsen

No, of course not. Clamping affects all coordinates <0 and > 1. Inside a texture, it has no effect. As said: All the problems that arise from combining multiple textures into one have to be solved in the art pipeline.

gamenewer

#8
Thanks Egon,  Could you give me a simple way  to solve this problem?  I'm sorry for  I realy no idea  :-[ (Modify either the texture coordinates at the edges or the texture atlas, I 'm not clear how to do this, could you give me a simple example ?)

EgonOlsen

I don't know. Maybe adding an alpha channel to the texture or whatever. I'm not sure where that black border comes from in your case. The behaviour that causes these issues is simply that the bilinear filter applied to the texels takes texture coordinates into account that lie outside of the actual uv coordinates of the model. This happens on single textures too (as it has too, because otherwise you wouldn't be able to get seemless textuering) but as long as it happens on the egdes, you can fight it with clamping and such.
I usually don't combine textures into one because in most cases, the advantages don't outweigh the drawbacks IMHO.

gamenewer

#10
Thanks Egon, I only want to improve the game performace by this way, thanks for your advise. I want to know  If packed all textures into one texture,  the jpct can perfomace a  fast GL draw?

EgonOlsen

No. All that this changes is that it doesn't have to switch between textures. And while this is a little performance improvement, i highly doubt that it would be noticable unless you are using a lot of different textures in an unoptimizable rendering order (i.e. transparent objects). For opaque objects, jPCT will sort by state anyway, so texture changes are reduced to a minimum.

gamenewer

hello, "using a lot of different textures in an unoptimizable rendering order (i.e. transparent objects)" , I don't know how to config rending order, is this do by jpct default? thanks

EgonOlsen

jPCT sorts by state unless it can't, because some other criteria is more important like distance for transparent objects.

gamenewer

Thanks Egon.  Another question , when I run game , it always output this log:

12-16 21:43:20.124: D/dalvikvm(2414): GC_CONCURRENT freed 1952K, 36% free 9981K/15367K, external 1326K/2221K, paused 4ms+4ms
12-16 21:43:26.540: D/dalvikvm(2414): GC_CONCURRENT freed 1956K, 36% free 9969K/15367K, external 1326K/2221K, paused 6ms+3ms
12-16 21:43:33.237: D/dalvikvm(2414): GC_CONCURRENT freed 1945K, 36% free 9978K/15367K, external 1326K/2221K, paused 4ms+3ms
12-16 21:43:40.153: D/dalvikvm(2414): GC_CONCURRENT freed 1945K, 36% free 9987K/15367K, external 1326K/2221K, paused 6ms+5ms
12-16 21:43:47.040: D/dalvikvm(2414): GC_CONCURRENT freed 1963K, 36% free 9978K/15367K, external 1326K/2221K, paused 4ms+3ms
12-16 21:43:53.937: D/dalvikvm(2414): GC_CONCURRENT freed 1954K, 36% free 9978K/15367K, external 1326K/2221K, paused 4ms+3ms
12-16 21:44:00.814: D/dalvikvm(2414): GC_CONCURRENT freed 1954K, 36% free 9978K/15367K, external 1326K/2221K, paused 3ms+3ms
12-16 21:44:07.850: D/dalvikvm(2414): GC_CONCURRENT freed 1954K, 36% free 9975K/15367K, external 1326K/2221K, paused 7ms+3ms

What's this ? and How to resolve this ?  Thanks !