Merge pull request #1489 from Areloch/DirectImageFileOption

Direct image file option
This commit is contained in:
Brian Roberts 2025-05-31 07:18:24 -05:00 committed by GitHub
commit f709130e72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 92 additions and 154 deletions

View file

@ -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;
}

View file

@ -244,7 +244,8 @@ DefineEnumType(ImageAssetType);
#define DECLARE_IMAGEASSET(className, name, profile) \
private: \
AssetPtr<ImageAsset> m##name##Asset; \
AssetPtr<ImageAsset> 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<ImageAsset> 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<ImageAsset> 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<ImageAsset> 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) \

View file

@ -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;

View file

@ -132,6 +132,7 @@ GuiBitmapButtonCtrl::GuiBitmapButtonCtrl()
mBitmapName = StringTable->EmptyString();
mBitmap = NULL;
mBitmapAsset.registerRefreshNotify(this);
mBitmapFile = String::EmptyString;
}
//-----------------------------------------------------------------------------

View file

@ -118,7 +118,11 @@ class GuiBitmapButtonCtrl : public GuiButtonCtrl, protected AssetPtrCallback
///
BitmapMode mBitmapMode;
private: AssetPtr<ImageAsset> mBitmapAsset; public: void _setBitmap(StringTableEntry _in) {
private:
AssetPtr<ImageAsset> 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];

View file

@ -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);

View file

@ -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;
}

View file

@ -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

View file

@ -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 )
{

View file

@ -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;
}
}

View file

@ -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 )

View file

@ -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 )

View file

@ -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;