-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmocap_controller.lua
More file actions
89 lines (68 loc) · 1.8 KB
/
mocap_controller.lua
File metadata and controls
89 lines (68 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
local ENT = {}
ENT.Type = "anim"
function ENT:Initialize()
self:DrawShadow(false)
self:SetMoveType(MOVETYPE_NONE)
self:SetSolid(SOLID_NONE)
if SERVER then
self:SetStartTime(CurTime())
end
end
function ENT:OnRemove()
if SERVER then
local parent = self:GetParent()
if parent:IsValid() and parent:Alive() then
local rag = parent:GetRagdollEntity()
if IsValid(rag) then rag:Remove() end
end
end
end
function ENT:Think()
if SERVER then return end
local animdata = self:GetAnimationData()
if not animdata then return end
local parent = self:GetParent()
if not parent:IsValid() then return end
local rag = parent:GetRagdollEntity()
if not IsValid(rag) then return end
local delta = CurTime() - self:GetStartTime()
local frame = math.Clamp(delta, 1, animdata.NumFrames)
for iBoneID, tBoneInfo in pairs(animdata.FrameData) do
local tFrameData = tBoneInfo[frame]
if not tFrameData then continue end
if type(iBoneID) ~= "number" then
iBoneID = rag:LookupBone(iBoneID)
end
if not iBoneID then continue end
local iPhysID = rag:TranslateBoneToPhysBone(iBoneID)
if not iPhysID then continue end
local phys = rag:GetPhysicsObjectNum(iPhysID)
if IsValid(phys) then
phys:SetPos(parent:LocalToWorld(tFrameData[1]))
phys:SetAngles(parent:LocalToWorldAngles(tFrameData[2]))
end
end
self:NextThink(CurTime())
self:SetNextClientThink(CurTime())
return true
end
function ENT:SetStartTime(m)
self:SetDTFloat(0, m)
end
function ENT:GetStartTime()
return self:GetDTFloat(0)
end
function ENT:SetAnimationName(m)
self:SetDTString(0, m)
end
function ENT:GetAnimationName()
return self:GetDTString(0)
end
function ENT:GetAnimationData()
return GetMocapAnimations()[self:GetAnimationName()]
end
if CLIENT then
function ENT:Draw()
end
end
scripted_ents.Register(ENT, "mocap_controller")