112 | function 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 |
127 | end |
31 | function 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 |
63 | end |
73 | function 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 |
108 | end |
153 | function 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 |
164 | end |