AcousticTextureParamLookup.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "WwiseUnrealHelper.h"
  19. #include "IAudiokineticTools.h"
  20. #include "Wwise/WwiseProjectDatabase.h"
  21. void AkAcousticTextureParamLookup::LoadAllTextures()
  22. {
  23. FWwiseProjectDatabase* ProjectDatabase = FWwiseProjectDatabase::Get();
  24. if (UNLIKELY(!ProjectDatabase))
  25. {
  26. UE_LOG(LogAudiokineticTools, Error, TEXT("LoadAllTextures: ProjectDatabase not loaded"));
  27. return;
  28. }
  29. const FWwiseDataStructureScopeLock DataStructure(*ProjectDatabase);
  30. const auto& AcousticTextures = DataStructure.GetAcousticTextures();
  31. if (AcousticTextures.Num() == 0)
  32. {
  33. return;
  34. }
  35. UAkSettings* AkSettings = GetMutableDefault<UAkSettings>();
  36. if (UNLIKELY(!AkSettings))
  37. {
  38. UE_LOG(LogAudiokineticTools, Error, TEXT("No AkSettings while loading Acoustic Textures"));
  39. return;
  40. }
  41. for (auto& AcousticTexture : AcousticTextures)
  42. {
  43. const FString& TextureName = AcousticTexture.Value.AcousticTextureName().ToString();
  44. float AbsorptionLow = AcousticTexture.Value.GetAcousticTexture()->AbsorptionLow;
  45. float AbsorptionMidLow = AcousticTexture.Value.GetAcousticTexture()->AbsorptionMidLow;
  46. float AbsorptionMidHigh = AcousticTexture.Value.GetAcousticTexture()->AbsorptionMidHigh;
  47. float AbsorptionHigh = AcousticTexture.Value.GetAcousticTexture()->AbsorptionHigh;
  48. uint32 TextureShortID = AcousticTexture.Key.Id;
  49. UE_LOG(LogAudiokineticTools, VeryVerbose, TEXT("Properties for texture %s (%" PRIu32 "): Absorption High: %.0f%%, MidHigh: %.0f%%, MidLow: %.0f%%, Low: %.0f%%"),
  50. *TextureName, TextureShortID, AbsorptionHigh, AbsorptionMidHigh, AbsorptionMidLow, AbsorptionLow);
  51. FGuid Id = AcousticTexture.Value.AcousticTextureGuid();
  52. const FVector4 AbsorptionValues = FVector4(AbsorptionLow, AbsorptionMidLow, AbsorptionMidHigh, AbsorptionHigh) / 100.0f;
  53. AkSettings->SetAcousticTextureParams(Id,{AbsorptionValues, TextureShortID});
  54. }
  55. }
  56. void AkAcousticTextureParamLookup::UpdateParamsMap() const
  57. {
  58. UAkSettings* AkSettings = GetMutableDefault<UAkSettings>();
  59. if (AkSettings != nullptr)
  60. {
  61. AkSettings->ClearTextureParamsMap();
  62. LoadAllTextures();
  63. }
  64. }