87 | function PlaceableDynamicallyLoadedParts:onDynamicallyPartI3DLoaded(i3dNode, failedReason, args) |
88 | local spec = self.spec_dynamicallyLoadedParts |
89 | |
90 | local loadingTask = args.loadingTask |
91 | local filename = args.filename |
92 | local xmlFile = args.xmlFile |
93 | local partKey = args.key |
94 | |
95 | if i3dNode ~= 0 then |
96 | local node = xmlFile:getValue(partKey .. "#node", "0", i3dNode) |
97 | if node == nil then |
98 | Logging.xmlWarning(xmlFile, "Failed to load dynamicallyLoadedPart '%s'. Unable to find node in loaded i3d", partKey) |
99 | return false |
100 | end |
101 | |
102 | local linkNode = xmlFile:getValue(partKey .. "#linkNode", "0>", self.components, self.i3dMappings) |
103 | if linkNode == nil then |
104 | Logging.xmlWarning(xmlFile, "Failed to load dynamicallyLoadedPart '%s'. Unable to find linkNode", partKey) |
105 | return false |
106 | end |
107 | |
108 | local x, y, z = xmlFile:getValue(partKey .. "#position") |
109 | if x ~= nil and y ~= nil and z ~= nil then |
110 | setTranslation(node, x,y,z) |
111 | end |
112 | |
113 | local rotationNode = xmlFile:getValue(partKey .. "#rotationNode", node, i3dNode) |
114 | local rotX, rotY, rotZ = xmlFile:getValue(partKey .. "#rotation") |
115 | if rotX ~= nil and rotY ~= nil and rotZ ~= nil then |
116 | setRotation(rotationNode, rotX, rotY, rotZ) |
117 | end |
118 | |
119 | local shaderParameterName = xmlFile:getValue(partKey .. "#shaderParameterName") |
120 | local sx, sy, sz, sw = xmlFile:getValue(partKey .. "#shaderParameter") |
121 | if shaderParameterName ~= nil and sx ~= nil and sy ~= nil and sz ~= nil and sw ~= nil then |
122 | setShaderParameter(node, shaderParameterName, sx, sy, sz, sw, false) |
123 | end |
124 | |
125 | local objects = {} |
126 | ObjectChangeUtil.loadObjectChangeFromXML(xmlFile, partKey, objects, i3dNode, nil) |
127 | ObjectChangeUtil.setObjectChanges(objects, true, nil) |
128 | |
129 | link(linkNode, node) |
130 | delete(i3dNode) |
131 | |
132 | |
133 | local dynamicallyLoadedPart = {} |
134 | dynamicallyLoadedPart.filename = filename |
135 | dynamicallyLoadedPart.node = node |
136 | |
137 | table.insert(spec.parts, dynamicallyLoadedPart) |
138 | end |
139 | |
140 | self:finishLoadingTask(loadingTask) |
141 | end |
59 | function PlaceableDynamicallyLoadedParts:onLoad(savegame) |
60 | local spec = self.spec_dynamicallyLoadedParts |
61 | |
62 | spec.sharedLoadRequestIds = {} |
63 | spec.parts = {} |
64 | |
65 | self.xmlFile:iterate("placeable.dynamicallyLoadedParts.dynamicallyLoadedPart", function (_, partKey) |
66 | local filename = self.xmlFile:getValue(partKey .. "#filename") |
67 | if filename ~= nil then |
68 | filename = Utils.getFilename(filename, self.baseDirectory) |
69 | |
70 | local args = { |
71 | xmlFile = self.xmlFile, |
72 | key = partKey, |
73 | loadingTask = self:createLoadingTask(spec), |
74 | filename = filename |
75 | } |
76 | |
77 | local sharedLoadRequestId = g_i3DManager:loadSharedI3DFileAsync(filename, false, false, self.onDynamicallyPartI3DLoaded, self, args) |
78 | table.insert(spec.sharedLoadRequestIds, sharedLoadRequestId) |
79 | else |
80 | Logging.xmlWarning(self.xmlFile, "Missing filename for dynamically loaded part '%s'", partKey) |
81 | end |
82 | end) |
83 | end |
37 | function PlaceableDynamicallyLoadedParts.registerXMLPaths(schema, basePath) |
38 | schema:setXMLSpecializationType("DynamicallyLoadedParts") |
39 | |
40 | basePath = basePath .. ".dynamicallyLoadedParts.dynamicallyLoadedPart(?)" |
41 | |
42 | schema:register(XMLValueType.STRING, basePath .. "#filename", "Filename to i3d file") |
43 | schema:register(XMLValueType.NODE_INDEX, basePath .. "#node", "Node in external i3d file", "0") |
44 | schema:register(XMLValueType.NODE_INDEX, basePath .. "#linkNode", "Link node", "0>") |
45 | schema:register(XMLValueType.VECTOR_TRANS, basePath .. "#position", "Position") |
46 | schema:register(XMLValueType.NODE_INDEX, basePath .. "#rotationNode", "Rotation node", "node") |
47 | schema:register(XMLValueType.VECTOR_ROT, basePath .. "#rotation", "Rotation node rotation") |
48 | schema:register(XMLValueType.STRING, basePath .. "#shaderParameterName", "Shader parameter name") |
49 | schema:register(XMLValueType.VECTOR_4, basePath .. "#shaderParameter", "Shader parameter to apply") |
50 | |
51 | ObjectChangeUtil.registerObjectChangeSingleXMLPaths(schema, basePath) |
52 | |
53 | schema:setXMLSpecializationType() |
54 | end |