Author Topic: TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)  (Read 1981 times)

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)
« on: October 29, 2012, 02:20:34 pm »
Me again :)

I'm trying to scale the texture being modulated into the textures on my polygons using the longer add method in the TextureInfo class.

I have this line initially just for the normal texture:
Code: [Select]
texInf[i]=new TextureInfo(tm.getTextureID("layer"+i));
Originally I had this after it, to add a second texture to the surface:
Code: [Select]
texInf[i].add(tm.getTextureID("floorTexN"),TextureInfo.MODE_MODULATE);^This works fine, but I wanted the second texture to occur more frequently (there isn't a nice way to tile texture stages)

So I found the long add method and tried something like this:
Code: [Select]
texInf[i].add(tm.getTextureID("floorTexN"),2f,2f,2f,2f,2f,2f,TextureInfo.MODE_MODULATE);No difference. :(

Infact, all of these:
Code: [Select]
texInf[i].add(tm.getTextureID("floorTexN"),2f,2f,2f,2f,0f,0f,TextureInfo.MODE_MODULATE);
texInf[i].add(tm.getTextureID("floorTexN"),3f,4f,5f,6f,7f,8f,TextureInfo.MODE_MODULATE);
texInf[i].add(tm.getTextureID("floorTexN"),0.1f,0.1f,1f,1f,0.2f,0.2f,TextureInfo.MODE_MODULATE);
Look exactly the same. :(

The second texture stage doesn't tile or stretch at all. :(

This seems to be a bug to me, or am I doing something silly and should be using a different method?

EDIT:
I should point out, this is all without shaders. (I'm in the middle of coding a version that works without a shader to make things faster. - All I want is a fairly frequent multitexture.)

EDIT2:
Also for the record, if I manually tile the image loaded (from 256x256 to 512x512) it does work. (I just want to tile it to the equivelant of about 16384x16384 using texture tiling in the code.)
« Last Edit: October 29, 2012, 02:41:40 pm by Cowbox »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)
« Reply #1 on: October 29, 2012, 05:25:34 pm »
I'm not aware of any problems with that method...and i'm using it all the time to tile textures. Make sure to assign the textures before calling compile() on the objects. If that still doesn't work, please try to make a simple test case that shows the problem.

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)
« Reply #2 on: October 29, 2012, 05:47:17 pm »
Ok, here's a very simple example snippet of the outline of what I'm trying to do and it just simply doesn't work:
Code: [Select]
tm.addTexture("test1",new Texture("res/test1.png"));
tm.addTexture("test2",new Texture("res/test2.png"));
float scale=1f;
testInfo=new TextureInfo(tm.getTextureID("test1"),scale,scale,scale,scale,scale,scale);
scale=4f;
testInfo.add(tm.getTextureID("test2"),scale,scale,scale,scale,scale,scale,TextureInfo.MODE_MODULATE);
testObject=Primitives.getPlane(1,50);
testObject.build();
testObject.translate(0,50,50);
testObject.setTexture(testInfo);
testObject.compileAndStrip();
world.addObject(testObject);

As far as I'm concerned, the 2nd texture stage should surely be being textured 4 times as often.

No matter what I do with any of the uv.x or uv.ys, nothing changes. :(

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)
« Reply #3 on: October 29, 2012, 07:42:46 pm »
Silly me..i somehow didn't notice before that you are trying to set the texture for the whole object with some coordinates that way. You can't do that, which is why the docs for setTexture(<TextureInfo>) say:

Quote
Texture coordinates for all layers are taken from the coordinates defined for the base layer of the Object3D.

I'll make it more clear in the docs that uv mapping will be ignored in this case. It has to, because it's given per vertex and if you assign one TextureInfo to a number of vertices at once, how should the uv mapping be applied?

To get what you want, you have to use the PolygonManager instead and do something like this:

http://www.jpct.net/forum2/index.php/topic,2599.msg19272.html#msg19272

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)
« Reply #4 on: October 29, 2012, 08:09:56 pm »
I understand.

However, I have already tried that method (I got it from the Advanced example).

It doesn't allow me to change "only" the texture ontop of the base texture. It will change both. :(

How do I change UV of just the blended texture?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)
« Reply #5 on: October 29, 2012, 08:19:55 pm »
Simply by not changing the coordinates for layer 0, i.e. get the u/vs, create a new TextureInfo with the original u/vs on the first layer and the modified ones on the second.

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)
« Reply #6 on: October 29, 2012, 09:24:28 pm »
Ohhhhhhhhhhhh

