ousnius / BodySlide-and-Outfit-Studio

BodySlide and Outfit Studio, a tool to convert, create, and customize outfits and bodies for Bethesda games.
GNU General Public License v3.0
290 stars 64 forks source link

Feature request: Copy segment data #320

Closed GrafPanzer closed 2 years ago

GrafPanzer commented 3 years ago

Fallout 4 uses mesh segmentation to enable dismemberment and Pip-Boy sleeve removal. Outfit Studio v5.2.0 has good tools to add and remove mesh segments (and subsegments) and paint(/assign) faces to them. However, each face must be hand painted, and this painting must be redone whenever a mesh is imported from an .obj. (I use Blender, so don't know whether it's possible to preserve segments in .fbx imports.) It seems that all FO4 bodies, at least, use the same segment/subsegment arrangement (6 segments, 4 subsegments for each arm, 5 for each leg).

An automated process to copy segment data from the reference body would help speed the work of assigning each outfit face the most appropriate segment. This could conceptually work just like copying bone weights, with each outfit face copying its segment/subsegment assignment from the nearest reference body face. Hand painting would then only be required to clean up misassignations. As a sub-feature, it would also be useful to be able to mask faces to exclude them from the copy operation. As a second sub-feature, copying Cut Offset values from the reference body subsegments to the outfit subsegments would save users from having to manually copy them in NifSkope. I know ousnius is familiar with segments, but for those who aren't, there is a discussion of the current workflow here: https://forums.nexusmods.com/index.php?/topic/7680148-attach-dismemberment-to-cbbe-outfit/.

Request: Add an Outfit Studio tool to automate copying segment data from the reference body to the outfit.

GrafPanzer commented 3 years ago

Y'know, I think this may just be too hard, and I have real doubts that it would attract enough users to justify your time. After some experimentation with applying segmentation manually, I find that I am able to apply basic dismemberment functionality to my meshes but the results are poor. I've concluded that the interaction between segments, .ssf files, per segment/cut offset data, and the game's implementation of dismemberment gore meshes is too complex for me to master without either a tutorial or much more experimentation than I'm willing to do. Thanks for creating and maintaining BS&OS. They are amazing tools. Thanks too for your continuing support to the modding community from here at GitHub, at Discord, and elsewhere.

GrafPanzer commented 3 years ago

Sorry for the hin und her, but I think this feature might be worthwhile after all. I've applied dismemberment to a number of outfits now, and it isn't hard, but is very time intensive. Since it needs to be done every time an outfit is imported from an .obj to OS, the amount of work is daunting to mod authors. This might be one reason so few mods implement it now. A series of software algorithms could make it much quicker. The key processes are (1) painting segments onto the mesh, (2) adding cut offset data to the appropriate subsegments, and (3) creating a tailored .ssf file to match the segment bones that the mesh uses.

For (1), I think an algorithm similar to Copy Bone Weights could work. It would need to dynamically add segments and subsegments to the target mesh, as well as copy segment assignments to the polys. By default, meshes in OS include 4 segments. Seven are needed for a full outfit. #0 is a dummy, #1 is the head, #2 is the right arm, #3 is the torso, #4 is the left arm, #5 is the right leg, and #6 is the left leg. Depending on the length of the sleeves, pants, and footwear, up to 4 subsegments are needed for each arm and 5 for each leg. Hand segments are harder, for outfits that have hands or gloves.

For (2), there are generally 8 segments that need cut offset data added. I've attached a spreadsheet with the details. Currently, those cut offsets must be individually copied and pasted to the mesh's Per Segment Data in Nifskope. The standard cut offset values in the base body seem to work fine on outfits, so long as the outfit contains those segments (Index and Bone ID values must match). Again, an algorithm could automate this. Segments CutOffsets.xlsx

For (3), one possibility is to add a line to the Project section of the Save Project As dialog box to create the .ssf file based on the meshes and segments contained in the project. The .ssf file format is pretty straightforward, except that it only lists upper and lower arm and leg bones, not ankle/foot or hand bones.

I understand that implementing this is a lot of work just to simplify the process of adding dismemberment to outfits. Thanks if you've even read this far.

GrafPanzer commented 2 years ago

Following up on this again. I got a question about my conversion guide the other day that made me think this request is still relevant. Segments are important for VATS targeting in Fallout, as well as for dismemberment. An automated way to paint segments would be very handy. Instead of using the Copy Bone Weights algorithm, could it use the Conform Sliders algorithm to translate segment data from an existing mesh? All vanilla outfits have segment data, as do vanilla bodies. The algorithm could just copy segment data from the nearest faces of a reference mesh. That would be more precise than copying it from the bone nodes. This functionality would significantly reduce segment painting workload, making it as easy as conforming sliders.

