From 187e5f5d2e8fab19ad5805bccd759fb54f64dbbc Mon Sep 17 00:00:00 2001 From: PopcornFX Bot Date: Thu, 26 Oct 2023 14:40:02 +0200 Subject: [PATCH] PopcornFX Gem 2.15.15 --- Code/CMakeLists.txt | 2 +- Code/Platform/Linux/PAL_linux.cmake | 8 +- Code/Platform/Mac/PAL_mac.cmake | 4 +- Code/Platform/Windows/PAL_windows.cmake | 4 +- .../SceneInterface/SceneInterface.cpp | 177 +++++++++++------- .../SceneInterface/SceneInterface.h | 7 +- README.md | 2 +- gem.json | 8 +- 8 files changed, 127 insertions(+), 85 deletions(-) diff --git a/Code/CMakeLists.txt b/Code/CMakeLists.txt index 224db06..7cbb325 100644 --- a/Code/CMakeLists.txt +++ b/Code/CMakeLists.txt @@ -3,7 +3,7 @@ # https://www.popcornfx.com/terms-and-conditions/ #---------------------------------------------------------------------------- -set(POPCORNFX_VERSION 2.15.14) +set(POPCORNFX_VERSION 2.18.1) set(POPCORNFX_LICENSE O3DE) if (PK_O3DE_MAJOR_VERSION GREATER_EQUAL 2205) diff --git a/Code/Platform/Linux/PAL_linux.cmake b/Code/Platform/Linux/PAL_linux.cmake index 3790808..53df0c4 100644 --- a/Code/Platform/Linux/PAL_linux.cmake +++ b/Code/Platform/Linux/PAL_linux.cmake @@ -6,12 +6,12 @@ set(LY_PACKAGE_SERVER_URLS ${LY_PACKAGE_SERVER_URLS} "https://downloads.popcornfx.com/o3de-packages") if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") set(package_name PopcornFX-${POPCORNFX_VERSION}-${POPCORNFX_LICENSE}-linux) - set(pk_package_hash 7083eebe6a5a21dd40bd2f38824a8b28b1ead391bd7cc52c6d36e2df59ed91f6) - set(pk_package_id nNmxfK8MrGPqWgtm) + set(pk_package_hash 08e30c12813e29e53eae075f4f9f02a1a308c7e8713bcf73abd9b207659abcd9) + set(pk_package_id Ng3RaXuqyAUWAgHy) elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") set(package_name PopcornFX-${POPCORNFX_VERSION}-${POPCORNFX_LICENSE}-linux-aarch64) - set(pk_package_hash 7083eebe6a5a21dd40bd2f38824a8b28b1ead391bd7cc52c6d36e2df59ed91f6_ARM64) - set(pk_package_id nNmxfK8MrGPqWgtm_ARM64) + set(pk_package_hash 0a81eb7ca2d717416efe2aa9ea4c5c3014e1b56c2acdb190556b8c490214beb4) + set(pk_package_id ZDEps23sNQA5p7q5) else() message(FATAL_ERROR "Unsupported linux architecture ${CMAKE_SYSTEM_PROCESSOR}") endif() diff --git a/Code/Platform/Mac/PAL_mac.cmake b/Code/Platform/Mac/PAL_mac.cmake index 04211c4..5425749 100644 --- a/Code/Platform/Mac/PAL_mac.cmake +++ b/Code/Platform/Mac/PAL_mac.cmake @@ -5,8 +5,8 @@ set(LY_PACKAGE_SERVER_URLS ${LY_PACKAGE_SERVER_URLS} "https://downloads.popcornfx.com/o3de-packages") set(package_name PopcornFX-${POPCORNFX_VERSION}-${POPCORNFX_LICENSE}-mac) -set(pk_package_hash 34ac88830921d4027e769b640f915c1e18f7c426fa223d33e1b61b2458c1fef5) -set(pk_package_id 5wTMrDbLZVc2u7VE) +set(pk_package_hash 8e371903268af71a1a362194c7b58f43094b1ff9accc27f0fd4a117df470e760) +set(pk_package_id Kph45AXPVnUw9u6K) ly_associate_package(PACKAGE_NAME ${package_name} TARGETS PopcornFX PACKAGE_HASH ${pk_package_hash}) pk_download_package_ifn(${package_name} ${pk_package_id}) diff --git a/Code/Platform/Windows/PAL_windows.cmake b/Code/Platform/Windows/PAL_windows.cmake index e63ac2e..0435da6 100644 --- a/Code/Platform/Windows/PAL_windows.cmake +++ b/Code/Platform/Windows/PAL_windows.cmake @@ -5,8 +5,8 @@ set(LY_PACKAGE_SERVER_URLS ${LY_PACKAGE_SERVER_URLS} "https://downloads.popcornfx.com/o3de-packages") set(package_name PopcornFX-${POPCORNFX_VERSION}-${POPCORNFX_LICENSE}-windows) -set(pk_package_hash 8103753c8b990696755b8616e2784b43ea293b691acfddce7dac91c2c96e4cba) -set(pk_package_id 4PG9PxsadR4BnTZA) +set(pk_package_hash 4813982cd76ea251972abd8868f09a71d7f03fe3bd486dc1fc0ecbe243327354) +set(pk_package_id UntkQKUXJ57BnbcB) ly_associate_package(PACKAGE_NAME ${package_name} TARGETS PopcornFX PACKAGE_HASH ${pk_package_hash}) pk_download_package_ifn(${package_name} ${pk_package_id}) diff --git a/Code/Source/Integration/SceneInterface/SceneInterface.cpp b/Code/Source/Integration/SceneInterface/SceneInterface.cpp index 5b28537..040696c 100644 --- a/Code/Source/Integration/SceneInterface/SceneInterface.cpp +++ b/Code/Source/Integration/SceneInterface/SceneInterface.cpp @@ -9,34 +9,57 @@ #if defined(O3DE_USE_PK) -#include - #if defined(PK_USE_PHYSX) #include - #include + #include #include + #include #include - #if RESOLVE_MATERIAL_PROPERTIES - #include - #endif - #if RESOLVE_CONTACT_OBJECT - #include - #endif + #include #endif -#include "Integration/PopcornFXIntegrationBus.h" +#include + #include "Integration/PopcornFXUtils.h" namespace PopcornFX { + static void PrintPopcornFXPhysicsSurfaceTypesConstants(const AZ::ConsoleCommandContainer&) + { + if (auto *materialManager = AZ::Interface::Get()) + { + AZStd::shared_ptr defaultMaterial = materialManager->GetDefaultMaterial(); + if (defaultMaterial != null) + { + AZ_Printf("PopcornFX", "physics.surfaceTypes.Default %u", AZ::Crc32(defaultMaterial->GetId().ToString())); + } + } + + AZ::Data::AssetCatalogRequests::AssetEnumerationCB popcornFxAssetReloadCb = [](const AZ::Data::AssetId id, const AZ::Data::AssetInfo& info) + { + if (info.m_assetType == ::Physics::MaterialAsset::RTTI_Type()) + { + Physics::MaterialId materialId = Physics::MaterialId::CreateFromAssetId(id); + AZStd::string materialName = info.m_relativePath; + + AZ::StringFunc::Replace(materialName, ".physicsmaterial", ""); + AZ::StringFunc::Replace(materialName, "/", "."); + + AZ_Printf("PopcornFX", "physics.surfaceTypes.%s %u", materialName.c_str(), AZ::Crc32(materialId.ToString())); + } + }; + AZ::Data::AssetCatalogRequestBus::Broadcast(&AZ::Data::AssetCatalogRequestBus::Events::EnumerateAssets, null, popcornFxAssetReloadCb, null); + } + + AZ_CONSOLEFREEFUNC(PrintPopcornFXPhysicsSurfaceTypesConstants, AZ::ConsoleFunctorFlags::Null, "Print the physics surface types constants to add in your PopcornFX project settings."); + +#if defined(PK_USE_PHYSX) void CSceneInterface::RayTracePacket(const Colliders::STraceFilter &traceFilter, const Colliders::SRayPacket &packet, const Colliders::STracePacket &results) { -#if defined(PK_USE_PHYSX) - AzPhysics::SceneHandle sceneHandle = AzPhysics::InvalidSceneHandle; - auto *sceneInterface = AZ::Interface::Get(); - + AzPhysics::SceneHandle sceneHandle = AzPhysics::InvalidSceneHandle; + AzPhysics::SceneInterface *sceneInterface = AZ::Interface::Get(); if (sceneInterface != null) { #if defined(POPCORNFX_EDITOR) @@ -52,6 +75,14 @@ namespace PopcornFX { if (!PK_VERIFY(sceneHandle != AzPhysics::InvalidSceneHandle)) return; + Physics::MaterialManager *materialManager = null; + if (results.m_ContactSurfaces_Aligned16 != null) + { + materialManager = AZ::Interface::Get(); + if (!PK_VERIFY(materialManager != null)) + return; + } + AzPhysics::CollisionGroup collisionGroup(traceFilter.m_FilterFlags == 0 ? AzPhysics::CollisionGroup::All.GetMask() : traceFilter.m_FilterFlags); const u32 resCount = results.Count(); @@ -78,6 +109,7 @@ namespace PopcornFX { request.m_direction = ToAZ(dir); request.m_distance = _rayDirAndLen.w(); request.m_collisionGroup = collisionGroup; + PK_ASSERT(request.m_reportMultipleHits == false); hitResult = sceneInterface->QueryScene(sceneHandle, &request); } @@ -89,81 +121,94 @@ namespace PopcornFX { request.m_direction = ToAZ(dir); request.m_shapeConfiguration = AZStd::make_shared(packet.m_RaySweepRadii_Aligned16[rayi]); request.m_collisionGroup = collisionGroup; + PK_ASSERT(request.m_reportMultipleHits == false); hitResult = sceneInterface->QueryScene(sceneHandle, &request); } if (!hitResult.m_hits.empty()) { - //m_reportMultipleHits in AzPhysics::RayCastRequest and AzPhysics::ShapeCastRequest are set to false, only 1 hit possible + //m_reportMultipleHits in AzPhysics::RayCastRequest and AzPhysics::ShapeCastRequest are set to false by default, only 1 hit possible const AzPhysics::SceneQueryHit &hit = hitResult.m_hits[0]; results.m_HitTimes_Aligned16[rayi] = hit.m_distance; if (results.m_ContactObjects_Aligned16 != null) { -#if RESOLVE_CONTACT_OBJECT - Physics::RigidBody *rigidbody = null; - AZ::Entity *entity = null; - EBUS_EVENT_RESULT(entity, AZ::ComponentApplicationBus, FindEntity, hit.m_body->GetEntityId()); - if (entity) - { - Physics::RigidBodyRequestBus::EventResult(rigidbody, hit.m_body->GetEntityId(), &Physics::RigidBodyRequests::GetRigidBody); - } - if (rigidbody) - results.m_ContactObjects_Aligned16[rayi] = rigidbody; + const bool haveBodyHandle = hit.m_resultFlags & AzPhysics::SceneQuery::ResultFlags::BodyHandle; + if (!haveBodyHandle) + results.m_ContactObjects_Aligned16[rayi] = null; else -#endif - results.m_ContactObjects_Aligned16[rayi] = CollidableObject::DEFAULT; + results.m_ContactObjects_Aligned16[rayi] = sceneInterface->GetSimulatedBodyFromHandle(sceneHandle, hit.m_bodyHandle); } - if (results.m_ContactPoints_Aligned16 != null) - results.m_ContactPoints_Aligned16[rayi].xyz() = ToPk(hit.m_position); - if (results.m_ContactNormals_Aligned16 != null) - results.m_ContactNormals_Aligned16[rayi].xyz() = ToPk(hit.m_normal); -#if RESOLVE_MATERIAL_PROPERTIES if (results.m_ContactSurfaces_Aligned16 != null) { - AZ::Entity *entity = null; - EBUS_EVENT_RESULT(entity, AZ::ComponentApplicationBus, FindEntity, hit.m_entityId); - if (entity) + const bool havePhysicsMaterial = hit.m_resultFlags & AzPhysics::SceneQuery::ResultFlags::Material; + if (!havePhysicsMaterial) + results.m_ContactSurfaces_Aligned16[rayi] = null; + else { - Physics::RigidBody *rigidbody; - Physics::RigidBodyRequestBus::EventResult(rigidbody, hit.m_body->GetEntityId(), &Physics::RigidBodyRequests::GetRigidBody); - if (rigidbody) - { - Physics::MaterialId materialId = rigidbody->GetMaterialIdForShapeHierarchy(hit.m_hitShapeIdHierarchy); - Physics::MaterialProperties *matProperties = null; - Physics::MaterialRequestBus::BroadcastResult(matProperties, &Physics::MaterialRequests::GetPhysicsMaterialProperties, materialId); - results.m_ContactSurfaces_Aligned16[rayi] = matProperties; - } + AZStd::shared_ptr material = AZStd::rtti_pointer_cast(materialManager->GetMaterial(hit.m_physicsMaterialId)); + results.m_ContactSurfaces_Aligned16[rayi] = material.get(); } } -#endif //RESOLVE_MATERIAL_PROPERTIES + if (results.m_ContactPoints_Aligned16 != null) + results.m_ContactPoints_Aligned16[rayi].xyz() = ToPk(hit.m_position); + if (results.m_ContactNormals_Aligned16 != null) + results.m_ContactNormals_Aligned16[rayi].xyz() = ToPk(hit.m_normal); } } -#endif } -#if RESOLVE_MATERIAL_PROPERTIES -void CSceneInterface::ResolveContactMaterials( const TMemoryView &contactObjects, - const TMemoryView &contactSurfaces, - const TMemoryView&outSurfaceProperties) const -{ - const u32 materialCount = contactSurfaces.Count(); - - for (u32 iMaterial = 0; iMaterial < materialCount; ++iMaterial) + void CSceneInterface::ResolveContactMaterials( [[maybe_unused]] const TMemoryView &contactObjects, + const TMemoryView &contactSurfaces, + const TMemoryView &outSurfaceProperties) const { - PopcornFX::Colliders::SSurfaceProperties &surface = outSurfaceProperties[iMaterial]; - Physics::MaterialProperties *matProperties = reinterpret_cast(contactSurfaces[iMaterial]); - if (matProperties == null) - continue; - surface.m_Restitution = matProperties->m_restitution; - surface.m_StaticFriction = matProperties->m_friction; - surface.m_DynamicFriction = surface.m_StaticFriction; - surface.m_SurfaceType = AZStd::hash{}(matProperties->m_name); - surface.m_RestitutionCombineMode = Colliders::Combine_Average; - surface.m_FrictionCombineMode = Colliders::Combine_Average; + PK_ASSERT(contactObjects.Count() == contactSurfaces.Count()); + PK_ASSERT(contactObjects.Count() == outSurfaceProperties.Count()); + + static const PopcornFX::Colliders::SSurfaceProperties kDefaultSurface; + + const u32 materialCount = contactSurfaces.Count(); + for (u32 iMaterial = 0; iMaterial < materialCount; ++iMaterial) + { + PopcornFX::Colliders::SSurfaceProperties &surface = outSurfaceProperties[iMaterial]; + surface = kDefaultSurface; + + PhysX::Material *material = reinterpret_cast(contactSurfaces[iMaterial]); + if (material == null) + continue; + + surface.m_Restitution = material->GetRestitution(); + surface.m_StaticFriction = material->GetStaticFriction(); + surface.m_DynamicFriction = material->GetDynamicFriction(); + surface.m_SurfaceType = AZ::Crc32(material->GetId().ToString()); + +#define REMAP_COMBINE_MODE(__member, __val) \ + switch (__val) \ + { \ + case PhysX::CombineMode::Average: \ + surface.__member = PopcornFX::Colliders::ECombineMode::Combine_Average; \ + break; \ + case PhysX::CombineMode::Minimum: \ + surface.__member = PopcornFX::Colliders::ECombineMode::Combine_Min; \ + break; \ + case PhysX::CombineMode::Maximum: \ + surface.__member = PopcornFX::Colliders::ECombineMode::Combine_Max; \ + break; \ + case PhysX::CombineMode::Multiply: \ + surface.__member = PopcornFX::Colliders::ECombineMode::Combine_Multiply; \ + break; \ + default: \ + PK_ASSERT_NOT_REACHED(); \ + break; \ + } + + REMAP_COMBINE_MODE(m_FrictionCombineMode, material->GetFrictionCombineMode()); + REMAP_COMBINE_MODE(m_RestitutionCombineMode, material->GetRestitutionCombineMode()); + +#undef REMAP_COMBINE_MODE + } } -} -#endif //RESOLVE_MATERIAL_PROPERTIES +#endif //PK_USE_PHYSX } diff --git a/Code/Source/Integration/SceneInterface/SceneInterface.h b/Code/Source/Integration/SceneInterface/SceneInterface.h index 33c6911..b8297e9 100644 --- a/Code/Source/Integration/SceneInterface/SceneInterface.h +++ b/Code/Source/Integration/SceneInterface/SceneInterface.h @@ -8,23 +8,20 @@ #include -#define RESOLVE_MATERIAL_PROPERTIES 0 -#define RESOLVE_CONTACT_OBJECT 0 - namespace PopcornFX { class CSceneInterface : public IParticleScene { public: +#if defined(PK_USE_PHYSX) virtual void RayTracePacket( const Colliders::STraceFilter &traceFilter, const Colliders::SRayPacket &packet, const Colliders::STracePacket &results) override; -#if RESOLVE_MATERIAL_PROPERTIES virtual void ResolveContactMaterials(const TMemoryView &contactObjects, const TMemoryView &contactSurfaces, const TMemoryView&outSurfaceProperties) const override; -#endif +#endif //PK_USE_PHYSX void SetInGameMode(bool inGameMode) { m_InGameMode = inGameMode; } diff --git a/README.md b/README.md index 0f33ea1..83f0a41 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # O3DE PopcornFX Plugin Integrates the **PopcornFX Runtime SDK** into **O3DE** as a Gem. -* **Version:** `v2.15.14` +* **Version:** `v2.18.1` * **O3DE:** `23.05` * **Supported platforms:** `Windows`, `MacOS`, `Linux`, `iOS`, `Android` diff --git a/gem.json b/gem.json index e53f1a1..42eb58c 100644 --- a/gem.json +++ b/gem.json @@ -1,13 +1,13 @@ { "gem_name": "PopcornFX", - "display_name": "PopcornFX 2.15.14", + "display_name": "PopcornFX 2.18.1", "license": "Community", "license_url": "https://www.popcornfx.com/popcornfx-community-license", "origin": "Persistant Studios - popcornfx.com", "repo_uri": "https://downloads.popcornfx.com/o3de-repo", - "origin_uri": "https://downloads.popcornfx.com/o3de-repo/PopcornFX-2.15/O3DE_PopcornFXGem_v2.15.14_Win64_Linux64_LinuxARM64_Mac64.zip", - "version": "2.15.14", - "last_updated": "2023-09-27", + "origin_uri": "https://downloads.popcornfx.com/o3de-repo/PopcornFX-2.18/O3DE_PopcornFXGem_v2.18.1_Win64_Linux64_LinuxARM64_Mac64.zip", + "version": "2.18.1", + "last_updated": "2023-10-26", "type": "Code", "summary": "The PopcornFX Gem provides real-time FX solution for particle effects.", "canonical_tags": [