105 | function TipOccluder:finalizeWheel(superFunc, wheel, parentWheel) |
106 | superFunc(self, wheel, parentWheel) |
107 | |
108 | local spec = self.spec_tipOccluder |
109 | if wheel.tipOcclusionAreaGroupId ~= nil then |
110 | local vehicleRootNode = self.components[1].node |
111 | local doCreate = true |
112 | local area |
113 | for groupId, occluderArea in pairs(spec.createdTipOcclusionAreaGroupIds) do |
114 | if groupId == wheel.tipOcclusionAreaGroupId then |
115 | doCreate = false |
116 | area = occluderArea |
117 | break |
118 | end |
119 | end |
120 | |
121 | -- the first wheel with the group id creates the area, the other just recalculate the area |
122 | if doCreate then |
123 | local start = createTransformGroup(string.format("tipOcclusionAreaGroupId%d", wheel.tipOcclusionAreaGroupId)) |
124 | local width = createTransformGroup(string.format("tipOcclusionAreaGroupId%d", wheel.tipOcclusionAreaGroupId)) |
125 | local height = createTransformGroup(string.format("tipOcclusionAreaGroupId%d", wheel.tipOcclusionAreaGroupId)) |
126 | link(vehicleRootNode, start) |
127 | link(vehicleRootNode, width) |
128 | link(vehicleRootNode, height) |
129 | |
130 | area = {start=start, width=width, height=height} |
131 | table.insert(spec.tipOcclusionAreas, area) |
132 | spec.createdTipOcclusionAreaGroupIds[wheel.tipOcclusionAreaGroupId] = area |
133 | end |
134 | |
135 | if area ~= nil then |
136 | local xMax = -math.huge |
137 | local xMin = math.huge |
138 | local zMax = -math.huge |
139 | local zMin = math.huge |
140 | |
141 | -- get other wheels with the same area group id |
142 | local usedWheels = self:getWheelsWithTipOcclisionAreaGroupId(self:getWheels(), wheel.tipOcclusionAreaGroupId) |
143 | |
144 | -- also include myself into the calculation |
145 | table.insert(usedWheels, wheel) |
146 | |
147 | for _,usedWheel in pairs(usedWheels) do |
148 | local x,_,z = localToLocal(usedWheel.driveNode, vehicleRootNode, usedWheel.wheelshapeWidth - 0.5 * usedWheel.width, 0, -usedWheel.radius) |
149 | xMax = math.max(x, xMax) |
150 | zMin = math.min(z, zMin) |
151 | x,_,z = localToLocal(usedWheel.driveNode, vehicleRootNode, -usedWheel.wheelshapeWidth + 0.5 * usedWheel.width, 0, usedWheel.radius) |
152 | xMin = math.min(x, xMin) |
153 | zMax = math.max(z, zMax) |
154 | end |
155 | |
156 | setTranslation(area.start, xMax,0,zMin) |
157 | setTranslation(area.width, xMin,0,zMin) |
158 | setTranslation(area.height, xMax,0,zMax) |
159 | end |
160 | end |
161 | end |
43 | function TipOccluder:onLoad(savegame) |
44 | local spec = self.spec_tipOccluder |
45 | |
46 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.tipOcclusionAreas.tipOcclusionArea", "vehicle.tipOccluder.occlusionArea") --FS17 to FS19 |
47 | |
48 | -- load tip occlusion areas |
49 | spec.tipOcclusionAreas = {} |
50 | local i = 0 |
51 | while true do |
52 | local key = string.format("vehicle.tipOccluder.occlusionArea(%d)", i) |
53 | if not hasXMLProperty(self.xmlFile, key) then |
54 | break |
55 | end |
56 | local entry = {} |
57 | entry.start = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, key .. "#start"), self.i3dMappings) |
58 | entry.width = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, key .. "#width"), self.i3dMappings) |
59 | entry.height = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, key .. "#height"), self.i3dMappings) |
60 | if entry.start ~= nil and entry.width ~= nil and entry.height ~= nil then |
61 | table.insert(spec.tipOcclusionAreas, entry) |
62 | end |
63 | i = i + 1 |
64 | end |
65 | |
66 | spec.createdTipOcclusionAreaGroupIds = {} |
67 | end |