diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp index bf665f7f7..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.getFileName() == temp2.getFileName()) + if (temp1.getPath() == temp2.getPath() && temp1.getFileName() == temp2.getFileName()) { return imgAsset; } diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index c584b5b8d..f05514803 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) \ @@ -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/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/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/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 ae9e73eb1..52955f90d 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..d53e8a4cb 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; } @@ -2521,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 { @@ -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 { @@ -2783,7 +2778,7 @@ function getAssetPreviewImage(%asset) if(%previewPath $= "") %previewPath = "ToolsModule:unknownImage_image"; - + return %previewPath; } 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 3f938f78b..f571f2aa6 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,21 @@ 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; @@ -108,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/material.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript index 05cada34d..bd88e1274 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript @@ -64,7 +64,10 @@ 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 +111,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 +126,6 @@ function MaterialAsset::generatePreviewImage(%this, %previewButton, %forceRegene } } - %previewAssetName = %module.moduleId @ "_" @ %this.assetName @ "_PreviewImage"; - if(%generatePreview || %forceRegenerate) { if(isObject(%this.materialDefinitionName)) @@ -142,39 +143,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..6bad1868a 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 @ ".dds"; 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; @@ -175,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 ) 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;