-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemObjectPatch.cs
More file actions
59 lines (58 loc) · 2.29 KB
/
ItemObjectPatch.cs
File metadata and controls
59 lines (58 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaleWorlds.Core;
using TaleWorlds.Engine;
using TaleWorlds.MountAndBlade.View;
namespace ArmourVariationManager
{
[HarmonyPatch]
public static class ItemObjectPatch
{
[HarmonyPostfix]
[HarmonyPatch(typeof(ItemCollectionElementViewExtensions), "GetMultiMesh", typeof(ItemObject), typeof(bool), typeof(bool), typeof(bool))]
public static void OverrideMetaMesh(ref MetaMesh __result, ItemObject item, bool isFemale, bool hasGloves, bool needBatchedVersion)
{
if(__result != null && item.HasArmorComponent && item.HasAdditionalMeshes())
{
var data = item.GetVariation();
if(data != null)
{
var check = __result.HasAnyLods() || __result.HasAnyGeneratedLods();
MetaMesh finalMesh = __result;
List<MetaMesh> meshes = new List<MetaMesh>();
List<MetaMesh> clothMeshes = new List<MetaMesh>();
foreach (var mesh in data.AdditionalMeshes)
{
var copy = MetaMesh.GetCopy(mesh.MeshName, true, false);
if (copy.HasClothData())
{
clothMeshes.Add(copy);
}
else meshes.Add(copy);
}
foreach(var mesh in meshes)
{
finalMesh.MergeMultiMeshes(mesh);
}
foreach(var mesh in clothMeshes)
{
finalMesh.MergeMultiMeshes(mesh);
finalMesh.AssignClothBodyFrom(mesh);
}
for (int i = 0; i < finalMesh.MeshCount; i++)
{
var mesh = finalMesh.GetMeshAtIndex(i);
var material = mesh.GetMaterial();
material.SetEnableSkinning(true);
}
check = finalMesh.HasAnyLods() || finalMesh.HasAnyGeneratedLods();
__result = finalMesh;
}
}
}
}
}