Garry's Mod

Garry's Mod

Not enough ratings
VManip动作原理(How VManip animation work)?
By 白狼
How VManip animation work?
   
Award
Favorite
Favorited
Unfavorite
Legs Animation
if LegParent then LegParent:Remove() end
if LegModel then LegModel:Remove() end
LegParent = ClientsideModel( "models/c_vmaniplegs.mdl", RENDERGROUP_BOTH )
LegModel = ClientsideModel(IsValid(LocalPlayer()) and LocalPlayer():GetModel() or "models/player/Group01/male_07.mdl", RENDERGROUP_TRANSLUCENT )



LegModel:SetParent(LegParent)
LegModel:AddEffects(EF_BONEMERGE)

for i = 0,LegModel:GetNumBodyGroups() do
local bodyg = LocalPlayer():GetBodygroup(i)
LegModel:SetBodygroup(i, bodyg)
end
local playermodelbonesupper={"ValveBiped.Bip01_L_Forearm",
"ValveBiped.Bip01_L_UpperArm",
"ValveBiped.Bip01_L_Clavicle",
"ValveBiped.Bip01_L_Hand",
"ValveBiped.Bip01_Spine4",
"ValveBiped.Bip01_Neck1",
"ValveBiped.Bip01_Head1",
"ValveBiped.Bip01_L_Finger4",
"ValveBiped.Bip01_L_Finger41",
"ValveBiped.Bip01_L_Finger42",
"ValveBiped.Bip01_L_Finger3",
"ValveBiped.Bip01_L_Finger31",
"ValveBiped.Bip01_L_Finger32",
"ValveBiped.Bip01_L_Finger2",
"ValveBiped.Bip01_L_Finger21",
"ValveBiped.Bip01_L_Finger22",
"ValveBiped.Bip01_L_Finger1",
"ValveBiped.Bip01_L_Finger11",
"ValveBiped.Bip01_L_Finger12",
"ValveBiped.Bip01_L_Finger0",
"ValveBiped.Bip01_L_Finger01",
"ValveBiped.Bip01_L_Finger02",
"ValveBiped.Bip01_R_Forearm",
"ValveBiped.Bip01_R_UpperArm",
"ValveBiped.Bip01_R_Clavicle",
"ValveBiped.Bip01_R_Hand",
"ValveBiped.Bip01_R_Finger4",
"ValveBiped.Bip01_R_Finger41",
"ValveBiped.Bip01_R_Finger42",
"ValveBiped.Bip01_R_Finger3",
"ValveBiped.Bip01_R_Finger31",
"ValveBiped.Bip01_R_Finger32",
"ValveBiped.Bip01_R_Finger2",
"ValveBiped.Bip01_R_Finger21",
"ValveBiped.Bip01_R_Finger22",
"ValveBiped.Bip01_R_Finger1",
"ValveBiped.Bip01_R_Finger11",
"ValveBiped.Bip01_R_Finger12",
"ValveBiped.Bip01_R_Finger0",
"ValveBiped.Bip01_R_Finger01"}
for k,v in pairs(playermodelbonesupper) do
local plybone = LegModel:LookupBone(v)
if plybone!=nil then
LegModel:ManipulateBoneScale( plybone, Vector(0,0,0) )
end
end


SeqID = LegParent:LookupSequence('test')
LegParent:ResetSequenceInfo()
LegParent:ResetSequence(SeqID)
T = 0
Time = CurTime()

hook.Add("PostDrawTranslucentRenderables", "aaaaa", function()
if !IsValid(LegParent) then return end
if Time == CurTime() then return end
Time = CurTime()
T = T + FrameTime()*1
if T > 1 then T = 0 end
LegParent:SetCycle(T)
end)


LegParent:SetPos(LocalPlayer():GetViewModel():GetPos())
LegParent:SetParent(LocalPlayer():GetViewModel())

hook.Add("PostDrawTranslucentRenderables", "aaaaa", function()
if !IsValid(LegParent) then return end
if Time == CurTime() then return end
local ang = LocalPlayer():EyeAngles()
ang.p = 0
LegParent:SetAngles(ang)
Time = CurTime()
T = T + FrameTime()*1
if T > 1 then T = 0 end
LegParent:SetCycle(T)
end)



