PROPOSAL: Refactoring of UV Getting / Setting Functions

Hello.

I’m finding that the built in get and set functions for vertices’ UV maps are kinda half-hazard. The getUV functions only get the first or second index (according to which function you use), and similarly for the setUV functions. The uvs property has all of the UV values in a single list, and while you can use it to alter the UV map of each channel, it’s a bit awkward because as far as I can tell, you have to do this for all 8 channels at the same time, even if you only want to alter one, or even if you only have one channel actually created in Blender.

So, I propose an idea for a slight refactoring to see what others think.


Firstly, a SetUV() function that takes an argument (optionally) in addition to the UV values of the vertex to set that indicate what channel to set these UV values to. If left blank, then the channel will default to 0 (the first one). Also, a GetUV() function that takes an argument (optionally) to get the UV values of a specific channel.

Both of these are already implemented, of course; it’s just about being able to pass your specified channel to the underlying C++ function.

A function that returns a dictionary of UVs, organized according to the name of UV channel (and sorted in ascending order, if possible) would be nice, but would be the hardest to implement, for me. Perhaps I could get help on that sometime. In any case, the first two would be the ones to approach for me (a newbie C++ coder, essentially, haha).


Note that this proposal is INSTEAD of the current functions, so they would be basically deleted, or at least deprecated. I personally wouldn’t mind simply getting rid of the extraneous portions of the API, since they’ve been around for so long.


Thoughts?

EDIT: Vertex Color stuff moved to another thread as it’s a more complex, thoughtful discussion.

I can’t find this property in the documentation. Could you please provide a link?

and while you can use it to alter the UV map of each channel, it’s a bit awkward because as far as I can tell, you have to do this for all 8 channels at the same time, even if you only want to alter one, or even if you only have one channel actually created in Blender.

A function that returns a dictionary of UVs, organized according to the name of UV channel (and sorted in ascending order, if possible) would be nice, but would be the hardest to implement, for me. Perhaps I could get help on that sometime. In any case, the first two would be the ones to approach for me (a newbie C++ coder, essentially, haha).

Could you not write that function in Python? I’m assuming that you can differentiate the data in the uvs property by channel.

In either case, I think this would be the right approach, and that it should exist along with current UV functions (there is no need to break backward compatibility for something like this).

It would appear that the property isn’t documented, which is something that definitely needs to change.

Yeah, I forgot that I could implement such a function myself in Python. It would be quicker to implement than changing the API, but if the API could be improved, I think it’d be best to remove them rather than just let such functions lie.

The fundamental problem is in the fact that the getter returns a new list of new vectors, instead of a PyObject list of PyObject vectors, where the latter would actually hold reference to the underlying data.

I don’t know how to solve that problem specifically, but you should contact whoever wrote the Vector_CreatePyObject_cb function, used here, because that basically does what you want in this circumstance (for the vectors - the list would probably require a “List_CreatePyObject”, or something like that).

With that implemented, the uvs property would be the ideal interface, and all the other functions could/should be deprecated.

PS: Channel ordering corresponds to that visible in texture properties, which I think is proper. Would you like it to be in some other order (and if so, why)?

The channel ordering’s okay the way it is, I just thought it would be nice to be able to pull UV values according to the names of the UV maps, since you can name them in Blender.

And yeah, I’d be for the uvs property method if it didn’t require setting the entire list. Maybe I’ll get around to looking into it.

The uvs property could be a CListValue.

The get/setUV() should have been deprecated in favor of the new uvs property. This property was added when support for more than two UV channels was added to the BGE. So, really, we need to fix the property and make sure it is properly documented.