www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: AugTech on February 17, 2014, 04:00:09 pm

Title: Update texture coordinates on object?
Post by: AugTech 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.
Title: Re: Update texture coordinates on object?
Post by: EgonOlsen 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 (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.
Title: Re: Update texture coordinates on object?
Post by: AugTech 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...
Title: Re: Update texture coordinates on object?
Post by: AugTech 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..
Title: Re: Update texture coordinates on object?
Post by: EgonOlsen 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.
Title: Re: Update texture coordinates on object?
Post by: AugTech 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.

(http://www.awila.co.uk/files/terrain_split.png)

Still have to get the right tiles applied by incrementing the texture id at the correct time, but job for tomorrow now.
Title: Re: Update texture coordinates on object?
Post by: AugTech 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
(http://www.awila.co.uk/files/terrain1.png)

1st runtime update;
(http://www.awila.co.uk/files/terrain2.png)

2nd runtime update;
(http://www.awila.co.uk/files/terrain3.png)

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!