[SMC] UI Updates (#270)

* Update SMC prompt texts. Add progress dialog in shader variant generation script. Add "Generate Shader Variant List" command in context menu for shader files in Asset Browser.
This commit is contained in:
hershey5045
2021-04-28 09:56:55 -07:00
committed by GitHub
parent 5d53590434
commit 9ffca4df5d
4 changed files with 67 additions and 33 deletions
@@ -28,6 +28,7 @@
#include <AzToolsFramework/Thumbnails/SourceControlThumbnail.h>
#include <AtomToolsFramework/Util/Util.h>
#include <Atom/RPI.Edit/Shader/ShaderVariantListSourceData.h>
#include <Atom/Document/ShaderManagementConsoleDocumentSystemRequestBus.h>
#include <Source/Window/ShaderManagementConsoleBrowserInteractions.h>
@@ -81,7 +82,14 @@ namespace ShaderManagementConsole
{
menu->addAction("Open", [entry]()
{
QDesktopServices::openUrl(QUrl::fromLocalFile(entry->GetFullPath().c_str()));
if (AzFramework::StringFunc::Path::IsExtension(entry->GetFullPath().c_str(), AZ::RPI::ShaderVariantListSourceData::Extension))
{
ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::OpenDocument, entry->GetFullPath().c_str());
}
else
{
QDesktopServices::openUrl(QUrl::fromLocalFile(entry->GetFullPath().c_str()));
}
});
menu->addAction("Duplicate...", [entry, caller]()
@@ -100,20 +108,27 @@ namespace ShaderManagementConsole
}
});
menu->addAction("Run Python on Asset...", [entry]()
{
const QString script = QFileDialog::getOpenFileName(nullptr, "Run Script", QString(), QString("*.py"));
if (!script.isEmpty())
{
AZStd::vector<AZStd::string_view> pythonArgs { entry->GetFullPath() };
AzToolsFramework::EditorPythonRunnerRequestBus::Broadcast(&AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByFilenameWithArgs, script.toUtf8().constData(), pythonArgs);
}
});
menu->addAction(AzQtComponents::fileBrowserActionName(), [entry]()
{
AzQtComponents::ShowFileOnDesktop(entry->GetFullPath().c_str());
});
menu->addSeparator();
menu->addAction("Generate Shader Variant List", [entry]() {
const QString script = "@engroot@/Gems/Atom/Tools/ShaderManagementConsole/Scripts/GenerateShaderVariantListForMaterials.py";
AZStd::vector<AZStd::string_view> pythonArgs{ entry->GetFullPath() };
AzToolsFramework::EditorPythonRunnerRequestBus::Broadcast(&AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByFilenameWithArgs, script.toUtf8().constData(), pythonArgs);
});
menu->addAction("Run Python on Asset...", [entry]()
{
const QString script = QFileDialog::getOpenFileName(nullptr, "Run Script", QString(), QString("*.py"));
if (!script.isEmpty())
{
AzQtComponents::ShowFileOnDesktop(entry->GetFullPath().c_str());
});
AZStd::vector<AZStd::string_view> pythonArgs { entry->GetFullPath() };
AzToolsFramework::EditorPythonRunnerRequestBus::Broadcast(&AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByFilenameWithArgs, script.toUtf8().constData(), pythonArgs);
}
});
AddPerforceMenuActions(caller, menu, entry);
}
@@ -368,6 +368,7 @@ namespace ShaderManagementConsole
// The document tab contains a table view.
auto tableView = new QTableView(m_centralWidget);
tableView->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
auto model = new QStandardItemModel();
tableView->setModel(model);
@@ -15,4 +15,5 @@ set(FILES
Source/ShaderManagementConsoleApplication.h
Include/Atom/Document/ShaderManagementConsoleDocumentModule.h
Source/Document/ShaderManagementConsoleDocumentModule.cpp
../Scripts/GenerateShaderVariantListForMaterials.py
)
@@ -24,15 +24,6 @@ from PySide2 import QtWidgets
PROJECT_SHADER_VARIANTS_FOLDER = "ShaderVariants"
def prompt_message_box(text, informativeText = None, qButtons = QtWidgets.QMessageBox.Yes|QtWidgets.QMessageBox.No|QtWidgets.QMessageBox.Cancel):
msgBox = QtWidgets.QMessageBox()
msgBox.setText(text)
if informativeText:
msgBox.setInformativeText(informativeText)
msgBox.setStandardButtons(qButtons)
return msgBox.exec()
def clean_existing_shadervariantlist_files(filePaths):
for file in filePaths:
if os.path.exists(file):
@@ -66,21 +57,32 @@ def main():
shaderAssetInfo.relativePath
)
response = prompt_message_box(
"Generating .shadervariantlist File",
"This process may take a while. Would you like to save the generated .shadervariantlist file in the project folder? " \
"Otherwise, it will be saved in the same location as the .shader file."
msgBox = QtWidgets.QMessageBox(
QtWidgets.QMessageBox.Question,
"Choose Save Location for .shadervariantlist File",
"Save .shadervariantlist file in Project folder or in the same folder as shader file?"
)
projectButton = msgBox.addButton("Project Folder", QtWidgets.QMessageBox.AcceptRole)
msgBox.addButton("Same Folder as Shader", QtWidgets.QMessageBox.AcceptRole)
cancelButton = msgBox.addButton("Cancel", QtWidgets.QMessageBox.RejectRole)
msgBox.exec()
is_save_in_project_folder = False
if response == QtWidgets.QMessageBox.Yes:
if msgBox.clickedButton() == projectButton:
is_save_in_project_folder = True
elif response == QtWidgets.QMessageBox.Cancel:
elif msgBox.clickedButton() == cancelButton:
return
# This loop collects all uniquely-identified shader items used by the materials based on its shader variant id.
shader_file = os.path.basename(filename)
shaderVariantIds = []
shaderVariantListShaderOptionGroups = []
for materialAssetId in materialAssetIds:
progressDialog = QtWidgets.QProgressDialog(f"Generating .shadervariantlist file for:\n{shader_file}", "Cancel", 0, len(materialAssetIds))
progressDialog.setMaximumWidth(400)
progressDialog.setMaximumHeight(100)
progressDialog.setModal(True)
progressDialog.setWindowTitle("Generating Shader Variant List")
for i, materialAssetId in enumerate(materialAssetIds):
materialInstanceShaderItems = azlmbr.shadermanagementconsole.ShaderManagementConsoleRequestBus(azlmbr.bus.Broadcast, 'GetMaterialInstanceShaderItems', materialAssetId)
for shaderItem in materialInstanceShaderItems:
@@ -102,8 +104,14 @@ def main():
shaderVariantIds.append(shaderVariantId)
shaderVariantListShaderOptionGroups.append(shaderItem.GetShaderOptionGroup())
progressDialog.setValue(i)
if progressDialog.wasCanceled():
return
progressDialog.close()
# Generate the shader variant list data by collecting shader option name-value pairs.s
shaderVariantList = azlmbr.shader.ShaderVariantListSourceData ()
shaderVariantList = azlmbr.shader.ShaderVariantListSourceData()
shaderVariantList.shaderFilePath = shaderAssetInfo.relativePath
shaderVariants = []
stableId = 1
@@ -144,17 +152,26 @@ def main():
shaderVariantListFilePath = projectShaderVariantListFilePath
else:
shaderVariantListFilePath = defaultShaderVariantListFilePath
print(f"Saving .shadervariantlist file into: {shaderVariantListFilePath}")
shaderVariantListFilePath = shaderVariantListFilePath.replace("\\", "/")
azlmbr.shader.SaveShaderVariantListSourceData(shaderVariantListFilePath, shaderVariantList)
# Open the document in shader management console
azlmbr.shadermanagementconsole.ShaderManagementConsoleDocumentSystemRequestBus(
result = azlmbr.shadermanagementconsole.ShaderManagementConsoleDocumentSystemRequestBus(
azlmbr.bus.Broadcast,
'OpenDocument',
shaderVariantListFilePath
)
if not result.IsNull():
msgBox = QtWidgets.QMessageBox(
QtWidgets.QMessageBox.Information,
"Shader Variant List File Successfully Generated",
f".shadervariantlist file was saved in:\n{shaderVariantListFilePath}",
QtWidgets.QMessageBox.Ok
)
msgBox.exec()
print("==== End shader variant script ============================================================")
if __name__ == "__main__":