I'm a complete idiot.

I didn't realise the 6 parameters for the UV mapping were for 3 layers with 2 per layer. xD

Ok, so I've tried that, but now it's screwing up.

I'd have thought if I did something like this:
Code: [Select]
tileTexture(testObject,1,4,1);It would loop the 2nd layer 4 times.

It instead just messes up all the texturing, like so:

I've also tried calcTextureWrap and calcTextureWrapSpherical, neither of which fix it. :(

(I can't help but notice when I do this as well it no longer combines the textures, it's actually just messing up layer1 and ignoring layer2.)

(For completeness, here is the method after editing it to support 3 scales:
Code: [Select]
public static void tileTexture(Object3D obj,float tileFactor0,float tileFactor1,float tileFactor2)
{
PolygonManager pm=obj.getPolygonManager();
int lastPoly=pm.getMaxPolygonID();
for(int i=0;i<lastPoly;i++)
{
SimpleVector uv0=pm.getTextureUV(i,0);
SimpleVector uv1=pm.getTextureUV(i,1);
SimpleVector uv2=pm.getTextureUV(i,2);
uv0.scalarMul(tileFactor0);
uv1.scalarMul(tileFactor1);
uv2.scalarMul(tileFactor2);
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);
}
}
)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)
« Reply #7 on: October 29, 2012, 09:26:47 pm »
I didn't realise the 6 parameters for the UV mapping were for 3 layers with 2 per layer. xD
That's because the are not... ;) They are 2 for each vertex. Like the code shows it, you read the uv-values for each vertex of one polygon and create a new TextureInfo with that. In your case, the first layer gets the data just as it has been read before and the second layer gets the modified ones.

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)
« Reply #8 on: October 29, 2012, 09:28:14 pm »
Ahh, I'm thoroughly confused then. :(

I don't understand how you meant for me to access the other layers:
Quote
Simply by not changing the coordinates for layer 0, i.e. get the u/vs, create a new TextureInfo with the original u/vs on the first layer and the modified ones on the second.
D:?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)
« Reply #9 on: October 29, 2012, 09:37:34 pm »
Like so...

Code: [Select]
...
TextureInfo ti=new TextureInfo(id,uv0.x,uv0.y,uv1.x,uv1.y,uv2.x,uv2.y);
ti.add(layer2Id, uv0.x*2,uv0.y*2,uv1.x*2,uv1.y*2,uv2.x*2,uv2.y*2, TextureInfo.MODE_???);
...


Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)
« Reply #10 on: October 29, 2012, 09:45:24 pm »
Ah, right, I understand now.
xD

Phew, I'm GLaD that's over. D:

You can see why you made this engine and not me. xD

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)
« Reply #11 on: October 29, 2012, 09:48:06 pm »
No problem. It's not your fault, it's the fault of docs and/or the API because they don't make it clear. Any suggestions on how to improve the docs to make this more clear?

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: TextureInfo add(i,f,f,f,f,f,f,i) does the same as add(i,i)
« Reply #12 on: October 29, 2012, 10:41:10 pm »
I'd probably just remove the other parameters for http://www.jpct.net/doc/com/threed/jpct/TextureInfo.html#add(int, float, float, float, float, float, float, int) because giving it those 6 floats makes you think you can change the UV data for the texture just added. (Exactly what I was thinking.)

So there should only really be the constructor (where the UV values can be set) and an add method that just adds a layer, but doesn't allow any manipulation. That's where one would use set. :)