Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split model components into their own meshes #7

Merged
merged 5 commits into from
Jun 1, 2024

Conversation

ryanjsims
Copy link
Contributor

This is a feature I wanted when I extracted the Charger model, so I decided to implement it and share with the community.

Model "components" (just what I call them) are various portions of a model that the game uses for a few purposes, most notably the damage states of different body parts of enemies. At least one way of identifying them is via their UV coordinates - it looks like Arrowhead opted to take advantage of repeating texture coordinates to split the UVs for each component, maybe so when an artist was editing the overlapping portions of the model there wouldn't be so many vertices in the way? Whatever the reason, it gives us an easy way to split the components apart, making it easier to get enemies in a specific damage state in Blender.

With this change, I've added a unit config option components with values combined (default) and split. When split is selected, the model will be split into multiple meshes, one for each unique set of UV integer values. The components will be grouped together with a parent node so that they remain organized when imported.

This is my first time working with Go, so please let me know if I've committed any cardinal sins with these changes.

ryanjsims added 4 commits May 19, 2024 18:38
Mesh parts with different damage states seem to be differentiated by their UV coordinates' integer portions - the charger's undamaged head lies in U range [8, 9), and the destroyed head is in U range [9, 10). This change splits the exported mesh up by these U ranges.
@xypwn
Copy link
Owner

xypwn commented May 23, 2024

Hi, sorry for the late response!
This is a feature I wanted as well, so thanks for finding the correlation with the UVs and writing the code!

I noticed that the way in which components map to the actual parts of the model is sort of random (e.g. component 6 of the bile titan seems to be both the hind part of the abdomen and the gore on the lower part of the left hind leg; see images below).

Component 6 off
grafik
Component 6 on
grafik

You mentioned that this is only one way to split meshes apart. Do you know of any other possible way?

Other than that, the PR looks pretty good, nice work :)

I'd like to merge after discussing any other ways to split more accurately (if there are any).

@ryanjsims
Copy link
Contributor Author

ryanjsims commented May 28, 2024

I was mentioning it as "at least one way" because I wasn't sure if those components were described in any other way in the unit format. I'm not actually aware of a different way of doing it currently, that would need more research - sorry for the confusing wording

Also all the components should be split - the leg and hind gore shouldn't be combined - I'll have to check what's going on there when I get a chance

@xypwn
Copy link
Owner

xypwn commented May 28, 2024

Don't worry about it, I appreciate any contribution :)

That'd be cool if you could look into it, take your time

This fix may have issues if both positive and negative V coordinates exist within the same model
@ryanjsims
Copy link
Contributor Author

So it turns out the V coordinates were not incrementing (as blender was displaying) but decrementing - so components 0-31 would have UVs of (0.0, 0.0)-(31.0, 0.0), then components 32-63 would have UVs of (0.0, -0.0)-(31.0, -0.0), then 64-95 would be (0.0, -1.0)-(31.0, -1.0) and so on (Assuming the pattern holds, I haven't actually observed a model with more than ~40 components)

So to fix it I just took the absolute value of the V coordinate and added 1 to it: -0 maps to 1, -1 maps to 2, and so on. This fix would combine components again if there are positive and negative V coordinates in the same model. I haven't seen that case happen as of yet, so I don't know if its possible

@xypwn
Copy link
Owner

xypwn commented Jun 1, 2024

I haven't tested it with a lot of models so far, but it seems to work quite reliably now.

Nice work and thanks again!

@xypwn xypwn merged commit 7eeb014 into xypwn:master Jun 1, 2024
1 check passed
@ryanjsims ryanjsims deleted the feature/model-split-by-uvs branch June 3, 2024 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants