Skip to content

Commit

Permalink
Handle DrawBatches
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetrith committed Jul 11, 2021
1 parent 5b9508d commit 519b93b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Source/DynamicDrawPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ static void Postfix()
}
}

// todo handle DrawBatch
[HarmonyPatch]
static class OverlayDrawerPatch
{
Expand All @@ -141,13 +140,18 @@ static void Postfix()
[HarmonyPatch]
static class GraphicsDrawMeshPatch
{
// Rotation angle and center
public static (float, Vector3)? data;

static IEnumerable<MethodBase> TargetMethods()
{
foreach (var m in AccessTools.GetDeclaredMethods(typeof(Graphics)))
if (m.Name == "DrawMesh" && m.GetParameters().Length == 12 && m.GetParameters()[1].Name == "matrix")
yield return m;

foreach (var m in AccessTools.GetDeclaredMethods(typeof(DrawBatch)))
if (m.Name == "DrawMesh")
yield return m;
}

static void Prefix(ref Matrix4x4 matrix, Material material)
Expand Down
8 changes: 4 additions & 4 deletions Source/PrintedDrawPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst

static Material CacheMaterial(Material mat, Graphic graphic, Thing t)
{
// For these Graphics, not an actual rotation but a texture switch is used for rotating
if (ShouldExchangeVerts(graphic))
if (ShouldExchangeVertices(graphic))
{
var outMat = mat;
var rot = t.Rotation;
Expand All @@ -154,8 +153,9 @@ static Material CacheMaterial(Material mat, Graphic graphic, Thing t)
return mat;
}

public static bool ShouldExchangeVerts(Graphic graphic)
public static bool ShouldExchangeVertices(Graphic graphic)
{
// For these Graphics, not an actual rotation but a texture switch is used for rotating
return graphic.GetType() == typeof(Graphic_Multi) && !graphic.ShouldDrawRotated;
}

Expand Down Expand Up @@ -218,7 +218,7 @@ static void Prefix(Graphic __instance, Thing thing, ref int __state)
}

if (PrintPlanePatch.currentThingData == null &&
GraphicPrintPatch_TransformMats.ShouldExchangeVerts(__instance))
GraphicPrintPatch_TransformMats.ShouldExchangeVertices(__instance))
{
var multi = (Graphic_Multi)__instance;
if (!graphicToInt.TryGetValue(multi, out var id))
Expand Down

0 comments on commit 519b93b

Please sign in to comment.