From 0fa8b97f911e01e3ccb181a1e253b1ebce6bc608 Mon Sep 17 00:00:00 2001 From: JeffR Date: Tue, 27 May 2025 17:12:03 -0500 Subject: [PATCH 1/5] Reimplements ability to utilize direct file load alongside ImageAsset fields when utilizing the ImageAsset macros Updates Asset Browser generated preview images to not utilize full assets, but just the preview image files themselves --- Engine/source/T3D/assets/ImageAsset.h | 11 +++- .../source/gui/buttons/guiBitmapButtonCtrl.h | 6 +- Engine/source/gui/controls/guiBitmapCtrl.cpp | 2 +- .../assetBrowser/scripts/assetBrowser.tscript | 21 +++---- .../scripts/assetTypes/image.tscript | 57 ++++++------------- .../scripts/assetTypes/material.tscript | 44 +++----------- .../scripts/assetTypes/shape.tscript | 45 +++------------ 7 files changed, 56 insertions(+), 130 deletions(-) diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index c584b5b8d..0021b4e0d 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -244,7 +244,8 @@ DefineEnumType(ImageAssetType); #define DECLARE_IMAGEASSET(className, name, profile) \ private: \ - AssetPtr m##name##Asset; \ + AssetPtr m##name##Asset;\ + String m##name##File;\ public: \ void _set##name(StringTableEntry _in){ \ if(m##name##Asset.getAssetId() == _in) \ @@ -263,7 +264,7 @@ public: { \ imageAssetId = query.mAssetList[0]; \ } \ - else if(Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \ + else if(Torque::FS::IsFile(_in)) \ { \ imageAssetId = ImageAsset::getAssetIdByFilename(_in); \ if (imageAssetId == ImageAsset::smNoImageAssetFallback) \ @@ -296,6 +297,7 @@ public: #define DECLARE_IMAGEASSET_NET(className, name, profile, mask) \ private: \ AssetPtr m##name##Asset; \ + String m##name##File;\ public: \ void _set##name(StringTableEntry _in){ \ if(m##name##Asset.getAssetId() == _in) \ @@ -347,12 +349,14 @@ public: #define INITPERSISTFIELD_IMAGEASSET(name, consoleClass, docs) \ - addProtectedField(assetText(name, Asset), TypeImageAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.)); + addProtectedField(assetText(name, Asset), TypeImageAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.)); \ + addProtectedField(assetText(name, File), TypeFilename, Offset(m##name##File, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, file docs.)); #define DECLARE_IMAGEASSET_ARRAY(className, name, profile, max) \ private: \ AssetPtr m##name##Asset[max]; \ + String m##name##File[max];\ public: \ void _set##name(StringTableEntry _in, const U32& index){ \ if(m##name##Asset[index].getAssetId() == _in) \ @@ -405,6 +409,7 @@ public: #define DECLARE_IMAGEASSET_ARRAY_NET(className, name, profile, max, mask) \ private: \ AssetPtr m##name##Asset[max]; \ + String m##name##File[max];\ public: \ void _set##name(StringTableEntry _in, const U32& index){ \ if(m##name##Asset[index].getAssetId() == _in) \ diff --git a/Engine/source/gui/buttons/guiBitmapButtonCtrl.h b/Engine/source/gui/buttons/guiBitmapButtonCtrl.h index a4d9351e4..773f7eb2c 100644 --- a/Engine/source/gui/buttons/guiBitmapButtonCtrl.h +++ b/Engine/source/gui/buttons/guiBitmapButtonCtrl.h @@ -118,7 +118,11 @@ class GuiBitmapButtonCtrl : public GuiButtonCtrl, protected AssetPtrCallback /// BitmapMode mBitmapMode; -private: AssetPtr mBitmapAsset; public: void _setBitmap(StringTableEntry _in) { +private: + AssetPtr mBitmapAsset; + String mBitmapFile; +public: + void _setBitmap(StringTableEntry _in) { if (mBitmapAsset.getAssetId() == _in) return; if (!AssetDatabase.isDeclaredAsset(_in)) { StringTableEntry imageAssetId = ImageAsset::smNoImageAssetFallback; AssetQuery query; S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); if (foundAssetcount != 0) { imageAssetId = query.mAssetList[0]; diff --git a/Engine/source/gui/controls/guiBitmapCtrl.cpp b/Engine/source/gui/controls/guiBitmapCtrl.cpp index bcf667361..b169d0ba8 100644 --- a/Engine/source/gui/controls/guiBitmapCtrl.cpp +++ b/Engine/source/gui/controls/guiBitmapCtrl.cpp @@ -121,7 +121,7 @@ void GuiBitmapCtrl::setBitmap(const char* name, bool resize) if (assetId != StringTable->EmptyString()) _setBitmap(assetId); else - return; + _setBitmap(name); } mBitmap = mBitmapAsset->getTexture(&GFXDefaultGUIProfile); diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript index 9dcd48e63..a1e95cfcf 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript @@ -740,7 +740,7 @@ function AssetBrowser::buildAssetPreview( %this, %asset, %moduleName ) %previewButton.assetType = %assetType; %previewButton.assetBrowser = %this; - %previewButton.bitmapAsset = %this.previewData.previewImage; + %previewButton.setBitmap(%this.previewData.previewImage); %previewButton.profile = "AssetBrowserPreview" @ %previewButton.assetType; %previewButton.tooltip = %this.previewData.tooltip; @@ -789,21 +789,15 @@ function AssetBrowser::doRefresh(%this) function AssetBrowser::populatePreviewImages(%this) { - if (AssetPreviewArray.count()>0) - echo("AssetBrowser::populatePreviewImages() - Previews to generate: " @ AssetPreviewArray.count()); - for(%i=0; %i < AssetPreviewArray.count(); %i++) { %previewButton = AssetPreviewArray.getKey(%i); %assetType = %previewButton.assetType; - echo(" - Generating preview for asset: " @ %previewButton.moduleName @ ":" @ %previewButton.assetName); - %this.callAssetTypeFunc(%assetType, "generatePreviewImage", %previewButton.moduleName, %previewButton.assetName, %previewButton); AssetPreviewArray.erase(%i); - - echo(" - done, scheduling another pass"); + %this.schedule(32, "populatePreviewImages"); return; } @@ -2764,12 +2758,13 @@ function getAssetPreviewImage(%asset) { %moduleName = AssetDatabase.getAssetModule(%asset).ModuleId; %assetName = AssetDatabase.getAssetName(%asset); - %previewAssetName = "ToolsModule:" @ %moduleName @ "_" @ %assetName @ "_PreviewImage"; - if(AssetDatabase.isDeclaredAsset(%previewAssetName)) + + %previewPath = "tools/resources/previewCache/" @ %moduleName @ "/"; + %previewFilePath = %previewPath @ %assetName @ ".png"; + + if(isFile(%previewFilePath)) { - %previewDef = AssetDatabase.acquireAsset(%previewAssetName); - %previewPath = %previewDef.getImagePath(); - AssetDatabase.releaseAsset(%previewAssetName); + %previewPath = %previewFilePath; } else { diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript index 3f938f78b..cce914b8e 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript @@ -4,7 +4,17 @@ function ImageAsset::buildBrowserElement(%this, %previewData) { //%module = %this.dirHandler.getModuleFromAddress(makeRelativePath(filePath(%assetDef.getImagePath()))); - %previewData.previewImage = %this.isNamedTarget() ? "Core_Rendering:namedTarget_image" : "ToolsModule:genericAssetIcon_image"; + if( %this.isNamedTarget()) + %previewImage = "Core_Rendering:namedTarget_image"; + else + { + %previewImage = getAssetPreviewImage(%this.getAssetId()); + if(!isFile(%previewImage)) + %previewImage = "ToolsModule:genericAssetIcon_image"; + } + + %previewData.previewImage = %previewImage; + %previewData.previewLoaded = %this.isNamedTarget() ? true : false;//this marks it for loading progressively later %previewData.assetName = %this.assetName; @@ -39,55 +49,20 @@ function ImageAsset::generatePreviewImage(%this, %previewButton, %forceRegenerat $CurrentAssetBrowser.dirHandler.createFolder(%previewPath); } - %previewFilePath = %previewPath @ %this.assetName @ "_Preview.png"; + %previewFilePath = %previewPath @ %this.assetName @ ".png"; if(!isFile(%previewFilePath) || (compareFileTimes(%this.getImagePath(), %previewFilePath) == 1)) { %generatePreview = true; } - - %previewAssetName = %previewButton.moduleName @ "_" @ %this.assetName @ "_PreviewImage"; - + if(%generatePreview || %forceRegenerate) { %success = saveScaledImage(%this.getImagePath(), %previewFilePath, EditorSettings.value("Assets/Browser/PreviewImageSize")); if(%success) - { - if(!AssetDatabase.isDeclaredAsset("ToolsModule:" @ %previewAssetName)) - { - %previewAsset = new ImageAsset() - { - assetName = %previewAssetName; - versionId = 1; - imageFile = makeFullPath(%previewFilePath); - }; - - %previewAssetName = "ToolsModule:" @ %previewAssetName; - %previewImgAssetPath = %previewPath @ %previewAsset.assetName @ ".asset.taml"; - %assetImportSuccessful = TAMLWrite(%previewAsset, %previewImgAssetPath); - - %toolsModuleDef = ModuleDatabase.findModule("ToolsModule",1); - - %success = AssetDatabase.addDeclaredAsset(%toolsModuleDef, %previewImgAssetPath); - - if(!%success) - { - return false; //failed to register the preview image for some reason? - } - } - - %previewButton.bitmapAsset = %previewAssetName; - return true; - } - } - else - { - //just map the existing one then - if(AssetDatabase.isDeclaredAsset("ToolsModule:" @ %previewAssetName)) - { - %previewButton.bitmapAsset = "ToolsModule:" @ %previewAssetName; - return true; - } + %previewButton.setBitmap(%previewFilePath); + + return %success; } return false; diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript index 05cada34d..420ca2b1b 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript @@ -64,7 +64,9 @@ function AssetBrowser::renameMaterialAsset(%this, %assetDef, %newAssetName) function MaterialAsset::buildBrowserElement(%this, %previewData) { - %previewData.previewImage = "ToolsModule:genericAssetIcon_image"; + %previewImage = getAssetPreviewImage(%this.getAssetId()); + + %previewData.previewImage = isFile(%previewImage) ? %previewImage : "ToolsModule:genericAssetIcon_image"; %previewData.previewLoaded = false; //this marks it for loading progressively later %previewData.assetName = %this.assetName; @@ -108,7 +110,7 @@ function MaterialAsset::generatePreviewImage(%this, %previewButton, %forceRegene %generatePreview = false; - %previewFilePath = %previewPath @ %this.assetName @ "_Preview.dds"; + %previewFilePath = %previewPath @ %this.assetName @ ".png"; if(!isFile(%previewFilePath)) { %generatePreview = true; @@ -123,8 +125,6 @@ function MaterialAsset::generatePreviewImage(%this, %previewButton, %forceRegene } } - %previewAssetName = %module.moduleId @ "_" @ %this.assetName @ "_PreviewImage"; - if(%generatePreview || %forceRegenerate) { if(isObject(%this.materialDefinitionName)) @@ -142,39 +142,13 @@ function MaterialAsset::generatePreviewImage(%this, %previewButton, %forceRegene pathCopy(%generatedFilePath, %previewFilePath, false); fileDelete(%generatedFilePath); - if(!AssetDatabase.isDeclaredAsset("ToolsModule:" @ %previewAssetName)) + if(isFile(%previewFilePath)) { - %previewAsset = new ImageAsset() - { - assetName = %previewAssetName; - versionId = 1; - imageFile = makeFullPath(%previewFilePath); - }; - - %previewImgAssetPath = %previewPath @ %previewAsset.assetName @ ".asset.taml"; - - %assetImportSuccessful = TAMLWrite(%previewAsset, %previewImgAssetPath); - %toolsModuleDef = ModuleDatabase.findModule("ToolsModule",1); - - %success = AssetDatabase.addDeclaredAsset(%toolsModuleDef, %previewImgAssetPath); - - if(!%success) - { - return false; //failed to register the preview image for some reason? - } + %previewButton.setBitmap(%previewFilePath); + return true; } - - %previewButton.bitmapAsset = "ToolsModule:" @ %previewAssetName; - return true; - } - } - else - { - //just map the existing one then - if(AssetDatabase.isDeclaredAsset("ToolsModule:" @ %previewAssetName)) - { - %previewButton.bitmapAsset = "ToolsModule:" @ %previewAssetName; - return true; + + return false; } } diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript index 6749c688f..dd337ecb6 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript @@ -28,7 +28,7 @@ function ShapeAsset::onDelete(%this) { //Special handle the cache preview image %module = $CurrentAssetBrowser.dirHandler.getModuleFromAddress(makeRelativePath(filePath(%this.getShapePath()))); - %previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/" @ %this.assetName @ "_Preview.dds"; + %previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/" @ %this.assetName @ ".png"; if(isFile(%previewPath)) { @@ -41,7 +41,9 @@ function ShapeAsset::onDelete(%this) function ShapeAsset::buildBrowserElement(%this, %previewData) { - %previewData.previewImage = "ToolsModule:genericAssetIcon_image"; + %previewImage = getAssetPreviewImage(%this.getAssetId()); + + %previewData.previewImage = isFile(%previewImage) ? %previewImage : "ToolsModule:genericAssetIcon_image"; %previewData.previewLoaded = false; //this marks it for loading progressively later %previewData.assetName = %this.assetName; @@ -88,18 +90,15 @@ function ShapeAsset::generatePreviewImage(%this, %previewButton, %forceRegenerat %generatePreview = false; - %previewFilePath = %previewPath @ %this.assetName @ "_Preview.dds"; + %previewFilePath = %previewPath @ %this.assetName @ ".png"; if(!isFile(%previewFilePath) || (compareFileTimes(%this.getShapePath(), %previewFilePath) == 1)) { %generatePreview = true; } - %previewAssetName = %module.moduleId @ "_" @ %this.assetName @ "_PreviewImage"; - if(%generatePreview || %forceRegenerate) { //real fast, we'll be 100% sure that the image resource we need is loaded - %matSlot0AssetId = %this.materialSlot0; if(AssetDatabase.isDeclaredAsset(%matSlot0AssetId)) { @@ -115,39 +114,13 @@ function ShapeAsset::generatePreviewImage(%this, %previewButton, %forceRegenerat pathCopy(%filePath, %previewFilePath, false); fileDelete(%filePath); //cleanup - if(!AssetDatabase.isDeclaredAsset("ToolsModule:" @ %previewAssetName)) + if(isFile(%previewFilePath)) { - %previewAsset = new ImageAsset() - { - assetName = %previewAssetName; - versionId = 1; - imageFile = makeFullPath(%previewFilePath); - }; - - %previewImgAssetPath = %previewPath @ %previewAsset.assetName @ ".asset.taml"; - - %assetImportSuccessful = TAMLWrite(%previewAsset, %previewImgAssetPath); - %toolsModuleDef = ModuleDatabase.findModule("ToolsModule",1); - - %success = AssetDatabase.addDeclaredAsset(%toolsModuleDef, %previewImgAssetPath); - - if(!%success) - { - return false; //failed to register the preview image for some reason? - } - } - - %previewButton.bitmapAsset = "ToolsModule:" @ %previewAssetName; - return true; - } - else - { - //just map the existing one then - if(AssetDatabase.isDeclaredAsset("ToolsModule:" @ %previewAssetName)) - { - %previewButton.bitmapAsset = "ToolsModule:" @ %previewAssetName; + %previewButton.setBitmap(%previewFilePath); return true; } + + return false; } return false; From 8ed3bab44cb2c30ef48f85bcbdd4cdddd3ac0886 Mon Sep 17 00:00:00 2001 From: JeffR Date: Wed, 28 May 2025 17:47:23 -0500 Subject: [PATCH 2/5] Re-added prefix handling for named texture lookups for image asset fields Changed render-out of shape preview images to use png Added filter against previewCache folder --- Engine/source/T3D/assets/ImageAsset.h | 2 +- Engine/source/T3D/assets/ShapeAsset.cpp | 19 ++----------------- .../assetBrowser/scripts/assetBrowser.tscript | 2 +- .../scripts/assetTypes/image.tscript | 1 + .../scripts/assetTypes/material.tscript | 1 + .../scripts/assetTypes/shape.tscript | 2 +- .../scripts/directoryHandling.tscript | 3 +++ 7 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index 0021b4e0d..99230fb76 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -264,7 +264,7 @@ public: { \ imageAssetId = query.mAssetList[0]; \ } \ - else if(Torque::FS::IsFile(_in)) \ + else if(Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \ { \ imageAssetId = ImageAsset::getAssetIdByFilename(_in); \ if (imageAssetId == ImageAsset::smNoImageAssetFallback) \ diff --git a/Engine/source/T3D/assets/ShapeAsset.cpp b/Engine/source/T3D/assets/ShapeAsset.cpp index 8945335a7..ff27573cc 100644 --- a/Engine/source/T3D/assets/ShapeAsset.cpp +++ b/Engine/source/T3D/assets/ShapeAsset.cpp @@ -626,28 +626,13 @@ const char* ShapeAsset::generateCachedPreviewImage(S32 resolution, String overri delete imposterCap; delete shape; - String dumpPath = String(mFilePath) + "_Preview.dds"; + String dumpPath = String(mFilePath) + ".png"; char* returnBuffer = Con::getReturnBuffer(128); dSprintf(returnBuffer, 128, "%s", dumpPath.c_str()); - /*FileStream stream; - if (stream.open(dumpPath, Torque::FS::File::Write)) - destBmp.writeBitmap("png", stream); - stream.close();*/ + imposter->writeBitmap("png", dumpPath); - DDSFile* ddsDest = DDSFile::createDDSFileFromGBitmap(imposter); - ImageUtil::ddsCompress(ddsDest, GFXFormatBC2); - - // Finally save the imposters to disk. - FileStream fs; - if (fs.open(returnBuffer, Torque::FS::File::Write)) - { - ddsDest->write(fs); - fs.close(); - } - - delete ddsDest; delete imposter; delete imposterNrml; diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript index a1e95cfcf..78a17d041 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript @@ -2778,7 +2778,7 @@ function getAssetPreviewImage(%asset) if(%previewPath $= "") %previewPath = "ToolsModule:unknownImage_image"; - + return %previewPath; } diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript index cce914b8e..0a9350d50 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript @@ -50,6 +50,7 @@ function ImageAsset::generatePreviewImage(%this, %previewButton, %forceRegenerat } %previewFilePath = %previewPath @ %this.assetName @ ".png"; + if(!isFile(%previewFilePath) || (compareFileTimes(%this.getImagePath(), %previewFilePath) == 1)) { %generatePreview = true; diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript index 420ca2b1b..bd88e1274 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript @@ -67,6 +67,7 @@ function MaterialAsset::buildBrowserElement(%this, %previewData) %previewImage = getAssetPreviewImage(%this.getAssetId()); %previewData.previewImage = isFile(%previewImage) ? %previewImage : "ToolsModule:genericAssetIcon_image"; + %previewData.previewLoaded = false; //this marks it for loading progressively later %previewData.assetName = %this.assetName; diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript index dd337ecb6..c4fad9a5d 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript @@ -28,7 +28,7 @@ function ShapeAsset::onDelete(%this) { //Special handle the cache preview image %module = $CurrentAssetBrowser.dirHandler.getModuleFromAddress(makeRelativePath(filePath(%this.getShapePath()))); - %previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/" @ %this.assetName @ ".png"; + %previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/" @ %this.assetName @ ".dds"; if(isFile(%previewPath)) { diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.tscript index 92ecd22e8..4f7a12b6d 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.tscript @@ -40,6 +40,9 @@ function directoryHandler::loadFolders(%this, %path, %parentId) if(%parentName $= "Data" && (%folderName $= "shaderCache" || %folderName $= "cache")) continue; + if(%folderName $= "previewCache") + continue; + if(%folderName $= ".git") continue; From 029427d51cbc54713b197779f1f7ecbb6b79df3b Mon Sep 17 00:00:00 2001 From: JeffR Date: Wed, 28 May 2025 23:23:08 -0500 Subject: [PATCH 3/5] Fixes imageAsset lookup so if we're looking up a full filename path, we compare the actual full paths --- Engine/source/T3D/assets/ImageAsset.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp index bf665f7f7..fcc9570b8 100644 --- a/Engine/source/T3D/assets/ImageAsset.cpp +++ b/Engine/source/T3D/assets/ImageAsset.cpp @@ -289,7 +289,7 @@ StringTableEntry ImageAsset::getAssetIdByFilename(StringTableEntry fileName) Torque::Path temp1 = temp->getImageFile(); Torque::Path temp2 = fileName; - if (temp1.getFileName() == temp2.getFileName()) + if (temp1 == temp2) { return imgAsset; } From 41957cb98f09e30e1cd8c773fc00916722f30f7e Mon Sep 17 00:00:00 2001 From: JeffR Date: Thu, 29 May 2025 16:06:04 -0500 Subject: [PATCH 4/5] Compares path and filename, excludes png in case the user swapped a dds for a png or the like --- Engine/source/T3D/assets/ImageAsset.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp index fcc9570b8..a17b7f934 100644 --- a/Engine/source/T3D/assets/ImageAsset.cpp +++ b/Engine/source/T3D/assets/ImageAsset.cpp @@ -289,7 +289,7 @@ StringTableEntry ImageAsset::getAssetIdByFilename(StringTableEntry fileName) Torque::Path temp1 = temp->getImageFile(); Torque::Path temp2 = fileName; - if (temp1 == temp2) + if (temp1.getPath() == temp2.getPath() && temp1.getFileName() == temp2.getFileName()) { return imgAsset; } From 0e6c33f78af4b1871eec1a826dab5c665c66a66c Mon Sep 17 00:00:00 2001 From: JeffR Date: Fri, 30 May 2025 20:21:13 -0500 Subject: [PATCH 5/5] Fixed gui editor drag and drop behavior for image, shape, and sound Ensure BitmapFile is given a proper default --- Engine/source/T3D/assets/ImageAsset.h | 2 +- Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp | 1 + .../tools/assetBrowser/scripts/assetBrowser.tscript | 2 +- .../scripts/assetTypes/genericAsset.tscript | 8 ++++---- .../assetBrowser/scripts/assetTypes/image.tscript | 12 ++++++++++++ .../assetBrowser/scripts/assetTypes/shape.tscript | 9 ++++++++- .../assetBrowser/scripts/assetTypes/sound.tscript | 2 ++ 7 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index 99230fb76..f05514803 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -264,7 +264,7 @@ public: { \ imageAssetId = query.mAssetList[0]; \ } \ - else if(Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \ + else if(Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \ { \ imageAssetId = ImageAsset::getAssetIdByFilename(_in); \ if (imageAssetId == ImageAsset::smNoImageAssetFallback) \ diff --git a/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp b/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp index e6f063428..f2ee24d43 100644 --- a/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp +++ b/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp @@ -132,6 +132,7 @@ GuiBitmapButtonCtrl::GuiBitmapButtonCtrl() mBitmapName = StringTable->EmptyString(); mBitmap = NULL; mBitmapAsset.registerRefreshNotify(this); + mBitmapFile = String::EmptyString; } //----------------------------------------------------------------------------- diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript index 78a17d041..d53e8a4cb 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript @@ -2515,7 +2515,7 @@ function GuiEditor::onControlDropped(%this, %payload, %position) %assetId = %payload.moduleName @ ":" @ %payload.assetName; %assetType = AssetDatabase.getAssetType(%assetId); - AssetBrowser.callAssetTypeFunc(%assetType, "GUIEditorDropped", %payload.moduleName, %payload.assetName, %pos); + %ctrl = AssetBrowser.callAssetTypeFunc(%assetType, "onGUIEditorDropped", %payload.moduleName, %payload.assetName, %pos); } else { diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/genericAsset.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/genericAsset.tscript index 1b7b569ac..b725748f3 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/genericAsset.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/genericAsset.tscript @@ -319,18 +319,18 @@ function GenericAsset::onSaveProperties(%this) //Called when the asset's Preview has been dragged and dropped into the world editor //This would usually spawn an associated instance, or a scene object that can utilize the //asset in question(ie, Dropping a SoundAsset spawns a SoundEmitter) -function GenericAsset::onWorldEditorDropped(%this, %position) +/*function GenericAsset::onWorldEditorDropped(%this, %position) { echo("GenericAsset::onWorldEditorDropped() - " @ %this @ ", " @ %position); -} +}*/ //Called when the asset's Preview has been dragged and dropped into the GUI editor //This would usually spawn an associated instance, or a gui object that can utilize the //asset in question(ie, Dropping a SoundAsset spawns a guiAudioCtrl) -function GenericAsset::onGuiEditorDropped(%this, %position) +/*function GenericAsset::onGuiEditorDropped(%this, %position) { echo("GenericAsset::onGuiEditorDropped() - " @ %this @ ", " @ %position); -} +}*/ //An example case of handling other specialized editors, such as dropping a Datablock //Preview into the DatablockEditor. This would be very case-by-case diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript index 0a9350d50..f571f2aa6 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.tscript @@ -84,6 +84,18 @@ function ImageAsset::onSaveProperties(%this) { GenericAsset::onSaveProperties(%this); } + +function ImageAsset::onGuiEditorDropped(%this, %position) +{ + %assetId = %this.getAssetId(); + %cmd = "new GuiBitmapCtrl(){"; + %cmd = %cmd @ "BitmapAsset =\""@ %assetId @"\";"; + %cmd = %cmd @ "position =\""@ %position @"\";"; + %cmd = %cmd @ "};"; + %ctrl = GuiEditCanvas.createObject(%cmd); + + return %ctrl; +} function GuiInspectorTypeImageAssetPtr::onControlDropped( %this, %payload, %position ) { diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript index c4fad9a5d..6bad1868a 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.tscript @@ -148,9 +148,16 @@ function ShapeAsset::onWorldEditorDropped(%assetDef, %position) MECreateUndoAction::submit(%newStatic ); } -function ShapeAsset::onGUIEditorDropped(%assetDef, %position) +function ShapeAsset::onGUIEditorDropped(%this, %position) { + %assetId = %this.getAssetId(); + %cmd = "new GuiObjectView(){"; + %cmd = %cmd @ "ModelAsset =\""@ %assetId @"\";"; + %cmd = %cmd @ "position =\""@ %position @"\";"; + %cmd = %cmd @ "};"; + %ctrl = GuiEditCanvas.createObject(%cmd); + return %ctrl; } function GuiInspectorTypeShapeAssetPtr::onControlDropped( %this, %payload, %position ) diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/sound.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/sound.tscript index 8ed6919bf..5a90c3d6b 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/sound.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/sound.tscript @@ -87,6 +87,8 @@ function SoundAsset::onGUIEditorDropped(%this, %position) %cmd = %cmd @ "};"; %ctrl = GuiEditCanvas.createObject(%cmd); //echo(%ctrl SPC "created"); + + return %ctrl; } function GuiInspectorTypeSoundAssetPtr::onControlDropped( %this, %payload, %position )