Skip to content

Commit

Permalink
PopcornFX Gem 2.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
PopcornFX Bot committed Dec 4, 2023
1 parent ef65dd7 commit 3c17b3e
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 84 deletions.
2 changes: 1 addition & 1 deletion Code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# https://www.popcornfx.com/terms-and-conditions/
#----------------------------------------------------------------------------

set(POPCORNFX_VERSION 2.15.16)
set(POPCORNFX_VERSION 2.18.2)
set(POPCORNFX_LICENSE O3DE)

if (PK_O3DE_MAJOR_VERSION GREATER_EQUAL 2205)
Expand Down
8 changes: 4 additions & 4 deletions Code/Platform/Linux/PAL_linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 4f4c0bb1d4c5c19a3abbf11f0d49609ec1a6eb26363f64631e865747416293d4)
set(pk_package_id kX8RSRt2hZWQZutp)
set(pk_package_hash 3e821c3e52faef389aeb2fa4ffc26aea170ed6c4a195ad0a6261314d3d960d76)
set(pk_package_id tZdIQSnZYZd2lDyU)
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
set(package_name PopcornFX-${POPCORNFX_VERSION}-${POPCORNFX_LICENSE}-linux-aarch64)
set(pk_package_hash 4f4c0bb1d4c5c19a3abbf11f0d49609ec1a6eb26363f64631e865747416293d4_ARM64)
set(pk_package_id kX8RSRt2hZWQZutp_ARM64)
set(pk_package_hash 3e821c3e52faef389aeb2fa4ffc26aea170ed6c4a195ad0a6261314d3d960d76_ARM64)
set(pk_package_id tZdIQSnZYZd2lDyU_ARM64)
else()
message(FATAL_ERROR "Unsupported linux architecture ${CMAKE_SYSTEM_PROCESSOR}")
endif()
Expand Down
4 changes: 2 additions & 2 deletions Code/Platform/Mac/PAL_mac.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 1396b00ee9ccca3d8e1474277ed128595435e9f892f102f361514f78b39171db)
set(pk_package_id roDQZpBI1HS7O2SX)
set(pk_package_hash 002099b1ad44b562f5d1d540114cb567b419122316f0bb5285ae50584ffd71dc)
set(pk_package_id PGOsANDruxNVvhkd)

ly_associate_package(PACKAGE_NAME ${package_name} TARGETS PopcornFX PACKAGE_HASH ${pk_package_hash})
pk_download_package_ifn(${package_name} ${pk_package_id})
Expand Down
4 changes: 2 additions & 2 deletions Code/Platform/Windows/PAL_windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 52875a9f0274fa2da4736f4e6c0ef6d07fc9a118c80861059da5bcbfcee87085)
set(pk_package_id PsvjDNhF0Trboq2I)
set(pk_package_hash 22ea03390ecec87e682dff48a0f0aa1661512418440fd1e6f9b54ccd1e700cab)
set(pk_package_id soODNSq9K3HDKs9F)

ly_associate_package(PACKAGE_NAME ${package_name} TARGETS PopcornFX PACKAGE_HASH ${pk_package_hash})
pk_download_package_ifn(${package_name} ${pk_package_id})
Expand Down
177 changes: 111 additions & 66 deletions Code/Source/Integration/SceneInterface/SceneInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,57 @@

#if defined(O3DE_USE_PK)

#include <AzCore/Component/ComponentApplicationBus.h>

#if defined(PK_USE_PHYSX)
#include <AzFramework/Physics/PhysicsScene.h>
#include <AzFramework/Physics/ShapeConfiguration.h>
#include <AzFramework/Physics/Material/PhysicsMaterialManager.h>
#include <AzCore/Interface/Interface.h>
#include <AzFramework/Physics/ShapeConfiguration.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#if RESOLVE_MATERIAL_PROPERTIES
#include <AzFramework/Physics/Material.h>
#endif
#if RESOLVE_CONTACT_OBJECT
#include <AzFramework/Physics/RigidBodyBus.h>
#endif
#include <PhysX/Material/PhysXMaterial.h>
#endif

