21 | function DynamicallyLoadedParts.initSpecialization() |
22 | local schema = Vehicle.xmlSchema |
23 | schema:setXMLSpecializationType("DynamicallyLoadedParts") |
24 | |
25 | local basePath = "vehicle.dynamicallyLoadedParts.dynamicallyLoadedPart(?)" |
26 | schema:register(XMLValueType.STRING, basePath .. "#filename", "Filename to i3d file") |
27 | schema:register(XMLValueType.NODE_INDEX, basePath .. "#node", "Node in external i3d file", "0|0") |
28 | schema:register(XMLValueType.NODE_INDEX, basePath .. "#linkNode", "Link node", "0>") |
29 | schema:register(XMLValueType.VECTOR_TRANS, basePath .. "#position", "Position") |
30 | schema:register(XMLValueType.NODE_INDEX, basePath .. "#rotationNode", "Rotation node", "node") |
31 | schema:register(XMLValueType.VECTOR_ROT, basePath .. "#rotation", "Rotation node rotation") |
32 | schema:register(XMLValueType.STRING, basePath .. "#shaderParameterName", "Shader parameter name") |
33 | schema:register(XMLValueType.VECTOR_4, basePath .. "#shaderParameter", "Shader parameter to apply") |
34 | |
35 | schema:setXMLSpecializationType() |
36 | end |
92 | function DynamicallyLoadedParts:onDynamicallyPartI3DLoaded(i3dNode, failedReason, args) |
93 | local spec = self.spec_dynamicallyLoadedParts |
94 | |
95 | local xmlFile = args.xmlFile |
96 | local partKey = args.partKey |
97 | local dynamicallyLoadedPart = args.dynamicallyLoadedPart |
98 | |
99 | if i3dNode ~= 0 then |
100 | local node = xmlFile:getValue(partKey .. "#node", "0|0", i3dNode) |
101 | if node == nil then |
102 | Logging.xmlWarning(xmlFile, "Failed to load dynamicallyLoadedPart '%s'. Unable to find node in loaded i3d", partKey) |
103 | return false |
104 | end |
105 | |
106 | local linkNode = xmlFile:getValue(partKey .. "#linkNode", "0>", self.components, self.i3dMappings) |
107 | if linkNode == nil then |
108 | Logging.xmlWarning(xmlFile, "Failed to load dynamicallyLoadedPart '%s'. Unable to find linkNode", partKey) |
109 | return false |
110 | end |
111 | |
112 | local x, y, z = xmlFile:getValue(partKey .. "#position") |
113 | if x ~= nil and y ~= nil and z ~= nil then |
114 | setTranslation(node, x,y,z) |
115 | end |
116 | |
117 | local rotationNode = xmlFile:getValue(partKey .. "#rotationNode", node, i3dNode) |
118 | local rotX, rotY, rotZ = xmlFile:getValue(partKey .. "#rotation") |
119 | if rotX ~= nil and rotY ~= nil and rotZ ~= nil then |
120 | setRotation(rotationNode, rotX, rotY, rotZ) |
121 | end |
122 | |
123 | local shaderParameterName = xmlFile:getValue(partKey .. "#shaderParameterName") |
124 | local sx, sy, sz, sw = xmlFile:getValue(partKey .. "#shaderParameter") |
125 | if shaderParameterName ~= nil and sx ~= nil and sy ~= nil and sz ~= nil and sw ~= nil then |
126 | setShaderParameter(node, shaderParameterName, sx, sy, sz, sw, false) |
127 | end |
128 | |
129 | link(linkNode, node) |
130 | delete(i3dNode) |
131 | |
132 | table.insert(spec.parts, dynamicallyLoadedPart) |
133 | end |
134 | end |
53 | function DynamicallyLoadedParts:onLoad(savegame) |
54 | local spec = self.spec_dynamicallyLoadedParts |
55 | |
56 | spec.sharedLoadRequestIds = {} |
57 | spec.parts = {} |
58 | |
59 | self.xmlFile:iterate("vehicle.dynamicallyLoadedParts.dynamicallyLoadedPart", function (_, partKey) |
60 | local filename = self.xmlFile:getValue(partKey .. "#filename") |
61 | if filename ~= nil then |
62 | local dynamicallyLoadedPart = {} |
63 | dynamicallyLoadedPart.filename = Utils.getFilename(filename, self.baseDirectory) |
64 | local arguments = { |
65 | xmlFile = self.xmlFile, |
66 | partKey = partKey, |
67 | dynamicallyLoadedPart = dynamicallyLoadedPart |
68 | } |
69 | local sharedLoadRequestId = self:loadSubSharedI3DFile(dynamicallyLoadedPart.filename, false, false, self.onDynamicallyPartI3DLoaded, self, arguments) |
70 | table.insert(spec.sharedLoadRequestIds, sharedLoadRequestId) |
71 | else |
72 | Logging.xmlWarning(self.xmlFile, "Missing filename for dynamically loaded part '%s'", partKey) |
73 | end |
74 | end) |
75 | end |