Update texture coordinates on object?

Started by AugTech, February 17, 2014, 04:00:09 PM

Previous topic - Next topic

AugTech

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.

EgonOlsen

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.

AugTech

#2
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 plane.compile(false, false, true, false, Config.glBatchSize); method, not 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...

AugTech

Okay, ignore the previous post for now - just testing this and seeing if I can do it without splitting the object..

EgonOlsen

#4
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.

AugTech

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.

AugTech

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!