Hand Animation
if HandSkeleton then HandSkeleton:Remove() end
HandSkeleton = ClientsideModel( "models/weapons/c_exedrop.mdl", RENDERGROUP_BOTH )
SeqID = HandSkeleton:LookupSequence("exedrop")
HandSkeleton:ResetSequenceInfo()
HandSkeleton:ResetSequence(SeqID)
T = 0
time = CurTime()
local leftarmbones={"ValveBiped.Bip01_L_UpperArm",
"ValveBiped.Bip01_L_Forearm",
"ValveBiped.Bip01_L_Hand",
"ValveBiped.Bip01_L_Wrist",
"ValveBiped.Bip01_L_Ulna",
"ValveBiped.Bip01_L_Finger4",
"ValveBiped.Bip01_L_Finger41",
"ValveBiped.Bip01_L_Finger42",
"ValveBiped.Bip01_L_Finger3",
"ValveBiped.Bip01_L_Finger31",
"ValveBiped.Bip01_L_Finger32",
"ValveBiped.Bip01_L_Finger2",
"ValveBiped.Bip01_L_Finger21",
"ValveBiped.Bip01_L_Finger22",
"ValveBiped.Bip01_L_Finger1",
"ValveBiped.Bip01_L_Finger11",
"ValveBiped.Bip01_L_Finger12",
"ValveBiped.Bip01_L_Finger0",
"ValveBiped.Bip01_L_Finger01",
"ValveBiped.Bip01_L_Finger02"}
hook.Add("PostDrawViewModel", "aaaaaaaaaaaaaa", function(vm,ply,weapon)
if CurTime() == time then return end
T = T + FrameTime()*1
time = CurTime()
HandSkeleton:SetCycle(T)
if T > 1 then T = 0 end
end)


HandSkeleton:SetNoDraw(true)
hook.Add("PostDrawViewModel", "aaaaaaaaaaaaaa", function(vm,ply,weapon)
if CurTime() == time then return end
T = T + FrameTime()*1
time = CurTime()
HandSkeleton:SetCycle(T)
if T > 1 then T = 0 end
HandSkeleton:SetupBones()
HandSkeleton:DrawModel()
local temp,Mat
for i,b in pairs(leftarmbones) do
if i==5 then
Mat = HandSkeleton:GetBoneMatrix(HandSkeleton:LookupBone(leftarmbones[2]) or -1)
else
Mat = HandSkeleton:GetBoneMatrix(HandSkeleton:LookupBone(b) or -1)
end
temp = vm:LookupBone(b)
if temp and Mat then vm:SetBoneMatrix(temp,Mat) end
end
end)


HandSkeleton:SetPos(LocalPlayer():GetViewModel():GetPos())
HandSkeleton:SetAngles(LocalPlayer():GetViewModel():GetAngles())
HandSkeleton:SetParent(LocalPlayer():GetViewModel())



Hand animation interpolation improve

