Skip to content

Commit

Permalink
docs: add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Oct 12, 2024
1 parent 5d11eec commit af7fe67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public static void CopyEnablementAnimation(
}
}

// must preserve first material to be the first material for AutoMergeSkinnedMesh
public static (int[][] subMeshIndexMap, List<(MeshTopology topology, Material? material)> materials)
GenerateSubMeshMapping(
MeshInfo2[] meshInfos,
Expand Down Expand Up @@ -567,6 +568,7 @@ private static HashSet<AnimationLocation> GetAnimationLocations(BuildContext con
return locations;
}

// must preserve first material to be the first material for AutoMergeSkinnedMesh
private static (int[][] mapping, List<(MeshTopology topology, Material? material)> materials)
CreateMergedMaterialsAndSubMeshIndexMapping((MeshTopology topology, Material? material)[][] sourceMaterials,
HashSet<Material> doNotMerges)
Expand Down
4 changes: 4 additions & 0 deletions Editor/Processors/TraceAndOptimize/AutoMergeSkinnedMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public static void MergeMeshes(BuildContext context, TraceAndOptimizeState state

Func<MeshInfo2[], (int[][], List<(MeshTopology, Material?)>)> createSubMeshes;

// createSubMeshes must preserve first material to be the first material
if (state.SkipMergeMaterials)
createSubMeshes = CreateSubMeshesNoMerge;
else if (state.AllowShuffleMaterialSlots)
Expand Down Expand Up @@ -258,6 +259,7 @@ private static void MergeAnimatingSkinnedMesh(
var newMeshInfo = context.GetMeshInfoFor(newSkinnedMeshRenderer);
var meshInfosArray = meshInfos.ToArray();

// もしAnimationがPatrially Appliedなことがある場合は初期値を取れるマテリアルを最初のスロットに適用するべきかも。createSubMeshesの中で
var (subMeshIndexMap, materials) = createSubMeshes(meshInfosArray);

MergeSkinnedMeshProcessor.DoMerge(context, newMeshInfo, meshInfosArray, subMeshIndexMap,
Expand Down Expand Up @@ -461,6 +463,7 @@ CategorizationKey key
return newSkinnedMeshRenderer;
}

// must preserve first material to be the first material
public static (int[][], List<(MeshTopology, Material?)>) CreateSubMeshesNoMerge(MeshInfo2[] meshInfos)
{
var subMeshIndexMap = new int[meshInfos.Length][];
Expand All @@ -483,6 +486,7 @@ public static (int[][], List<(MeshTopology, Material?)>) CreateSubMeshesNoMerge(
public static (int[][], List<(MeshTopology, Material?)>) CreateSubMeshesMergeShuffling(MeshInfo2[] meshInfos) =>
MergeSkinnedMeshProcessor.GenerateSubMeshMapping(meshInfos, new HashSet<Material>());

// must preserve first material to be the first material
public static (int[][], List<(MeshTopology, Material?)>) CreateSubMeshesMergePreserveOrder(MeshInfo2[] meshInfos)
{
// merge consecutive submeshes with same material to one for simpler logic
Expand Down

0 comments on commit af7fe67

Please sign in to comment.