Author Topic: The question about setTexture  (Read 1982 times)

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
The question about setTexture
« on: December 14, 2014, 03:43:46 am »
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  :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: The question about setTexture
« Reply #1 on: December 15, 2014, 07:54:54 am »
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)

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: The question about setTexture
« Reply #2 on: December 15, 2014, 08:25:26 am »
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 ! :) 

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: The question about setTexture
« Reply #3 on: December 15, 2014, 08:28:12 am »
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.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: The question about setTexture
« Reply #4 on: December 15, 2014, 08:46:14 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: The question about setTexture
« Reply #5 on: December 15, 2014, 09:36:31 am »
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.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: The question about setTexture
« Reply #6 on: December 15, 2014, 10:10:52 am »
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 .
« Last Edit: December 15, 2014, 12:21:09 pm by gamenewer »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: The question about setTexture
« Reply #7 on: December 15, 2014, 12:52:48 pm »
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.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: The question about setTexture
« Reply #8 on: December 15, 2014, 01:19:10 pm »
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 ?)
« Last Edit: December 15, 2014, 01:25:58 pm by gamenewer »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: The question about setTexture
« Reply #9 on: December 15, 2014, 01:28:29 pm »
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.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: The question about setTexture
« Reply #10 on: December 15, 2014, 01:40:13 pm »
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?
« Last Edit: December 15, 2014, 02:38:13 pm by gamenewer »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: The question about setTexture
« Reply #11 on: December 16, 2014, 07:42:42 am »
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.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: The question about setTexture
« Reply #12 on: December 16, 2014, 09:47:49 am »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: The question about setTexture
« Reply #13 on: December 16, 2014, 10:02:50 am »
jPCT sorts by state unless it can't, because some other criteria is more important like distance for transparent objects.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: The question about setTexture
« Reply #14 on: December 16, 2014, 02:49:15 pm »
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 !