Shifts handling of material and terrain material definitions to be written into the asset definition taml file instead of having an extra loose file

Also updates importers to correctly handle this change
Adds ability for taml XML serialization to properly assign array'd fields
Adds 'inheritFrom' field to simobjects for when objects with parent objects are serialized
AssetBase how inherits from SimGroup so it can have objects like material definitions embedded in them for save/load in the taml definition file
Updated loading/handling logic in terrain material asset to be more similar to regular material assets
This commit is contained in:
JeffR 2022-01-30 11:50:16 -06:00
parent 656475deaf
commit 630285def6
20 changed files with 791 additions and 318 deletions

View file

@ -200,7 +200,7 @@ function T3Dpre4ProjectImporter::writeImportingFiles(%this)
if($ProjectImporter::useExistingModule)
{
//clean up legact files if they've been renamed or whatnot
if(%file !$= %rootFileSectionObject.fileDestination)
if(makeRelativePath(%file) !$= %rootFileSectionObject.fileDestination)
{
fileDelete(%file);
}
@ -659,8 +659,6 @@ function T3Dpre4ProjectImporter::processAssetFile(%this, %assetObj)
if(!isObject(%assetObj))
return;
%assetObj.echo();
//really, we only care here about ensuring the file extensions are cleaned up
for(%l=0; %l < %assetObj.count(); %l++)
{
@ -691,6 +689,9 @@ function T3Dpre4ProjectImporter::beginAssetAndModuleImport(%this)
if(%fileExt $= ".module")
{
if(%rootFileSectionObject.skip)
continue;
projectImporterLog("T3Dpre4ProjectImporter::beginAssetAndModuleImport() - processing file: " @ %file);
$ProjectImporter::currentFilePath = filePath(%rootFileSectionObject.fileDestination) @ "/";
%this.processModuleFile(%rootFileSectionObject);
@ -698,6 +699,9 @@ function T3Dpre4ProjectImporter::beginAssetAndModuleImport(%this)
}
else if(%fileExt $= ".asset.taml")
{
if(%rootFileSectionObject.skip)
continue;
projectImporterLog("T3Dpre4ProjectImporter::beginAssetAndModuleImport() - processing file: " @ %file);
$ProjectImporter::currentFilePath = filePath(%rootFileSectionObject.fileDestination) @ "/";
%this.processAssetFile(%rootFileSectionObject);
@ -913,12 +917,11 @@ function T3Dpre4ProjectImporter::processMaterialObject(%this, %fileObject, %obje
versionId = 1;
shaderData = "";
materialDefinitionName = %assetName;
scriptFile = fileBase(%scriptPath);
};
//Now we make our scripted definition "real", and append it to our asset
//so it is serialized.
/*%objectDefinition = "";
%objectDefinition = "";
for(%l=0; %l < %fileObject.count(); %l++)
{
%objectLine = %fileObject.getKey(%l);
@ -932,8 +935,14 @@ function T3Dpre4ProjectImporter::processMaterialObject(%this, %fileObject, %obje
if(isObject(%objectName))
{
//if we created it successfully, set up inheritance for serialization if needed
if(%fileObject.parentName !$= "")
{
%objectName.setFieldValue("inheritFrom",%fileObject.parentName);
}
%asset.add(%objectName);
}*/
}
if(!isDirectory(%assetPath))
{
@ -943,26 +952,6 @@ function T3Dpre4ProjectImporter::processMaterialObject(%this, %fileObject, %obje
%success = false;
if(TamlWrite(%asset, %tamlpath))
{
//now write the script file
if ( $ProjectImporter::fileObject.openForWrite( %scriptPath ) )
{
for(%i=0; %i < %fileObject.count(); %i++)
{
%objectLine = %fileObject.getKey(%i);
if(isObject(%objectLine))
{
%defineLine = %fileObject.getKey(0);
$ProjectImporter::fileObject.writeLine(%defineLine);
}
else
{
$ProjectImporter::fileObject.writeLine(%objectLine);
}
}
$ProjectImporter::fileObject.close();
}
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
%success = AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
@ -971,6 +960,43 @@ function T3Dpre4ProjectImporter::processMaterialObject(%this, %fileObject, %obje
if(!%success)
return false;
}
else
{
//process an existing material asset, if needbe
%assetDef = AssetDatabase.acquireAsset(%matAsset);
%assetScriptPath = %assetDef.getScriptPath();
if(isFile(%assetScriptPath) && isObject(%objectName))
{
//Regular material in a companion file, so we'll want to write it to the
//asset def file instead of the loose file
%assetDef.scriptFile = ""; //clear the old script path reference
%assetDef.add(%objectName); //child the definition to the asset def
if(%fileObject.parentName !$= "")
{
%objectName.setFieldValue("inheritFrom",%fileObject.parentName);
}
if(%assetDef.saveAsset())
{
%fileObject.processed = true;
%fileObject.skip = true; //don't write the def back out to script, it's not needed now
%assetFileObj = findFileInImporting(makeFullPath(AssetDatabase.getAssetFilePath(%matAsset)));
echo(%assetFileObj.fileDestination);
%assetFileObj.processed = true;
%assetFileObj.skip = true; //this asset definition has been processed
//so nothing else need be done
}
else
{
projectImporterLog("T3Dpre4ProjectImporter::processMaterialObject() - failed to save out modified material asset for: " @ %matAsset);
}
}
}
return false;
}
@ -1017,9 +1043,36 @@ function T3Dpre4ProjectImporter::processTerrainMaterialObject(%this, %fileObject
versionId = 1;
shaderData = "";
materialDefinitionName = %objectName;
scriptFile = fileName(%scriptPath);
};
//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;
}
}
//Shift to object name, internal name will be used for assetID store
%objectDefinition.name = findObjectField(%fileObject, "internalName");
eval(%objectDefinition);
if(isObject(%objectName))
{
//if we created it successfully, set up inheritance for serialization if needed
if(%fileObject.parentName !$= "")
{
%objectName.setFieldValue("inheritFrom",%fileObject.parentName);
}
%asset.add(%objectName);
}
%success = false;
if(TamlWrite(%asset, %tamlpath))
{
@ -1031,6 +1084,43 @@ function T3Dpre4ProjectImporter::processTerrainMaterialObject(%this, %fileObject
if(!%success)
return false;
}
else
{
//process an existing material asset, if needbe
%assetDef = AssetDatabase.acquireAsset(%matAsset);
%assetScriptPath = %assetDef.getScriptPath();
if(isFile(%assetScriptPath) && isObject(%objectName))
{
//Regular material in a companion file, so we'll want to write it to the
//asset def file instead of the loose file
%assetDef.scriptFile = ""; //clear the old script path reference
%assetDef.add(%objectName); //child the definition to the asset def
if(%fileObject.parentName !$= "")
{
%objectName.setFieldValue("inheritFrom",%fileObject.parentName);
}
if(%assetDef.saveAsset())
{
%fileObject.processed = true;
%fileObject.skip = true; //don't write the def back out to script, it's not needed now
%assetFileObj = findFileInImporting(makeFullPath(AssetDatabase.getAssetFilePath(%matAsset)));
echo(%assetFileObj.fileDestination);
%assetFileObj.processed = true;
%assetFileObj.skip = true; //this asset definition has been processed
//so nothing else need be done
}
else
{
projectImporterLog("T3Dpre4ProjectImporter::processTerrainMaterialObject() - failed to save out modified material asset for: " @ %matAsset);
}
}
}
return false;
}
@ -1122,25 +1212,12 @@ function T3Dpre4ProjectImporter::processSFXProfileObject(%this, %file, %objectNa
}
else
{
%objFileFinder = "";
//first check our cache
if(isObject($ProjectImporter::SFXDescriptionCache) &&
$ProjectImporter::SFXDescriptionCache.getIndexFromKey(%descriptionName) !$= "")
{
%key = $ProjectImporter::SFXDescriptionCache.getIndexFromKey(%descriptionName);
%objFileFinder = $ProjectImporter::SFXDescriptionCache.getValue(%key);
}
else
{
%objFileFinder = findObjectInFiles(%descriptionName);
}
%fileObj = findObjectInFiles(%descriptionName);
if(%objFileFinder !$= "")
if(%fileObj !$= "")
{
%valueArray = new ArrayObject();
%fileObj = getField(%objFileFinder, 0);
%valueArray.add("sourceGroup" SPC findObjectField(%fileObj, "sourceGroup"));
%valueArray.add("volume" SPC findObjectField(%fileObj, "volume"));
%valueArray.add("pitch" SPC findObjectField(%fileObj, "pitch"));
@ -1157,10 +1234,7 @@ function T3Dpre4ProjectImporter::processSFXProfileObject(%this, %file, %objectNa
%valueArray.add("rolloffFactor" SPC findObjectField(%fileObj, "rolloffFactor"));
%valueArray.add("isStreaming" SPC findObjectField(%fileObj, "isStreaming"));
if(isObject($ProjectImporter::SFXDescriptionCache))
{
$ProjectImporter::SFXDescriptionCache.add(%descriptionName, %objFileFinder);
}
%fileObj.skip = true;
for(%v=0; %v < %valueArray.Count(); %v++)
{

View file

@ -242,7 +242,7 @@ function ProjectImportWizardPage3::openPage(%this)
%dataFullPath = makeFullPath("data/");
%coreFullPath = makeFullPath("core/");
%toolsFullPath = makeFullPath("tools/");
if(startsWith(makeFullPath("data/"), $ProjectImporter::sourceContentFolder))
if(startsWith($ProjectImporter::sourceContentFolder, makeFullPath("data/")))
{
%moduleDef = AssetBrowser.dirHandler.getModuleFromAddress(makeRelativePath($ProjectImporter::sourceContentFolder));
if(isObject(%moduleDef))
@ -254,8 +254,8 @@ function ProjectImportWizardPage3::openPage(%this)
ProjectImportWindow.setStep(4);
}
}
else if(startsWith(makeFullPath("core/"), $ProjectImporter::sourceContentFolder) ||
startsWith(makeFullPath("tools/"), $ProjectImporter::sourceContentFolder))
else if(startsWith($ProjectImporter::sourceContentFolder, makeFullPath("core/")) ||
startsWith($ProjectImporter::sourceContentFolder, makeFullPath("tools/")))
{
ProjectImportWindow.setStep(5);
}
@ -490,9 +490,11 @@ function preprocessImportingFiles()
%objectName = getSubStr(%line, %end+1, %nameEnd-%end-1);
%parentName = "";
%inheritanceSplit = strpos(%objectName, ":");
if(%inheritanceSplit != -1)
{
%parentName = getSubStr(%objectName, %inheritanceSplit + 1);
%objectName = getSubStr(%objectName, 0, %inheritanceSplit);
}
@ -502,6 +504,7 @@ function preprocessImportingFiles()
%currentFileSectionObject.elementType = "object";
%currentFileSectionObject.classType = %className;
%currentFileSectionObject.objectName = %objectName;
%currentFileSectionObject.parentName = %parentName;
%currentFileSectionObject.fileName = %file;
%currentFileSectionObject.skip = false;
%currentFileSectionObject.fileDestination = %rootFileSectionObject.fileDestination;
@ -510,6 +513,7 @@ function preprocessImportingFiles()
%currentFileSectionObject.add(%line);
%parentFileSectionObject.add(%currentFileSectionObject);
%currentFileSectionObject.parentElement = %parentFileSectionObject;
//Now for a sanity check, see if we kill the object on the same line as we make it
//sometimes people try and be 'efficient' with their code linecount wise
@ -540,9 +544,11 @@ function preprocessImportingFiles()
%objectName = getSubStr(%line, %end+1, %nameEnd-%end-1);
%parentName = "";
%inheritanceSplit = strpos(%objectName, ":");
if(%inheritanceSplit != -1)
{
%parentName = getSubStr(%objectName, %inheritanceSplit + 1);
%objectName = getSubStr(%objectName, 0, %inheritanceSplit);
}
@ -552,6 +558,7 @@ function preprocessImportingFiles()
%currentFileSectionObject.elementType = "object";
%currentFileSectionObject.classType = %className;
%currentFileSectionObject.objectName = %objectName;
%currentFileSectionObject.parentName = %parentName;
%currentFileSectionObject.fileName = %file;
%currentFileSectionObject.skip = false;
%currentFileSectionObject.fileDestination = %rootFileSectionObject.fileDestination;
@ -560,6 +567,7 @@ function preprocessImportingFiles()
%currentFileSectionObject.add(%line);
%parentFileSectionObject.add(%currentFileSectionObject);
%currentFileSectionObject.parentElement = %parentFileSectionObject;
//Now for a sanity check, see if we kill the object on the same line as we make it
//sometimes people try and be 'efficient' with their code linecount wise
@ -590,9 +598,11 @@ function preprocessImportingFiles()
%objectName = getSubStr(%line, %end+1, %nameEnd-%end-1);
%parentName = "";
%inheritanceSplit = strpos(%objectName, ":");
if(%inheritanceSplit != -1)
{
%parentName = getSubStr(%objectName, %inheritanceSplit + 1);
%objectName = getSubStr(%objectName, 0, %inheritanceSplit);
}
@ -602,6 +612,7 @@ function preprocessImportingFiles()
%currentFileSectionObject.elementType = "object";
%currentFileSectionObject.classType = %className;
%currentFileSectionObject.objectName = %objectName;
%currentFileSectionObject.parentName = %parentName;
%currentFileSectionObject.fileName = %file;
%currentFileSectionObject.skip = false;
%currentFileSectionObject.fileDestination = %rootFileSectionObject.fileDestination;
@ -610,6 +621,7 @@ function preprocessImportingFiles()
%currentFileSectionObject.add(%line);
%parentFileSectionObject.add(%currentFileSectionObject);
%currentFileSectionObject.parentElement = %parentFileSectionObject;
//Now for a sanity check, see if we kill the object on the same line as we make it
//sometimes people try and be 'efficient' with their code linecount wise
@ -650,6 +662,7 @@ function preprocessImportingFiles()
%currentFileSectionObject.add(%line);
%parentFileSectionObject.add(%currentFileSectionObject);
%currentFileSectionObject.parentElement = %parentFileSectionObject;
if(strIsMatchExpr("*{*", %line))
{
@ -838,6 +851,48 @@ function isImportingFile(%checkFile)
return false;
}
//==============================================================================
// Returns the file object of the file in question is part of our pre-scanned list of importing files
//==============================================================================
function findFileInImporting(%checkFile)
{
for(%i=0; %i < $ProjectImporter::FileList.count(); %i++)
{
%file = $ProjectImporter::FileList.getKey(%i);
if(%file $= %checkFile)
return $ProjectImporter::FileList.getValue(%i);
}
return "";
}
//==============================================================================
// Checks if the object in question is defined in any of our pre-scanned list of importing files
//==============================================================================
function findObjectInFiles(%objectName, %arrayObj)
{
if(%arrayObj $= "")
%arrayObj = $ProjectImporter::FileList;
for(%i=0; %i < %arrayObj.count(); %i++)
{
%objectLine = %arrayObj.getKey(%i);
if(isObject(%objectLine))
{
if(%objectLine.objectName $= %objectName)
return %objectLine;
//If this object isn't it, try recursing any children
%result = findObjectInFiles(%objectName, %objectLine);
if(%result !$= "")
return %result;
}
}
return "";
}
//==============================================================================
// Takes a filename lacking an extension and then checks common file extensions
// to see if we can find the actual file in question
@ -1215,6 +1270,32 @@ function projectImporterLog(%line)
$ProjectImporter::log.add(%line);
}
//==============================================================================
// Traverses the object delcaration stack backwards to find the root file object
//==============================================================================
function getParentFileObjectFromObject(%object)
{
while(%object.parentElement !$= "")
{
%object = %object.parentElement;
}
return %object;
}
//==============================================================================
// Traverses the object delcaration stack backwards to find the root file object
//==============================================================================
function getParentFileObjectFromObject(%object)
{
while(%object.parentElement !$= "")
{
%object = %object.parentElement;
}
return %object;
}
//==============================================================================
//Shape Importing
//==============================================================================