sts1skj commented 2 years ago

Internally, the Copy Bone Weights algorithm uses the same code as the Conform Sliders algorithm. Doing something similar for copying partitions and segments should be possible, but with some significant differences. The big difference I see is that "Copy Partitions or Segments" would operate on triangles, not vertices. How should triangle proximity be measured? Should the three vertex coordinates be averaged to give a "center" for the triangle, and that used for measuring its distance to other triangles?

Internally, Outfit Studio keeps careful track of "Bone IDs" (called "material" internally) and "Cut Offsets" (called "extraData" internally). In the user interface, "material" can be edited in the "Type" box. "extraData", though, is not currently exposed in the user interface. For all this data, it's trivial to preserve it when copying segment data from one shape to another. If I just copied all the segment data from the source shape to the target shape, material and extraData would be copied along with everything else.

My impression, from reading the various documentation you've linked, is that the ssf file would be exactly the same for the target shape as for the source shape. Is there any reason to recreate the file?

sts1skj commented 2 years ago

I've implemented a bare-bones version of this algorithm in pull request #426 . It ignores the mask. All partitions or segments in the target shape are wiped out. It doesn't do a great job with segment/partition boundaries, which are often a bit jagged.

@GrafPanzer Is this good enough? Or do I need to do more?

GrafPanzer commented 2 years ago

Sorry, I need to check my email more often. I think I've now set up mobile push notifications for conversations I'm in here.

Thanks for taking a shot at implementing my request. Unfortunately I'm not a programmer, so can't give any feedback on your code, and I'm not competent to install your pulled files until they're merged back into a release. Sorry again. I'm happy to learn if it's simple, but if not I don't want to ask you to waste your time teaching me.

Based on your comments above, I'd say yes, please do copy all the segment data to the target shape. That should alleviate the need to manually copy it in NifSkope. You're right that the target shape's .ssf file will look similar to the source shape's. It may not contain all of the segments (e.g., pants only instead of a full outfit), but it's just a matter of deleting the unused segments from the copied .ssf. I'm not sure how important the .ssf is, so having extra segments in there might be fine. While it would be nice for OS to automatically generate an .ssf file, it's not hard to do manually, and the .ssf file needs to go in the built outfit's Meshes folder (not the project folder) anyway. Bottom line: not a high priority.

Regarding how to calculate tri positions, I agree that the average of vertices should be good enough. I expect the segment borders will often be jagged, but that's pretty common in unoptimized meshes anyway, and the user can touch them up with the split edge tool and segment brush if needed.

sts1skj commented 2 years ago

@GrafPanzer My computer runs Linux. I don't have a Windows or MacOS computer. I can easily provide a Linux executable of Outfit Studio, but it's highly unlikely you'd be able to use it. As for how to build Outfit Studio on Windows, I've never done it myself, so I don't know how it works.

GrafPanzer commented 2 years ago

Okay, thanks. So what will happen with the code your wrote?

sts1skj commented 2 years ago

Right now, Ousnius is busy. Once he has time, he'll take a look at what I've written. If he has any comments or suggestions, we'll discuss it, probably in the pull request #426 thread. (Add yourself to the notification list for that thread if you want to be notified as we discuss it. You can join in too, of course.) Since this is a fairly non-controversial pull request, there's a good chance he won't have any comments or suggestions. Then he will approve the pull request.

When Ousnius approves the pull request, the code of that pull request is merged into the main Outfit Studio branch: "dev". It becomes part of the official Outfit Studio source code. The merge is recorded in the project's history as a "commit". You can see a history of all commits by clicking on "1477 commits" on the main Outfit Studio page here on github. When Ousnius decides enough commits have accumulated that he really ought to make a new version available to users, he'll do a "release".

Doing a major release is a lot of work, so he won't do one unless he has plenty of time. He tags the current version of the source code with the official release name (which you can see in the commit history), compiles it, builds the appropriate packages for the different games, and publishes those packages through nexus. Usually, in the days after a major release, new bugs are reported that were added since the previous release, and he'll quickly publish minor bug-fix releases. So doing a major release requires a time commitment for about a week after it's published.

If you want to try my new code before the next major release of Outfit Studio, you can compile it yourself. I couldn't find any instructions for doing so for Windows, but I think that's because it's supposed to be obvious:

If you want to build for Linux (which I think is highly unlikely, since as far as I know I'm the only person using the Linux version of Outfit Studio), read the build instructions in "Readme-linux.txt".

ousnius commented 2 years ago

I've tried the feature. It's working fine and should be doing what @GrafPanzer wanted it to do. It'll be in the next release.

GrafPanzer commented 2 years ago

Super! Thanks @sts1skj for the detailed explanation. I really appreciate it.