Author Topic: Is there a way to offset Texture coordinates without using a custom shader  (Read 1096 times)

Offline zoalord12

  • byte
  • *
  • Posts: 29
    • View Profile
I cant get my shader to work, but the default shader works great
i want to change the UV for a texture, but dont want to write my own shader

is that possible ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
You can set a texture matrix to the object in question if that's what you mean. It basically transforms all uv-coordinates depending on the matrix.

Offline zoalord12

  • byte
  • *
  • Posts: 29
    • View Profile
oh wow, yeah that's exactly what i mean, like translate, scale and rotate the UV

Offline zoalord12

  • byte
  • *
  • Posts: 29
    • View Profile
but i want o do it per texture, not all the textures used on the object.

Offline zoalord12

  • byte
  • *
  • Posts: 29
    • View Profile
Hmm i found this thread where you talk about it , but you haven't answered that guy's question

http://www.jpct.net/forum2/index.php?topic=3452.0

face texture is tex-1
show-texture is tex-2

i just want to transform UV on 1 of them, but both are applied to an Object3D.



just FYI: this thread should be moved to JPCT-AE

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Isn't it possible to split the object then? That would be the easiest solution IMHO. What do you have in mind exactly? Maybe it helps to know better what you are after to find a solution...

Offline zoalord12

  • byte
  • *
  • Posts: 29
    • View Profile
I want to provide a UI (of some sort) to position a texture on a part of the mesh,


Its for a model viewer project.

so lets say i texture the clothes of a character, with a certain image, but i want the user to correctly place it using a finger. so the user move the finger left --> right, and i offset the UV in the x-direction.

I can get the x, y and how much the user wants to move the texture, but i need to offset that texture only on the clothes (sub-mesh), and not the torso, feet etc.


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
I see. If it's not required to be super fast, you can use the PolygonManager for this. It offers this method to change the uv-coordinates: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/PolygonManager.html#setPolygonTexture(int, com.threed.jpct.TextureInfo). To use it, you have to call a special form of build(): http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#build(boolean) and you should call http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#touch() on the Object3D after you are done. This requires a new upload of the mesh to the GPU, which can be slow for large meshes and frequent updates, but for a model viewer, it should be ok IMHO.

Offline zoalord12

  • byte
  • *
  • Posts: 29
    • View Profile
Hmm you steer me towards the polygonmanager and the polygon IDs, but i don't know how to correctly use them.

Like, it has 0 ---5K ids, one for each of my polygons, how do i know polygon 0 - 1400 are the face, 1401 - 2500 is the torso etc., is that done in the .obj file somehow through node-id or grouping or something ?


Offline zoalord12

  • byte
  • *
  • Posts: 29
    • View Profile
i was hoping for a realtime view if possible, so as the finger moves on the screen, the texture scrolls over the polys,
that build step will cause a 3-5 second delay everytime,

guess i need to write a shader with an individual UV transform matrix and be able to identify different sub parts of the mesh.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Polygon-IDs don't matter in that case. You have to iterate over all polygons, check for the texture ID and if it's the right one, create new coordinates (just make sure to reuse the TextureInfo or you'll run into garbage collection issues) and set them. Then call touch(). There's no build() call except the initial one involved, just a new mesh upload to the GPU with is much cheaper and happen automatically.