From 0de9346eac88c80c5ecd794d0453496cd8ddbbe4 Mon Sep 17 00:00:00 2001 From: c0ffee Date: Fri, 19 Apr 2024 21:38:04 -0700 Subject: [PATCH] fixes for addon rotations more robust pawnrendertree animating node selection --- 1.5/Assemblies/Rimworld-Animations.dll | Bin 26112 -> 26112 bytes 1.5/Defs/AnimationDefs/TestAnimation2.xml | 28 +- 1.5/Defs/XMLFile1.xml | 11 + .../HarmonyPatch_PawnRenderNode.cs | 2 +- .../HarmonyPatch_PawnRenderTree.cs | 35 +- .../Patch_HumanoidAlienRaces.csproj | 4 +- .../Source/HarmonyPatch_AlienRace.cs | 354 ------------------ Rimworld-Animations.csproj | 2 +- 8 files changed, 47 insertions(+), 389 deletions(-) create mode 100644 1.5/Defs/XMLFile1.xml delete mode 100644 Patch_HumanoidAlienRaces/Source/HarmonyPatch_AlienRace.cs diff --git a/1.5/Assemblies/Rimworld-Animations.dll b/1.5/Assemblies/Rimworld-Animations.dll index 45220c0e413d717e25afdc4851f4e20e45b8b684..bc82647e246bba8f5bc4adb07f5f363425e94ecf 100644 GIT binary patch delta 7636 zcmaJ`3wTu3wO)IlGv~~ld7pU%NCE*881kSYfRF@KhzNlyAcTjCHXC0_ zLaoF@DJWjcLj~&#LVLCJA&OC|{cNh&ODwh`c)y~e^;*>Q3cdecGl{`|_YRr=tbeVw z*Is+=ea_xzNWU)9uZvABdZJ|KBdtFy5W`#d&J7%EBAQP4q={bDS_ejaKPB>kzW_sl zGfb2Zf}FI8^82f-pn z*r;yd^7aZ4G0`1XfG9WDjwI4C3lX=R(X<6^Bc6D~@-(f2XePo)+36p-$l3~eW!SoE z%~t2e$RM%J*%0YhbR{B`#Fq`0v}9*V-m+=xnl4AY(hD)LCdWA(8EvRiBp-7A`Hff; zEfm|GdC@P#zd6%m*NaD-1F?zKJK#sgvgcj2BsBstqJvb{fb>Plob4lJQ~91}bG{SL z7dxD3@v((Dzfu!^!~ezar|kEuc>eI5-#?V!=x_UF^BCoZZ47LQosKK7MC@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Hx=GkAy`f~a9ipe+YAGqlWbNobXFJ@@o0=gW&0CU&s6!*=O*%kHRMjikOw{RPn%D^v=ciGd7S zzR}H4@^?PcAVLTwACxBg-y>v3P#{nCW`?9xEHg(6cbK@7?vRSuk{%UbhPu2#djb9> zk+$I+nw^&rVZ_0p`*~#($L>>RlV%CO;X*QxrpDW?$X=*@(V)~tkPE`O2!AM9fj`6I zI_W@Ps>KkaTp(37qU|Q?($XzGIfn2Do#whZ*}cM^jDrggAxs!a%iT~!F^eh(=c~Gr zRV^o?p*bSd@+0Oklsss+toL(GPN0^c_~Q{DcBP#%Pz4zKn&fC`bHuq~PD|{V@JrL@ z;To#RbSugE$D9K1=N!Vrkm2NA98Y*jLy&`ZLojr$hdAKDlq6BZVCX{Jz!=C8xbX!= zZCURkDPfcN%@OXOqcEr|X3j-I1nri#RFgJkPI^w6@jnTej|_NxgI^%kDzF!H4Vt^# ubY8k5Xzxw`k1XG TestAnimation2 - 50 + 120 False False @@ -20,20 +20,20 @@
  • (0, -1, 0) - 20 - 0 + 30 + 15 North
  • (-1, -1, 0) - 30 + 60 0 North
  • (0, -1, 0) - 40 - 0 + 90 + -15 North
  • @@ -50,19 +50,19 @@ North
  • - 6 - 0 - North + 15 + 30 + East
  • - 12 + 30 0 - North + South
  • - 18 - 0 - North + 45 + -30 + West
  • diff --git a/1.5/Defs/XMLFile1.xml b/1.5/Defs/XMLFile1.xml new file mode 100644 index 0000000..2ddecfa --- /dev/null +++ b/1.5/Defs/XMLFile1.xml @@ -0,0 +1,11 @@ + + + + Root + + Hand + PawnRenderNode + P + + + diff --git a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs index cf45a65..1e423a7 100644 --- a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs +++ b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs @@ -9,7 +9,7 @@ using Verse; namespace Rimworld_Animations { - //Head Rotation Code + //Head Rotation Code - Textures [HarmonyPatch(typeof(PawnRenderNode), "AppendRequests")] public static class HarmonyPatch_PawnRenderNode { diff --git a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderTree.cs b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderTree.cs index b932135..6dc336f 100644 --- a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderTree.cs +++ b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderTree.cs @@ -9,32 +9,35 @@ using Verse; namespace Rimworld_Animations { + [HarmonyPatch(typeof(PawnRenderTree), "TryGetMatrix")] public class HarmonyPatch_PawnRenderTree { - public static void Prefix(PawnRenderTree __instance, PawnRenderNode node, ref PawnDrawParms parms) + public static void Prefix(PawnRenderTree __instance, Dictionary ___nodesByTag, PawnRenderNode node, ref PawnDrawParms parms) { - //Note: Maybe need to change this to check all ancestors if it's the head node - //in case of deeper nodes in the PawnRenderTree - //This code only checks for node and parent, if either are head - - // Change facing for all head and apparelhead nodes - // So that the offset is based on body rotation, not head rotation - - //fixes misaligned hairs and headaddons - if ((node.Props.tagDef == PawnRenderNodeTagDefOf.Head || node.Props.tagDef == PawnRenderNodeTagDefOf.ApparelHead - || node?.parent?.Props?.tagDef == PawnRenderNodeTagDefOf.Head || node?.parent?.Props?.tagDef == PawnRenderNodeTagDefOf.ApparelHead) - && node.tree.rootNode.AnimationWorker is AnimationWorker_KeyframesExtended rootNodeAnimationWorker) + //find lowest parent that is animating, or nothing if not animating + PawnRenderNode animatingNode = node; + while (animatingNode != null + && !(animatingNode.AnimationWorker is AnimationWorker_KeyframesExtended)) { - - // this is only for the Vector3 position to work right - parms.facing = rootNodeAnimationWorker.facingAtTick(node.tree.AnimationTick); + animatingNode = animatingNode.parent; + } + + //if animating parent node found, + if (animatingNode?.AnimationWorker is AnimationWorker_KeyframesExtended animatingNodeAnimationWorker) + { + //change parm to facing to animate correctly + parms.facing = animatingNodeAnimationWorker.facingAtTick(__instance.AnimationTick); } } + } + + //recaching + //done here because changing parms causes recaching anyway, so might as well do it here [HarmonyPatch(typeof(PawnRenderTree), "AdjustParms")] public class HarmonyPatch_PawnRenderTree2 { @@ -57,7 +60,7 @@ namespace Rimworld_Animations { if (node.AnimationWorker is AnimationWorker_KeyframesExtended animWorkerExtended) { - //recache during facing turn + //recache during flicker on/off if (animWorkerExtended.shouldRecache(animationTick)) { node.requestRecache = true; diff --git a/Patch_HumanoidAlienRaces/Patch_HumanoidAlienRaces.csproj b/Patch_HumanoidAlienRaces/Patch_HumanoidAlienRaces.csproj index 797d0a4..4661863 100644 --- a/Patch_HumanoidAlienRaces/Patch_HumanoidAlienRaces.csproj +++ b/Patch_HumanoidAlienRaces/Patch_HumanoidAlienRaces.csproj @@ -37,8 +37,7 @@ False - ..\..\..\..\..\workshop\content\294100\839005762\1.4\Assemblies\AlienRace.dll - False + ..\..\..\..\..\workshop\content\294100\839005762\1.5\Assemblies\AlienRace.dll ..\..\..\RimWorldWin64_Data\Managed\Assembly-CSharp.dll @@ -72,6 +71,5 @@ - \ No newline at end of file diff --git a/Patch_HumanoidAlienRaces/Source/HarmonyPatch_AlienRace.cs b/Patch_HumanoidAlienRaces/Source/HarmonyPatch_AlienRace.cs deleted file mode 100644 index f06e987..0000000 --- a/Patch_HumanoidAlienRaces/Source/HarmonyPatch_AlienRace.cs +++ /dev/null @@ -1,354 +0,0 @@ -using HarmonyLib; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Reflection.Emit; -using System.Text; -using System.Threading.Tasks; -using UnityEngine; -using Verse; -using AlienRace; - -namespace Rimworld_Animations { - - - [StaticConstructorOnStartup] - public static class HarmonyPatch_AlienRace - { - static HarmonyPatch_AlienRace() - { - (new Harmony("rjwanim")).Patch(AccessTools.Method(AccessTools.TypeByName("AlienRace.HarmonyPatches"), "DrawAddons"), - prefix: new HarmonyMethod(AccessTools.Method(typeof(HarmonyPatch_AlienRace), "Prefix_AnimateHeadAddons"))); - } - - /* todo: replace jank prefix with this - public static void Prefix_DrawAddonsFinalHook(ref Pawn pawn, ref AlienPartGenerator.BodyAddon addon, ref Rot4 rot, ref Graphic graphic, ref Vector3 offsetVector, ref float angle, ref Material mat) - { - CompBodyAnimator animator = pawn.TryGetComp(); - - if (animator == null || !animator.isAnimating) - { - return; - } - - if(addon.alignWithHead || addon.drawnInBed) - { - rot = animator.headFacing; - angle = animator.headAngle; - offsetVector += animator.deltaPos + animator.bodyAngle * animator.headBob; - - } - else - { - rot = animator.bodyFacing; - angle = animator.bodyAngle; - offsetVector += animator.deltaPos; - } - - } - */ - public static bool Prefix_AnimateHeadAddons(PawnRenderFlags renderFlags, Vector3 vector, Vector3 headOffset, Pawn pawn, Quaternion quat, Rot4 rotation) - { - - if (renderFlags.FlagSet(PawnRenderFlags.Portrait) || !CompBodyAnimator.IsAnimating(pawn)) return true; - if (!(pawn.def is ThingDef_AlienRace alienProps) || renderFlags.FlagSet(PawnRenderFlags.Invisible)) return false; - - List addons = alienProps.alienRace.generalSettings.alienPartGenerator.bodyAddons; - AlienPartGenerator.AlienComp comp = pawn.GetComp(); - CompBodyAnimator pawnAnimator = pawn.TryGetComp(); - - bool flag = renderFlags.FlagSet(PawnRenderFlags.Portrait); - bool flag2 = renderFlags.FlagSet(PawnRenderFlags.Invisible); - - for (int i = 0; i < addons.Count; i++) - { - AlienPartGenerator.BodyAddon ba = addons[index: i]; - - if (!ba.CanDrawAddon(pawn: pawn)) continue; - - bool forceDrawForBody = false; - if (alienProps.defName.Contains("Orassan") && ba.path.ToLower().Contains("tail")) - { - forceDrawForBody = true; - } - AlienPartGenerator.RotationOffset offset = ba.defaultOffsets.GetOffset((ba.drawnInBed && !forceDrawForBody) || ba.alignWithHead ? pawnAnimator.headFacing : pawnAnimator.bodyFacing); - Vector3 a = (offset != null) ? offset.GetOffset(renderFlags.FlagSet(PawnRenderFlags.Portrait), pawn.story.bodyType, pawn.story.headType) : Vector3.zero; - AlienPartGenerator.RotationOffset offset2 = ba.offsets.GetOffset((ba.drawnInBed && !forceDrawForBody) || ba.alignWithHead ? pawnAnimator.headFacing : pawnAnimator.bodyFacing); - Vector3 vector2 = a + ((offset2 != null) ? offset2.GetOffset(renderFlags.FlagSet(PawnRenderFlags.Portrait), pawn.story.bodyType, pawn.story.headType) : Vector3.zero); - vector2.y = (ba.inFrontOfBody ? (0.3f + vector2.y) : (-0.3f - vector2.y)); - float num = ba.angle; - if (((ba.drawnInBed && !forceDrawForBody) || ba.alignWithHead ? pawnAnimator.headFacing : pawnAnimator.bodyFacing) == Rot4.North) - { - if (ba.layerInvert) - { - vector2.y = 0f - vector2.y; - } - num = 0f; - } - if (((ba.drawnInBed && !forceDrawForBody) || ba.alignWithHead ? pawnAnimator.headFacing : pawnAnimator.bodyFacing) == Rot4.East) - { - num = 0f - num; - vector2.x = 0f - vector2.x; - } - Graphic addonGraphic = comp.addonGraphics[i]; - - addonGraphic.drawSize = ((flag && ba.drawSizePortrait != Vector2.zero) ? ba.drawSizePortrait : ba.drawSize) * (ba.scaleWithPawnDrawsize ? (ba.alignWithHead ? ((flag ? comp.customPortraitHeadDrawSize : comp.customHeadDrawSize) * (ModsConfig.BiotechActive ? (pawn.ageTracker.CurLifeStage.headSizeFactor ?? 1.5f) : 1.5f)) : ((flag ? comp.customPortraitDrawSize : comp.customDrawSize) * (ModsConfig.BiotechActive ? pawn.ageTracker.CurLifeStage.bodySizeFactor : 1f) * 1.5f)) : (Vector2.one * 1.5f)); - - if ((ba.drawnInBed && !forceDrawForBody) || ba.alignWithHead) - { - - Quaternion addonRotation = Quaternion.AngleAxis(pawnAnimator.headAngle < 0 ? 360 - (360 % pawnAnimator.headAngle) : pawnAnimator.headAngle, Vector3.up); - - GenDraw.DrawMeshNowOrLater(mesh: addonGraphic.MeshAt(rot: pawnAnimator.headFacing), loc: vector + (ba.alignWithHead ? headOffset : headOffset - addonRotation * pawn.Drawer.renderer.BaseHeadOffsetAt(pawnAnimator.headFacing)) + vector2.RotatedBy(angle: Mathf.Acos(f: Quaternion.Dot(a: Quaternion.identity, b: addonRotation)) * 2f * 57.29578f), - quat: Quaternion.AngleAxis(angle: num, axis: Vector3.up) * addonRotation, mat: addonGraphic.MatAt(rot: pawnAnimator.headFacing), renderFlags.FlagSet(PawnRenderFlags.DrawNow)); - - - } - - else - { - Quaternion addonRotation; - if (AnimationSettings.controlGenitalRotation && ba.path.ToLower().Contains("penis")) - { - addonRotation = Quaternion.AngleAxis(pawnAnimator.genitalAngle, Vector3.up); - } - else - { - addonRotation = Quaternion.AngleAxis(pawnAnimator.bodyAngle, Vector3.up); - } - - if (AnimationSettings.controlGenitalRotation && pawnAnimator.controlGenitalAngle && ba?.hediffGraphics != null && ba.hediffGraphics.Count != 0 && ba.hediffGraphics[0]?.path != null && (ba.hediffGraphics[0].path.Contains("Penis") || ba.hediffGraphics[0].path.Contains("penis"))) - { - GenDraw.DrawMeshNowOrLater(mesh: addonGraphic.MeshAt(rot: rotation), loc: vector + (ba.alignWithHead ? headOffset : Vector3.zero) + vector2.RotatedBy(angle: Mathf.Acos(f: Quaternion.Dot(a: Quaternion.identity, b: addonRotation)) * 2f * 57.29578f), - quat: Quaternion.AngleAxis(angle: pawnAnimator.genitalAngle, axis: Vector3.up), mat: addonGraphic.MatAt(rot: rotation), renderFlags.FlagSet(PawnRenderFlags.DrawNow)); - } - - else - { - GenDraw.DrawMeshNowOrLater(mesh: addonGraphic.MeshAt(rot: rotation), loc: vector + (ba.alignWithHead ? headOffset : Vector3.zero) + vector2.RotatedBy(angle: Mathf.Acos(f: Quaternion.Dot(a: Quaternion.identity, b: addonRotation)) * 2f * 57.29578f), - quat: Quaternion.AngleAxis(angle: num, axis: Vector3.up) * addonRotation, mat: addonGraphic.MatAt(rot: rotation), renderFlags.FlagSet(PawnRenderFlags.DrawNow)); - } - - } - - - } - - return false; - } - } - - - - /* - - [HarmonyPatch(typeof(AlienRace.HarmonyPatches), "DrawAddons")] - public static class HarmonyPatch_AlienRace { - - public static void RenderHeadAddonInAnimation(Mesh mesh, Vector3 loc, Quaternion quat, Material mat, bool drawNow, Graphic graphic, AlienPartGenerator.BodyAddon bodyAddon, Vector3 v, Vector3 headOffset, Pawn pawn, PawnRenderFlags renderFlags, Vector3 vector, Rot4 rotation) - { - - CompBodyAnimator pawnAnimator = pawn.TryGetComp(); - AlienPartGenerator.AlienComp comp = pawn.GetComp(); - - if (pawnAnimator != null && pawnAnimator.isAnimating) - { - - if((bodyAddon.drawnInBed || bodyAddon.alignWithHead)) - { - - AlienPartGenerator.RotationOffset offset = bodyAddon.defaultOffsets.GetOffset(rotation); - Vector3 a = (offset != null) ? offset.GetOffset(renderFlags.FlagSet(PawnRenderFlags.Portrait), pawn.story.bodyType, comp.crownType) : Vector3.zero; - AlienPartGenerator.RotationOffset offset2 = bodyAddon.offsets.GetOffset(rotation); - Vector3 vector2 = a + ((offset2 != null) ? offset2.GetOffset(renderFlags.FlagSet(PawnRenderFlags.Portrait), pawn.story.bodyType, comp.crownType) : Vector3.zero); - vector2.y = (bodyAddon.inFrontOfBody ? (0.3f + vector2.y) : (-0.3f - vector2.y)); - float num = bodyAddon.angle; - if (rotation == Rot4.North) - { - if (bodyAddon.layerInvert) - { - vector2.y = -vector2.y; - } - num = 0f; - } - if (rotation == Rot4.East) - { - num = -num; - vector2.x = -vector2.x; - } - - vector = vector + Quaternion.AngleAxis(pawnAnimator.bodyAngle, Vector3.up) * pawn.Drawer.renderer.BaseHeadOffsetAt(pawnAnimator.bodyFacing) - pawnAnimator.getPawnHeadOffset(); //convert vector into pseudo body pos for head - quat = Quaternion.AngleAxis(pawnAnimator.headAngle, Vector3.up); - loc = vector + (bodyAddon.alignWithHead ? headOffset : Vector3.zero) + vector2.RotatedBy(Mathf.Acos(Quaternion.Dot(Quaternion.identity, quat)) * 2f * 57.29578f); - mat = graphic.MatAt(rot: pawnAnimator.headFacing); - } - else - { - - AlienPartGenerator.RotationOffset offset = bodyAddon.defaultOffsets.GetOffset(rotation); - Vector3 a = (offset != null) ? offset.GetOffset(renderFlags.FlagSet(PawnRenderFlags.Portrait), pawn.story.bodyType, comp.crownType) : Vector3.zero; - AlienPartGenerator.RotationOffset offset2 = bodyAddon.offsets.GetOffset(rotation); - Vector3 vector2 = a + ((offset2 != null) ? offset2.GetOffset(renderFlags.FlagSet(PawnRenderFlags.Portrait), pawn.story.bodyType, comp.crownType) : Vector3.zero); - vector2.y = (bodyAddon.inFrontOfBody ? (0.3f + vector2.y) : (-0.3f - vector2.y)); - float num = bodyAddon.angle; - if (rotation == Rot4.North) - { - if (bodyAddon.layerInvert) - { - vector2.y = -vector2.y; - } - num = 0f; - } - if (rotation == Rot4.East) - { - num = -num; - vector2.x = -vector2.x; - } - quat = Quaternion.AngleAxis(pawnAnimator.bodyAngle, Vector3.up); - loc = vector + (bodyAddon.alignWithHead ? headOffset : Vector3.zero) + vector2.RotatedBy(Mathf.Acos(Quaternion.Dot(Quaternion.identity, quat)) * 2f * 57.29578f); - - } - - } - GenDraw.DrawMeshNowOrLater(mesh, loc, quat, mat, drawNow); - - /* - if (pawnAnimator != null && !renderFlags.FlagSet(PawnRenderFlags.Portrait) && pawnAnimator.isAnimating && (bodyAddon.drawnInBed || bodyAddon.alignWithHead)) - { - - - if ((pawn.def as ThingDef_AlienRace).defName == "Alien_Orassan") - { - orassan = true; - - if(bodyAddon.path.Contains("closed")) - { - return; - } - - if (bodyAddon.bodyPart.Contains("ear")) - - { - orassan = true; - - orassanv = new Vector3(0, 0, 0.23f); - if (pawnAnimator.headFacing == Rot4.North) - { - orassanv.z -= 0.1f; - orassanv.y += 1f; - - if(bodyAddon.bodyPart.Contains("left")) - { - orassanv.x += 0.03f; - } else - { - orassanv.x -= 0.03f; - } - - } - else if (pawnAnimator.headFacing == Rot4.East) - { - orassanv.x -= 0.1f; - } - else if (pawnAnimator.headFacing == Rot4.West) - { - orassanv.x = 0.1f; - } - else - { - orassanv.z -= 0.1f; - orassanv.y += 1f; - - if (bodyAddon.bodyPart.Contains("right")) - { - orassanv.x += 0.05f; - } - else - { - orassanv.x -= 0.05f; - } - } - orassanv = orassanv.RotatedBy(pawnAnimator.headAngle); - } - } - - - - - - GenDraw.DrawMeshNowOrLater(mesh: graphic.MeshAt(rot: headRotInAnimation), loc: loc + orassanv + (bodyAddon.alignWithHead ? headOffset : Vector3.zero),// + v.RotatedBy(Mathf.Acos(Quaternion.Dot(Quaternion.identity, quat)) * 2f * 57.29578f), - quat: Quaternion.AngleAxis(angle: num, axis: Vector3.up) * headQuatInAnimation, mat: graphic.MatAt(rot: pawnAnimator.headFacing), drawNow: drawNow);; - } - - else - { - - } - - - } - - - public static IEnumerable Transpiler(IEnumerable instructions) - { - List ins = instructions.ToList(); - for (int i = 0; i < ins.Count; i++) - { - - Type[] type = new Type[] { typeof(Mesh), typeof(Vector3), typeof(Quaternion), typeof(Material), typeof(bool) }; - - - if (ins[i].OperandIs(AccessTools.Method(typeof(GenDraw), "DrawMeshNowOrLater", type))) - { - - yield return new CodeInstruction(OpCodes.Ldloc, (object)7); //graphic - yield return new CodeInstruction(OpCodes.Ldloc, (object)4); //bodyAddon - yield return new CodeInstruction(OpCodes.Ldloc, (object)5); //offsetVector/AddonOffset (v) - yield return new CodeInstruction(OpCodes.Ldarg, (object)2); //headOffset - yield return new CodeInstruction(OpCodes.Ldarg, (object)3); //pawn - yield return new CodeInstruction(OpCodes.Ldarg, (object)0); //renderflags - yield return new CodeInstruction(OpCodes.Ldarg, (object)1); //vector - yield return new CodeInstruction(OpCodes.Ldarg, (object)5); //rotation - - yield return new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(HarmonyPatch_AlienRace), "RenderHeadAddonInAnimation")); - - } - - else - { - yield return ins[i]; - } - } - } - - public static bool Prefix(PawnRenderFlags renderFlags, ref Vector3 vector, ref Vector3 headOffset, Pawn pawn, ref Quaternion quat, ref Rot4 rotation) - { - if(pawn == null) - { - return true; - } - - CompBodyAnimator anim = pawn.TryGetComp(); - - if(anim == null) - { - return true; - } - - if (anim != null && !renderFlags.FlagSet(PawnRenderFlags.Portrait) && anim.isAnimating) - { - //quat = Quaternion.AngleAxis(anim.bodyAngle, Vector3.up); - } - - return true; - - } - } - - - */ - -} - - diff --git a/Rimworld-Animations.csproj b/Rimworld-Animations.csproj index 2317000..b6b9d15 100644 --- a/Rimworld-Animations.csproj +++ b/Rimworld-Animations.csproj @@ -119,6 +119,7 @@ + @@ -166,7 +167,6 @@ -