LUADOC - Farming Simulator 19

VehicleCharacter

Description
Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
Functions

delete

Description
Definition
delete()
Code
112function VehicleCharacter:delete()
113 if self.isCharacterLoaded then
114 local specIK = self.vehicle.spec_ikChains
115 if specIK ~= nil then
116 for chainId, _ in pairs(self.ikChains) do
117 specIK.chains[chainId] = nil
118 end
119 end
120 Player.deleteVisuals(self, self.ikChains)
121 end
122 self.isCharacterLoaded = false
123 if self.animationPlayer ~= 0 then
124 delete(self.animationPlayer)
125 self.animationPlayer = 0
126 end
127end

getAllowCharacterUpdate

Description
Definition
getAllowCharacterUpdate()
Code
195function VehicleCharacter:getAllowCharacterUpdate()
196 return self.allowUpdate
197end

getIKChainTargets

Description
Definition
getIKChainTargets()
Code
209function VehicleCharacter:getIKChainTargets()
210 return self.ikChainTargets
211end

getParentComponent

Description
Definition
getParentComponent()
Code
67function VehicleCharacter:getParentComponent()
68 return self.vehicle:getParentComponent(self.characterNode)
69end

getPlayerStyle

Description
Definition
getPlayerStyle()
Code
229function VehicleCharacter:getPlayerStyle()
230 return self.visualInformation
231end

load

Description
Definition
load()
Code
31function VehicleCharacter:load(xmlFile, xmlNode)
32
33 if getXMLString(xmlFile, xmlNode .. "#index") ~= nil then
34 g_logManager:warning("'%s' is not supported anymore, use '%s' instead!", xmlNode .. "#index", xmlNode .. "#node")
35 end
36
37 self.characterNode = I3DUtil.indexToObject(self.vehicle.components, getXMLString(xmlFile, xmlNode.."#node"), self.vehicle.i3dMappings)
38 if self.characterNode ~= nil then
39 self.characterCameraMinDistance = Utils.getNoNil(getXMLFloat(xmlFile, xmlNode.."#cameraMinDistance"), 1.5)
40 self.characterDistanceRefNode = I3DUtil.indexToObject(self.vehicle.components, getXMLString(xmlFile, xmlNode.."#distanceRefNode"), self.vehiclei3dMappings)
41 if self.characterDistanceRefNode == nil then
42 self.characterDistanceRefNode = self.characterNode
43 end
44 setVisibility(self.characterNode, false)
45 self.useAnimation = Utils.getNoNil(getXMLFloat(xmlFile, xmlNode.."#useAnimation"), false)
46
47 if not self.useAnimation then
48 self.ikChainTargets = {}
49 IKUtil.loadIKChainTargets(xmlFile, xmlNode, self.vehicle.components, self.ikChainTargets, self.vehicle.i3dMappings)
50 end
51 self.characterSpineRotation = StringUtil.getRadiansFromString(getXMLString(xmlFile, xmlNode.."#spineRotation"), 3)
52 self.characterSpineSpeedDepended = Utils.getNoNil(getXMLBool(xmlFile, xmlNode.."#speedDependedSpine"), false)
53 self.characterSpineNodeMinRot = math.rad(Utils.getNoNil(getXMLFloat(xmlFile, xmlNode.."#spineNodeMinRot"), 10))
54 self.characterSpineNodeMaxRot = math.rad(Utils.getNoNil(getXMLFloat(xmlFile, xmlNode.."#spineNodeMaxRot"), -10))
55 self.characterSpineNodeMinAcc = Utils.getNoNil(getXMLFloat(xmlFile, xmlNode.."#spineNodeMinAcc"), -1)/(1000*1000)
56 self.characterSpineNodeMaxAcc = Utils.getNoNil(getXMLFloat(xmlFile, xmlNode.."#spineNodeMaxAcc"), 1)/(1000*1000)
57 self.characterSpineNodeAccDeadZone = Utils.getNoNil(getXMLFloat(xmlFile, xmlNode.."#spineNodeAccDeadZone"), 0.2)/(1000*1000)
58 self.characterSpineLastRotation = 0
59 self:setCharacterVisibility(false)
60 return true
61 end
62 return false
63end

loadCharacter

