37 | function ObjectChangeUtil.loadValuesFromXML(xmlFile, key, node, object, parent) |
38 | object.visibilityActive = getXMLBool(xmlFile, key.."#visibilityActive") |
39 | object.visibilityInactive = getXMLBool(xmlFile, key.."#visibilityInactive") |
40 | object.translationActive = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#translationActive"), 3) |
41 | object.translationInactive = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#translationInactive"), 3) |
42 | object.rotationActive = StringUtil.getRadiansFromString(getXMLString(xmlFile, key.."#rotationActive"), 3) |
43 | object.rotationInactive = StringUtil.getRadiansFromString(getXMLString(xmlFile, key.."#rotationInactive"), 3) |
44 | object.scaleActive = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#scaleActive"), 3) |
45 | object.scaleInactive = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#scaleInactive"), 3) |
46 | |
47 | XMLUtil.checkDeprecatedXMLElements(xmlFile, "", key.."#collisionActive", key.."#compoundChildActive or #rigidBodyTypeActive") --FS17 to FS19 |
48 | XMLUtil.checkDeprecatedXMLElements(xmlFile, "", key.."#collisionInactive", key.."#compoundChildInactive or #rigidBodyTypeInactive") --FS17 to FS19 |
49 | |
50 | object.massActive = nil |
51 | object.massInactive = nil |
52 | local massActive = getXMLFloat(xmlFile, key.."#massActive") |
53 | if massActive ~= nil then |
54 | object.massActive = massActive / 1000 |
55 | end |
56 | local massInactive = getXMLFloat(xmlFile, key.."#massInactive") |
57 | if massInactive ~= nil then |
58 | object.massInactive = massInactive / 1000 |
59 | end |
60 | object.centerOfMassActive = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#centerOfMassActive"), 3) |
61 | object.centerOfMassInactive = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#centerOfMassInactive"), 3) |
62 | object.compoundChildActive = getXMLBool(xmlFile, key.."#compoundChildActive") |
63 | object.compoundChildInactive = getXMLBool(xmlFile, key.."#compoundChildInactive") |
64 | object.rigidBodyTypeActive = getXMLString(xmlFile, key.."#rigidBodyTypeActive") |
65 | object.rigidBodyTypeInactive = getXMLString(xmlFile, key.."#rigidBodyTypeInactive") |
66 | |
67 | if object.rigidBodyTypeActive ~= nil then |
68 | local t = object.rigidBodyTypeActive |
69 | if t ~= "Static" and t ~= "Dynamic" and t ~= "Kinematic" and t ~= "NoRigidBody" then |
70 | g_logManager:warning("Invalid rigidBodyTypeActive '%s' for object change node '%s'. Use 'Static', 'Dynamic', 'Kinematic' or 'NoRigidBody'!", t, key) |
71 | object.rigidBodyTypeActive = nil |
72 | end |
73 | end |
74 | if object.rigidBodyTypeInactive ~= nil then |
75 | local t = object.rigidBodyTypeInactive |
76 | if t ~= "Static" and t ~= "Dynamic" and t ~= "Kinematic" and t ~= "NoRigidBody" then |
77 | g_logManager:warning("Invalid rigidBodyTypeInactive '%s' for object change node '%s'. Use 'Static', 'Dynamic', 'Kinematic' or 'NoRigidBody'!", t, key) |
78 | object.rigidBodyTypeInactive = nil |
79 | end |
80 | end |
81 | |
82 | if parent ~= nil and parent.loadObjectChangeValuesFromXML ~= nil then |
83 | parent:loadObjectChangeValuesFromXML(xmlFile, key, node, object) |
84 | end |
85 | end |
105 | function ObjectChangeUtil.setObjectChange(object, isActive, target, updateFunc) |
106 | if isActive then |
107 | if object.visibilityActive ~= nil then |
108 | setVisibility(object.node, object.visibilityActive) |
109 | end |
110 | if object.translationActive ~= nil then |
111 | setTranslation(object.node, object.translationActive[1], object.translationActive[2], object.translationActive[3]) |
112 | end |
113 | if object.rotationActive ~= nil then |
114 | setRotation(object.node, object.rotationActive[1], object.rotationActive[2], object.rotationActive[3]) |
115 | end |
116 | if object.scaleActive ~= nil then |
117 | setScale(object.node, object.scaleActive[1], object.scaleActive[2], object.scaleActive[3]) |
118 | end |
119 | if object.massActive ~= nil then |
120 | setMass(object.node, object.massActive) |
121 | |
122 | if target ~= nil and target.components ~= nil then |
123 | for _, component in ipairs(target.components) do |
124 | if component.node == object.node then |
125 | component.defaultMass = object.massActive |
126 | target:setMassDirty() |
127 | end |
128 | end |
129 | end |
130 | end |
131 | if object.centerOfMassActive ~= nil then |
132 | setCenterOfMass(object.node, unpack(object.centerOfMassActive)) |
133 | end |
134 | if object.compoundChildActive ~= nil then |
135 | setIsCompoundChild(object.node, object.compoundChildActive) |
136 | end |
137 | if object.rigidBodyTypeActive ~= nil then |
138 | setRigidBodyType(object.node, object.rigidBodyTypeActive) |
139 | end |
140 | else |
141 | if object.visibilityInactive ~= nil then |
142 | setVisibility(object.node, object.visibilityInactive) |
143 | end |
144 | if object.translationInactive ~= nil then |
145 | setTranslation(object.node, object.translationInactive[1], object.translationInactive[2], object.translationInactive[3]) |
146 | end |
147 | if object.rotationInactive ~= nil then |
148 | setRotation(object.node, object.rotationInactive[1], object.rotationInactive[2], object.rotationInactive[3]) |
149 | end |
150 | if object.scaleInactive ~= nil then |
151 | setScale(object.node, object.scaleInactive[1], object.scaleInactive[2], object.scaleInactive[3]) |
152 | end |
153 | if object.massInactive ~= nil then |
154 | setMass(object.node, object.massInactive) |
155 | |
156 | if target ~= nil and target.components ~= nil then |
157 | for _, component in ipairs(target.components) do |
158 | if component.node == object.node then |
159 | component.defaultMass = object.massInactive |
160 | target:setMassDirty() |
161 | end |
162 | end |
163 | end |
164 | end |
165 | if object.centerOfMassInactive ~= nil then |
166 | setCenterOfMass(object.node, unpack(object.centerOfMassInactive)) |
167 | end |
168 | if object.compoundChildInactive ~= nil then |
169 | setIsCompoundChild(object.node, object.compoundChildInactive) |
170 | end |
171 | if object.rigidBodyTypeInactive ~= nil then |
172 | setRigidBodyType(object.node, object.rigidBodyTypeInactive) |
173 | end |
174 | end |
175 | if target ~= nil then |
176 | if target.setObjectChangeValues ~= nil then |
177 | target:setObjectChangeValues(object, isActive) |
178 | end |
179 | if updateFunc ~= nil then |
180 | updateFunc(target, object.node) |
181 | end |
182 | end |
183 | end |
192 | function ObjectChangeUtil.updateObjectChanges(xmlFile, key, configKey, rootNode, parent) |
193 | local i = 0 |
194 | local activeI = (configKey - 1) |
195 | while true do |
196 | local objectChangeKey = string.format(key.."(%d)", i) |
197 | if not hasXMLProperty(xmlFile, objectChangeKey) then |
198 | break |
199 | end |
200 | if i ~= activeI then |
201 | local objects = {} |
202 | ObjectChangeUtil.loadObjectChangeFromXML(xmlFile, objectChangeKey, objects, rootNode, parent) |
203 | ObjectChangeUtil.setObjectChanges(objects, false, parent) |
204 | end |
205 | i = i + 1 |
206 | end |
207 | |
208 | -- Set the active config last so that it can overwrite settings of inactive configurations |
209 | if i > activeI then |
210 | local objectChangeKey = string.format(key.."(%d)", activeI) |
211 | local objects = {} |
212 | ObjectChangeUtil.loadObjectChangeFromXML(xmlFile, objectChangeKey, objects, rootNode, parent) |
213 | ObjectChangeUtil.setObjectChanges(objects, true, parent) |
214 | end |
215 | end |