#include "Integration/PopcornFXIntegrationBus.h"
#include <AzCore/Console/IConsole.h>

#include "Integration/PopcornFXUtils.h"

namespace PopcornFX {

static void PrintPopcornFXPhysicsSurfaceTypesConstants(const AZ::ConsoleCommandContainer&)
{
if (auto *materialManager = AZ::Interface<Physics::MaterialManager>::Get())
{
AZStd::shared_ptr<Physics::Material> defaultMaterial = materialManager->GetDefaultMaterial();
if (defaultMaterial != null)
{
AZ_Printf("PopcornFX", "physics.surfaceTypes.Default %u", AZ::Crc32(defaultMaterial->GetId().ToString<AZStd::string>()));
}
}

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<AZStd::string>()));
}
};
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<AzPhysics::SceneInterface>::Get();

AzPhysics::SceneHandle sceneHandle = AzPhysics::InvalidSceneHandle;
AzPhysics::SceneInterface *sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get();
if (sceneInterface != null)
{
#if defined(POPCORNFX_EDITOR)
Expand All @@ -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<Physics::MaterialManager>::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();
Expand All @@ -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);
}
Expand All @@ -89,81 +121,94 @@ namespace PopcornFX {
request.m_direction = ToAZ(dir);
request.m_shapeConfiguration = AZStd::make_shared<Physics::SphereShapeConfiguration>(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<PhysX::Material> material = AZStd::rtti_pointer_cast<PhysX::Material>(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<void * const> &contactObjects,
const TMemoryView<void * const> &contactSurfaces,
const TMemoryView<Colliders::SSurfaceProperties>&outSurfaceProperties) const
{
const u32 materialCount = contactSurfaces.Count();

for (u32 iMaterial = 0; iMaterial < materialCount; ++iMaterial)
void CSceneInterface::ResolveContactMaterials( [[maybe_unused]] const TMemoryView<void * const> &contactObjects,
const TMemoryView<void * const> &contactSurfaces,
const TMemoryView<Colliders::SSurfaceProperties> &outSurfaceProperties) const
{
PopcornFX::Colliders::SSurfaceProperties &surface = outSurfaceProperties[iMaterial];
Physics::MaterialProperties *matProperties = reinterpret_cast<Physics::MaterialProperties*>(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<AZStd::string>{}(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<PhysX::Material*>(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<AZStd::string>());

#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

}

Expand Down
7 changes: 2 additions & 5 deletions Code/Source/Integration/SceneInterface/SceneInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@

#include <pk_particles/include/ps_scene.h>

#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<void * const> &contactObjects,
const TMemoryView<void * const> &contactSurfaces,
const TMemoryView<Colliders::SSurfaceProperties>&outSurfaceProperties) const override;
#endif
#endif //PK_USE_PHYSX

void SetInGameMode(bool inGameMode) { m_InGameMode = inGameMode; }

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# O3DE PopcornFX Plugin

Integrates the **PopcornFX Runtime SDK** into **O3DE** as a Gem.
* **Version:** `v2.15.16`
* **Version:** `v2.18.2`
* **O3DE:** `23.05`, `23.10`
* **Supported platforms:** `Windows`, `MacOS`, `Linux`, `iOS`, `Android`

Expand Down
6 changes: 3 additions & 3 deletions gem.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"gem_name": "PopcornFX",
"display_name": "PopcornFX 2.15.16",
"display_name": "PopcornFX 2.18.2",
"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.16_Win64_Linux64_LinuxARM64_Mac64.zip",
"version": "2.15.16",
"origin_uri": "https://downloads.popcornfx.com/o3de-repo/PopcornFX-2.18/O3DE_PopcornFXGem_v2.18.2_Win64_Linux64_LinuxARM64_Mac64.zip",
"version": "2.18.2",
"last_updated": "2023-12-04",
"type": "Code",
"summary": "The PopcornFX Gem provides real-time FX solution for particle effects.",
Expand Down

0 comments on commit 3c17b3e

Please sign in to comment.