diff --git a/Engine/source/T3D/assets/assetImporter.cpp b/Engine/source/T3D/assets/assetImporter.cpp index 1b1f8c2b1..2334f12eb 100644 --- a/Engine/source/T3D/assets/assetImporter.cpp +++ b/Engine/source/T3D/assets/assetImporter.cpp @@ -616,6 +616,9 @@ String AssetImporter::parseImageSuffixes(String assetName, String* suffixType) if (FindMatch::isMatch(searchSuffix.c_str(), assetName.c_str(), false)) { //We have a match, so indicate as such + S32 pos = assetName.length(); + pos -= searchSuffix.length(); + suffix = assetName.substr(pos+1); return suffix; } } @@ -649,6 +652,103 @@ String AssetImporter::getAssetTypeByFile(Torque::Path filePath) return ""; } +String AssetImporter::getTrueFilename(const String& fileName) +{ + Torque::Path pth(fileName); + String pattern = pth.getFullPath() + "*"; + + static const String sSlash("/"); + + Vector findFilesResults; + + String sPattern(Torque::Path::CleanSeparators(pattern)); + if (sPattern.isEmpty()) + { + Con::errorf("findFirstFile() requires a search pattern"); + return ""; + } + + char scriptFilenameBuffer[1024]; + + if (!Con::expandScriptFilename(scriptFilenameBuffer, sizeof(scriptFilenameBuffer), sPattern.c_str())) + { + Con::errorf("findFirstFile() given initial directory cannot be expanded: '%s'", pattern); + return ""; + } + sPattern = String::ToString(scriptFilenameBuffer); + + String::SizeType slashPos = sPattern.find('/', 0, String::Right); + // if(slashPos == String::NPos) + // { + // Con::errorf("findFirstFile() missing search directory or expression: '%s'", sPattern.c_str()); + // return -1; + // } + + // Build the initial search path + Torque::Path givenPath(Torque::Path::CompressPath(sPattern)); + givenPath.setFileName("*"); + givenPath.setExtension("*"); + + if (givenPath.getPath().length() > 0 && givenPath.getPath().find('*', 0, String::Right) == givenPath.getPath().length() - 1) + { + // Deal with legacy searches of the form '*/*.*' + String suspectPath = givenPath.getPath(); + String::SizeType newLen = suspectPath.length() - 1; + if (newLen > 0 && suspectPath.find('/', 0, String::Right) == suspectPath.length() - 2) + { + --newLen; + } + givenPath.setPath(suspectPath.substr(0, newLen)); + } + + Torque::FS::FileSystemRef fs = Torque::FS::GetFileSystem(givenPath); + //Torque::Path path = fs->mapTo(givenPath); + Torque::Path path = givenPath; + + // Make sure that we have a root so the correct file system can be determined when using zips + if (givenPath.isRelative()) + path = Torque::Path::Join(Torque::FS::GetCwd(), '/', givenPath); + + path.setFileName(String::EmptyString); + path.setExtension(String::EmptyString); + if (!Torque::FS::IsDirectory(path)) + { + Con::errorf("findFirstFile() invalid initial search directory: '%s'", path.getFullPath().c_str()); + return ""; + } + + // Build the search expression + const String expression(slashPos != String::NPos ? sPattern.substr(slashPos + 1) : sPattern); + if (expression.isEmpty()) + { + Con::errorf("findFirstFile() requires a search expression: '%s'", sPattern.c_str()); + return ""; + } + + S32 results = Torque::FS::FindByPattern(path, expression, false, findFilesResults, false); + if (givenPath.isRelative() && results > 0) + { + // Strip the CWD out of the returned paths + // MakeRelativePath() returns incorrect results (it adds a leading ..) so doing this the dirty way + const String cwd = Torque::FS::GetCwd().getFullPath(); + for (S32 i = 0; i < findFilesResults.size(); ++i) + { + String str = findFilesResults[i]; + if (str.compare(cwd, cwd.length(), String::NoCase) == 0) + str = str.substr(cwd.length()); + findFilesResults[i] = str; + } + } + + for (U32 i = 0; i < findFilesResults.size(); i++) + { + if (!findFilesResults[i].compare(fileName, 0, String::NoCase|String::Left)) + return findFilesResults[i]; + } + + return ""; +} + void AssetImporter::resetImportSession(bool hardClearSession) { importingAssets.clear(); @@ -660,9 +760,12 @@ void AssetImporter::resetImportSession(bool hardClearSession) } else { - for (U32 i = 0; i < originalImportingFiles.size(); i++) + Vector tempImportingFiles = originalImportingFiles; + originalImportingFiles.clear(); + + for (U32 i = 0; i < tempImportingFiles.size(); i++) { - addImportingFile(originalImportingFiles[i]); + addImportingFile(tempImportingFiles[i]); } } } @@ -1345,7 +1448,7 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem) for (U32 i = 0; i < suffixCount; i++) { //First, try checking based on the material's assetName for our patternbase - String testPath = assetItem->filePath.getPath(); + String testPath = assetItem->filePath.getRootAndPath(); testPath += "/" + assetItem->cleanAssetName + StringUnit::getUnit(suffixList.c_str(), i, ",;"); String imagePath = AssetImporter::findImagePath(testPath); @@ -1355,7 +1458,7 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem) //got a match! AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, ""); - newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)i); + newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t); matchedImageTypes[t] = newImageAssetObj; break; @@ -1364,7 +1467,7 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem) { if(materialImageNoSuffix.isNotEmpty()) { - testPath = assetItem->filePath.getPath(); + testPath = assetItem->filePath.getRootAndPath(); testPath += "/" + materialImageNoSuffix + StringUnit::getUnit(suffixList.c_str(), i, ",;"); imagePath = AssetImporter::findImagePath(testPath); @@ -1374,7 +1477,7 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem) //got a match! AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, ""); - newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)i); + newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t); matchedImageTypes[t] = newImageAssetObj; break; @@ -1513,6 +1616,21 @@ void AssetImporter::processShapeMaterialInfo(AssetImportObject* assetItem, S32 m matAssetName += String("_Mat"); } + //Do a check so we don't import materials that are on our ignore list + if (activeImportConfig.IgnoreMaterials.isNotEmpty()) + { + U32 ignoredMatNamesCount = StringUnit::getUnitCount(activeImportConfig.IgnoreMaterials, ",;"); + for (U32 i = 0; i < ignoredMatNamesCount; i++) + { + const char* ignoreMatName = StringUnit::getUnit(activeImportConfig.IgnoreMaterials, i, ",;"); + if (FindMatch::isMatch(ignoreMatName, matName.c_str(), false)) + { + //If we have a match to one of our ignore names, just bail out here and skip the material wholesale + return; + } + } + } + String materialItemValue = assetItem->shapeInfo->getItemValue(materialItemId); AssetImportObject* matAssetItem = nullptr; @@ -1556,7 +1674,7 @@ void AssetImporter::processShapeMaterialInfo(AssetImportObject* assetItem, S32 m filePath = imgFileName; } } - + matAssetItem = addImportingAsset("MaterialAsset", shapePathBase + "/", assetItem, matName); AssetImportObject* imageAssetItem = addImportingAsset("ImageAsset", filePath, matAssetItem, ""); diff --git a/Engine/source/T3D/assets/assetImporter.h b/Engine/source/T3D/assets/assetImporter.h index 76050f764..ff05f4a4c 100644 --- a/Engine/source/T3D/assets/assetImporter.h +++ b/Engine/source/T3D/assets/assetImporter.h @@ -805,6 +805,14 @@ public: /// AssetImportConfig* getImportConfig() { return &activeImportConfig; } + void setImportConfig(AssetImportConfig* importConfig) { + if(importConfig != nullptr) + activeImportConfig = *importConfig; + } + + // + static String getTrueFilename(const String& fileName); + // /// /// @@ -821,6 +829,10 @@ public: else if (Platform::isFile(testPath + String(".tif"))) imagePath = testPath + String(".tif"); + if(imagePath.isNotEmpty()) + //This ensures case-correct for the filename + imagePath = getTrueFilename(imagePath); + return imagePath; } diff --git a/Engine/source/T3D/assets/assetImporter_ScriptBinding.h b/Engine/source/T3D/assets/assetImporter_ScriptBinding.h index 31f619fa6..cb0f6cadc 100644 --- a/Engine/source/T3D/assets/assetImporter_ScriptBinding.h +++ b/Engine/source/T3D/assets/assetImporter_ScriptBinding.h @@ -137,6 +137,14 @@ DefineEngineMethod(AssetImporter, deleteImportingAsset, void, (AssetImportObject return object->deleteImportingAsset(assetItem); } +DefineEngineMethod(AssetImporter, setImportConfig, void, (AssetImportConfig* importConfig), (nullAsType< AssetImportConfig*>()), + "Creates a new script asset using the targetFilePath.\n" + "@return The bool result of calling exec") +{ + return object->setImportConfig(importConfig); +} + + /*DefineEngineFunction(enumColladaForImport, bool, (const char* shapePath, const char* ctrl, bool loadCachedDts), ("", "", true), "(string shapePath, GuiTreeViewCtrl ctrl) Collect scene information from " "a COLLADA file and store it in a GuiTreeView control. This function is " diff --git a/Templates/BaseGame/game/tools/assetBrowser/_assetImportConfigs.xml b/Templates/BaseGame/game/tools/assetBrowser/_assetImportConfigs.xml deleted file mode 100644 index 72050b04f..000000000 --- a/Templates/BaseGame/game/tools/assetBrowser/_assetImportConfigs.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Templates/BaseGame/game/tools/assetBrowser/assetImportConfigs.xml b/Templates/BaseGame/game/tools/assetBrowser/assetImportConfigs.xml index c8a5afeda..ef06ea2b3 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/assetImportConfigs.xml +++ b/Templates/BaseGame/game/tools/assetBrowser/assetImportConfigs.xml @@ -1,138 +1,138 @@ - - - 1 - 1 - - - 1 - _METAL,_MET,_METALNESS,_METALLIC - _AO,_AMBIENT,_AMBIENTOCCLUSION - 0 - Bilinear - _ROUGH,_ROUGHNESS - 1 - _ALBEDO,_DIFFUSE,_ALB,_DIF,_COLOR,_COL,_baseColor,_a, - _SMOOTH,_SMOOTHNESS - _COMP,_COMPOSITE - 1.0 - _NORMAL,_NORM - 1 - N/A - 1 - + - 0 + 0 0 + TrailingNumber + 0 + 1 0 Z_AXIS - 0 - 1 - 1 - 0 - 0.01 + 0 + 0 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 0 - TrailingNumber + 1 + 0 0 - 1.0 1.0 + 1.0 + + + _METAL,_MET,_METALNESS,_METALLIC + 1.0 + 0 + N/A + 1 + _COMP,_COMPOSITE,_PBR,-COMP,-COMPOSITE,-PBR + _NORMAL,_NORM + _AO,_AMBIENT,_AMBIENTOCCLUSION + _ALBEDO,_DIFFUSE,_ALB,_DIF,_COLOR,_COL + _SMOOTH,_SMOOTHNESS + 1 + Bilinear + 1 + _ROUGH,_ROUGHNESS + + + Seconds + 2 + 1 + 1 + + + 0 + 0 + AutoPrune + 1 - CollisionMesh + CollisionMesh LOS Col + 1 + CollisionMesh + 1 + + + 1 + 1 + 1 + 1 + 1 + + + + + LOS + 1 + Col 1 CollisionMesh - 1 + CollisionMesh + + + 0 + 0 + 0 + 1 + 0 + 1 + 0 + Z_AXIS + 0 + TrailingNumber + 0 + 0 + + + _AO,_AMBIENT,_AMBIENTOCCLUSION + _ALBEDO,_DIFFUSE,_ALB,_DIF,_COLOR,_COL,_baseColor,_a, + 1 + N/A + 1 + _NORMAL,_NORM + Bilinear + _ROUGH,_ROUGHNESS + _COMP,_COMPOSITE,_PBR,-COMP,-COMPOSITE,-PBR + 1 + 1 + 1.0 + _METAL,_MET,_METALNESS,_METALLIC + 0 + _SMOOTH,_SMOOTHNESS - ColorEffect*, - 1 1 1 1 0 1 - - - AutoPrune - - - - - _AO,_AMBIENT,_AMBIENTOCCLUSION - 1 - _ALBEDO,_DIFFUSE,_ALB,_DIF,_COLOR,_COL - _SMOOTH,_SMOOTHNESS - _NORMAL,_NORM - N/A - 0 - _ROUGH,_ROUGHNESS - 1.0 - _METAL,_MET,_METALNESS,_METALLIC - 1 - _COMP,_COMPOSITE - Bilinear - 1 - - - 0 - 0 - 0 - 0 - Z_AXIS - 0 - 0 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 1 - TrailingNumber - - - 1 - Col - LOS - 1 - CollisionMesh - CollisionMesh - - - 1 - 1 - Seconds - 2 - - - 1 - 0 - 0 - AutoPrune + Default*; + 1 1.0 - 0 1.0 + 0 - - 1 - 1 - 1 - 1 - 1 + + AutoPrune + + + 1 + 1 diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.cs index 381ccff65..3a8b15be6 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.cs @@ -1492,6 +1492,15 @@ function AssetBrowser::doRebuildAssetArray(%this) else { //got it. + if(%folderName $= "shaderCache" || %folderName $= "cache" || %folderName $= ".git") + continue; + + if(!%this.coreModulesFilter && %folderName $= "core" && %breadcrumbPath $= "") + continue; + + if(!%this.toolsModulesFilter && %folderName $= "tools" && %breadcrumbPath $= "") + continue; + %assetArray.add( %breadcrumbPath, "Folder" TAB %folderName ); } } @@ -1856,6 +1865,10 @@ function AssetBrowserAssetSearchBtn::onClick( %this ) // Navigation function AssetBrowser::navigateTo(%this, %address, %historyNav) { + //Sanitize + if(startsWith(%address, "/")) + %address = strreplace(%address, "/", ""); + //Don't bother navigating if it's to the place we already are if(AssetBrowser.dirHandler.currentAddress !$= %address) { diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImport.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImport.cs index 860c282b3..461a525f5 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImport.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImport.cs @@ -686,6 +686,7 @@ function ImportAssetWindow::doRefresh(%this) //Go ahead and check if we have any issues, and if not, run the import! ImportAssetWindow.importer.ImportAssets(); + ImportAssetWindow.importer.resetImportSession(true); } else { diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImportConfig.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImportConfig.cs index 62fcf8b7d..72802c731 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImportConfig.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImportConfig.cs @@ -12,10 +12,11 @@ function ImportAssetConfigList::onSelect( %this, %id, %text ) ImportAssetWindow.activeImportConfigIndex = %id; //ImportAssetWindow.activeImportConfig = ImportAssetWindow.importConfigsList.getKey(%id); - if(!isObject(%this.activeImporConfig)) - %this.activeImporConfig = new AssetImportConfig(); + if(!isObject(ImportAssetWindow.activeImportConfig)) + ImportAssetWindow.activeImportConfig = new AssetImportConfig(); - %this.activeImporConfig.loadImportConfig(AssetImportSettings, ImportAssetWindow.importConfigsList.getKey(%id)); + ImportAssetWindow.activeImportConfig.loadImportConfig(AssetImportSettings, ImportAssetWindow.importConfigsList.getKey(%id)); + ImportAssetWindow.importer.setImportConfig(ImportAssetWindow.activeImportConfig); //If we were trying to import anything, refresh it with the new config ImportAssetWindow.importer.resetImportSession(); diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.cs index f073ba6c6..642c9827d 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.cs @@ -39,6 +39,9 @@ function directoryHandler::loadFolders(%this, %path, %parentId) //we don't need to display the shadercache folder if(%parentName $= "Data" && (%folderName $= "shaderCache" || %folderName $= "cache")) continue; + + if(%folderName $= ".git") + continue; %iconIdx = 3;