diff --git a/Engine/source/console/simObject.cpp b/Engine/source/console/simObject.cpp index 1a76e23fe..3552f4dd1 100644 --- a/Engine/source/console/simObject.cpp +++ b/Engine/source/console/simObject.cpp @@ -338,7 +338,7 @@ void SimObject::writeFields(Stream &stream, U32 tabStop) //If the field hasn't been changed from the default value, then don't bother writing it out const char* defaultValueCheck = defaultObject->getDataField(f->pFieldname, array); - if (dStricmp(defaultValueCheck, valCopy) == 0) + if (defaultValueCheck != '\0' && dStricmp(defaultValueCheck, valCopy) == 0) continue; val = valCopy; diff --git a/Engine/source/persistence/taml/taml.cpp b/Engine/source/persistence/taml/taml.cpp index 782731a80..5200dcf28 100644 --- a/Engine/source/persistence/taml/taml.cpp +++ b/Engine/source/persistence/taml/taml.cpp @@ -728,7 +728,8 @@ ImplementEnumType(_TamlFormatMode, if (!getWriteDefaults()) { //If the field hasn't been changed from the default value, then don't bother writing it out - if (dStricmp(defaultObject->getDataField(fieldName, indexBuffer), pFieldValue) == 0) + const char* fieldData = defaultObject->getDataField(fieldName, indexBuffer); + if (fieldData != '\0' && dStricmp(fieldData, pFieldValue) == 0) continue; } diff --git a/Templates/BaseGame/game/tools/projectImporter/importers/pre40/T3Dpre4ProjectImporter.tscript b/Templates/BaseGame/game/tools/projectImporter/importers/pre40/T3Dpre4ProjectImporter.tscript index e109d2f5e..c6ac5c2b2 100644 --- a/Templates/BaseGame/game/tools/projectImporter/importers/pre40/T3Dpre4ProjectImporter.tscript +++ b/Templates/BaseGame/game/tools/projectImporter/importers/pre40/T3Dpre4ProjectImporter.tscript @@ -892,6 +892,77 @@ T3Dpre4ProjectImporter::genProcessor("Material", $MaterialEntriesList); //============================================================================== function T3Dpre4ProjectImporter::processMaterialObject(%this, %fileObject, %objectName) { + //first, lets do a bit of use-case checking. Materials are sometimes companion to + //a terrain material for effects and game physics behavior and may not be immediately + //obviously assocated. Lets check for that first before processing this as a regular material + %mapTo = findObjectField(%fileObject, "mapTo"); + if(%mapTo !$= "") + { + %terrainMatAsset = ""; + %terrainMat = ""; + if(isObject(%mapTo) && %mapTo.getClassName() $= "TerrainMaterial") + { + //If the terrain material already exists as a full object, look up it's + //asset to associate this FX material to it + %terrainMatAsset = TerrainMaterialAsset::getAssetIdByMaterialName(%mapTo.getName()); + + //Now we make our scripted definition "real", and append it to our asset + //so it is serialized. + %objectDefinition = ""; + for(%l=0; %l < %fileObject.count(); %l++) + { + %objectLine = %fileObject.getKey(%l); + if(!isObject(%objectLine)) + { + %objectDefinition = %objectDefinition @ %objectLine; + } + } + + eval(%objectDefinition); + + if(isObject(%objectName)) + { + %terrainMatAsset.add(%objectName); + + %terrainMatAsset.saveAsset(); + %fileObject.processed = true; + %fileObject.skip = true; //don't write the def back out to script, it's not needed now + } + + return false; + } + else + { + //No existing object, so probably incoming with the import, so lets go + //look for it + %terrMatList = getObjectsInFilesByClass("TerrainMaterial"); + for(%i=0; %i < getFieldCount(%terrMatList); %i++) + { + %terrainMatObj = getField(%terrMatList, %i); + if(%terrainMatObj.objectName $= %mapTo) + { + %terrainMat = %terrainMatObj; + } + else + { + %terrainObjIntName = findObjectField(%terrainMatObj, "internalName"); + if(%terrainObjIntName $= %mapTo) + { + %terrainMat = %terrainMatObj; + } + } + + if(%terrainMat !$= "") + { + //found it, not imported yet, so mark it for later + %terrainMat.FXMaterial = %fileObject; + + return false; + } + } + } + } + %matAsset = MaterialAsset::getAssetIdByMaterialName(%objectName); if(%matAsset $= "" || %matAsset $= "Core_Rendering:NoMaterial") @@ -1045,6 +1116,8 @@ function T3Dpre4ProjectImporter::processTerrainMaterialObject(%this, %fileObject materialDefinitionName = %objectName; }; + renameObjectName(%fileObject, %objectName); + //Now we make our scripted definition "real", and append it to our asset //so it is serialized. %objectDefinition = ""; @@ -1057,9 +1130,6 @@ function T3Dpre4ProjectImporter::processTerrainMaterialObject(%this, %fileObject } } - //Shift to object name, internal name will be used for assetID store - %objectDefinition.name = findObjectField(%fileObject, "internalName"); - eval(%objectDefinition); if(isObject(%objectName)) @@ -1072,6 +1142,69 @@ function T3Dpre4ProjectImporter::processTerrainMaterialObject(%this, %fileObject %asset.add(%objectName); } + else + { + error("T3Dpre4ProjectImporter::processTerrainMaterialObject() - failed to parse terrainmat object: "); + echo(%objectDefinition); + } + + if(%fileObject.FXMaterial $= "") + { + //on the off-chance it exists, try scanning for FX materials associated + //to this terrain material + %fxMat = findObjectInFiles("TerrainFX_" @ %objectName); + if(%fxMat !$= "" && %objectName.classType $= "Material") + { + %fileObject.FXMaterial = %fxMat; + } + else + { + %fxMatList = getObjectsInFilesByClass("Material"); + for(%i=0; %i < getFieldCount(%fxMatList); %i++) + { + %fxMatObj = getField(%fxMatList, %i); + %fxMatObjMapTo = findObjectField(%fxMatObj, "mapTo"); + if(%fxMatObjMapTo $= %objectName) + { + %fileObject.FXMaterial = %fxMatObj; + break; + } + } + } + } + + if(%fileObject.FXMaterial !$= "") + { + //Ensure our mapto is up to date for any name sanitize/tweaks + setObjectField(%fileObject.FXMaterial, "mapTo", %objectName); + + //we associated to an FX material, so process that now + %objectDefinition = ""; + for(%l=0; %l < %fileObject.FXMaterial.count(); %l++) + { + %objectLine = %fileObject.FXMaterial.getKey(%l); + if(!isObject(%objectLine)) + { + %objectDefinition = %objectDefinition @ %objectLine; + } + } + + eval(%objectDefinition); + + if(isObject(%fileObject.FXMaterial.objectName)) + { + //if we created it successfully, set up inheritance for serialization if needed + if(%fileObject.FXMaterial.parentName !$= "") + { + %fileObject.FXMaterial.setFieldValue("inheritFrom",%fileObject.FXMaterial.parentName); + } + + %asset.add(%fileObject.FXMaterial.objectName); + } + + %fileObject.FXMaterial.processed = true; + %fileObject.FXMaterial.skip = true; + } %success = false; if(TamlWrite(%asset, %tamlpath)) diff --git a/Templates/BaseGame/game/tools/projectImporter/scripts/projectImporter.tscript b/Templates/BaseGame/game/tools/projectImporter/scripts/projectImporter.tscript index af600e8c3..2e98c9b03 100644 --- a/Templates/BaseGame/game/tools/projectImporter/scripts/projectImporter.tscript +++ b/Templates/BaseGame/game/tools/projectImporter/scripts/projectImporter.tscript @@ -870,11 +870,8 @@ function findFileInImporting(%checkFile) //============================================================================== // Checks if the object in question is defined in any of our pre-scanned list of importing files //============================================================================== -function findObjectInFiles(%objectName, %arrayObj) +function findObjectInFilesRecurse(%objectName, %arrayObj) { - if(%arrayObj $= "") - %arrayObj = $ProjectImporter::FileList; - for(%i=0; %i < %arrayObj.count(); %i++) { %objectLine = %arrayObj.getKey(%i); @@ -884,7 +881,7 @@ function findObjectInFiles(%objectName, %arrayObj) return %objectLine; //If this object isn't it, try recursing any children - %result = findObjectInFiles(%objectName, %objectLine); + %result = findObjectInFilesRecurse(%objectName, %objectLine); if(%result !$= "") return %result; } @@ -893,6 +890,65 @@ function findObjectInFiles(%objectName, %arrayObj) return ""; } +function findObjectInFiles(%objectName) +{ + for(%i=0; %i < $ProjectImporter::FileList.count(); %i++) + { + %objectLine = $ProjectImporter::FileList.getValue(%i); + if(isObject(%objectLine)) + { + if(%objectLine.objectName $= %objectName) + return %objectLine; + + //If this object isn't it, try recursing any children + %result = findObjectInFilesRecurse(%objectName, %objectLine); + if(%result !$= "") + return %result; + } + } + + return ""; +} + +//============================================================================== +// Checks if the object in question is defined in any of our pre-scanned list of importing files +//============================================================================== +function getObjectsInFilesByClassRecurse(%className, %arrayObj) +{ + for(%i=0; %i < %arrayObj.count(); %i++) + { + %objectLine = %arrayObj.getKey(%i); + if(isObject(%objectLine)) + { + if(%objectLine.classType $= %className) + $ProjectImporter::queryList = $ProjectImporter::queryList TAB %objectLine; + + //If this object isn't it, try recursing any children + getObjectsInFilesByClassRecurse(%className, %objectLine); + } + } +} + +function getObjectsInFilesByClass(%className) +{ + $ProjectImporter::queryList = ""; + + for(%i=0; %i < $ProjectImporter::FileList.count(); %i++) + { + %objectLine = $ProjectImporter::FileList.getValue(%i); + if(isObject(%objectLine)) + { + if(%objectLine.classType $= %className) + $ProjectImporter::queryList = $ProjectImporter::queryList TAB %objectLine; + + //If this object isn't it, try recursing any children + getObjectsInFilesByClassRecurse(%className, %objectLine); + } + } + + return ltrim($ProjectImporter::queryList); +} + //============================================================================== // Takes a filename lacking an extension and then checks common file extensions // to see if we can find the actual file in question @@ -1110,18 +1166,30 @@ function renameObjectName(%object, %newName) %objectLine = %object.getKey(%e); if(!isObject(%objectLine)) { - if(strIsMatchExpr("*singleton*(*)*", %objectLine) && - strIsMatchExpr("*new*(*)*", %objectLine) && + if(strIsMatchExpr("*singleton*(*)*", %objectLine) || + strIsMatchExpr("*new*(*)*", %objectLine) || strIsMatchExpr("*datablock*(*)*", %objectLine)) { - %newLine = strreplace(%object.objectName, %newName); - - echo("renameObjectName() - lines changed from:"); - echo(%objectLine); - echo("to:"); - echo(%newLine); + if(%object.objectName $= "") + { + %start = strpos(%objectLine, "("); + %end = strpos(%objectLine, ")", %start); + + %preString = getSubStr(%objectLine, 0, %start+1); + %postString = getSubStr(%objectLine, %end); + + %renamedString = %preString @ %newName @ %postString; + + %newLine = %renamedString; + } + else + { + %newLine = strreplace(%objectLine, %object.objectName, %newName); + } %object.setKey(%newLine, %e); + + %object.objectName = %newName; } } } @@ -1258,6 +1326,28 @@ function setObjectField(%object, %fieldName, %newValue) } } +//============================================================================== +// Inserts a new field to an object's block in the preprocessed data +//============================================================================== +function insertObjectLine(%object, %newLine) +{ + for(%e=0; %e < %object.count(); %e++) + { + %objectLine = %object.getKey(%e); + + if(strIsMatchExpr("*{*", %objectLine) || + strIsMatchExpr("*singleton*(*)*", %objectLine) || + strIsMatchExpr("*new*(*)*", %objectLine) || + strIsMatchExpr("*datablock*(*)*", %objectLine)) + { + continue; + } + + %object.insert(%newLine, "", %e); + return; + } +} + //============================================================================== // Takes a string and adds it to the importer's log. Optionally can print the line // directly to console for debugging purposes