3
0

MaterialBuilderUtils.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "MaterialBuilderUtils.h"
  9. #include <Atom/RPI.Edit/Common/AssetUtils.h>
  10. #include <Atom/RPI.Edit/Material/MaterialSourceData.h>
  11. #include <Atom/RPI.Edit/Material/MaterialTypeSourceData.h>
  12. #include <AzCore/Settings/SettingsRegistry.h>
  13. namespace AZ::RPI::MaterialBuilderUtils
  14. {
  15. AssetBuilderSDK::JobDependency& AddJobDependency(
  16. AssetBuilderSDK::JobDescriptor& jobDescriptor,
  17. const AZStd::string& path,
  18. const AZStd::string& jobKey,
  19. const AZStd::string& platformId,
  20. const AZStd::vector<AZ::u32>& subIds,
  21. const bool updateFingerprint)
  22. {
  23. if (updateFingerprint)
  24. {
  25. AddFingerprintForDependency(path, jobDescriptor);
  26. }
  27. AssetBuilderSDK::JobDependency jobDependency(
  28. jobKey,
  29. platformId,
  30. AssetBuilderSDK::JobDependencyType::Order,
  31. AssetBuilderSDK::SourceFileDependency(
  32. path, AZ::Uuid{}, AssetBuilderSDK::SourceFileDependency::SourceFileDependencyType::Absolute));
  33. jobDependency.m_productSubIds = subIds;
  34. return jobDescriptor.m_jobDependencyList.emplace_back(AZStd::move(jobDependency));
  35. }
  36. void AddPossibleImageDependencies(
  37. const AZStd::string& originatingSourceFilePath,
  38. const AZStd::string& referencedSourceFilePath,
  39. AssetBuilderSDK::JobDescriptor& jobDescriptor)
  40. {
  41. if (!referencedSourceFilePath.empty())
  42. {
  43. AZStd::string ext;
  44. AzFramework::StringFunc::Path::GetExtension(referencedSourceFilePath.c_str(), ext, false);
  45. AZStd::to_upper(ext.begin(), ext.end());
  46. if (!ext.empty())
  47. {
  48. auto& jobDependency = MaterialBuilderUtils::AddJobDependency(
  49. jobDescriptor,
  50. AssetUtils::ResolvePathReference(originatingSourceFilePath, referencedSourceFilePath),
  51. "Image Compile: " + ext,
  52. {},
  53. { 0 });
  54. jobDependency.m_type = AssetBuilderSDK::JobDependencyType::OrderOnce;
  55. }
  56. }
  57. }
  58. void AddFingerprintForDependency(const AZStd::string& path, AssetBuilderSDK::JobDescriptor& jobDescriptor)
  59. {
  60. jobDescriptor.m_additionalFingerprintInfo +=
  61. AZStd::string::format("|%u:%llu", (AZ::u32)AZ::Crc32(path), AZ::IO::SystemFile::ModificationTime(path.c_str()));
  62. }
  63. } // namespace AZ::RPI::MaterialBuilderUtils