soberfish

r15 mirror

Mar 24th, 2020 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. -- Table containing the paired names of the body parts, NOT the names of the joints
  2. local bodyPartPairs = {
  3. {"Head"},
  4. {"UpperTorso"},
  5. {"LowerTorso"},
  6. {"LeftUpperArm", "RightUpperArm"},
  7. {"LeftLowerArm", "RightLowerArm"},
  8. {"LeftHand", "RightHand"},
  9. {"LeftUpperLeg", "RightUpperLeg"},
  10. {"LeftLowerLeg", "RightLowerLeg"},
  11. {"LeftFoot", "RightFoot"}
  12. }
  13.  
  14. -- Private
  15. function MirrorPoseCFrame(cf)
  16. local x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22 = cf:components()
  17. x = -x
  18. -- R00, R10, R20 (x)
  19. R10 = -R10
  20. R20 = -R20
  21. -- R01, R11, R21 (y)
  22. R01 = -R01
  23. -- R02, R12, R22 (z)
  24. R02 = -R02
  25.  
  26. return CFrame.new(x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22)
  27. end
  28.  
  29. function GetKeyframeSequenceLength(keyframeSequence)
  30. local keyframes = keyframeSequence:GetChildren()
  31. local max = keyframes[1].Time
  32. for i, v in pairs(keyframes) do
  33. if v.Time > max then
  34. max = v.Time
  35. end
  36. end
  37. return max
  38. end
  39.  
  40. function MirrorKeyframe(keyframe)
  41. for i, v in pairs(bodyPartPairs) do
  42. if #v == 1 then
  43. local pose = keyframe:FindFirstChild(v[1], true)
  44. if pose then
  45. pose.CFrame = MirrorPoseCFrame(pose.CFrame)
  46. end
  47. elseif #v == 2 then
  48. local leftName = v[1]
  49. local rightName = v[2]
  50. local leftPose = keyframe:FindFirstChild(leftName, true)
  51. local rightPose = keyframe:FindFirstChild(rightName, true)
  52. if leftPose and rightPose then
  53. leftPose.Name = rightName
  54. rightPose.Name = leftName
  55. leftPose.CFrame = MirrorPoseCFrame(leftPose.CFrame)
  56. rightPose.CFrame = MirrorPoseCFrame(rightPose.CFrame)
  57. elseif leftPose then
  58. leftPose.Name = rightName
  59. leftPose.CFrame = MirrorPoseCFrame(leftPose.CFrame)
  60. elseif rightPose then
  61. rightPose.Name = leftName
  62. rightPose.CFrame = MirrorPoseCFrame(rightPose.CFrame)
  63. end
  64. end
  65. end
  66. end
  67.  
  68. -- Public
  69. -- Precondition: ONLY Keyframes to be flipped are in the KeyframeSequence
  70. -- Postcondition: The Keyframes are flipped and appended to the end of the KeyframeSequence
  71. local MIRROR_GAP = 0.1667 -- how far apart the unmirrored and mirrored parts are
  72. function SymmetricKeyframeSequence(keyframeSequence)
  73. local length = GetKeyframeSequenceLength(keyframeSequence)
  74. for i, v in pairs(keyframeSequence:GetChildren()) do
  75. local keyframeClone = v:Clone()
  76. keyframeClone.Name = v.Name .. "_mirrored"
  77. keyframeClone.Time = length + keyframeClone.Time + MIRROR_GAP
  78. MirrorKeyframe(keyframeClone)
  79. keyframeClone.Parent = keyframeSequence
  80. end
  81. end
  82.  
  83. local dummy = game.Workspace.Player1
  84. local animSaves = dummy.AnimSaves
  85. local keyframeSequenceOrig = animSaves["mirrortest"]
  86. local keyframeSequenceClone = keyframeSequenceOrig:Clone()
  87. SymmetricKeyframeSequence(keyframeSequenceClone)
  88. keyframeSequenceClone.Name = keyframeSequenceOrig.Name .. "_symmetric"
  89. keyframeSequenceClone.Parent = animSaves
Add Comment
Please, Sign In to add comment