mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-12 19:31:41 +00:00
Adds console function to compare file modified times
Adds console function to save a scaled image Improved logic of generating previews for shape, material and image assets to regen if original asset loose file was modified Added logic to generate scaled preview image for material and image assets to improve load times of AB
This commit is contained in:
parent
555c563b39
commit
34f0f01cea
6 changed files with 206 additions and 41 deletions
|
|
@ -346,6 +346,13 @@ DefineEngineStaticMethod(MaterialAsset, getAssetIdByMaterialName, const char*, (
|
|||
{
|
||||
return MaterialAsset::getAssetIdByMaterialName(StringTable->insert(materialName));
|
||||
}
|
||||
|
||||
DefineEngineMethod(MaterialAsset, getScriptPath, const char*, (), ,
|
||||
"Queries the Asset Database to see if any asset exists that is associated with the provided material name.\n"
|
||||
"@return The AssetId of the associated asset, if any.")
|
||||
{
|
||||
return object->getScriptPath();
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -580,6 +580,27 @@ DefineEngineFunction( fileCreatedTime, String, ( const char* fileName ),,
|
|||
return buffer;
|
||||
}
|
||||
|
||||
DefineEngineFunction(compareFileTimes, S32, (const char* fileA, const char* fileB), ("", ""),
|
||||
"@brief Compares 2 files' modified file times."
|
||||
|
||||
"@param fileName Name and path of first file to compare\n"
|
||||
"@param fileName Name and path of second file to compare\n"
|
||||
"@return S32. If value is 1, then fileA is newer. If value is -1, then fileB is newer. If value is 0, they are equal.\n"
|
||||
"@ingroup FileSystem")
|
||||
{
|
||||
Con::expandScriptFilename(sgScriptFilenameBuffer, sizeof(sgScriptFilenameBuffer), fileA);
|
||||
|
||||
FileTime fileATime = { 0 };
|
||||
Platform::getFileTimes(sgScriptFilenameBuffer, NULL, &fileATime);
|
||||
|
||||
Con::expandScriptFilename(sgScriptFilenameBuffer, sizeof(sgScriptFilenameBuffer), fileB);
|
||||
|
||||
FileTime fileBTime = { 0 };
|
||||
Platform::getFileTimes(sgScriptFilenameBuffer, NULL, &fileBTime);
|
||||
|
||||
return Platform::compareFileTimes(fileATime, fileBTime);
|
||||
}
|
||||
|
||||
DefineEngineFunction(fileDelete, bool, ( const char* path ),,
|
||||
"@brief Delete a file from the hard drive\n\n"
|
||||
|
||||
|
|
|
|||
|
|
@ -1360,3 +1360,55 @@ DefineEngineFunction( getBitmapInfo, String, ( const char *filename ),,
|
|||
image->getBytesPerPixel(),
|
||||
image->getFormat());
|
||||
}
|
||||
|
||||
DefineEngineFunction(saveScaledImage, bool, (const char* bitmapSource, const char* bitmapDest, S32 resolutionSize), ("", "", 512),
|
||||
"Returns image info in the following format: width TAB height TAB bytesPerPixel TAB format. "
|
||||
"It will return an empty string if the file is not found.\n"
|
||||
"@ingroup Rendering\n")
|
||||
{
|
||||
Resource<GBitmap> image = GBitmap::load(bitmapSource);
|
||||
if (!image)
|
||||
return false;
|
||||
|
||||
Torque::Path sourcePath = Torque::Path(bitmapSource);
|
||||
|
||||
/*if (String("dds").equal(sourcePath.getExtension(), String::NoCase))
|
||||
{
|
||||
dds = DDSFile::load(correctPath, scalePower);
|
||||
if (dds != NULL)
|
||||
{
|
||||
if (!dds->decompressToGBitmap(image))
|
||||
{
|
||||
delete image;
|
||||
image = NULL;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
image->extrudeMipLevels();
|
||||
|
||||
U32 mipCount = image->getNumMipLevels();
|
||||
U32 targetMips = mFloor(mLog2((F32)resolutionSize)) + 1;
|
||||
|
||||
if (mipCount > targetMips)
|
||||
{
|
||||
image->chopTopMips(mipCount - targetMips);
|
||||
}
|
||||
|
||||
// Open up the file on disk.
|
||||
FileStream fs;
|
||||
if (!fs.open(bitmapDest, Torque::FS::File::Write))
|
||||
{
|
||||
Con::errorf("saveScaledImage() - Failed to open output file '%s'!", bitmapDest);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
image->writeBitmap("png", fs);
|
||||
|
||||
fs.close();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,15 +172,55 @@ function AssetBrowser::importImageAsset(%this, %assetItem)
|
|||
|
||||
function AssetBrowser::buildImageAssetPreview(%this, %assetDef, %previewData)
|
||||
{
|
||||
%module = %this.dirHandler.getModuleFromAddress(makeRelativePath(filePath(%assetDef.getImagePath())));
|
||||
%previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/";
|
||||
|
||||
if(!IsDirectory(%previewPath))
|
||||
{
|
||||
%this.dirHandler.createFolder(%previewPath);
|
||||
}
|
||||
|
||||
%generatePreview = false;
|
||||
|
||||
%previewFilePath = %previewPath @ %assetDef.assetName @ "_Preview.png";
|
||||
if(!isFile(%previewFilePath) || (compareFileTimes(%assetDef.getImagePath(), %previewFilePath) == 1))
|
||||
{
|
||||
%generatePreview = true;
|
||||
}
|
||||
|
||||
%previewAssetName = %module.moduleId @ "_" @ %assetDef.assetName @ "_PreviewImage";
|
||||
|
||||
if(%generatePreview)
|
||||
{
|
||||
displayEditorLoadingGui("Generating Image Asset Preview...");
|
||||
|
||||
%success = saveScaledImage(%assetDef.getImagePath(), %previewFilePath);
|
||||
|
||||
%previewAsset = new ImageAsset()
|
||||
{
|
||||
assetName = %previewAssetName;
|
||||
versionId = 1;
|
||||
imageFile = fileName(%previewFilePath);
|
||||
};
|
||||
|
||||
%previewImgAssetPath = %previewPath @ %previewAsset.assetName @ ".asset.taml";
|
||||
%assetImportSuccessful = TAMLWrite(%previewAsset, %previewImgAssetPath);
|
||||
|
||||
%toolsModuleDef = ModuleDatabase.findModule("ToolsModule",1);
|
||||
|
||||
%success = AssetDatabase.addDeclaredAsset(%toolsModuleDef, %previewImgAssetPath);
|
||||
|
||||
hideEditorLoadingGui();
|
||||
}
|
||||
|
||||
//Revalidate. If it didn't work, just use the default placeholder one
|
||||
if(!isFile(%previewFilePath))
|
||||
%previewAssetName = "ToolsModule:genericAssetIcon_image";
|
||||
|
||||
%previewData.assetName = %assetDef.assetName;
|
||||
%previewData.assetPath = %assetDef.scriptFile;
|
||||
//%previewData.doubleClickCommand = "EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );";
|
||||
|
||||
%imageFilePath = %assetDef.getImagePath();
|
||||
if(isFile(%imageFilePath))
|
||||
%previewData.previewImage = %imageFilePath;
|
||||
else
|
||||
%previewData.previewImage = "core/rendering/images/unavailable";
|
||||
%previewData.previewImage = "ToolsModule:" @ %previewAssetName;//%assetDef.fileName;
|
||||
|
||||
%previewData.assetFriendlyName = %assetDef.assetName;
|
||||
%previewData.assetDesc = %assetDef.description;
|
||||
|
|
|
|||
|
|
@ -423,41 +423,77 @@ function AssetBrowser::importMaterialAsset(%this, %assetItem)
|
|||
|
||||
function AssetBrowser::buildMaterialAssetPreview(%this, %assetDef, %previewData)
|
||||
{
|
||||
%module = %this.dirHandler.getModuleFromAddress(makeRelativePath(filePath(%assetDef.getScriptPath())));
|
||||
%previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/";
|
||||
|
||||
if(!IsDirectory(%previewPath))
|
||||
{
|
||||
%this.dirHandler.createFolder(%previewPath);
|
||||
}
|
||||
|
||||
%generatePreview = false;
|
||||
|
||||
%previewFilePath = %previewPath @ %assetDef.assetName @ "_Preview.png";
|
||||
if(!isFile(%previewFilePath) || (compareFileTimes(%assetDef.getImagePath(), %previewFilePath) == 1))
|
||||
{
|
||||
%generatePreview = true;
|
||||
}
|
||||
|
||||
%previewAssetName = %module.moduleId @ "_" @ %assetDef.assetName @ "_PreviewImage";
|
||||
|
||||
if(%generatePreview)
|
||||
{
|
||||
displayEditorLoadingGui("Generating Material Asset Preview...");
|
||||
|
||||
if(isObject(%assetDef.materialDefinitionName))
|
||||
{
|
||||
if(isFile(%assetDef.materialDefinitionName.getDiffuseMap(0)))
|
||||
{
|
||||
%difMap = %assetDef.materialDefinitionName.getDiffuseMap(0);
|
||||
}
|
||||
else if(%assetDef.materialDefinitionName.getDiffuseMapAsset(0) !$= "")
|
||||
{
|
||||
%imgAsset = AssetDatabase.acquireAsset(%assetDef.materialDefinitionName.getDiffuseMapAsset(0));
|
||||
%difMap = %imgAsset.getImagePath();
|
||||
}
|
||||
|
||||
//%success = saveScaledImage(%difMap, %previewFilePath);
|
||||
|
||||
%previewAsset = new ImageAsset()
|
||||
{
|
||||
assetName = %previewAssetName;
|
||||
versionId = 1;
|
||||
imageFile = fileName(%previewFilePath);
|
||||
};
|
||||
|
||||
%previewImgAssetPath = %previewPath @ %previewAsset.assetName @ ".asset.taml";
|
||||
%assetImportSuccessful = TAMLWrite(%previewAsset, %previewImgAssetPath);
|
||||
|
||||
%toolsModuleDef = ModuleDatabase.findModule("ToolsModule",1);
|
||||
|
||||
%success = AssetDatabase.addDeclaredAsset(%toolsModuleDef, %previewImgAssetPath);
|
||||
}
|
||||
|
||||
hideEditorLoadingGui();
|
||||
}
|
||||
|
||||
//Revalidate. If it didn't work, just use the default placeholder one
|
||||
if(!isFile(%previewFilePath))
|
||||
%previewAssetName = "ToolsModule:genericAssetIcon_image";
|
||||
|
||||
%previewData.assetName = %assetDef.assetName;
|
||||
%previewData.assetPath = %assetDef.scriptFile;
|
||||
|
||||
%previewData.previewImage = "ToolsModule:" @ %previewAssetName;//%assetDef.fileName;
|
||||
|
||||
%previewData.assetFriendlyName = %assetDef.assetName;
|
||||
%previewData.assetDesc = %assetDef.description;
|
||||
|
||||
//Lotta prepwork
|
||||
/*%previewData.doubleClickCommand = %assetDef@".materialDefinitionName.reload(); "
|
||||
@ "$Tools::materialEditorList = \"\";"
|
||||
@ "EWorldEditor.clearSelection();"
|
||||
@ "MaterialEditorGui.currentObject = 0;"
|
||||
@ "MaterialEditorGui.currentMode = \"asset\";"
|
||||
@ "MaterialEditorGui.currentMaterial = "@%assetDef@".materialDefinitionName;"
|
||||
@ "MaterialEditorGui.setActiveMaterial( "@%assetDef@".materialDefinitionName );"
|
||||
@ "EditorGui.setEditor(MaterialEditorPlugin); "
|
||||
@ "AssetBrowser.hideDialog();";*/
|
||||
|
||||
if(%this.selectMode)
|
||||
%previewData.doubleClickCommand = "AssetBrowser.selectAsset( AssetBrowser.selectedAsset );";
|
||||
else
|
||||
%previewData.doubleClickCommand = "AssetBrowser.editAsset( "@%assetDef@" );";
|
||||
|
||||
%previewData.previewImage = "ToolsModule:materialIcon_image";
|
||||
|
||||
if(isObject(%assetDef.materialDefinitionName))
|
||||
{
|
||||
if(isFile(%assetDef.materialDefinitionName.getDiffuseMap(0)))
|
||||
%previewData.previewImage = %assetDef.materialDefinitionName.getDiffuseMap(0);
|
||||
else if(%assetDef.materialDefinitionName.getDiffuseMapAsset(0) !$= "")
|
||||
{
|
||||
%imgAsset = AssetDatabase.acquireAsset(%assetDef.materialDefinitionName.getDiffuseMapAsset(0));
|
||||
%previewData.previewImage = %imgAsset.getImagePath();
|
||||
}
|
||||
//add cubemap preview here(for skybox materials)
|
||||
}
|
||||
|
||||
%previewData.assetFriendlyName = %assetDef.assetName;
|
||||
%previewData.assetDesc = %assetDef.description;
|
||||
%previewData.tooltip = "Asset Name: " @ %assetDef.assetName @ "\n" @
|
||||
"Asset Type: Material Asset\n" @
|
||||
"Asset Definition ID: " @ %assetDef;
|
||||
|
|
|
|||
|
|
@ -245,15 +245,24 @@ function AssetBrowser::importShapeAsset(%this, %assetItem)
|
|||
function AssetBrowser::buildShapeAssetPreview(%this, %assetDef, %previewData)
|
||||
{
|
||||
%module = %this.dirHandler.getModuleFromAddress(makeRelativePath(filePath(%assetDef.getShapeFile())));
|
||||
%previewPath = "tools/resources/shapePreviewCache/" @ %module.moduleId @ "/";
|
||||
%previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/";
|
||||
|
||||
if(!IsDirectory(%previewPath))
|
||||
{
|
||||
%this.dirHandler.createFolder(%previewPath);
|
||||
}
|
||||
|
||||
%generatePreview = false;
|
||||
|
||||
%previewFilePath = %previewPath @ %assetDef.assetName @ "_Preview.png";
|
||||
if(!isFile(%previewFilePath))
|
||||
if(!isFile(%previewFilePath) || (compareFileTimes(%assetDef.getShapeFile(), %previewFilePath) == 1))
|
||||
{
|
||||
%generatePreview = true;
|
||||
}
|
||||
|
||||
%previewAssetName = %module.moduleId @ "_" @ %assetDef.assetName @ "_PreviewImage";
|
||||
|
||||
if(%generatePreview)
|
||||
{
|
||||
displayEditorLoadingGui("Generating Shape Asset Preview...");
|
||||
|
||||
|
|
@ -275,15 +284,15 @@ function AssetBrowser::buildShapeAssetPreview(%this, %assetDef, %previewData)
|
|||
|
||||
$TSLastDetail::dumpImposters = %oldImposterSetting;
|
||||
|
||||
%newAsset = new ImageAsset()
|
||||
%previewAsset = new ImageAsset()
|
||||
{
|
||||
assetName = %assetDef.assetName @ "_PreviewImage";
|
||||
assetName = %previewAssetName;
|
||||
versionId = 1;
|
||||
imageFile = fileName(%previewFilePath);
|
||||
};
|
||||
|
||||
%previewImgAssetPath = %previewPath @ %newAsset.assetName @ ".asset.taml";
|
||||
%assetImportSuccessful = TAMLWrite(%newAsset, %previewImgAssetPath);
|
||||
%previewImgAssetPath = %previewPath @ %previewAsset.assetName @ ".asset.taml";
|
||||
%assetImportSuccessful = TAMLWrite(%previewAsset, %previewImgAssetPath);
|
||||
|
||||
%toolsModuleDef = ModuleDatabase.findModule("ToolsModule",1);
|
||||
|
||||
|
|
@ -294,12 +303,12 @@ function AssetBrowser::buildShapeAssetPreview(%this, %assetDef, %previewData)
|
|||
|
||||
//Revalidate. If it didn't work, just use the default placeholder one
|
||||
if(!isFile(%previewFilePath))
|
||||
%previewFilePath = "ToolsModule:genericAssetIcon_image";
|
||||
%previewAssetName = "ToolsModule:genericAssetIcon_image";
|
||||
|
||||
%previewData.assetName = %assetDef.assetName;
|
||||
%previewData.assetPath = %assetDef.fileName;
|
||||
|
||||
%previewData.previewImage = "ToolsModule:" @ %assetDef.assetName @ "_PreviewImage";//%assetDef.fileName;
|
||||
%previewData.previewImage = "ToolsModule:" @ %previewAssetName;//%assetDef.fileName;
|
||||
|
||||
%previewData.assetFriendlyName = %assetDef.assetName;
|
||||
%previewData.assetDesc = %assetDef.description;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue