|
@@ -36,6 +36,7 @@ AssetImportConfig::AssetImportConfig() :
|
|
|
WarningsAsErrors(false),
|
|
|
PreventImportWithErrors(true),
|
|
|
AutomaticallyPromptMissingFiles(false),
|
|
|
+ AddDirectoryPrefixToAssetName(false),
|
|
|
ImportMesh(true),
|
|
|
AlwaysAddShapeSuffix(false),
|
|
|
AddedShapeSuffix("_shape"),
|
|
@@ -89,7 +90,7 @@ AssetImportConfig::AssetImportConfig() :
|
|
|
ImageType("GUI"),
|
|
|
DiffuseTypeSuffixes("_ALBEDO,_DIFFUSE,_ALB,_DIF,_COLOR,_COL,_A,_C,-ALBEDO,-DIFFUSE,-ALB,-DIF,-COLOR,-COL,-A,-C"),
|
|
|
NormalTypeSuffixes("_NORMAL,_NORM,_N,-NORMAL,-NORM,-N"),
|
|
|
- MetalnessTypeSuffixes("_METAL,_MET,_METALNESS,_METALLIC,_M,-METAL, -MET, -METALNESS, -METALLIC, -M"),
|
|
|
+ MetalnessTypeSuffixes("_METAL,_MET,_METALNESS,_METALLIC,_M,-METAL,-MET,-METALNESS,-METALLIC,-M"),
|
|
|
RoughnessTypeSuffixes("_ROUGH,_ROUGHNESS,_R,-ROUGH,-ROUGHNESS,-R"),
|
|
|
SmoothnessTypeSuffixes("_SMOOTH,_SMOOTHNESS,_S,-SMOOTH,-SMOOTHNESS,-S"),
|
|
|
AOTypeSuffixes("_AO,_AMBIENT,_AMBIENTOCCLUSION,-AO,-AMBIENT,-AMBIENTOCCLUSION"),
|
|
@@ -135,6 +136,7 @@ void AssetImportConfig::initPersistFields()
|
|
|
addField("WarningsAsErrors", TypeBool, Offset(WarningsAsErrors, AssetImportConfig), "Indicates if warnings should be treated as errors");
|
|
|
addField("PreventImportWithErrors", TypeBool, Offset(PreventImportWithErrors, AssetImportConfig), "Indicates if importing should be prevented from completing if any errors are detected at all");
|
|
|
addField("AutomaticallyPromptMissingFiles", TypeBool, Offset(AutomaticallyPromptMissingFiles, AssetImportConfig), "Should the importer automatically prompt to find missing files if they are not detected automatically by the importer");
|
|
|
+ addField("AddDirectoryPrefixToAssetName", TypeBool, Offset(AddDirectoryPrefixToAssetName, AssetImportConfig), "Should the importer add the folder name as a prefix to the assetName. Helps prevent name collisions.");
|
|
|
endGroup("General");
|
|
|
|
|
|
addGroup("Meshes");
|
|
@@ -232,6 +234,7 @@ void AssetImportConfig::loadImportConfig(Settings* configSettings, String config
|
|
|
WarningsAsErrors = dAtob(configSettings->value(String(configName + "/General/WarningsAsErrors").c_str()));
|
|
|
PreventImportWithErrors = dAtob(configSettings->value(String(configName + "/General/PreventImportWithErrors").c_str()));
|
|
|
AutomaticallyPromptMissingFiles = dAtob(configSettings->value(String(configName + "/General/AutomaticallyPromptMissingFiles").c_str()));
|
|
|
+ AddDirectoryPrefixToAssetName = dAtob(configSettings->value(String(configName + "/General/AddDirectoryPrefixToAssetName").c_str()));
|
|
|
|
|
|
//Meshes
|
|
|
ImportMesh = dAtob(configSettings->value(String(configName + "/Meshes/ImportMesh").c_str()));
|
|
@@ -321,6 +324,7 @@ void AssetImportConfig::CopyTo(AssetImportConfig* target) const
|
|
|
target->WarningsAsErrors = WarningsAsErrors;
|
|
|
target->PreventImportWithErrors = PreventImportWithErrors;
|
|
|
target->AutomaticallyPromptMissingFiles = AutomaticallyPromptMissingFiles;
|
|
|
+ target->AddDirectoryPrefixToAssetName = AddDirectoryPrefixToAssetName;
|
|
|
|
|
|
//Meshes
|
|
|
target->ImportMesh = ImportMesh;
|
|
@@ -1444,8 +1448,8 @@ void AssetImporter::processImportAssets(AssetImportObject* assetItem)
|
|
|
if (!childItem->processed)
|
|
|
{
|
|
|
//Sanitize before modifying our asset name(suffix additions, etc)
|
|
|
- if (childItem->assetName != childItem->cleanAssetName)
|
|
|
- childItem->assetName = childItem->cleanAssetName;
|
|
|
+ //if (childItem->assetName != childItem->cleanAssetName)
|
|
|
+ // childItem->assetName = childItem->cleanAssetName;
|
|
|
|
|
|
//handle special pre-processing here for any types that need it
|
|
|
|
|
@@ -1579,6 +1583,28 @@ void AssetImporter::processImageAsset(AssetImportObject* assetItem)
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //If we're processing an unaffiliated image without generating materials for it, we can check some other bits
|
|
|
+ if (assetItem->parentAssetItem == nullptr)
|
|
|
+ {
|
|
|
+ if (assetItem->typeHint != String::EmptyString)
|
|
|
+ {
|
|
|
+ ImageAssetType type = ImageAsset::getImageTypeFromName(StringTable->insert(assetItem->typeHint.c_str()));
|
|
|
+
|
|
|
+ if (type == ImageAssetType::GUI)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(assetItem->assetName == assetItem->cleanAssetName && activeImportConfig->AlwaysAddImageSuffix)
|
|
|
+ {
|
|
|
+ assetItem->assetName = assetItem->assetName + activeImportConfig->AddedImageSuffix;
|
|
|
+ assetItem->cleanAssetName = assetItem->assetName;
|
|
|
+ }
|
|
|
|
|
|
assetItem->processed = true;
|
|
|
}
|
|
@@ -1612,174 +1638,214 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (activeImportConfig->AlwaysAddMaterialSuffix)
|
|
|
+ if (activeImportConfig->UseExistingMaterials)
|
|
|
{
|
|
|
- assetItem->assetName += activeImportConfig->AddedMaterialSuffix;
|
|
|
- }
|
|
|
+ //So if the material already exists, we should just use that. So first, let's find out if it already exists
|
|
|
|
|
|
- if (activeImportConfig->PopulateMaterialMaps)
|
|
|
- {
|
|
|
- //If we're trying to populate the rest of our material maps, we need to go looking
|
|
|
- dSprintf(importLogBuffer, sizeof(importLogBuffer), "Attempting to Auto-Populate Material Maps");
|
|
|
- activityLog.push_back(importLogBuffer);
|
|
|
+ //check to see if the definition for this already exists
|
|
|
+ StringTableEntry existingMatAsset = MaterialAsset::getAssetIdByMaterialName(StringTable->insert(assetName));
|
|
|
|
|
|
- AssetImportObject* matchedImageTypes[ImageAsset::ImageTypeCount] = { nullptr };
|
|
|
+ if (existingMatAsset != StringTable->EmptyString())
|
|
|
+ {
|
|
|
+ assetItem->skip = true;
|
|
|
+ dSprintf(importLogBuffer, sizeof(importLogBuffer), "Material %s has been skipped because we already found an asset Id that uses that material definition. The found assetId is: %s", assetItem->assetName.c_str(), existingMatAsset);
|
|
|
+ activityLog.push_back(importLogBuffer);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- String materialImageNoSuffix;
|
|
|
+ //If there was no existing assetId, then lets see if it already exists in a legacy file, like a materials.cs or materials.tscript
|
|
|
+ //If it does, we'll just make our asset point to that instead of a new file
|
|
|
+ Material* mat = MATMGR->getMaterialDefinitionByName(assetName);
|
|
|
|
|
|
- for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
|
|
|
+ if (!mat)
|
|
|
+ mat = MATMGR->getMaterialDefinitionByMapTo(assetName);
|
|
|
+
|
|
|
+ if (!mat && assetItem->assetName != assetItem->cleanAssetName)
|
|
|
{
|
|
|
- AssetImportObject* childAssetItem = assetItem->childAssetItems[i];
|
|
|
+ mat = MATMGR->getMaterialDefinitionByName(assetItem->cleanAssetName);
|
|
|
|
|
|
- if (childAssetItem->skip || childAssetItem->assetType != String("ImageAsset"))
|
|
|
- continue;
|
|
|
+ if (!mat)
|
|
|
+ mat = MATMGR->getMaterialDefinitionByMapTo(assetItem->cleanAssetName);
|
|
|
+ }
|
|
|
|
|
|
- for (S32 t = 0; t < ImageAsset::ImageTypeCount; t++)
|
|
|
+ if(mat)
|
|
|
+ {
|
|
|
+ //We found a match, so just modify our asset item's info to point against it. This will create the asset definition, but otherwise leave the material definition as-is.
|
|
|
+ assetItem->filePath = mat->getFilename();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (activeImportConfig->AlwaysAddMaterialSuffix) //we only opt to force on the suffix if we're not obligating using the original material defs
|
|
|
+ {
|
|
|
+ assetItem->assetName += activeImportConfig->AddedMaterialSuffix;
|
|
|
+ assetItem->cleanAssetName = assetItem->assetName;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (activeImportConfig->PopulateMaterialMaps)
|
|
|
+ {
|
|
|
+ //If we're trying to populate the rest of our material maps, we need to go looking
|
|
|
+ dSprintf(importLogBuffer, sizeof(importLogBuffer), "Attempting to Auto-Populate Material Maps");
|
|
|
+ activityLog.push_back(importLogBuffer);
|
|
|
+
|
|
|
+ AssetImportObject* matchedImageTypes[ImageAsset::ImageTypeCount] = { nullptr };
|
|
|
+
|
|
|
+ String materialImageNoSuffix;
|
|
|
+
|
|
|
+ for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
|
|
|
{
|
|
|
- //If the imageType name and child asset image type match, check it off our list
|
|
|
- if (!dStricmp(ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t), childAssetItem->imageSuffixType.c_str()))
|
|
|
- {
|
|
|
- matchedImageTypes[t] = childAssetItem;
|
|
|
+ AssetImportObject* childAssetItem = assetItem->childAssetItems[i];
|
|
|
+
|
|
|
+ if (childAssetItem->skip || childAssetItem->assetType != String("ImageAsset"))
|
|
|
+ continue;
|
|
|
|
|
|
- if (t == ImageAsset::ImageTypes::Albedo)
|
|
|
+ for (S32 t = 0; t < ImageAsset::ImageTypeCount; t++)
|
|
|
+ {
|
|
|
+ //If the imageType name and child asset image type match, check it off our list
|
|
|
+ if (!dStricmp(ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t), childAssetItem->imageSuffixType.c_str()))
|
|
|
{
|
|
|
- String sufType;
|
|
|
- String suffix = parseImageSuffixes(childAssetItem->assetName, &sufType);
|
|
|
+ matchedImageTypes[t] = childAssetItem;
|
|
|
|
|
|
- String imageAssetName = childAssetItem->assetName;
|
|
|
+ if (t == ImageAsset::ImageTypes::Albedo)
|
|
|
+ {
|
|
|
+ String sufType;
|
|
|
+ String suffix = parseImageSuffixes(childAssetItem->assetName, &sufType);
|
|
|
|
|
|
- if (suffix.isEmpty())
|
|
|
- materialImageNoSuffix = imageAssetName;
|
|
|
- else
|
|
|
- materialImageNoSuffix = imageAssetName.erase(imageAssetName.length() - suffix.length(), suffix.length());//cache this for later as we may need it for file association lookups
|
|
|
+ String imageAssetName = childAssetItem->assetName;
|
|
|
+
|
|
|
+ if (suffix.isEmpty())
|
|
|
+ materialImageNoSuffix = imageAssetName;
|
|
|
+ else
|
|
|
+ materialImageNoSuffix = imageAssetName.erase(imageAssetName.length() - suffix.length(), suffix.length());//cache this for later as we may need it for file association lookups
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //Now that we've checked off any existingly matched image types, process through the unmatched to look for files that associate
|
|
|
- for (S32 t = 0; t < ImageAsset::ImageTypeCount; t++)
|
|
|
- {
|
|
|
- //This type wasn't found, so try and find a match based on suffix
|
|
|
- String suffixList;
|
|
|
-
|
|
|
- switch (t)
|
|
|
+ //Now that we've checked off any existingly matched image types, process through the unmatched to look for files that associate
|
|
|
+ for (S32 t = 0; t < ImageAsset::ImageTypeCount; t++)
|
|
|
{
|
|
|
- case ImageAsset::Albedo:
|
|
|
- suffixList = activeImportConfig->DiffuseTypeSuffixes;
|
|
|
- break;
|
|
|
- case ImageAsset::Normal:
|
|
|
- suffixList = activeImportConfig->NormalTypeSuffixes;
|
|
|
- break;
|
|
|
- case ImageAsset::ORMConfig:
|
|
|
- suffixList = activeImportConfig->PBRTypeSuffixes;
|
|
|
- break;
|
|
|
- case ImageAsset::Metalness:
|
|
|
- suffixList = activeImportConfig->MetalnessTypeSuffixes;
|
|
|
- break;
|
|
|
- case ImageAsset::AO:
|
|
|
- suffixList = activeImportConfig->AOTypeSuffixes;
|
|
|
- break;
|
|
|
- case ImageAsset::Roughness:
|
|
|
- suffixList = activeImportConfig->RoughnessTypeSuffixes;
|
|
|
- break;
|
|
|
- //TODO: Glow map lookup too
|
|
|
- }
|
|
|
+ //This type wasn't found, so try and find a match based on suffix
|
|
|
+ String suffixList;
|
|
|
|
|
|
- if (!matchedImageTypes[t])
|
|
|
- {
|
|
|
- U32 suffixCount = StringUnit::getUnitCount(suffixList.c_str(), ",;\t");
|
|
|
- for (U32 i = 0; i < suffixCount; i++)
|
|
|
+ switch (t)
|
|
|
{
|
|
|
- //First, try checking based on the material's assetName for our patternbase
|
|
|
- String testPath = assetItem->filePath.getRootAndPath();
|
|
|
- testPath += "/" + assetItem->cleanAssetName + StringUnit::getUnit(suffixList.c_str(), i, ",;\t");
|
|
|
-
|
|
|
- String imagePath = AssetImporter::findImagePath(testPath);
|
|
|
+ case ImageAsset::Albedo:
|
|
|
+ suffixList = activeImportConfig->DiffuseTypeSuffixes;
|
|
|
+ break;
|
|
|
+ case ImageAsset::Normal:
|
|
|
+ suffixList = activeImportConfig->NormalTypeSuffixes;
|
|
|
+ break;
|
|
|
+ case ImageAsset::ORMConfig:
|
|
|
+ suffixList = activeImportConfig->PBRTypeSuffixes;
|
|
|
+ break;
|
|
|
+ case ImageAsset::Metalness:
|
|
|
+ suffixList = activeImportConfig->MetalnessTypeSuffixes;
|
|
|
+ break;
|
|
|
+ case ImageAsset::AO:
|
|
|
+ suffixList = activeImportConfig->AOTypeSuffixes;
|
|
|
+ break;
|
|
|
+ case ImageAsset::Roughness:
|
|
|
+ suffixList = activeImportConfig->RoughnessTypeSuffixes;
|
|
|
+ break;
|
|
|
+ //TODO: Glow map lookup too
|
|
|
+ }
|
|
|
|
|
|
- if (imagePath.isNotEmpty())
|
|
|
+ if (!matchedImageTypes[t])
|
|
|
+ {
|
|
|
+ U32 suffixCount = StringUnit::getUnitCount(suffixList.c_str(), ",;\t");
|
|
|
+ for (U32 i = 0; i < suffixCount; i++)
|
|
|
{
|
|
|
- //got a match!
|
|
|
- AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
|
|
|
+ //First, try checking based on the material's assetName for our patternbase
|
|
|
+ String testPath = assetItem->filePath.getRootAndPath();
|
|
|
+ testPath += "/" + assetItem->cleanAssetName + StringUnit::getUnit(suffixList.c_str(), i, ",;\t");
|
|
|
|
|
|
- newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t);
|
|
|
+ String imagePath = AssetImporter::findImagePath(testPath);
|
|
|
|
|
|
- matchedImageTypes[t] = newImageAssetObj;
|
|
|
- break;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if(materialImageNoSuffix.isNotEmpty())
|
|
|
+ if (imagePath.isNotEmpty())
|
|
|
{
|
|
|
- testPath = assetItem->filePath.getRootAndPath();
|
|
|
- testPath += "/" + materialImageNoSuffix + StringUnit::getUnit(suffixList.c_str(), i, ",;\t");
|
|
|
+ //got a match!
|
|
|
+ AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
|
|
|
|
|
|
- imagePath = AssetImporter::findImagePath(testPath);
|
|
|
+ newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t);
|
|
|
|
|
|
- if (imagePath.isNotEmpty())
|
|
|
+ matchedImageTypes[t] = newImageAssetObj;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (materialImageNoSuffix.isNotEmpty())
|
|
|
{
|
|
|
- //got a match!
|
|
|
- AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
|
|
|
+ testPath = assetItem->filePath.getRootAndPath();
|
|
|
+ testPath += "/" + materialImageNoSuffix + StringUnit::getUnit(suffixList.c_str(), i, ",;\t");
|
|
|
|
|
|
- newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t);
|
|
|
+ imagePath = AssetImporter::findImagePath(testPath);
|
|
|
|
|
|
- matchedImageTypes[t] = newImageAssetObj;
|
|
|
- break;
|
|
|
+ if (imagePath.isNotEmpty())
|
|
|
+ {
|
|
|
+ //got a match!
|
|
|
+ AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
|
|
|
+
|
|
|
+ newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t);
|
|
|
+
|
|
|
+ matchedImageTypes[t] = newImageAssetObj;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- //If we're the abledo slot and after all that we didn't find anything, it probably is a suffixless image
|
|
|
- if (t == ImageAsset::Albedo && matchedImageTypes[t] == nullptr)
|
|
|
- {
|
|
|
- String testPath = assetItem->filePath.getRootAndPath() + "/" + assetItem->cleanAssetName;
|
|
|
- String imagePath = AssetImporter::findImagePath(testPath);
|
|
|
|
|
|
- if (imagePath.isNotEmpty())
|
|
|
+ //If we're the abledo slot and after all that we didn't find anything, it probably is a suffixless image
|
|
|
+ if (t == ImageAsset::Albedo && matchedImageTypes[t] == nullptr)
|
|
|
{
|
|
|
- //got a match!
|
|
|
- AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
|
|
|
+ String testPath = assetItem->filePath.getRootAndPath() + "/" + assetItem->cleanAssetName;
|
|
|
+ String imagePath = AssetImporter::findImagePath(testPath);
|
|
|
|
|
|
- //In the event that the names match, we want to avoid duplications, so we'll go ahead and append a suffix onto our new image asset
|
|
|
- if (newImageAssetObj->assetName == assetItem->assetName)
|
|
|
+ if (imagePath.isNotEmpty())
|
|
|
{
|
|
|
- newImageAssetObj->assetName += StringUnit::getUnit(suffixList.c_str(), 0, ",;\t");
|
|
|
- newImageAssetObj->cleanAssetName = newImageAssetObj->assetName;
|
|
|
- }
|
|
|
+ //got a match!
|
|
|
+ AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
|
|
|
+
|
|
|
+ //In the event that the names match, we want to avoid duplications, so we'll go ahead and append a suffix onto our new image asset
|
|
|
+ if (newImageAssetObj->assetName == assetItem->assetName)
|
|
|
+ {
|
|
|
+ newImageAssetObj->assetName += StringUnit::getUnit(suffixList.c_str(), 0, ",;\t");
|
|
|
+ newImageAssetObj->cleanAssetName = newImageAssetObj->assetName;
|
|
|
+ }
|
|
|
|
|
|
- newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes::Albedo);
|
|
|
+ newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes::Albedo);
|
|
|
|
|
|
- matchedImageTypes[t] = newImageAssetObj;
|
|
|
+ matchedImageTypes[t] = newImageAssetObj;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //just a bit of cleanup and logical testing for matches
|
|
|
- //in the event we KNOW what the type is, but we don't have a suffix, such as a found image on a material lookup
|
|
|
- //that doesn't have a suffix, we assume it to be the albedo, so we'll just append the suffix to avoid collisions if
|
|
|
- //the name already matches our material name, similar to above logic
|
|
|
- if (matchedImageTypes[t]->assetName == assetItem->assetName)
|
|
|
+ else
|
|
|
{
|
|
|
- matchedImageTypes[t]->assetName += StringUnit::getUnit(suffixList.c_str(), 0, ",;\t");
|
|
|
- matchedImageTypes[t]->cleanAssetName = matchedImageTypes[t]->assetName;
|
|
|
+ //just a bit of cleanup and logical testing for matches
|
|
|
+ //in the event we KNOW what the type is, but we don't have a suffix, such as a found image on a material lookup
|
|
|
+ //that doesn't have a suffix, we assume it to be the albedo, so we'll just append the suffix to avoid collisions if
|
|
|
+ //the name already matches our material name, similar to above logic
|
|
|
+ if (matchedImageTypes[t]->assetName == assetItem->assetName)
|
|
|
+ {
|
|
|
+ matchedImageTypes[t]->assetName += StringUnit::getUnit(suffixList.c_str(), 0, ",;\t");
|
|
|
+ matchedImageTypes[t]->cleanAssetName = matchedImageTypes[t]->assetName;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- /*for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
|
|
|
- {
|
|
|
- AssetImportObject* childAssetItem = assetItem->childAssetItems[i];
|
|
|
+ /*for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
|
|
|
+ {
|
|
|
+ AssetImportObject* childAssetItem = assetItem->childAssetItems[i];
|
|
|
|
|
|
- if (childAssetItem->skip || childAssetItem->processed || childAssetItem->assetType != String("ImageAsset"))
|
|
|
- continue;
|
|
|
+ if (childAssetItem->skip || childAssetItem->processed || childAssetItem->assetType != String("ImageAsset"))
|
|
|
+ continue;
|
|
|
|
|
|
- if (childAssetItem->imageSuffixType == String("Albedo"))
|
|
|
- {
|
|
|
- assetItem->diffuseImageAsset = % childAssetItem;
|
|
|
- }
|
|
|
- }*/
|
|
|
+ if (childAssetItem->imageSuffixType == String("Albedo"))
|
|
|
+ {
|
|
|
+ assetItem->diffuseImageAsset = % childAssetItem;
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
assetItem->processed = true;
|
|
@@ -1822,6 +1888,7 @@ void AssetImporter::processShapeAsset(AssetImportObject* assetItem)
|
|
|
if (activeImportConfig->AlwaysAddShapeSuffix)
|
|
|
{
|
|
|
assetItem->assetName += activeImportConfig->AddedShapeSuffix;
|
|
|
+ assetItem->cleanAssetName = assetItem->assetName;
|
|
|
}
|
|
|
|
|
|
S32 meshCount = dAtoi(assetItem->shapeInfo->getDataField(StringTable->insert("_meshCount"), nullptr));
|
|
@@ -1888,7 +1955,7 @@ void AssetImporter::processShapeMaterialInfo(AssetImportObject* assetItem, S32 m
|
|
|
if (matName == assetItem->assetName)
|
|
|
{
|
|
|
//So apparently we managed to name the material the same as the shape. So we'll tweak the name
|
|
|
- matAssetName += activeImportConfig->AlwaysAddMaterialSuffix;
|
|
|
+ matAssetName += activeImportConfig->AddedMaterialSuffix;
|
|
|
}
|
|
|
|
|
|
//Do a check so we don't import materials that are on our ignore list
|
|
@@ -2284,7 +2351,7 @@ void AssetImporter::resolveAssetItemIssues(AssetImportObject* assetItem)
|
|
|
deleteImportingAsset(assetItem);
|
|
|
|
|
|
//log it's deletion
|
|
|
- dSprintf(importLogBuffer, sizeof(importLogBuffer), "Asset %s was autoprined due to %s as part of the Import Configuration", assetItem->assetName.c_str(), humanReadableReason.c_str());
|
|
|
+ dSprintf(importLogBuffer, sizeof(importLogBuffer), "Asset %s was autopruned due to %s as part of the Import Configuration", assetItem->assetName.c_str(), humanReadableReason.c_str());
|
|
|
activityLog.push_back(importLogBuffer);
|
|
|
|
|
|
importIssues = false;
|
|
@@ -2348,7 +2415,7 @@ void AssetImporter::resetImportConfig()
|
|
|
//
|
|
|
// Importing
|
|
|
//
|
|
|
-StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath)
|
|
|
+StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath, String typeHint)
|
|
|
{
|
|
|
//Just in case we're reusing the same importer object from another import session, nuke any existing files
|
|
|
resetImportSession(true);
|
|
@@ -2359,6 +2426,8 @@ StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath)
|
|
|
{
|
|
|
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Unable to import file %s because it is a folder or zip.", filePath.getFullPath().c_str());
|
|
|
activityLog.push_back(importLogBuffer);
|
|
|
+
|
|
|
+ dumpActivityLog();
|
|
|
return StringTable->EmptyString();
|
|
|
}
|
|
|
|
|
@@ -2366,6 +2435,8 @@ StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath)
|
|
|
{
|
|
|
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Unable to import file %s because it is of an unrecognized/unsupported type.", filePath.getFullPath().c_str());
|
|
|
activityLog.push_back(importLogBuffer);
|
|
|
+
|
|
|
+ dumpActivityLog();
|
|
|
return StringTable->EmptyString();
|
|
|
}
|
|
|
|
|
@@ -2374,7 +2445,10 @@ StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath)
|
|
|
|
|
|
if (targetModuleDef == nullptr)
|
|
|
{
|
|
|
- //log it
|
|
|
+ dSprintf(importLogBuffer, sizeof(importLogBuffer), "Unable to import file %s because it is not in a valid module folder.", filePath.getFullPath().c_str());
|
|
|
+ activityLog.push_back(importLogBuffer);
|
|
|
+
|
|
|
+ dumpActivityLog();
|
|
|
return StringTable->EmptyString();
|
|
|
}
|
|
|
else
|
|
@@ -2404,14 +2478,7 @@ StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath)
|
|
|
importAssets();
|
|
|
}
|
|
|
|
|
|
-#if TORQUE_DEBUG
|
|
|
- Con::printf("/***************/");
|
|
|
- for (U32 i = 0; i < activityLog.size(); i++)
|
|
|
- {
|
|
|
- Con::printf(activityLog[i].c_str());
|
|
|
- }
|
|
|
- Con::printf("/***************/");
|
|
|
-#endif
|
|
|
+ dumpActivityLog();
|
|
|
|
|
|
if (hasIssues)
|
|
|
{
|
|
@@ -2628,8 +2695,15 @@ Torque::Path AssetImporter::importImageAsset(AssetImportObject* assetItem)
|
|
|
newAsset->setDataField(StringTable->insert("originalFilePath"), nullptr, qualifiedFromFile);
|
|
|
}
|
|
|
|
|
|
- ImageAsset::ImageTypes imageType = ImageAsset::getImageTypeFromName(assetItem->imageSuffixType.c_str());
|
|
|
- newAsset->setImageType(imageType);
|
|
|
+ if (assetItem->typeHint != String::EmptyString)
|
|
|
+ {
|
|
|
+ newAsset->setImageType(ImageAsset::getImageTypeFromName(StringTable->insert(assetItem->typeHint.c_str())));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ImageAsset::ImageTypes imageType = ImageAsset::getImageTypeFromName(assetItem->imageSuffixType.c_str());
|
|
|
+ newAsset->setImageType(imageType);
|
|
|
+ }
|
|
|
|
|
|
Taml tamlWriter;
|
|
|
bool importSuccessful = tamlWriter.write(newAsset, tamlPath.c_str());
|
|
@@ -2694,7 +2768,7 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem)
|
|
|
dSprintf(dependencyFieldName, 64, "imageMap%i", dependencySlotId);
|
|
|
|
|
|
char dependencyFieldDef[512];
|
|
|
- dSprintf(dependencyFieldDef, 512, "@Asset=%s:%s", targetModuleId.c_str(), childItem->assetName.c_str());
|
|
|
+ dSprintf(dependencyFieldDef, 512, "%s=%s:%s", ASSET_ID_SIGNATURE, targetModuleId.c_str(), childItem->assetName.c_str());
|
|
|
|
|
|
newAsset->setDataField(StringTable->insert(dependencyFieldName), nullptr, dependencyFieldDef);
|
|
|
|
|
@@ -2752,74 +2826,96 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem)
|
|
|
FileObject* file = new FileObject();
|
|
|
file->registerObject();
|
|
|
|
|
|
- //Now write the script file containing our material out
|
|
|
- //There's 2 ways to do this. If we're in-place importing an existing asset, we can see if the definition existed already, like in an old
|
|
|
- //materials.tscript file. if it does, we can just find the object by name, and save it out to our new file
|
|
|
- //If not, we'll just generate one
|
|
|
- Material* existingMat = MATMGR->getMaterialDefinitionByName(assetName);
|
|
|
-
|
|
|
- //It's also possible that, for legacy models, the material hooks in via the material's mapTo field, and the material name is something completely different
|
|
|
- //So we'll check for that as well if we didn't find it by name up above
|
|
|
- if (existingMat == nullptr)
|
|
|
+ if (activeImportConfig->UseExistingMaterials && Platform::isFile(qualifiedFromFile))
|
|
|
{
|
|
|
- existingMat = MATMGR->getMaterialDefinitionByMapTo(assetName);
|
|
|
- }
|
|
|
+ //Now write the script file containing our material out
|
|
|
+ //There's 2 ways to do this. If we're in-place importing an existing asset, we can see if the definition existed already, like in an old
|
|
|
+ //materials.tscript file. if it does, we can just find the object by name, and save it out to our new file
|
|
|
+ //If not, we'll just generate one
|
|
|
+ Material* existingMat = MATMGR->getMaterialDefinitionByName(assetName);
|
|
|
|
|
|
- if (existingMat)
|
|
|
- {
|
|
|
- for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
|
|
|
+ //It's also possible that, for legacy models, the material hooks in via the material's mapTo field, and the material name is something completely different
|
|
|
+ //So we'll check for that as well if we didn't find it by name up above
|
|
|
+ if (existingMat == nullptr)
|
|
|
+ existingMat = MATMGR->getMaterialDefinitionByMapTo(assetName);
|
|
|
+
|
|
|
+ if (existingMat == nullptr && assetItem->assetName != assetItem->cleanAssetName)
|
|
|
{
|
|
|
- AssetImportObject* childItem = assetItem->childAssetItems[i];
|
|
|
+ existingMat = MATMGR->getMaterialDefinitionByName(assetItem->cleanAssetName);
|
|
|
+ if (existingMat == nullptr)
|
|
|
+ existingMat = MATMGR->getMaterialDefinitionByMapTo(assetItem->cleanAssetName);
|
|
|
+ }
|
|
|
|
|
|
- if (childItem->skip || !childItem->processed || childItem->assetType.compare("ImageAsset") != 0)
|
|
|
- continue;
|
|
|
+ if (existingMat)
|
|
|
+ {
|
|
|
+ PersistenceManager* persistMgr;
|
|
|
+ if (Sim::findObject("ImageAssetValidator", persistMgr))
|
|
|
+ {
|
|
|
+ for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
|
|
|
+ {
|
|
|
+ AssetImportObject* childItem = assetItem->childAssetItems[i];
|
|
|
|
|
|
- String path = childItem->filePath.getFullFileName();
|
|
|
+ if (childItem->skip || !childItem->processed || childItem->assetType.compare("ImageAsset") != 0)
|
|
|
+ continue;
|
|
|
|
|
|
- String mapFieldName = "";
|
|
|
- String assetFieldName = "";
|
|
|
+ String path = childItem->filePath.getFullFileName();
|
|
|
|
|
|
- ImageAsset::ImageTypes imageType = ImageAsset::getImageTypeFromName(childItem->imageSuffixType);
|
|
|
+ String mapFieldName = "";
|
|
|
+ String assetFieldName = "";
|
|
|
|
|
|
- if (imageType == ImageAsset::ImageTypes::Albedo || childItem->imageSuffixType.isEmpty())
|
|
|
- {
|
|
|
- mapFieldName = "DiffuseMap";
|
|
|
- }
|
|
|
- else if (imageType == ImageAsset::ImageTypes::Normal)
|
|
|
- {
|
|
|
- mapFieldName = "NormalMap";
|
|
|
- }
|
|
|
- else if (imageType == ImageAsset::ImageTypes::ORMConfig)
|
|
|
- {
|
|
|
- mapFieldName = "ORMConfig";
|
|
|
- }
|
|
|
- else if (imageType == ImageAsset::ImageTypes::Metalness)
|
|
|
- {
|
|
|
- mapFieldName = "MetalnessMap";
|
|
|
- }
|
|
|
- else if (imageType == ImageAsset::ImageTypes::AO)
|
|
|
- {
|
|
|
- mapFieldName = "AOMap";
|
|
|
- }
|
|
|
- else if (imageType == ImageAsset::ImageTypes::Roughness)
|
|
|
- {
|
|
|
- mapFieldName = "RoughnessMap";
|
|
|
- }
|
|
|
+ ImageAsset::ImageTypes imageType = ImageAsset::getImageTypeFromName(childItem->imageSuffixType);
|
|
|
|
|
|
- assetFieldName = mapFieldName + "Asset[0]";
|
|
|
- mapFieldName += "[0]";
|
|
|
+ if (imageType == ImageAsset::ImageTypes::Albedo || childItem->imageSuffixType.isEmpty())
|
|
|
+ {
|
|
|
+ mapFieldName = "DiffuseMap";
|
|
|
+ }
|
|
|
+ else if (imageType == ImageAsset::ImageTypes::Normal)
|
|
|
+ {
|
|
|
+ mapFieldName = "NormalMap";
|
|
|
+ }
|
|
|
+ else if (imageType == ImageAsset::ImageTypes::ORMConfig)
|
|
|
+ {
|
|
|
+ mapFieldName = "ORMConfig";
|
|
|
+ }
|
|
|
+ else if (imageType == ImageAsset::ImageTypes::Metalness)
|
|
|
+ {
|
|
|
+ mapFieldName = "MetalnessMap";
|
|
|
+ }
|
|
|
+ else if (imageType == ImageAsset::ImageTypes::AO)
|
|
|
+ {
|
|
|
+ mapFieldName = "AOMap";
|
|
|
+ }
|
|
|
+ else if (imageType == ImageAsset::ImageTypes::Roughness)
|
|
|
+ {
|
|
|
+ mapFieldName = "RoughnessMap";
|
|
|
+ }
|
|
|
+
|
|
|
+ assetFieldName = mapFieldName + "Asset[0]";
|
|
|
+ mapFieldName += "[0]";
|
|
|
|
|
|
- //If there's already an existing image map file on the material definition in this slot, don't override it
|
|
|
- if(!path.isEmpty())
|
|
|
- existingMat->writeField(mapFieldName.c_str(), path.c_str());
|
|
|
+ //If there's already an existing image map file on the material definition in this slot, don't override it
|
|
|
+ if (!path.isEmpty())
|
|
|
+ existingMat->writeField(mapFieldName.c_str(), path.c_str());
|
|
|
|
|
|
- String targetAsset = targetModuleId + ":" + childItem->assetName;
|
|
|
+ String targetAsset = targetModuleId + ":" + childItem->assetName;
|
|
|
+
|
|
|
+ existingMat->writeField(assetFieldName.c_str(), targetAsset.c_str());
|
|
|
+ }
|
|
|
|
|
|
- existingMat->writeField(assetFieldName.c_str(), targetAsset.c_str());
|
|
|
+ persistMgr->setDirty(existingMat);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Con::errorf("ImageAssetValidator not found!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Failed to find original material definition %s!", assetName);
|
|
|
+ activityLog.push_back(importLogBuffer);
|
|
|
+ return tamlPath;
|
|
|
}
|
|
|
- existingMat->save(scriptPath.c_str());
|
|
|
}
|
|
|
- //However, if we didn't find any existing material, then we'll want to go ahead and just write out a new one
|
|
|
else if (file->openForWrite(scriptPath.c_str()))
|
|
|
{
|
|
|
file->writeLine((U8*)"//--- OBJECT WRITE BEGIN ---");
|
|
@@ -2936,7 +3032,7 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
|
|
|
newAsset->setShapeFile(shapeFileName.c_str());
|
|
|
newAsset->setShapeConstructorFile(constructorFileName.c_str());
|
|
|
|
|
|
- AssetImportConfig* cachedConfig = new AssetImportConfig();;
|
|
|
+ AssetImportConfig* cachedConfig = new AssetImportConfig();
|
|
|
cachedConfig->registerObject();
|
|
|
activeImportConfig->CopyTo(cachedConfig);
|
|
|
|
|
@@ -2968,7 +3064,7 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
|
|
|
dSprintf(dependencyFieldName, 64, "materialSlot%i", dependencySlotId);
|
|
|
|
|
|
char dependencyFieldDef[512];
|
|
|
- dSprintf(dependencyFieldDef, 512, "@Asset=%s:%s", targetModuleId.c_str(), childItem->assetName.c_str());
|
|
|
+ dSprintf(dependencyFieldDef, 512, "%s=%s:%s", ASSET_ID_SIGNATURE, targetModuleId.c_str(), childItem->assetName.c_str());
|
|
|
|
|
|
newAsset->setDataField(StringTable->insert(dependencyFieldName), nullptr, dependencyFieldDef);
|
|
|
|
|
@@ -2980,7 +3076,7 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
|
|
|
dSprintf(dependencyFieldName, 64, "animationSequence%i", dependencySlotId);
|
|
|
|
|
|
char dependencyFieldDef[512];
|
|
|
- dSprintf(dependencyFieldDef, 512, "@Asset=%s:%s", targetModuleId.c_str(), childItem->assetName.c_str());
|
|
|
+ dSprintf(dependencyFieldDef, 512, "%s=%s:%s", ASSET_ID_SIGNATURE, targetModuleId.c_str(), childItem->assetName.c_str());
|
|
|
|
|
|
newAsset->setDataField(StringTable->insert(dependencyFieldName), nullptr, dependencyFieldDef);
|
|
|
|
|
@@ -3036,7 +3132,7 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
|
|
|
TSShapeConstructor* constructor = TSShapeConstructor::findShapeConstructor(Torque::Path(qualifiedToFile).getFullPath());
|
|
|
if (constructor == nullptr)
|
|
|
{
|
|
|
- constructor = new TSShapeConstructor(qualifiedToFile);
|
|
|
+ constructor = new TSShapeConstructor(StringTable->insert(qualifiedToFile));
|
|
|
|
|
|
String constructorName = assetItem->filePath.getFileName() + assetItem->filePath.getExtension().substr(0, 3);
|
|
|
constructorName.replace(" ", "_");
|
|
@@ -3046,7 +3142,6 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
|
|
|
constructor->registerObject(constructorName.c_str());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//now we write the import config logic into the constructor itself to ensure we load like we wanted it to
|
|
|
String neverImportMats;
|
|
|
|