AcousticTextureParamLookup.cpp 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. #include "AcousticTextureParamLookup.h"
  16. #include "AkSettings.h"
  17. #include "AkAcousticTexture.h"
  18. #include "AkUnrealHelper.h"
  19. #include "AssetManagement/AkAssetDatabase.h"
  20. #include "IAudiokineticTools.h"
  21. #include "Wwise/WwiseProjectDatabase.h"
  22. void AkAcousticTextureParamLookup::LoadAllTextures()
  23. {
  24. FWwiseProjectDatabase* ProjectDatabase = FWwiseProjectDatabase::Get();
  25. if (UNLIKELY(!ProjectDatabase))
  26. {
  27. UE_LOG(LogAudiokineticTools, Error, TEXT("LoadAllTextures: ProjectDatabase not loaded"));
  28. return;
  29. }
  30. const FWwiseDataStructureScopeLock DataStructure(*ProjectDatabase);
  31. const auto& AcousticTextures = DataStructure.GetAcousticTextures();
  32. if (AcousticTextures.Num() == 0)
  33. {
  34. return;
  35. }
  36. UAkSettings* AkSettings = GetMutableDefault<UAkSettings>();
  37. auto& AkAssetDatabase = AkAssetDatabase::Get();
  38. if (UNLIKELY(!AkSettings))
  39. {
  40. UE_LOG(LogAudiokineticTools, Error, TEXT("No AkSettings while loading Acoustic Textures"));
  41. return;
  42. }
  43. for (auto& AcousticTexture : AcousticTextures)
  44. {
  45. const FString& TextureName = AcousticTexture.Value.AcousticTextureName().ToString();
  46. float AbsorptionLow = AcousticTexture.Value.GetAcousticTexture()->AbsorptionLow;
  47. float AbsorptionMidLow = AcousticTexture.Value.GetAcousticTexture()->AbsorptionMidLow;
  48. float AbsorptionMidHigh = AcousticTexture.Value.GetAcousticTexture()->AbsorptionMidHigh;
  49. float AbsorptionHigh = AcousticTexture.Value.GetAcousticTexture()->AbsorptionHigh;
  50. uint32 TextureShortID = 0;
  51. FAssetData Texture;
  52. FGuid Id = AcousticTexture.Value.AcousticTextureGuid();
  53. if (LIKELY(AkAssetDatabase.FindFirstAsset(Id, Texture)))
  54. {
  55. const auto AcousticTextureAsset = Cast<UAkAcousticTexture>(Texture.GetAsset());
  56. if (LIKELY(AcousticTextureAsset))
  57. {
  58. TextureShortID = AcousticTextureAsset->GetShortID();
  59. UE_LOG(LogAudiokineticTools, VeryVerbose, TEXT("Properties for texture %s (%" PRIu32 "): Absorption High: %.0f%%, MidHigh: %.0f%%, MidLow: %.0f%%, Low: %.0f%%"),
  60. *TextureName, TextureShortID, AbsorptionHigh, AbsorptionMidHigh, AbsorptionMidLow, AbsorptionLow);
  61. }
  62. else
  63. {
  64. UE_LOG(LogAudiokineticTools, Error, TEXT("Invalid AkAcousticTexture for GUID %s (%s)"), *Id.ToString(), *TextureName);
  65. }
  66. }
  67. else
  68. {
  69. UE_LOG(LogAudiokineticTools, Log, TEXT("Properties for texture %s (No AkAcousticTexture): Absorption High: %.0f%%, MidHigh: %.0f%%, MidLow: %.0f%%, Low: %.0f%%"),
  70. *TextureName, AbsorptionHigh, AbsorptionMidHigh, AbsorptionMidLow, AbsorptionLow);
  71. }
  72. const FVector4 AbsorptionValues = FVector4(AbsorptionLow, AbsorptionMidLow, AbsorptionMidHigh, AbsorptionHigh) / 100.0f;
  73. AkSettings->SetAcousticTextureParams(Id,{AbsorptionValues, TextureShortID});
  74. }
  75. }
  76. void AkAcousticTextureParamLookup::UpdateParamsMap() const
  77. {
  78. UAkSettings* AkSettings = GetMutableDefault<UAkSettings>();
  79. if (AkSettings != nullptr)
  80. {
  81. AkSettings->ClearTextureParamsMap();
  82. LoadAllTextures();
  83. }
  84. }