forked from AirFoxTwo/FS25_FieldsOfStories
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIAHumanCharacter.lua
More file actions
145 lines (132 loc) · 3.66 KB
/
Copy pathIAHumanCharacter.lua
File metadata and controls
145 lines (132 loc) · 3.66 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
--
-- FS25 Fields of Stories — HumanModel host: create with IAHumanCharacter.forHumanModel(model).
-- PlayerStyle index application: applyPlayerStyleParamTable (IAHelper.lua).
--
IAHumanCharacter = {}
local HumanModelHost = {}
HumanModelHost.__index = HumanModelHost
function HumanModelHost:_findFirstAnimCharSet(nodeId)
if nodeId == nil or nodeId == 0 then
return 0
end
local cs = getAnimCharacterSet(nodeId)
if cs ~= nil and cs ~= 0 then
return cs
end
for i = 0, getNumOfChildren(nodeId) - 1 do
cs = self:_findFirstAnimCharSet(getChildAt(nodeId, i))
if cs ~= nil and cs ~= 0 then
return cs
end
end
return 0
end
function HumanModelHost:_assignLoopingClip(charSet, clipName)
local ix = getAnimClipIndex(charSet, clipName)
if ix < 0 then
return false
end
assignAnimTrackClip(charSet, 0, ix)
setAnimTrackLoopState(charSet, 0, true)
enableAnimTrack(charSet, 0)
return true
end
function HumanModelHost:_startFirstMatchingIdle(charSet, clipNames)
for i = 1, #clipNames do
if self:_assignLoopingClip(charSet, clipNames[i]) then
return true
end
end
return false
end
function HumanModelHost:_idleClipNamesForGender(isFemale)
if isFemale then
return { "idle1FemaleSource", "NPCFemaleIdle01Source", "NPCFemaleIdle02Source", "idle1Source" }
end
return { "idle1Source", "NPCMaleIdle01Source", "NPCMaleIdle02Source" }
end
function HumanModelHost:_resolveCharSetAfterClone(skeleton)
if skeleton == nil then
return nil
end
local charSet = nil
if getNumOfChildren(skeleton) > 0 then
charSet = getAnimCharacterSet(getChildAt(skeleton, 0))
end
if charSet == nil or charSet == 0 then
charSet = getAnimCharacterSet(skeleton)
end
if charSet == nil or charSet == 0 then
return nil
end
return charSet
end
--- @param humanModel HumanModel
--- @return HumanModelHost
function IAHumanCharacter.forHumanModel(humanModel)
return setmetatable({ model = humanModel }, HumanModelHost)
end
function HumanModelHost:getModel()
return self.model
end
function HumanModelHost:forceVisible()
local model = self.model
if model == nil or model.rootNode == nil then
return
end
if model.setVisibility then
model:setVisibility(true)
end
iaSetNodeSubtreeVisible(model.rootNode, true)
end
function HumanModelHost:setEngineVisibility(visible)
local model = self.model
if model == nil or model.rootNode == nil then
return
end
if model.setVisibility then
model:setVisibility(visible == true)
end
iaSetNodeSubtreeVisible(model.rootNode, visible == true)
end
--- @return boolean false if rig not ready (caller may retry)
function HumanModelHost:tryStartStandingIdle(isFemale)
local model = self.model
if model == nil or model.rootNode == nil then
return false
end
local female = isFemale == true
local names = self:_idleClipNamesForGender(female)
local charSet = self:_findFirstAnimCharSet(model.rootNode)
if charSet ~= 0 then
self:_startFirstMatchingIdle(charSet, names)
return true
end
if model.skeleton == nil then
return false
end
if g_animCache == nil or AnimationCache == nil or AnimationCache.CHARACTER == nil then
return false
end
local animNode = g_animCache:getNode(AnimationCache.CHARACTER)
if animNode == nil or animNode == 0 then
return false
end
local animRoot = (getNumOfChildren(animNode) > 0) and getChildAt(animNode, 0) or animNode
cloneAnimCharacterSet(animRoot, model.skeleton)
charSet = self:_resolveCharSetAfterClone(model.skeleton)
if charSet == nil then
return false
end
if not self:_startFirstMatchingIdle(charSet, names) then
self:_assignLoopingClip(charSet, "idle1Source")
end
return true
end
function HumanModelHost:dispose()
local model = self.model
if model ~= nil and model.delete then
model:delete()
end
self.model = nil
end