Author Topic: Update texture coordinates on object?  (Read 1240 times)

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Update texture coordinates on object?
« on: February 17, 2014, 04:00:09 pm »
Is it possible to update the texture coordinates on an existing object at runtime?

In producing a real terrain I now have an issue with sheer volume of data. After reading a few posts, it appears the way to reduce creation time and memory overhead on Android is to pre-create models, serialize them and then load on the mobile device.
The issue I have with this approach is that I want to change the texture (and texture size) on the model dynamically once it is loaded. i.e.  I have a 200x200 quad plane as a serialize'd model which, once loaded, I can assign either one 200x200 texture to it, or 4 x 100 or 16 x 50 texture's etc.

Is this possible, or do I have to stick with creating the plane dynamically at runtime as well?!

Thanks.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Update texture coordinates on object?
« Reply #1 on: February 17, 2014, 08:21:02 pm »
Yes, you can...but i'm not sure if really helps in your case. You can use a special version of the build-method, which would be build(false); in your case. You can then change the uv-coordinates by using the PolygonManager. However, what you can't do is to split polygon groups that used to use one texture into two. I tried to explain this here: http://www.jpct.net/forum2/index.php/topic,3706.msg26194.html#msg26194

Another option might be use a texture matrix, if that fits your needs. You can basically scale and translate existing coordinates with it.

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: Update texture coordinates on object?
« Reply #2 on: February 20, 2014, 12:46:54 pm »
Hmm, okay. As your referenced post mentions that the polygon group can't be changed after its compiled or rendered, I could in theory try;

Load my 'master' plane
Clone it (create 'split' Object)
Use Polygon Manager to re-assign uv coords
Pass the 'split' object in to the world.

Once done with the 'split' object, remove it and repeat the above process for the new size tiles?

Btw: Did you mean the
Code: [Select]
plane.compile(false, false, true, false, Config.glBatchSize); method, not
Code: [Select]
build(false) ?

If this sounds correct, I think I'll need a bit of experimentation to see if there is any performance gain compared to just building new objects on Android...
« Last Edit: February 20, 2014, 01:03:31 pm by AugTech »

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: Update texture coordinates on object?
« Reply #3 on: February 20, 2014, 03:04:15 pm »
Okay, ignore the previous post for now - just testing this and seeing if I can do it without splitting the object..

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Update texture coordinates on object?
« Reply #4 on: February 20, 2014, 07:18:42 pm »
It's not about splitting objects. It's more about that you are not allowed to paint two walls in different colors that used to share the same color.
« Last Edit: February 20, 2014, 11:35:07 pm by EgonOlsen »

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: Update texture coordinates on object?
« Reply #5 on: February 20, 2014, 07:38:45 pm »
I realised that after posting Egon, wasn't thinking about it correctly.

Anyway, making progress in testing anyway. (All on desktop at the moment)

The basic mesh takes around 7.5s to create, but 0.4-0.5 to load and manipulate the u,v coordinates, so its looking promising.



Still have to get the right tiles applied by incrementing the texture id at the correct time, but job for tomorrow now.

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: Update texture coordinates on object?
« Reply #6 on: February 21, 2014, 06:44:44 pm »
Okay, I think I have a way forward.. ??? Thanks for the direction on PolygonManager!

Some stats if anyone is interested (all with desktop at the moment);

1.49s to create a terrain tile covering approx 3Km sq. with 26,912 polys.
Saved as compressed .ser file @ 429Kb.
Time to load from file = 0.21s
Time to clone and apply 4 new textures  = 0.317s (Not actually sure why its slower the first time?!)
Time to clone and apply 16 new textures = 0.159s

Results;
Initial terrain


1st runtime update;


2nd runtime update;


Quite a few things left to work out (like working around a sub-tile calculating that 1/2 a polygon is the correct size!), but I think this will all be quicker than trying to create every time on Android!