lerp = 0
local leftarmbones={}
leftarmbones[1] = {"ValveBiped.Bip01_L_UpperArm",nil}
leftarmbones[2] = {"ValveBiped.Bip01_L_Forearm",1}
leftarmbones[3] = {"ValveBiped.Bip01_L_Hand",2}
leftarmbones[4] = {"ValveBiped.Bip01_L_Wrist",2}
leftarmbones[5] = {"ValveBiped.Bip01_L_Ulna",2}
leftarmbones[6] = {"ValveBiped.Bip01_L_Finger4",3}
leftarmbones[7] = {"ValveBiped.Bip01_L_Finger41",6}
leftarmbones[8] = {"ValveBiped.Bip01_L_Finger42",7}
leftarmbones[9] = {"ValveBiped.Bip01_L_Finger3",3}
leftarmbones[10] = {"ValveBiped.Bip01_L_Finger31",9}
leftarmbones[11] = {"ValveBiped.Bip01_L_Finger32",10}
leftarmbones[12] = {"ValveBiped.Bip01_L_Finger2",3}
leftarmbones[13] = {"ValveBiped.Bip01_L_Finger21",12}
leftarmbones[14] = {"ValveBiped.Bip01_L_Finger22",13}
leftarmbones[15] = {"ValveBiped.Bip01_L_Finger1",3}
leftarmbones[16] = {"ValveBiped.Bip01_L_Finger11",15}
leftarmbones[17] = {"ValveBiped.Bip01_L_Finger12",16}
leftarmbones[18] = {"ValveBiped.Bip01_L_Finger0",3}
leftarmbones[19] = {"ValveBiped.Bip01_L_Finger01",18}
leftarmbones[20] = {"ValveBiped.Bip01_L_Finger02",19}
hook.Add("PostDrawViewModel", "aaaaaaaaaaaaaa", function(vm,ply,weapon)
if !IsValid(HandSkeleton) then return end
if CurTime() == time then return end
T = T + FrameTime()*2
time = CurTime()
HandSkeleton:SetCycle(T)
if T > 1 then lerp,T = 0,0 end
HandSkeleton:SetupBones()
HandSkeleton:DrawModel()
if T > 0 and T<0.8 then lerp = lerp+10*FrameTime() else lerp= lerp-10*FrameTime() end
lerp = math.Clamp(lerp, 0, 1)
local BoneMatrixNow,BoneMatrixStart,temp,MatAnim,MatPAnim = {},{}
for i,b in pairs(leftarmbones) do
temp = vm:LookupBone(b[1])
if temp then BoneMatrixStart = vm:GetBoneMatrix(temp) end
end
for i,b in pairs(leftarmbones) do
temp = HandSkeleton:LookupBone(b[1])
if temp then
MatAnim = HandSkeleton:GetBoneMatrix(temp)
temp = HandSkeleton:GetBoneParent(temp)
if temp then MatPAnim = HandSkeleton:GetBoneMatrix(temp) end
elseif i==5 then
MatAnim = BoneMatrixStart[5]
MatPAnim = BoneMatrixStart[b[2]]
end
temp = vm:LookupBone(b[1])
if temp then BoneMatrixNow = vm:GetBoneMatrix(temp) end
if MatAnim and BoneMatrixStart then
if MatPAnim and BoneMatrixStart[b[2]] then
MatAnim = MatPAnim:GetInverse()*MatAnim
BoneMatrixNow = BoneMatrixStart[b[2]]:GetInverse()*BoneMatrixStart
BoneMatrixNow:SetAngles(LerpAngle(lerp, BoneMatrixNow:GetAngles(), MatAnim:GetAngles()))
BoneMatrixNow:SetTranslation(LerpVector(lerp,BoneMatrixNow:GetTranslation(), MatAnim:GetTranslation()))
BoneMatrixNow = BoneMatrixNow[b[2]]*BoneMatrixNow
else
BoneMatrixNow:SetAngles(LerpAngle(lerp,BoneMatrixNow:GetAngles(), MatAnim:GetAngles()))
BoneMatrixNow:SetTranslation(LerpVector(lerp,BoneMatrixNow:GetTranslation(), MatAnim:GetTranslation()))
end
vm:SetBoneMatrix(temp,BoneMatrixNow)
end
MatAnim,MatPAnim = nil
end
end)
Transform between Different Camera Pos

hook.Add("PostDrawViewModel", "aaaaaaaaaaaaaa", function(vm,ply,weapon)
if CurTime() == time then return end
T = T + FrameTime()*1
time = CurTime()
HandSkeleton:SetCycle(T)
if T > 1 then T = 0 end
HandSkeleton:SetupBones()
HandSkeleton:DrawModel()
local temp,Mat
for i,b in pairs(leftarmbones) do
if i==5 then
Mat = HandSkeleton:GetBoneMatrix(HandSkeleton:LookupBone(leftarmbones[2]) or -1)
else
Mat = HandSkeleton:GetBoneMatrix(HandSkeleton:LookupBone(b) or -1)
end
temp = vm:LookupBone(b)
if temp and Mat then vm:SetBoneMatrix(temp,Mat) end
end
local t2 = math.tan(((weapon.ViewModelFOV or 54)+ply:GetFOV()-GetConVar('fov_desired'):GetFloat())*0.01745*0.5)
local t1 = math.tan(ply:GetFOV()*0.01745*0.5)
local of = ((Vector() - EyePos()):Dot(EyeAngles():Forward())*(t1/t2-1))*ply:EyeAngles():Forward()
HandSkeleton:SetPos(Vector() + of)
end)