Author Topic: How to dynamic change the texture U V ?  (Read 3473 times)

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
How to dynamic change the texture U V ?
« on: October 23, 2014, 11:24:54 am »
Hello , I want to do animation action by change texture U V , but I don't know how to do this? any sugestion or sample  , very Thanks !

Offline Darai

  • byte
  • *
  • Posts: 45
    • View Profile
Re: How to dynamic change the texture U V ?
« Reply #1 on: October 23, 2014, 01:07:26 pm »
What you need to know is:
  • Use Object3D.build(false) instead of Object3D.build() to tell JPCT that you DONT want static texture
  • Use Object3D.touch() to tell the object that you changed something and he should do again the "lazy transformation".
  • The texture setting is done through "Polygon manager" in following fashion: Object3D.getPolygonManager().setPolygonTexture(TriaID, new TextureInfo(TexID, U1, V1, U2, V2, U3, V3) Where TriaID is the ID of triangle on which you want to change the texture, TexID is the ID of your texture (still the same if you don't want to change the whole thing) and U1 .. V3 are coordinates of the points of the triangle on the texture (U1 - V3 are in range 0 - 1)

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: How to dynamic change the texture U V ?
« Reply #2 on: October 23, 2014, 01:14:13 pm »
If I do this in ondrawFrame ,  maybe this will cause the framerate drop huge?

Offline Darai

  • byte
  • *
  • Posts: 45
    • View Profile
Re: How to dynamic change the texture U V ?
« Reply #3 on: October 23, 2014, 02:06:56 pm »
Well,

onDrawFrame is a good place to do this. I don't know if there is a better way or place to do it, maybe Egon will give you another advise. For me, it works there.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to dynamic change the texture U V ?
« Reply #4 on: October 23, 2014, 08:14:18 pm »
That's one way of doing it. Depending on the kind of animation, a texture matrix (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#setTextureMatrix(com.threed.jpct.Matrix)) might do the trick as well and it's faster.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: How to dynamic change the texture U V ?
« Reply #5 on: October 24, 2014, 11:28:24 am »
Sets a matrix that is applied to transform the texture in stage 0, What's stage 0 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to dynamic change the texture U V ?
« Reply #6 on: October 24, 2014, 11:31:34 am »
The first texture layer.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: How to dynamic change the texture U V ?
« Reply #7 on: October 24, 2014, 11:58:14 am »
hi, I use following code , but nothing happen , what's wrong

      billbord = Primitives.getPlane(1, 20);
      billbord.setTexture("speedup");
      billbord.build(false);
      world.addObject(billbord);


 and  ondrawframe

                mx.translate(-1, 0, 0);
      billbord.setTextureMatrix(mx);


I want  picture translate from right to left and repeat this action 
« Last Edit: October 24, 2014, 12:16:44 pm by gamenewer »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to dynamic change the texture U V ?
« Reply #8 on: October 24, 2014, 01:45:28 pm »
Translation happens in normalized texture coordinates. -1 is as good as no translation. Try lower values instead (like 0.01f or something).

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: How to dynamic change the texture U V ?
« Reply #9 on: October 24, 2014, 02:30:08 pm »
It's ok , thank you very much !