'vmask' is just the name I gave to the
FVF code variable.
If you haven't heard of it before, FVF code is basically an integer composed of smaller power of 2 numbers (2^n).
Each 2^n number is assigned to a specific vertex property, so by analyzing the FVF code you can tell which properties are available in a vertex buffer.
These are always different from game to game, but in case of Gameloft Pig format this is what we have:
2^0 = vertex positions
2^1 = vertex normals
2^7 = UV coordinates for channel 1
2^8 = UV coordinates for channel 2
So for example a vmask of 387 has all of the above, and
bit.or checks if 256 is in 387 (which it is).
There are other properties such as tangents, binormals or blend weights, but they weren't needed so I'm just seeking over them.
I should also be noted that vertex properties are always in the same order.
The second part of the code is a workaround for an issue I had with this format.
Most elements of a vertex property are 16bit integers, but in some cases they are 32bit floats. There should be an indicator somewhere that tells the game which is when, but I couldn't find it in the time I worked on this format.
So I came up with a quick and dirty solution that guesses if the values were read properly or not. It's based on the fact that after each set of vertex properties there is a 16bit integer for alignment - which I read as 'align'.
'align' should always be higher than 0 but lower than 16, and a multiple of 2. If one of these conditions isn't met, it means the script hasn't reached the end of the set, so it goes back and reads the values again as 32bit floats.
It's not an ideal solution but it seems to work.
I hope I cleared everything up, if not let me know.
Please post any requests or issues with my tools in the appropriate topics.
I'm sorry if I don't reply or if I ignore PMs. My time is very limited.