Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,116 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AtomToolsFramework/Util/MaterialPropertyUtil.h>
#include <Atom/RPI.Reflect/Image/StreamingImageAsset.h>
namespace AtomToolsFramework
{
AZ::RPI::MaterialPropertyValue ConvertToRuntimeType(const AZStd::any& value)
{
return AZ::RPI::MaterialPropertyValue::FromAny(value);
}
AZStd::any ConvertToEditableType(const AZ::RPI::MaterialPropertyValue& value)
{
if (value.Is<AZ::Data::Asset<AZ::RPI::ImageAsset>>())
{
const AZ::Data::Asset<AZ::RPI::ImageAsset>& imageAsset = value.GetValue<AZ::Data::Asset<AZ::RPI::ImageAsset>>();
return AZStd::any(AZ::Data::Asset<AZ::RPI::StreamingImageAsset>(
imageAsset.GetId(),
azrtti_typeid<AZ::RPI::StreamingImageAsset>(),
imageAsset.GetHint()));
}
return AZ::RPI::MaterialPropertyValue::ToAny(value);
}
AtomToolsFramework::DynamicPropertyType ConvertToEditableType(const AZ::RPI::MaterialPropertyDataType dataType)
{
switch (dataType)
{
case AZ::RPI::MaterialPropertyDataType::Bool:
return AtomToolsFramework::DynamicPropertyType::Bool;
case AZ::RPI::MaterialPropertyDataType::Int:
return AtomToolsFramework::DynamicPropertyType::Int;
case AZ::RPI::MaterialPropertyDataType::UInt:
return AtomToolsFramework::DynamicPropertyType::UInt;
case AZ::RPI::MaterialPropertyDataType::Float:
return AtomToolsFramework::DynamicPropertyType::Float;
case AZ::RPI::MaterialPropertyDataType::Vector2:
return AtomToolsFramework::DynamicPropertyType::Vector2;
case AZ::RPI::MaterialPropertyDataType::Vector3:
return AtomToolsFramework::DynamicPropertyType::Vector3;
case AZ::RPI::MaterialPropertyDataType::Vector4:
return AtomToolsFramework::DynamicPropertyType::Vector4;
case AZ::RPI::MaterialPropertyDataType::Color:
return AtomToolsFramework::DynamicPropertyType::Color;
case AZ::RPI::MaterialPropertyDataType::Image:
return AtomToolsFramework::DynamicPropertyType::Asset;
case AZ::RPI::MaterialPropertyDataType::Enum:
return AtomToolsFramework::DynamicPropertyType::Enum;
}
AZ_Assert(false, "Attempting to convert an unsupported property type.");
return AtomToolsFramework::DynamicPropertyType::Invalid;
}
void ConvertToPropertyConfig(AtomToolsFramework::DynamicPropertyConfig& propertyConfig, const AZ::RPI::MaterialTypeSourceData::PropertyDefinition& propertyDefinition)
{
propertyConfig.m_dataType = ConvertToEditableType(propertyDefinition.m_dataType);
propertyConfig.m_nameId = propertyDefinition.m_nameId;
propertyConfig.m_displayName = propertyDefinition.m_displayName;
propertyConfig.m_description = propertyDefinition.m_description;
propertyConfig.m_defaultValue = ConvertToEditableType(propertyDefinition.m_value);
propertyConfig.m_min = ConvertToEditableType(propertyDefinition.m_min);
propertyConfig.m_max = ConvertToEditableType(propertyDefinition.m_max);
propertyConfig.m_softMin = ConvertToEditableType(propertyDefinition.m_softMin);
propertyConfig.m_softMax = ConvertToEditableType(propertyDefinition.m_softMax);
propertyConfig.m_step = ConvertToEditableType(propertyDefinition.m_step);
propertyConfig.m_enumValues = propertyDefinition.m_enumValues;
propertyConfig.m_vectorLabels = propertyDefinition.m_vectorLabels;
propertyConfig.m_visible = propertyDefinition.m_visibility != AZ::RPI::MaterialPropertyVisibility::Hidden;
propertyConfig.m_readOnly = propertyDefinition.m_visibility == AZ::RPI::MaterialPropertyVisibility::Disabled;
}
void ConvertToPropertyConfig(AtomToolsFramework::DynamicPropertyConfig& propertyConfig, const AZ::RPI::MaterialPropertyDynamicMetadata& propertyMetaData)
{
propertyConfig.m_description = propertyMetaData.m_description;
propertyConfig.m_min = ConvertToEditableType(propertyMetaData.m_propertyRange.m_min);
propertyConfig.m_max = ConvertToEditableType(propertyMetaData.m_propertyRange.m_max);
propertyConfig.m_softMin = ConvertToEditableType(propertyMetaData.m_propertyRange.m_softMin);
propertyConfig.m_softMax = ConvertToEditableType(propertyMetaData.m_propertyRange.m_softMax);
propertyConfig.m_visible = propertyMetaData.m_visibility != AZ::RPI::MaterialPropertyVisibility::Hidden;
propertyConfig.m_readOnly = propertyMetaData.m_visibility == AZ::RPI::MaterialPropertyVisibility::Disabled;
}
void ConvertToPropertyMetaData(AZ::RPI::MaterialPropertyDynamicMetadata& propertyMetaData, const AtomToolsFramework::DynamicPropertyConfig& propertyConfig)
{
propertyMetaData.m_description = propertyConfig.m_description;
propertyMetaData.m_propertyRange.m_min = ConvertToRuntimeType(propertyConfig.m_min);
propertyMetaData.m_propertyRange.m_max = ConvertToRuntimeType(propertyConfig.m_max);
propertyMetaData.m_propertyRange.m_softMin = ConvertToRuntimeType(propertyConfig.m_softMin);
propertyMetaData.m_propertyRange.m_softMax = ConvertToRuntimeType(propertyConfig.m_softMax);
if (!propertyConfig.m_visible)
{
propertyMetaData.m_visibility = AZ::RPI::MaterialPropertyVisibility::Hidden;
}
else if (propertyConfig.m_readOnly)
{
propertyMetaData.m_visibility = AZ::RPI::MaterialPropertyVisibility::Disabled;
}
else
{
propertyMetaData.m_visibility = AZ::RPI::MaterialPropertyVisibility::Enabled;
}
}
} // namespace AtomToolsFramework
@@ -0,0 +1,165 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AtomToolsFramework/Util/Util.h>
#include <AzCore/IO/SystemFile.h>
#include <AzCore/StringFunc/StringFunc.h>
#include <AzCore/Utils/Utils.h>
#include <AzFramework/API/ApplicationAPI.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
#include <AzToolsFramework/AssetBrowser/AssetSelectionModel.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT
#include <QApplication>
#include <QFileDialog>
#include <QMessageBox>
#include <QProcess>
AZ_POP_DISABLE_WARNING
namespace AtomToolsFramework
{
QFileInfo GetSaveFileInfo(const QString& initialPath)
{
const QFileInfo initialFileInfo(initialPath);
const QString initialExt(initialFileInfo.completeSuffix());
const QFileInfo selectedFileInfo(QFileDialog::getSaveFileName(
QApplication::activeWindow(),
"Save File",
initialFileInfo.absolutePath() +
AZ_CORRECT_FILESYSTEM_SEPARATOR_STRING +
initialFileInfo.baseName(),
QString("Files (*.%1)").arg(initialExt)));
if (selectedFileInfo.absoluteFilePath().isEmpty())
{
// Cancelled operation
return QFileInfo();
}
if (!selectedFileInfo.absoluteFilePath().endsWith(initialExt))
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("File name must have .%1 extension.").arg(initialExt));
return QFileInfo();
}
return selectedFileInfo;
}
QFileInfo GetOpenFileInfo(const AZStd::vector<AZ::Data::AssetType>& assetTypes)
{
using namespace AZ::Data;
using namespace AzToolsFramework::AssetBrowser;
// [GFX TODO] Should this just be an open file dialog filtered to supported source data extensions?
auto selection = AssetSelectionModel::AssetTypesSelection(assetTypes);
// [GFX TODO] This is functional but UI is not as designed
AssetBrowserComponentRequestBus::Broadcast(&AssetBrowserComponentRequests::PickAssets, selection, QApplication::activeWindow());
if (!selection.IsValid())
{
return QFileInfo();
}
auto entry = selection.GetResult();
const SourceAssetBrowserEntry* sourceEntry = azrtti_cast<const SourceAssetBrowserEntry*>(entry);
if (!sourceEntry)
{
const ProductAssetBrowserEntry* productEntry = azrtti_cast<const ProductAssetBrowserEntry*>(entry);
if (productEntry)
{
sourceEntry = azrtti_cast<const SourceAssetBrowserEntry*>(productEntry->GetParent());
}
}
if (!sourceEntry)
{
return QFileInfo();
}
return QFileInfo(sourceEntry->GetFullPath().c_str());
}
QFileInfo GetUniqueFileInfo(const QString& initialPath)
{
int counter = 0;
QFileInfo fileInfo = initialPath;
const QString extension = "." + fileInfo.completeSuffix();
const QString basePathAndName = fileInfo.absoluteFilePath().left(fileInfo.absoluteFilePath().size() - extension.size());
while (fileInfo.exists())
{
fileInfo = QString("%1_%2%3").arg(basePathAndName).arg(++counter).arg(extension);
}
return fileInfo;
}
QFileInfo GetDuplicationFileInfo(const QString& initialPath)
{
const QFileInfo initialFileInfo(initialPath);
const QString initialExt(initialFileInfo.completeSuffix());
const QFileInfo duplicateFileInfo(QFileDialog::getSaveFileName(
QApplication::activeWindow(),
"Duplicate File",
GetUniqueFileInfo(initialPath).absoluteFilePath(),
QString("Files (*.%1)").arg(initialExt)));
if (duplicateFileInfo == initialFileInfo)
{
// Cancelled operation or selected same path
return QFileInfo();
}
if (duplicateFileInfo.absoluteFilePath().isEmpty())
{
// Cancelled operation or selected same path
return QFileInfo();
}
if (!duplicateFileInfo.absoluteFilePath().endsWith(initialExt))
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("File name must have .%1 extension.").arg(initialExt));
return QFileInfo();
}
return duplicateFileInfo;
}
bool LaunchTool(const QString& baseName, const QString& extension, const QStringList& arguments)
{
const char* engineRoot = nullptr;
AzFramework::ApplicationRequests::Bus::BroadcastResult(engineRoot, &AzFramework::ApplicationRequests::GetEngineRoot);
AZ_Assert(engineRoot != nullptr, "AzFramework::ApplicationRequests::GetEngineRoot failed");
char binFolderName[AZ_MAX_PATH_LEN] = {};
AZ::Utils::GetExecutablePathReturnType ret = AZ::Utils::GetExecutablePath(binFolderName, AZ_MAX_PATH_LEN);
// If it contains the filename, zero out the last path separator character...
if (ret.m_pathIncludesFilename)
{
char* lastSlash = strrchr(binFolderName, AZ_CORRECT_FILESYSTEM_SEPARATOR);
if (lastSlash)
{
*lastSlash = '\0';
}
}
const QString path = QString("%1%2%3%4")
.arg(binFolderName)
.arg(AZ_CORRECT_FILESYSTEM_SEPARATOR_STRING)
.arg(baseName)
.arg(extension);
return QProcess::startDetached(path, arguments, engineRoot);
}
}