Mesh Segmentation Tutorial - eArmada8/Ys8_IT3 GitHub Wiki

Mesh Segmentation Tutorial

Games older than Ys VIII use VPA8 (or older), which come with a curious restriction - any given mesh cannot have more than 4 vertex groups in it. (Actually to be precise, no mesh I have seen uses more than 4 so the ceiling might be a bit higher, but I do not know.) This leads to numerous submeshes despite these games using low-poly models. For example, Karna's body is comprised of more than 30 submeshes, many of which share the same material.

If one is making simple modifications to existing submeshes, this is generally not a problem as all existing models already conform to the restriction. However, when inserting a new mesh, the new mesh must adhere to this restriction. We achieve this through mesh segmentation.

NOTE: This tutorial assumes you have already completed the costume transfer tutorial and will skip all the steps in that tutorial. Once you have extracted the raw buffers from the .glb (or if you export raw buffers directly from Blender as per the Basic Tutorial), you will use this tool to segment the buffer prior to assigning materials.

Introduction

For this tutorial, we will attempt to place this dress on Karna. (The dress itself is taken from Laura's ToCS2 DLC, just recolored and modified to make this tutorial easier.)

As you can imagine from looking at the dress, it will have quite a few different vertex group influences - right shoulder, left shoulder, upper torso, hips, left upper leg, right upper leg, etc. In fact, looking in Blender, one can see that I have assigned 9 groups in the weight transfer process.

We need to split it into enough chunks that any given chunk is only influenced by 4 or fewer groups. This is what the final segmentation will look like:

Segmenting the mesh and finding unsegmentable triangles

Once you have exported your mesh as a .fmt/.ib/.vb/.vgmap (either via the basic modding tutorial) or the advanced transfer tutorial), run ys7_segment_mesh_for_restricted_bone_palette.py on the .vb file to segment it. For example, I have exported the dress as dress.vb (and dress.fmt, dress.ib, dress.vgmap - all four files are needed).

python ys7_segment_mesh_for_restricted_bone_palette.py dress.vb

If you do not get any error messages, then your mesh is segmented and you can proceed to the end. Congratulations! (The segmented files are in a folder matching the name of the original mesh. For example, if you segmented dress.vb then the segmented meshes are in the dress folder.)

However, in my case, parts of the mesh are too complex to segment, and I get this error message:

The script still proceeds to segment the mesh, but all the triangles with too many groups are collected together in a single mesh. As you can see from the picture below, the segmented meshes are dress_01, dress_02, dress_03, etc, and the unusable triangles are in dress_unusable.

Reducing vertex groups to make triangles compatible

First, note that all work will be done on the intact pre-segmentation mesh, not the mesh fragments! This saves work and reduces errors, and makes life much easier when going back to further refine the mesh via sculpting etc.

Load all the fragments into Blender (including the unusable fragment). You can see how the script has split the mesh into several pieces.

Here is the unusable piece. Sometimes this can be dozens of triangles split across the mesh, but luckily this time it is only a single triangle!

Looking at the three vertices of the triangle, we only need to remove one group. The group that makes the most sense to remove is the left shoulder, which has minimal influence (0.8%) and conceptually should not be influencing the middle back anyway. We will remove this group from the vertex on the original mesh.

Here is the vertex on the original mesh. Note that it actually has four groups, including the right shoulder which has a near-zero assignment on the right shoulder. Now we could just remove the left shoulder influence, but then when we normalize then the right shoulder may increase sufficiently to cause a new unsolvable triangle (unlikely but possible). We will delete both groups (click the X to the right of the weight).

Once we have deleted the groups, press Normalize to make sure the remaining groups add up to 1.0 (100%).

Once you are done, export the mesh. Delete the output of the last run, and run the script again. This time, there are no unusable triangles and the meshes are ready to be used in your mod!

NOTE: If there are a lot of broken triangles, you may want to do this step multiple times. Sometimes one vertex can cause several triangles to be problematic, so it can be worthwhile experimenting until you find a good solution, rather than trying to fix everything in a single pass.

As we can see, the dress is now successfully inserted into the game! (Full disclosure: this specific mod is nowhere near usable, and I would need to do a lot more cleanup work to make it fully usable. For the purposes of this tutorial, however, I am happy enough with this result.)