Description
Definition
loadCharacter()
Code
73function VehicleCharacter:loadCharacter(xmlFilename, playerStyle)
74 local linkNode = Utils.getNoNil(self.characterNode, self.vehicle.rootNode)
75 if not Player.loadVisuals(self, xmlFilename, playerStyle, linkNode, false, self.ikChains, nil, nil, self.characterNode) then
76 self:delete()
77 return false
78 end
79 local specIK = self.vehicle.spec_ikChains
80 if specIK ~= nil then
81 for chainId, chain in pairs(self.ikChains) do
82 specIK.chains[chainId] = chain
83 end
84 for ikChainId, target in pairs(self.ikChainTargets) do
85 IKUtil.setTarget(self.ikChains, ikChainId, target)
86 end
87 end
88 if self.characterSpineRotation ~= nil and self.thirdPersonSpineNode ~= nil then
89 setRotation(self.thirdPersonSpineNode, unpack(self.characterSpineRotation))
90 end
91
92 if self.useAnimation and self.skeletonThirdPerson ~= nil and getNumOfChildren(self.skeletonThirdPerson) > 0 then
93 local animNode = g_animCache:getNode(AnimationCache.CHARACTER)
94 cloneAnimCharacterSet(getChildAt(animNode, 0), self.skeletonThirdPerson)
95 self.animationCharsetId = getAnimCharacterSet(getChildAt(self.skeletonThirdPerson, 0))
96 self.animationPlayer = createConditionalAnimation()
97
98 if self.animationCharsetId == 0 then
99 g_logManager:devError("-- [VehicleCharacter:loadCharacter] Could not load animation CharSet from: [%s/%s]", getName(getParent(self.skeletonThirdPerson)), getName(self.skeletonThirdPerson))
100 printScenegraph(getParent(self.skeletonThirdPerson))
101 end
102 end
103
104 self:setCharacterDirty()
105 self:setCharacterVisibility(true)
106 self.isCharacterLoaded = true
107 return true
108end

new

Description
Definition
new()
Code
11function VehicleCharacter:new(vehicle, customMt)
12 if customMt == nil then
13 customMt = VehicleCharacter_mt
14 end
15 local self = setmetatable({}, customMt)
16
17 self.vehicle = vehicle
18 self.characterNode = nil
19 self.allowUpdate = true
20 self.ikChains = {}
21 self.ikChainTargets = {}
22 self.animationCharsetId = 0
23 self.animationPlayer = 0
24 self.useAnimation = false
25
26 return self
27end

setAllowCharacterUpdate

Description
Definition
setAllowCharacterUpdate()
Code
189function VehicleCharacter:setAllowCharacterUpdate(state)
190 self.allowUpdate = state
191end

setCharacterDirty

Description
Definition
setCharacterDirty()
Code
131function VehicleCharacter:setCharacterDirty()
132 self:setDirty(true)
133end

setCharacterVisibility

Description
Definition
setCharacterVisibility()
Code
178function VehicleCharacter:setCharacterVisibility(isVisible)
179 if self.characterNode ~= nil then
180 setVisibility(self.characterNode, isVisible)
181 end
182 if self.meshThirdPerson ~= nil then
183 setVisibility(self.meshThirdPerson, isVisible)
184 end
185end

setDirty

Description
Definition
setDirty()
Code
137function VehicleCharacter:setDirty(setAllDirty)
138 for chainId, target in pairs(self.ikChainTargets) do
139 if target.setDirty or setAllDirty then
140 IKUtil.setIKChainDirty(self.ikChains, chainId)
141 end
142 end
143end

setIKChainTargets

Description
Definition
setIKChainTargets()
Code
215function VehicleCharacter:setIKChainTargets(targets, force)
216 if self.ikChainTargets ~= targets or force then
217 self.ikChainTargets = targets
218 if self.isCharacterLoaded then
219 for ikChainId, target in pairs(self.ikChainTargets) do
220 IKUtil.setTarget(self.ikChains, ikChainId, target)
221 end
222 self:setCharacterDirty()
223 end
224 end
225end

setSpineDirty

Description
Definition
setSpineDirty()
Code
153function VehicleCharacter:setSpineDirty(acc)
154 if math.abs(acc) < self.characterSpineNodeAccDeadZone then
155 acc = 0
156 end
157 local alpha = MathUtil.clamp((acc - self.characterSpineNodeMinAcc) / (self.characterSpineNodeMaxAcc - self.characterSpineNodeMinAcc), 0, 1)
158 local rotation = MathUtil.lerp(self.characterSpineNodeMinRot, self.characterSpineNodeMaxRot, alpha)
159 if rotation ~= self.characterSpineLastRotation then
160 self.characterSpineLastRotation = self.characterSpineLastRotation * 0.95 + rotation * 0.05
161 setRotation(self.spineNode, self.characterSpineLastRotation, 0, 0)
162 self:setDirty()
163 end
164end

update

Description
Definition
update()
Code
201function VehicleCharacter:update(dt)
202 if self:getAllowCharacterUpdate() then
203 self:setCharacterDirty()
204 end
205end

updateIKChains

Description
Definition
updateIKChains()
Code
147function VehicleCharacter:updateIKChains()
148 IKUtil.updateIKChains(self.ikChains)
149end

updateVisibility

Description
Definition
updateVisibility()
Code
168function VehicleCharacter:updateVisibility(isVisible)
169 if entityExists(self.characterDistanceRefNode) and entityExists(getCamera()) then
170 local dist = calcDistanceFrom(self.characterDistanceRefNode, getCamera())
171 local visible = dist >= self.characterCameraMinDistance
172 self:setCharacterVisibility(visible)
173 end
174end