Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
MaterialManager
DescriptionThis class handles all materialsParent
AbstractManagerFunctions
- addBaseMaterial
- addMaterial
- addMaterialToTarget
- addMaterialType
- addModMaterialHolder
- addParticleMaterial
- fontMaterialLoaded
- getBaseMaterialByName
- getFontMaterial
- getMaterial
- getMaterialFromTarget
- getMaterialTypeByName
- getParticleMaterial
- initDataStructures
- loadFontMaterialsXML
- loadMapData
- loadModMaterialHolders
- materialHolderLoaded
- new
- registerXMLPaths
- unloadMapData
addBaseMaterial
DescriptionAdds a new base materialDefinition
addBaseMaterial(string materialName, integer materialId)Arguments
string | materialName | materialName |
integer | materialId | internal material id |
149 | function MaterialManager:addBaseMaterial(materialName, materialId) |
150 | self.baseMaterialsByName[materialName:upper()] = materialId |
151 | table.insert(self.baseMaterials, materialId) |
152 | end |
addMaterial
DescriptionAdds a new material typeDefinition
addMaterial(integer fillTypeIndex, string materialType, integer materialIndex, integer materialId)Arguments
integer | fillTypeIndex | filltype index |
string | materialType | materialType |
integer | materialIndex | material index |
integer | materialId | internal material id |
172 | function MaterialManager:addMaterial(fillTypeIndex, materialType, materialIndex, materialId) |
173 | self:addMaterialToTarget(self.materials, fillTypeIndex, materialType, materialIndex, materialId) |
174 | end |
addMaterialToTarget
DescriptionAdds a new material type to given target tableDefinition
addMaterialToTarget(table target, integer fillTypeIndex, string materialType, integer materialIndex, integer materialId)Arguments
table | target | target table |
integer | fillTypeIndex | filltype index |
string | materialType | materialType |
integer | materialIndex | material index |
integer | materialId | internal material id |
193 | function MaterialManager:addMaterialToTarget(target, fillTypeIndex, materialType, materialIndex, materialId) |
194 | if fillTypeIndex == nil or materialType == nil or materialIndex == nil or materialId == nil then |
195 | return nil |
196 | end |
197 | |
198 | if target[fillTypeIndex] == nil then |
199 | target[fillTypeIndex] = {} |
200 | end |
201 | local fillTypeMaterials = target[fillTypeIndex] |
202 | |
203 | if fillTypeMaterials[materialType] == nil then |
204 | fillTypeMaterials[materialType] = {} |
205 | end |
206 | local materialTypes = fillTypeMaterials[materialType] |
207 | |
208 | if g_showDevelopmentWarnings and materialTypes[materialIndex] ~= nil then |
209 | local fillType = g_fillTypeManager:getFillTypeByIndex(fillTypeIndex) |
210 | Logging.devWarning("Material type '%s' already exists for fillType '%s'. It will be overwritten!", tostring(materialType), tostring(fillType.name)) |
211 | end |
212 | |
213 | materialTypes[materialIndex] = materialId |
214 | end |
addMaterialType
DescriptionAdds a new material typeDefinition
addMaterialType(string name)Arguments
string | name | name |
114 | function MaterialManager:addMaterialType(name) |
115 | if not ClassUtil.getIsValidIndexName(name) then |
116 | print("Warning: '"..tostring(name).."' is not a valid name for a materialType. Ignoring it!") |
117 | return nil |
118 | end |
119 | |
120 | name = name:upper() |
121 | |
122 | if self.nameToIndex[name] == nil then |
123 | table.insert(self.materialTypes, name) |
124 | self.nameToIndex[name] = #self.materialTypes |
125 | end |
126 | end |
addModMaterialHolder
DescriptionReturns material for given propertiesDefinition
addModMaterialHolder()Code
269 | function MaterialManager:addModMaterialHolder(filename) |
270 | self.modMaterialHoldersToLoad[filename] = filename |
271 | end |
addParticleMaterial
DescriptionAdds a new particle material typeDefinition
addParticleMaterial(integer fillTypeIndex, string materialType, integer materialIndex, integer materialId)Arguments
integer | fillTypeIndex | filltype index |
string | materialType | materialType |
integer | materialIndex | material index |
integer | materialId | internal material id |
182 | function MaterialManager:addParticleMaterial(fillTypeIndex, materialType, materialIndex, materialId) |
183 | self:addMaterialToTarget(self.particleMaterials, fillTypeIndex, materialType, materialIndex, materialId) |
184 | end |
fontMaterialLoaded
DescriptionDefinitionfontMaterialLoaded()Code
347 | function MaterialManager:fontMaterialLoaded(i3dNode, failedReason, arguments, loadingId) |
348 | local xmlFile = arguments.xmlFile |
349 | local key = arguments.key |
350 | local font = arguments.font |
351 | |
352 | if i3dNode ~= 0 then |
353 | local materialNode = I3DUtil.indexToObject(i3dNode, font.node) |
354 | if materialNode ~= nil then |
355 | font.materialId = getMaterial(materialNode, 0) |
356 | font.materialNode = materialNode |
357 | |
358 | if font.noNormalNode ~= nil then |
359 | font.materialNodeNoNormal = I3DUtil.indexToObject(i3dNode, font.noNormalNode) |
360 | font.materialIdNoNormal = getMaterial(font.materialNodeNoNormal, 0) |
361 | end |
362 | |
363 | if font.characterShapePath ~= nil then |
364 | font.characterShape = I3DUtil.indexToObject(i3dNode, font.characterShapePath) |
365 | end |
366 | |
367 | unlink(font.materialNodeNoNormal) |
368 | unlink(font.characterShape) |
369 | unlink(materialNode) |
370 | |
371 | font.spacingX = xmlFile:getValue(key .. ".spacing#x", 0) |
372 | font.spacingY = xmlFile:getValue(key .. ".spacing#y", 0) |
373 | |
374 | font.charToCharSpace = xmlFile:getValue(key .. ".spacing#charToChar", 0.05) |
375 | |
376 | font.characters = {} |
377 | |
378 | font.charactersByType = {} |
379 | font.charactersByType[MaterialManager.FONT_CHARACTER_TYPE.NUMERICAL] = {} |
380 | font.charactersByType[MaterialManager.FONT_CHARACTER_TYPE.ALPHABETICAL] = {} |
381 | font.charactersByType[MaterialManager.FONT_CHARACTER_TYPE.SPECIAL] = {} |
382 | |
383 | xmlFile:iterate(key .. ".character", function(index, charKey) |
384 | local character = {} |
385 | character.uvIndex = xmlFile:getValue(charKey .. "#uvIndex", 0) |
386 | character.value = xmlFile:getValue(charKey .. "#value") |
387 | local typeStr = xmlFile:getValue(charKey .. "#type", "alphabetical") |
388 | character.type = MaterialManager.FONT_CHARACTER_TYPE[typeStr:upper()] or MaterialManager.FONT_CHARACTER_TYPE.ALPHABETICAL |
389 | |
390 | character.spacingX = math.max(xmlFile:getValue(charKey .. "#spacingX", font.spacingX), 0.0001) |
391 | character.spacingY = math.max(xmlFile:getValue(charKey .. "#spacingY", font.spacingY), 0.0001) |
392 | character.offsetX = xmlFile:getValue(charKey .. "#offsetX", 0) |
393 | character.offsetY = xmlFile:getValue(charKey .. "#offsetY", 0) |
394 | character.realSpacingX = math.max(xmlFile:getValue(charKey .. "#realSpacingX", character.spacingX), 0.0001) |
395 | |
396 | if character.value ~= nil then |
397 | table.insert(font.characters, character) |
398 | table.insert(font.charactersByType[character.type], character) |
399 | end |
400 | end) |
401 | |
402 | font.getCharacterIndexByCharacter = function(_, char) |
403 | for i=1, #font.characters do |
404 | if font.characters[i].value:lower() == char:lower() then |
405 | return i |
406 | end |
407 | end |
408 | |
409 | return 1 |
410 | end |
411 | |
412 | font.getCharacterByCharacterIndex = function(_, index) |
413 | local char = font.characters[index] |
414 | if char ~= nil then |
415 | return char.value |
416 | end |
417 | |
418 | return "0" |
419 | end |
420 | |
421 | font.assignFontMaterialToNode = function(_, node, hasNormal) |
422 | if node ~= nil then |
423 | local materialId = font.materialId |
424 | if hasNormal == false then |
425 | materialId = font.materialIdNoNormal or materialId |
426 | end |
427 | |
428 | setMaterial(node, materialId, 0) |
429 | setShaderParameter(node, "spacing", font.spacingX, font.spacingY, 0, 0, false) |
430 | end |
431 | end |
432 | |
433 | font.setFontCharacter = function(_, node, targetCharacter, color, hiddenColor) |
434 | if node ~= nil then |
435 | if hiddenColor ~= nil then |
436 | if targetCharacter == " " then |
437 | targetCharacter = "0" |
438 | font:setFontCharacterColor(node, hiddenColor[1], hiddenColor[2], hiddenColor[3]) |
439 | else |
440 | font:setFontCharacterColor(node, color[1], color[2], color[3]) |
441 | end |
442 | end |
443 | |
444 | -- try first if we have a character with matching case |
445 | local foundCharacter = nil |
446 | for i=1, #font.characters do |
447 | local character = font.characters[i] |
448 | if character.value == targetCharacter then |
449 | foundCharacter = character |
450 | break |
451 | end |
452 | end |
453 | |
454 | -- if not we use any character independent of the case |
455 | if foundCharacter == nil then |
456 | for i=1, #font.characters do |
457 | local character = font.characters[i] |
458 | if character.value:lower() == targetCharacter:lower() then |
459 | foundCharacter = character |
460 | break |
461 | end |
462 | end |
463 | end |
464 | |
465 | if foundCharacter ~= nil then |
466 | setVisibility(node, true) |
467 | setShaderParameter(node, "index", foundCharacter.uvIndex, 0, 0, 0, false) |
468 | setShaderParameter(node, "spacing", foundCharacter.spacingX or font.spacingX, foundCharacter.spacingY or font.spacingY, 0, 0, false) |
469 | else |
470 | setVisibility(node, false) |
471 | end |
472 | |
473 | return foundCharacter |
474 | end |
475 | end |
476 | |
477 | font.setFontCharacterColor = function(_, node, r, g, b, a, emissive) |
478 | if node ~= nil then |
479 | local oldR, oldG, oldB, oldA = getShaderParameter(node, "colorScale") |
480 | setShaderParameter(node, "colorScale", r or oldR, g or oldG, b or oldB, a or oldA, false) |
481 | |
482 | if emissive ~= nil then |
483 | local lightControl, _, _, _ = getShaderParameter(node, "lightControl") |
484 | setShaderParameter(node, "lightControl", emissive or lightControl, 0, 0, 0, false) |
485 | end |
486 | end |
487 | end |
488 | |
489 | font.createCharacterLine = function(_, linkNode, numChars, textSize, textColor, hiddenColor, textEmissiveScale, scaleX, scaleY, textAlignment, hiddenAlpha, fontThickness) |
490 | if font.characterShape ~= nil then |
491 | local characterLine = {} |
492 | characterLine.characters = {} |
493 | characterLine.textSize = textSize or 1 |
494 | characterLine.scaleX = scaleX or 1 |
495 | characterLine.scaleY = scaleY or 1 |
496 | characterLine.textAlignment = textAlignment or RenderText.ALIGN_RIGHT |
497 | characterLine.fontThickness = ((fontThickness or 1) - 1) / 8 + 1 |
498 | characterLine.textColor = textColor |
499 | characterLine.hiddenColor = hiddenColor |
500 | characterLine.textEmissiveScale = textEmissiveScale or 0 |
501 | characterLine.hiddenAlpha = hiddenAlpha or 0 |
502 | characterLine.rootNode = createTransformGroup("characterLine") |
503 | link(linkNode, characterLine.rootNode) |
504 | |
505 | for i=1, numChars do |
506 | local char = clone(font.characterShape, false, false, false) |
507 | link(characterLine.rootNode, char) |
508 | font:assignFontMaterialToNode(char) |
509 | |
510 | setShaderParameter(char, "alphaErosion", 1-characterLine.fontThickness, 0, 0, 0, false) |
511 | |
512 | local r, g, b |
513 | if characterLine.textColor ~= nil then |
514 | r, g, b = characterLine.textColor[1], characterLine.textColor[2], characterLine.textColor[3] |
515 | end |
516 | font:setFontCharacterColor(char, r, g, b, 1, characterLine.textEmissiveScale) |
517 | |
518 | table.insert(characterLine.characters, char) |
519 | end |
520 | |
521 | font:updateCharacterLine(characterLine, "") |
522 | |
523 | return characterLine |
524 | else |
525 | Logging.error("Could not create characters from font '%s'. No source character mesh found!", font.name) |
526 | end |
527 | end |
528 | |
529 | font.updateCharacterLine = function(_, characterLine, text) |
530 | if characterLine ~= nil then |
531 | local realWidth = 0 |
532 | local xPos = 0 |
533 | local textLength = text:len() |
534 | for i=1, #characterLine.characters do |
535 | local charNode = characterLine.characters[i] |
536 | local targetCharacter = text:sub(textLength - (i-1), textLength - (i-1)) or " " |
537 | local characterData = font:setFontCharacter(charNode, targetCharacter, characterLine.textColor, characterLine.hiddenColor) |
538 | |
539 | local offsetX, offsetY = 0, 0 |
540 | local spacingX, spacingY, realSpacingX = font.spacingX, font.spacingY, font.spacingX |
541 | if characterData ~= nil then |
542 | spacingX = characterData.spacingX or spacingX |
543 | spacingY = characterData.spacingY or spacingY |
544 | realSpacingX = characterData.realSpacingX or spacingY |
545 | offsetX, offsetY = characterData.offsetX, characterData.offsetY |
546 | end |
547 | |
548 | local ratio = (1 - (spacingX * 2)) / (1 - (spacingY * 2)) |
549 | local scaleX = (characterLine.textSize * ratio) * characterLine.scaleX |
550 | local scaleY = characterLine.textSize * characterLine.scaleY |
551 | |
552 | setScale(charNode, scaleX, scaleY, 1) |
553 | |
554 | local charWidth = scaleX + (characterLine.textSize * font.charToCharSpace) * (spacingX / realSpacingX) |
555 | setTranslation(charNode, xPos - charWidth * 0.5 + (charWidth * offsetX), scaleY * 0.5 + (scaleY * offsetY), 0) |
556 | |
557 | xPos = xPos - charWidth |
558 | |
559 | if targetCharacter ~= " " and targetCharacter ~= "" then |
560 | realWidth = xPos |
561 | end |
562 | end |
563 | |
564 | if characterLine.textAlignment == RenderText.ALIGN_LEFT then |
565 | setTranslation(characterLine.rootNode, -realWidth, 0, 0) |
566 | elseif characterLine.textAlignment == RenderText.ALIGN_CENTER then |
567 | setTranslation(characterLine.rootNode, -realWidth * 0.5, 0, 0) |
568 | else |
569 | setTranslation(characterLine.rootNode, 0, 0, 0) |
570 | end |
571 | end |
572 | end |
573 | |
574 | font.createSingleCharacter = function(_, linkNode, textSize, textColor, hiddenColor, textEmissiveScale, scaleX, scaleY, hiddenAlpha) |
575 | if font.characterShape ~= nil then |
576 | local singleCharacter = {} |
577 | singleCharacter.textSize = textSize or 1 |
578 | singleCharacter.scaleX = scaleX or 1 |
579 | singleCharacter.scaleY = scaleY or 1 |
580 | singleCharacter.textColor = textColor |
581 | singleCharacter.hiddenColor = hiddenColor |
582 | singleCharacter.textEmissiveScale = textEmissiveScale or 0 |
583 | singleCharacter.hiddenAlpha = hiddenAlpha or 0 |
584 | |
585 | singleCharacter.charNode = clone(font.characterShape, false, false, false) |
586 | link(linkNode, singleCharacter.charNode) |
587 | setTranslation(singleCharacter.charNode, 0, 0, 0) |
588 | setRotation(singleCharacter.charNode, 0, 0, 0) |
589 | font:assignFontMaterialToNode(singleCharacter.charNode) |
590 | |
591 | local r, g, b |
592 | if singleCharacter.textColor ~= nil then |
593 | r, g, b = singleCharacter.textColor[1], singleCharacter.textColor[2], singleCharacter.textColor[3] |
594 | end |
595 | font:setFontCharacterColor(singleCharacter.charNode, r, g, b, 1, singleCharacter.textEmissiveScale) |
596 | |
597 | font:updateSingleCharacter(singleCharacter, "") |
598 | |
599 | return singleCharacter |
600 | else |
601 | Logging.error("Could not create characters from font '%s'. No source character mesh found!", font.name) |
602 | end |
603 | end |
604 | |
605 | font.updateSingleCharacter = function(_, singleCharacter, targetCharacter) |
606 | if singleCharacter ~= nil then |
607 | local characterData = font:setFontCharacter(singleCharacter.charNode, targetCharacter, singleCharacter.textColor, singleCharacter.hiddenColor) |
608 | |
609 | local offsetX, offsetY = 0, 0 |
610 | local spacingX, spacingY = font.spacingX, font.spacingY |
611 | if characterData ~= nil then |
612 | spacingX = characterData.spacingX or spacingX |
613 | spacingY = characterData.spacingY or spacingY |
614 | offsetX = characterData.offsetX or offsetX |
615 | offsetY = characterData.offsetY or offsetY |
616 | end |
617 | |
618 | local ratio = (1 - (spacingX * 2)) / (1 - (spacingY * 2)) |
619 | local scaleX = (singleCharacter.textSize * ratio) * singleCharacter.scaleX |
620 | local scaleY = singleCharacter.textSize * singleCharacter.scaleY |
621 | |
622 | setScale(singleCharacter.charNode, scaleX, scaleY, 1) |
623 | setTranslation(singleCharacter.charNode, scaleY * offsetX, scaleY * offsetY, 0) |
624 | end |
625 | end |
626 | |
627 | font.getFontMaxWidthRatio = function(_, alphabetical, numerical, special) |
628 | local maxRatio = 0 |
629 | for i=1, #font.characters do |
630 | local character = font.characters[i] |
631 | |
632 | if character.type == MaterialManager.FONT_CHARACTER_TYPE.ALPHABETICAL and alphabetical ~= false |
633 | or character.type == MaterialManager.FONT_CHARACTER_TYPE.NUMERICAL and numerical ~= false |
634 | or character.type == MaterialManager.FONT_CHARACTER_TYPE.SPECIAL and special ~= false then |
635 | local spacingX, spacingY = character.spacingX or font.spacingX, character.spacingY or font.spacingY |
636 | local ratio = (1 - (spacingX * 2)) / (1 - (spacingY * 2)) |
637 | maxRatio = math.max(ratio, maxRatio) |
638 | end |
639 | end |
640 | |
641 | return maxRatio |
642 | end |
643 | |
644 | table.insert(self.fontMaterials, font) |
645 | self.fontMaterialsByName[font.name] = font |
646 | end |
647 | |
648 | delete(i3dNode) |
649 | end |
650 | |
651 | xmlFile.references = xmlFile.references - 1 |
652 | if xmlFile.references == 0 then |
653 | xmlFile:delete() |
654 | |
655 | if self.finishedLoadingCallback ~= nil then |
656 | self.finishedLoadingCallback(self.callbackTarget) |
657 | self.finishedLoadingCallback = nil |
658 | self.callbackTarget = nil |
659 | end |
660 | end |
661 | end |
getBaseMaterialByName
DescriptionReturns base material by given nameDefinition
getBaseMaterialByName(string materialName)Arguments
string | materialName | materialName |
integer | materialId | internal material id |
158 | function MaterialManager:getBaseMaterialByName(materialName) |
159 | if materialName ~= nil then |
160 | return self.baseMaterialsByName[materialName:upper()] |
161 | end |
162 | |
163 | return nil |
164 | end |
getFontMaterial
DescriptionDefinitiongetFontMaterial()Code
295 | function MaterialManager:getFontMaterial(materialName, customEnvironment) |
296 | if customEnvironment ~= nil and customEnvironment ~= "" then |
297 | local customMaterialName = customEnvironment .. "." .. materialName |
298 | if self.fontMaterialsByName[customMaterialName] ~= nil then |
299 | return self.fontMaterialsByName[customMaterialName] |
300 | end |
301 | end |
302 | |
303 | return self.fontMaterialsByName[materialName] |
304 | end |
getMaterial
DescriptionReturns material for given propertiesDefinition
getMaterial(integer fillType, string materialTypeName, integer materialIndex)Arguments
integer | fillType | fill type |
string | materialTypeName | name of material type |
integer | materialIndex | index of material |
integer | materialId | id of material |
222 | function MaterialManager:getMaterial(fillType, materialTypeName, materialIndex) |
223 | return self:getMaterialFromTarget(self.materials, fillType, materialTypeName, materialIndex) |
224 | end |
getMaterialFromTarget
DescriptionReturns material for given propertiesDefinition
getMaterialFromTarget(integer fillType, string materialTypeName, integer materialIndex)Arguments
integer | fillType | fill type |
string | materialTypeName | name of material type |
integer | materialIndex | index of material |
integer | materialId | id of material |
242 | function MaterialManager:getMaterialFromTarget(target, fillType, materialTypeName, materialIndex) |
243 | if fillType == nil or materialTypeName == nil or materialIndex == nil then |
244 | return nil |
245 | end |
246 | |
247 | local materialType = self:getMaterialTypeByName(materialTypeName) |
248 | if materialType == nil then |
249 | return nil |
250 | end |
251 | |
252 | local fillTypeMaterials = target[fillType] |
253 | if fillTypeMaterials == nil then |
254 | --#debug log("Warning: missing fillType materials for fillType", g_fillTypeManager:getFillTypeNameByIndex(fillType), materialTypeName, materialIndex) |
255 | return nil |
256 | end |
257 | |
258 | local materials = fillTypeMaterials[materialType] |
259 | if materials == nil then |
260 | --#debug log("Warning: missing fillType materials for materialType", materialType) |
261 | return nil |
262 | end |
263 | |
264 | return materials[materialIndex] |
265 | end |
getMaterialTypeByName
DescriptionReturns a materialType by nameDefinition
getMaterialTypeByName(string name)Arguments
string | name | name of material type |
string | materialType | the real material name, nil if not defined |
132 | function MaterialManager:getMaterialTypeByName(name) |
133 | if name ~= nil then |
134 | name = name:upper() |
135 | |
136 | -- atm we just return the uppercase name because a material type is only defined as a base string |
137 | if self.nameToIndex[name] ~= nil then |
138 | return name |
139 | end |
140 | end |
141 | |
142 | return nil |
143 | end |
getParticleMaterial
DescriptionReturns material for given propertiesDefinition
getParticleMaterial(integer fillType, string materialTypeName, integer materialIndex)Arguments
integer | fillType | fill type |
string | materialTypeName | name of material type |
integer | materialIndex | index of material |
integer | materialId | id of material |
232 | function MaterialManager:getParticleMaterial(fillType, materialTypeName, materialIndex) |
233 | return self:getMaterialFromTarget(self.particleMaterials, fillType, materialTypeName, materialIndex) |
234 | end |
initDataStructures
DescriptionInitialize data structuresDefinition
initDataStructures()Code
38 | function MaterialManager:initDataStructures() |
39 | self.nameToIndex = {} |
40 | self.materialTypes = {} |
41 | self.materials = {} |
42 | self.particleMaterials = {} |
43 | self.modMaterialHoldersToLoad = {} |
44 | self.fontMaterials = {} |
45 | self.fontMaterialsByName = {} |
46 | |
47 | self.baseMaterials = {} |
48 | self.baseMaterialsByName = {} |
49 | |
50 | self.loadedMaterialHolderNodes = {} |
51 | end |
loadFontMaterialsXML
DescriptionDefinitionloadFontMaterialsXML()Code
308 | function MaterialManager:loadFontMaterialsXML(xmlFilename, customEnvironment, baseDirectory) |
309 | local xmlFile = XMLFile.load("TempFonts", xmlFilename, MaterialManager.fontMaterialXMLSchema) |
310 | if xmlFile ~= nil then |
311 | xmlFile.references = 0 |
312 | |
313 | xmlFile:iterate("fonts.font", function(index, key) |
314 | local name = xmlFile:getValue(key .. "#name") |
315 | local filename = xmlFile:getValue(key .. "#filename") |
316 | local node = xmlFile:getValue(key .. "#node") |
317 | local noNormalNode = xmlFile:getValue(key .. "#noNormalNode") |
318 | local characterShapePath = xmlFile:getValue(key .. "#characterShape") |
319 | if name ~= nil and filename ~= nil and node ~= nil then |
320 | if customEnvironment ~= nil and customEnvironment ~= "" then |
321 | name = customEnvironment .. "." .. name |
322 | end |
323 | |
324 | local font = {} |
325 | font.name = name |
326 | font.node = node |
327 | font.noNormalNode = noNormalNode |
328 | font.characterShapePath = characterShapePath |
329 | |
330 | xmlFile.references = xmlFile.references + 1 |
331 | |
332 | filename = Utils.getFilename(filename, baseDirectory) |
333 | |
334 | local arguments = { |
335 | xmlFile = xmlFile, |
336 | key = key, |
337 | font = font |
338 | } |
339 | font.sharedLoadRequestId = g_i3DManager:loadSharedI3DFileAsync(filename, false, false, self.fontMaterialLoaded, self, arguments) |
340 | end |
341 | end) |
342 | end |
343 | end |
loadMapData
DescriptionLoad data on map loadDefinition
loadMapData()Return Values
boolean | true | if loading was successful else false |
56 | function MaterialManager:loadMapData(xmlFile, missionInfo, baseDirectory, finishedLoadingCallback, callbackTarget) |
57 | MaterialManager:superClass().loadMapData(self) |
58 | |
59 | self:addMaterialType("fillplane") |
60 | self:addMaterialType("icon") |
61 | self:addMaterialType("unloading") |
62 | self:addMaterialType("smoke") |
63 | self:addMaterialType("straw") |
64 | self:addMaterialType("chopper") |
65 | self:addMaterialType("soil") |
66 | self:addMaterialType("sprayer") |
67 | self:addMaterialType("spreader") |
68 | self:addMaterialType("pipe") |
69 | self:addMaterialType("mower") |
70 | self:addMaterialType("belt") |
71 | self:addMaterialType("belt_cropDirt") |
72 | self:addMaterialType("belt_cropClean") |
73 | self:addMaterialType("leveler") |
74 | self:addMaterialType("washer") |
75 | self:addMaterialType("pickup") |
76 | |
77 | MaterialType = self.nameToIndex |
78 | |
79 | -- called after last font material was loaded |
80 | self.finishedLoadingCallback = finishedLoadingCallback |
81 | self.callbackTarget = callbackTarget |
82 | |
83 | self:loadFontMaterialsXML(MaterialManager.DEFAULT_FONT_MATERIAL_XML, nil, self.baseDirectory) |
84 | |
85 | return true |
86 | end |
loadModMaterialHolders
DescriptionDefinitionloadModMaterialHolders()Code
275 | function MaterialManager:loadModMaterialHolders() |
276 | for filename, _ in pairs(self.modMaterialHoldersToLoad) do |
277 | g_i3DManager:loadI3DFileAsync(filename, true, true, MaterialManager.materialHolderLoaded, self, nil) |
278 | end |
279 | end |
materialHolderLoaded
DescriptionDefinitionmaterialHolderLoaded()Code
283 | function MaterialManager:materialHolderLoaded(i3dNode, failedReason, args) |
284 | for i=getNumOfChildren(i3dNode)-1, 0, -1 do |
285 | local child = getChildAt(i3dNode, i) |
286 | unlink(child) |
287 | table.insert(self.loadedMaterialHolderNodes, child) |
288 | end |
289 | |
290 | delete(i3dNode) |
291 | end |
new
DescriptionCreating managerDefinition
new()Return Values
table | instance | instance of object |
27 | function MaterialManager.new(customMt) |
28 | local self = AbstractManager.new(customMt or MaterialManager_mt) |
29 | |
30 | MaterialManager.fontMaterialXMLSchema = XMLSchema.new("fontMaterials") |
31 | MaterialManager.registerXMLPaths(MaterialManager.fontMaterialXMLSchema) |
32 | |
33 | return self |
34 | end |
registerXMLPaths
DescriptionDefinitionregisterXMLPaths()Code
665 | function MaterialManager.registerXMLPaths(schema) |
666 | schema:register(XMLValueType.STRING, "fonts.font(?)#name", "Name if font") |
667 | schema:register(XMLValueType.STRING, "fonts.font(?)#filename", "Path to i3d file") |
668 | schema:register(XMLValueType.STRING, "fonts.font(?)#node", "Path to material node") |
669 | schema:register(XMLValueType.STRING, "fonts.font(?)#characterShape", "Path to character mesh") |
670 | schema:register(XMLValueType.STRING, "fonts.font(?)#noNormalNode", "Path to material node without normal map") |
671 | |
672 | schema:register(XMLValueType.FLOAT, "fonts.font(?).spacing#x", "X Spacing", 0) |
673 | schema:register(XMLValueType.FLOAT, "fonts.font(?).spacing#y", "Y Spacing", 0) |
674 | schema:register(XMLValueType.FLOAT, "fonts.font(?).spacing#charToChar", "Spacing from character to character in percentage", 0.1) |
675 | |
676 | schema:register(XMLValueType.INT, "fonts.font(?).character(?)#uvIndex", "Index on uv map", 0) |
677 | schema:register(XMLValueType.STRING, "fonts.font(?).character(?)#value", "Character value") |
678 | schema:register(XMLValueType.STRING, "fonts.font(?).character(?)#type", "Character type", "alphabetical") |
679 | schema:register(XMLValueType.FLOAT, "fonts.font(?).character(?)#spacingX", "Custom spacing X") |
680 | schema:register(XMLValueType.FLOAT, "fonts.font(?).character(?)#spacingY", "Custom spacing Y") |
681 | schema:register(XMLValueType.FLOAT, "fonts.font(?).character(?)#offsetX", "Custom X offset for created char lines (percentage)", 0) |
682 | schema:register(XMLValueType.FLOAT, "fonts.font(?).character(?)#offsetY", "Custom Y offset for created char lines (percentage)", 0) |
683 | schema:register(XMLValueType.FLOAT, "fonts.font(?).character(?)#realSpacingX", "Real spacing from border to visual beginning") |
684 | end |
unloadMapData
DescriptionDefinitionunloadMapData()Code
90 | function MaterialManager:unloadMapData() |
91 | for _, node in ipairs(self.loadedMaterialHolderNodes) do |
92 | delete(node) |
93 | end |
94 | |
95 | for _, font in ipairs(self.fontMaterials) do |
96 | delete(font.materialNode) |
97 | if font.materialNodeNoNormal ~= nil then |
98 | delete(font.materialNodeNoNormal) |
99 | end |
100 | if font.characterShape ~= nil then |
101 | delete(font.characterShape) |
102 | end |
103 | if font.sharedLoadRequestId ~= nil then |
104 | g_i3DManager:releaseSharedI3DFile(font.sharedLoadRequestId) |
105 | end |
106 | end |
107 | |
108 | MaterialManager:superClass().unloadMapData(self) |
109 | end |