Skip to content

Commit

Permalink
PopcornFX Gem 2.15.15
Browse files Browse the repository at this point in the history
  • Loading branch information
PopcornFX Bot committed Oct 26, 2023
1 parent 49a3b48 commit 187e5f5
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 85 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.14)
set(POPCORNFX_VERSION 2.18.1)
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 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()
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 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})
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 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})
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.14`
* **Version:** `v2.18.1`
* **O3DE:** `23.05`
* **Supported platforms:** `Windows`, `MacOS`, `Linux`, `iOS`, `Android`

Expand Down
8 changes: 4 additions & 4 deletions gem.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit 187e5f5

Please sign in to comment.