BobDoleOwndU / FMDL-Studio-v2

Unity Engine importer and exporter for Fox Engine models.
MIT License
46 stars 13 forks source link

Vertex weights questions #28

Closed leus closed 3 years ago

leus commented 3 years ago

Hey, Bob, sorry for using this space for this question, which is not related to FMDL-Studio.

I'm trying to come up with a way to create PES face models from scratch using Blender and some modified existing Python plugins. And I managed to do it; I created a model that is actually loaded in game, and that all tools can import, so it's basically correct.

However, I haven't solved one issue: when I assign vertex groups and weights, the model go haywire. And I mean it: image

So, here's my question: do you know what restrictions FMDL models have regarding vertex weights? I know a single model can have only 32 vertex groups, and I know each vertex weight is stored as a single byte and then used as a weight by dividing it by 255. But a vertex can belong to several groups, with a weight associated to each group, and here's where I found problems: in my models, when I do certain operations (deleting or adding vertices, etc.) the weights get distorted and the default animation shows weird stuff like above.

Any help regarding how vertex weights needs to be... normalized? in FMDL models and how the Fox engine handles it would be more than welcome.

BobDoleOwndU commented 3 years ago

I know a single model can have only 32 vertex groups

Not quite. A single mesh can only be weighted to 32 bones.

But a vertex can belong to several groups

A vertex will only ever be weighted to four bones at maximum. It'll never be in multiple bone groups, because each mesh and thus vertex, is assigned to a single bone group. Bones can be in multiple bone groups though.

To me, it looks like all of your triangles might be starting from the same vertex? It's hard to say.

Weights are fairly simple. Just divide by 255 as you said. The only thing you have to look out for regarding custom models is that you can end up with values of 256 and 254 just multiplying by 255 because of the way the math works. You can take a look at how I handled that problem here.

leus commented 3 years ago

Thank you very much! Yeah, bones in a single mesh (in Blender they get organized in vertex groups).

This is really helpful. I think I'm getting it now.

leus commented 3 years ago

Just a note for anybody visiting this: I solved this problem by normalizing weights in Blender.