Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Table containing the paired names of the body parts, NOT the names of the joints
- local bodyPartPairs = {
- {"Head"},
- {"UpperTorso"},
- {"LowerTorso"},
- {"LeftUpperArm", "RightUpperArm"},
- {"LeftLowerArm", "RightLowerArm"},
- {"LeftHand", "RightHand"},
- {"LeftUpperLeg", "RightUpperLeg"},
- {"LeftLowerLeg", "RightLowerLeg"},
- {"LeftFoot", "RightFoot"}
- }
- -- Private
- function MirrorPoseCFrame(cf)
- local x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22 = cf:components()
- x = -x
- -- R00, R10, R20 (x)
- R10 = -R10
- R20 = -R20
- -- R01, R11, R21 (y)
- R01 = -R01
- -- R02, R12, R22 (z)
- R02 = -R02
- return CFrame.new(x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22)
- end
- function GetKeyframeSequenceLength(keyframeSequence)
- local keyframes = keyframeSequence:GetChildren()
- local max = keyframes[1].Time
- for i, v in pairs(keyframes) do
- if v.Time > max then
- max = v.Time
- end
- end
- return max
- end
- function MirrorKeyframe(keyframe)
- for i, v in pairs(bodyPartPairs) do
- if #v == 1 then
- local pose = keyframe:FindFirstChild(v[1], true)
- if pose then
- pose.CFrame = MirrorPoseCFrame(pose.CFrame)
- end
- elseif #v == 2 then
- local leftName = v[1]
- local rightName = v[2]
- local leftPose = keyframe:FindFirstChild(leftName, true)
- local rightPose = keyframe:FindFirstChild(rightName, true)
- if leftPose and rightPose then
- leftPose.Name = rightName
- rightPose.Name = leftName
- leftPose.CFrame = MirrorPoseCFrame(leftPose.CFrame)
- rightPose.CFrame = MirrorPoseCFrame(rightPose.CFrame)
- elseif leftPose then
- leftPose.Name = rightName
- leftPose.CFrame = MirrorPoseCFrame(leftPose.CFrame)
- elseif rightPose then
- rightPose.Name = leftName
- rightPose.CFrame = MirrorPoseCFrame(rightPose.CFrame)
- end
- end
- end
- end
- -- Public
- -- Precondition: ONLY Keyframes to be flipped are in the KeyframeSequence
- -- Postcondition: The Keyframes are flipped and appended to the end of the KeyframeSequence
- local MIRROR_GAP = 0.1667 -- how far apart the unmirrored and mirrored parts are
- function SymmetricKeyframeSequence(keyframeSequence)
- local length = GetKeyframeSequenceLength(keyframeSequence)
- for i, v in pairs(keyframeSequence:GetChildren()) do
- local keyframeClone = v:Clone()
- keyframeClone.Name = v.Name .. "_mirrored"
- keyframeClone.Time = length + keyframeClone.Time + MIRROR_GAP
- MirrorKeyframe(keyframeClone)
- keyframeClone.Parent = keyframeSequence
- end
- end
- local dummy = game.Workspace.Player1
- local animSaves = dummy.AnimSaves
- local keyframeSequenceOrig = animSaves["mirrortest"]
- local keyframeSequenceClone = keyframeSequenceOrig:Clone()
- SymmetricKeyframeSequence(keyframeSequenceClone)
- keyframeSequenceClone.Name = keyframeSequenceOrig.Name .. "_symmetric"
- keyframeSequenceClone.Parent = animSaves
Add Comment
Please, Sign In to add comment