- Implemented texture caching to reduce the performance hit induced by dynamically cropping apparel
- Dynamically cropping apparel is now compatible with Sized Apparel
This commit is contained in:
AbstractConcept 2023-02-07 19:30:02 -06:00
parent 767317773b
commit 9144029fec
15 changed files with 108 additions and 25 deletions

View file

@ -30,29 +30,24 @@ namespace Rimworld_Animations_Patch
}
}
[HarmonyAfter("SizedApparelforRJW")]
public static void Postfix(ref bool __result, ref Apparel apparel, ref BodyTypeDef bodyType, ref ApparelGraphicRecord rec)
{
if (__result == false || apparel == null || bodyType == null || rec.graphic == null || ApparelSettings.cropApparel == false || IsRunningSizedApparel) return;
if (__result == false || apparel == null || bodyType == null || rec.graphic == null || apparel?.Wearer?.RaceProps?.Humanlike != true || ApparelSettings.cropApparel == false) return;
// Get graphic
Graphic graphic = rec.graphic;
// This graphic may need to be masked if the apparel sits on the skin layer and does not cover the legs
if (apparel.def.apparel.LastLayer == ApparelLayerDefOf.OnSkin && apparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso) && !apparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Legs))
{
Dictionary<GraphicRequest, Graphic> allGraphics = Traverse.Create(typeof(GraphicDatabase)).Field("allGraphics").GetValue() as Dictionary<GraphicRequest, Graphic>;
GraphicRequest graphicRequest = new GraphicRequest(typeof(Graphic_Multi), graphic.path, ShaderDatabase.CutoutComplex, graphic.drawSize, apparel.DrawColor, apparel.DrawColor, null, 0, null, "Masks/apparel_shirt_mask_" + bodyType.defName);
ApparelTexture2DPack pack = ApparelSettingsUtility.GetCachedApparelTextures(rec.graphic, bodyType);
if (pack == null) return;
if (allGraphics.TryGetValue(graphicRequest) == null)
for (int i = 0; i < 3; i++)
{
Graphic graphicWithApparelMasks = GraphicDatabase.Get<Graphic_Multi>(graphic.path, ShaderDatabase.CutoutComplex, graphic.drawSize, apparel.DrawColor, apparel.DrawColor, null, "Masks/apparel_shirt_mask_" + bodyType.defName);
graphic = GraphicMaskingUtility.ApplyGraphicMasks(graphic, graphicWithApparelMasks, true);
//DebugMode.Message("Applying apparel mask: Masks/apparel_shirt_mask_" + bodyType.defName + " to " + apparel.def.defName + " (" + graphic.path + ")");
if (pack.textures[i] == null) continue;
rec.graphic.MatAt(new Rot4(i)).mainTexture = pack.textures[i];
}
}
rec = new ApparelGraphicRecord(graphic, apparel);
}
}
}
}
//"Masks/apparel_shirt_mask_" + bodyType.defName