AkGeometryComponentDetailsCustomization.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 "AkGeometryComponentDetailsCustomization.h"
  16. #include "DetailCategoryBuilder.h"
  17. #include "DetailLayoutBuilder.h"
  18. #include "DetailWidgetRow.h"
  19. #include "PropertyCustomizationHelpers.h"
  20. #include "Editor/TransBuffer.h"
  21. #include "UI/SAkGeometrySurfaceOverrideController.h"
  22. #include "Widgets/Input/SButton.h"
  23. #include "Widgets/Layout/SBox.h"
  24. #include "AkGeometryComponent.h"
  25. #define LOCTEXT_NAMESPACE "AudiokineticTools"
  26. static int SurfacePropertiesHeight = 72;
  27. //////////////////////////////////////////////////////////////////////////
  28. // FAkGeometryDetailsCustomization
  29. FAkGeometryComponentDetailsCustomization::FAkGeometryComponentDetailsCustomization()
  30. {
  31. ComponentBeingCustomized = nullptr;
  32. }
  33. FAkGeometryComponentDetailsCustomization::~FAkGeometryComponentDetailsCustomization()
  34. {
  35. if (ComponentBeingCustomized.IsValid() && ComponentBeingCustomized->GetOnRefreshDetails())
  36. {
  37. if (ComponentBeingCustomized->GetOnRefreshDetails()->IsBoundToObject(this))
  38. {
  39. ComponentBeingCustomized->ClearOnRefreshDetails();
  40. }
  41. }
  42. ComponentBeingCustomized.Reset();
  43. }
  44. void FAkGeometryComponentDetailsCustomization::BeginModify(FText TransactionText)
  45. {
  46. if (GEditor && GEditor->Trans)
  47. {
  48. UTransBuffer* TransBuffer = CastChecked<UTransBuffer>(GEditor->Trans);
  49. if (TransBuffer != nullptr)
  50. TransBuffer->Begin(*FString("AkGeometry Acoustic Surfaces"), TransactionText);
  51. }
  52. if (ComponentBeingCustomized.IsValid())
  53. ComponentBeingCustomized->Modify();
  54. }
  55. void FAkGeometryComponentDetailsCustomization::EndModify()
  56. {
  57. if (GEditor && GEditor->Trans)
  58. {
  59. UTransBuffer* TransBuffer = CastChecked<UTransBuffer>(GEditor->Trans);
  60. if (TransBuffer != nullptr)
  61. TransBuffer->End();
  62. }
  63. }
  64. TSharedRef<IDetailCustomization> FAkGeometryComponentDetailsCustomization::MakeInstance()
  65. {
  66. return MakeShared<FAkGeometryComponentDetailsCustomization>();
  67. }
  68. void FAkGeometryComponentDetailsCustomization::CustomizeDetails(const TSharedPtr<IDetailLayoutBuilder>& InDetailBuilder)
  69. {
  70. DetailBuilder = InDetailBuilder;
  71. CustomizeDetails(*InDetailBuilder);
  72. }
  73. void FAkGeometryComponentDetailsCustomization::CustomizeDetails(IDetailLayoutBuilder& InDetailBuilder)
  74. {
  75. TArray<TWeakObjectPtr<UObject>> ObjectsBeingCustomized;
  76. InDetailBuilder.GetObjectsBeingCustomized(ObjectsBeingCustomized);
  77. InDetailBuilder.EditCategory("Geometry", FText::GetEmpty(), ECategoryPriority::TypeSpecific);
  78. for (TWeakObjectPtr<UObject>& Object : ObjectsBeingCustomized)
  79. {
  80. UAkGeometryComponent* GeometryComponentBeingCustomized = Cast<UAkGeometryComponent>(Object.Get());
  81. if (GeometryComponentBeingCustomized)
  82. {
  83. UObject* OuterObj = GeometryComponentBeingCustomized->GetOuter();
  84. UActorComponent* OuterComponent = Cast<UActorComponent>(OuterObj);
  85. AActor* OuterActor = Cast<AActor>(OuterObj);
  86. // Do not hide the transform if the component has been created from within a component or actor, as this will hide the transform for that component / actor as well
  87. // (i.e. - only hide the transform if the component has been added to the hierarchy of a blueprint class or actor instance from the editor)
  88. if (OuterComponent == nullptr && OuterActor == nullptr)
  89. {
  90. IDetailCategoryBuilder& TransformCategory = InDetailBuilder.EditCategory("TransformCommon", LOCTEXT("TransformCommonCategory", "Transform"), ECategoryPriority::Transform);
  91. TransformCategory.SetCategoryVisibility(false);
  92. break;
  93. }
  94. }
  95. }
  96. if (ObjectsBeingCustomized.Num() != 1)
  97. {
  98. return;
  99. }
  100. auto Component = Cast<UAkGeometryComponent>(ObjectsBeingCustomized[0].Get());
  101. if (Component == nullptr)
  102. {
  103. return;
  104. }
  105. auto LockedDetailBuilder = DetailBuilder.Pin();
  106. if (UNLIKELY(!LockedDetailBuilder))
  107. {
  108. return;
  109. }
  110. ComponentBeingCustomized = TWeakObjectPtr<UAkGeometryComponent>(Component);
  111. auto meshTypeChangedHandle = LockedDetailBuilder->GetProperty("MeshType");
  112. meshTypeChangedHandle->SetOnPropertyValueChanged(FSimpleDelegate::CreateSP(this, &FAkGeometryComponentDetailsCustomization::RefreshDetails));
  113. FOnRefreshDetails refreshDetails = FOnRefreshDetails::CreateSP(this, &FAkGeometryComponentDetailsCustomization::RefreshDetails);
  114. ComponentBeingCustomized->SetOnRefreshDetails(refreshDetails);
  115. if (ComponentBeingCustomized->MeshType == AkMeshType::StaticMesh)
  116. {
  117. InDetailBuilder.HideProperty("CollisionMeshSurfaceOverride");
  118. if (ObjectsBeingCustomized.Num() == 1)
  119. {
  120. IDetailCategoryBuilder& CategoryBuilder = InDetailBuilder.EditCategory("Surface Overrides", FText::GetEmpty(), ECategoryPriority::TypeSpecific);
  121. InDetailBuilder.HideProperty("StaticMeshSurfaceOverride");
  122. auto SurfacesPropHandle = InDetailBuilder.GetProperty("StaticMeshSurfaceOverride");
  123. CategoryBuilder.HeaderContent
  124. (
  125. SNew(SHorizontalBox)
  126. + SHorizontalBox::Slot()
  127. .AutoWidth()
  128. .HAlign(HAlign_Left)
  129. .VAlign(VAlign_Center)
  130. [
  131. SNew(SButton)
  132. .Text(FText::FromString("Reset to Defaults"))
  133. .ToolTipText(FText::FromString(FString("Reset the surface properties to their default values.")))
  134. .OnClicked_Lambda([this, SurfacesPropHandle]()
  135. {
  136. BeginModify(FText::FromString(FString("Reset surface properties to defaults")));
  137. if (ComponentBeingCustomized->HasAnyFlags(RF_ArchetypeObject)
  138. || ComponentBeingCustomized->CreationMethod == EComponentCreationMethod::Instance)
  139. {
  140. TArray<UMaterialInterface*> Materials;
  141. ComponentBeingCustomized->StaticMeshSurfaceOverride.GetKeys(Materials);
  142. for (UMaterialInterface* Material : Materials)
  143. {
  144. ComponentBeingCustomized->StaticMeshSurfaceOverride[Material].AcousticTexture = nullptr;
  145. ComponentBeingCustomized->StaticMeshSurfaceOverride[Material].bEnableOcclusionOverride = false;
  146. ComponentBeingCustomized->StaticMeshSurfaceOverride[Material].OcclusionValue = 1.0f;
  147. }
  148. }
  149. else
  150. {
  151. ComponentBeingCustomized->StaticMeshSurfaceOverride.Empty();
  152. SurfacesPropHandle->ResetToDefault();
  153. }
  154. EndModify();
  155. return FReply::Handled();
  156. })
  157. ]
  158. );
  159. ComponentBeingCustomized->UpdateStaticMeshOverride();
  160. TArray<UMaterialInterface*> Materials;
  161. ComponentBeingCustomized->StaticMeshSurfaceOverride.GetKeys(Materials);
  162. for (UMaterialInterface* Material : Materials)
  163. {
  164. FDetailWidgetRow& SurfacesRow = CategoryBuilder.AddCustomRow(FText::FromString("Texture Surface Occlusion"));
  165. SurfacesRow.NameContent()
  166. [
  167. SNew(SBox)
  168. .HeightOverride(SurfacePropertiesHeight)
  169. .ToolTipText(FText::FromString("The material(s) in this list are populated using the materials assigned to the AkGeometry Component's Static Mesh parent Component."))
  170. [
  171. SNew(SObjectPropertyEntryBox)
  172. .AllowedClass(UMaterialInterface::StaticClass())
  173. .ObjectPath_Lambda([Material]() { return FSoftObjectPath(Material).GetAssetPathString(); })
  174. .ToolTipText(FText::FromString("The material(s) in this list are populated using the materials assigned to the AkGeometry Component's Static Mesh parent Component."))
  175. .IsEnabled(false)
  176. ]
  177. ];
  178. SurfacesRow.ValueContent()
  179. [
  180. SNew(SBox)
  181. .HeightOverride(SurfacePropertiesHeight)
  182. [
  183. SNew(SAkGeometryStaticMeshSurfaceController, ObjectsBeingCustomized[0], LockedDetailBuilder, Material)
  184. ]
  185. ];
  186. }
  187. }
  188. }
  189. else if (ComponentBeingCustomized->MeshType == AkMeshType::CollisionMesh)
  190. {
  191. InDetailBuilder.HideProperty("LOD");
  192. InDetailBuilder.HideProperty("WeldingThreshold");
  193. InDetailBuilder.HideProperty("StaticMeshSurfaceOverride");
  194. if (ObjectsBeingCustomized.Num() == 1)
  195. {
  196. IDetailCategoryBuilder& CategoryBuilder = InDetailBuilder.EditCategory("Surface Overrides", FText::GetEmpty(), ECategoryPriority::TypeSpecific);
  197. auto SurfacesPropHandle = InDetailBuilder.GetProperty("CollisionMeshSurfaceOverride");
  198. InDetailBuilder.HideProperty("CollisionMeshSurfaceOverride");
  199. CategoryBuilder.HeaderContent
  200. (
  201. SNew(SHorizontalBox)
  202. + SHorizontalBox::Slot()
  203. .AutoWidth()
  204. .HAlign(HAlign_Left)
  205. .VAlign(VAlign_Center)
  206. [
  207. SNew(SButton)
  208. .Text(FText::FromString("Reset to Defaults"))
  209. .ToolTipText(FText::FromString(FString("Reset the surface properties to their default values.")))
  210. .OnClicked_Lambda([this, SurfacesPropHandle]()
  211. {
  212. BeginModify(FText::FromString(FString("Reset surface properties to defaults")));
  213. if (ComponentBeingCustomized->HasAnyFlags(RF_ArchetypeObject)
  214. || ComponentBeingCustomized->CreationMethod == EComponentCreationMethod::Instance)
  215. {
  216. ComponentBeingCustomized->CollisionMeshSurfaceOverride.AcousticTexture = nullptr;
  217. ComponentBeingCustomized->CollisionMeshSurfaceOverride.bEnableOcclusionOverride = false;
  218. ComponentBeingCustomized->CollisionMeshSurfaceOverride.OcclusionValue = 1.0f;
  219. }
  220. else
  221. {
  222. SurfacesPropHandle->ResetToDefault();
  223. }
  224. EndModify();
  225. return FReply::Handled();
  226. })
  227. ]
  228. );
  229. FDetailWidgetRow& SurfacesRow = CategoryBuilder.AddCustomRow(FText::FromString("Texture Surface Occlusion"));
  230. SurfacesRow.ValueContent()
  231. [
  232. SNew(SBox)
  233. .HeightOverride(SurfacePropertiesHeight)
  234. [
  235. SNew(SAkGeometryCollisionMeshSurfaceController, ObjectsBeingCustomized[0], LockedDetailBuilder)
  236. ]
  237. ];
  238. }
  239. }
  240. }
  241. void FAkGeometryComponentDetailsCustomization::RefreshDetails()
  242. {
  243. if (ComponentBeingCustomized.IsValid())
  244. {
  245. ComponentBeingCustomized->ClearOnRefreshDetails();
  246. }
  247. if (DetailBuilder.IsValid())
  248. {
  249. IDetailLayoutBuilder* Layout = nullptr;
  250. if (auto LockedDetailBuilder = DetailBuilder.Pin())
  251. {
  252. Layout = LockedDetailBuilder.Get();
  253. }
  254. if (LIKELY(Layout))
  255. {
  256. Layout->ForceRefreshDetails();
  257. }
  258. }
  259. }
  260. //////////////////////////////////////////////////////////////////////////
  261. #undef LOCTEXT_NAMESPACE