Author Topic: How to make UV animation effect?  (Read 1086 times)

Offline tao

  • byte
  • *
  • Posts: 16
    • View Profile
How to make UV animation effect?
« on: April 04, 2014, 10:54:06 am »
Hi,

I have a plane, and how can I make UV animations? I didn't find a way to change the UV attribute of a vertex. Pls help~

Thanks

Offline tao

  • byte
  • *
  • Posts: 16
    • View Profile
Re: How to make UV animation effect?
« Reply #1 on: April 04, 2014, 12:56:08 pm »
I found TextureInfo can change the vertex UV of each triangle, but still no idea how to make a 'water flow' animation using UV animation. Someone says I need to use shaders. Is that the only way? To use shader I have to use OpenGL2.0?

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to make UV animation effect?
« Reply #2 on: April 04, 2014, 01:16:40 pm »
TextureInfo is one way of doing it, but for a water animation, it might not be the best one. Using TextureInfo, you are going to change the coordinates on the client side. That means that after a change, the data has to be uploaded to the GPU again, which can be expensive in terms of performance. If you want to do this, you have to use a special build() call to allow for uv coordinate changes (build(true);). You also have to use touch() on the object after modifying the coordinates.
Shaders are another way to do it. It's very flexible, but you have to use OpenGL ES 2.0 and you have to write your own shaders.
The easiest way is to assign a texture matrix to the object (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#setTextureMatrix(com.threed.jpct.Matrix)). You can translate the matrix just like a normal tranformation matrix and it will translate the texture coordinates in the same way. Just make sure that your translation values don't get too large after time, so it's a good idea to reset them when possible (like if your value is larger than 1, you set it to value-1 instead).

Offline tao

  • byte
  • *
  • Posts: 16
    • View Profile
Re: How to make UV animation effect?
« Reply #3 on: April 04, 2014, 02:12:52 pm »
Thanks Egon, it's very detail  :)

public void build(boolean staticUV), I should use build(false), right?

Also, let me catch your idea ... so the way is like,

1) plane.build(false) at the creation of the plane.

2) then in each frame update ...
   2.1) translate texture matrix and plane.setTextureMatrix(matrix)
   2.2) plane.touch()

Am I right?

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to make UV animation effect?
« Reply #4 on: April 05, 2014, 08:56:36 am »
No, not quite. If you are using a texture matrix, there's no need for a special build call or touch. Just set the matrix...that's all.

Offline tao

  • byte
  • *
  • Posts: 16
    • View Profile
Re: How to make UV animation effect?
« Reply #5 on: April 06, 2014, 07:33:36 am »
Yes, Texture Matrix does the job, thanks!  ;D