Skip to content

Commit

Permalink
Add support for 'Coordinate system change' modifier to PhysX tab in S…
Browse files Browse the repository at this point in the history
…cene Settings (#15028)

## What does this PR do?

Added support for "Coordinate system change" modifier to PhysX tab so the users can add the transformation to the PhysX collider to match the transformation applied to the Mesh.

Fixes #14649
Fixes #11330
Fixes #2426

## How was this PR tested?

Manually tested in a level using a Mesh Collider with a mesh exported as:
- primitive
- primitive with decomposition
- convex
- convex with decomposition
- triangle mesh

Tested with "Coordinate system change" modifier simple and advance modes.

Signed-off-by: moraaar <moraaar@amazon.com>
  • Loading branch information
moraaar committed Mar 10, 2023
1 parent d97c576 commit d0bf5e2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
26 changes: 26 additions & 0 deletions Gems/PhysX/Code/Source/Pipeline/MeshBehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <SceneAPI/SceneCore/Utilities/SceneGraphSelector.h>
#include <SceneAPI/SceneData/Groups/MeshGroup.h>
#include <SceneAPI/SceneCore/Containers/Utilities/SceneGraphUtilities.h>
#include <SceneAPI/SceneData/Rules/CoordinateSystemRule.h>

#include <Source/Pipeline/MeshBehavior.h>
#include <Source/Pipeline/MeshGroup.h>
Expand Down Expand Up @@ -62,6 +63,31 @@ namespace PhysX
}
}

void MeshBehavior::GetAvailableModifiers(
AZ::SceneAPI::Events::ManifestMetaInfo::ModifiersList& modifiers,
[[maybe_unused]] const AZ::SceneAPI::Containers::Scene& scene,
const AZ::SceneAPI::DataTypes::IManifestObject& target)
{
if (!target.RTTI_IsTypeOf(MeshGroup::TYPEINFO_Uuid()))
{
return;
}

const MeshGroup* group = azrtti_cast<const MeshGroup*>(&target);
const AZ::SceneAPI::Containers::RuleContainer& rules = group->GetRuleContainerConst();

AZStd::unordered_set<AZ::Uuid> existingRules;
const size_t ruleCount = rules.GetRuleCount();
for (size_t i = 0; i < ruleCount; ++i)
{
existingRules.insert(rules.GetRule(i)->RTTI_GetType());
}
if (existingRules.find(azrtti_typeid<AZ::SceneAPI::SceneData::CoordinateSystemRule>()) == existingRules.end())
{
modifiers.push_back(azrtti_typeid<AZ::SceneAPI::SceneData::CoordinateSystemRule>());
}
}

void MeshBehavior::InitializeObject(const AZ::SceneAPI::Containers::Scene& scene, AZ::SceneAPI::DataTypes::IManifestObject& target)
{
if (!target.RTTI_IsTypeOf(MeshGroup::TYPEINFO_Uuid()))
Expand Down
10 changes: 9 additions & 1 deletion Gems/PhysX/Code/Source/Pipeline/MeshBehavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ namespace PhysX
{
public:
AZ_COMPONENT(MeshBehavior, "{B6AFB216-2A49-402F-A2B1-C3A17812D53F}", AZ::SceneAPI::SceneCore::BehaviorComponent);
static void Reflect(AZ::ReflectContext* context);

~MeshBehavior() override = default;

// BehaviorComponent overrides ...
void Activate() override;
void Deactivate() override;
static void Reflect(AZ::ReflectContext* context);

// ManifestMetaInfoBus overrides ...
void GetCategoryAssignments(CategoryRegistrationList& categories, const AZ::SceneAPI::Containers::Scene& scene) override;
void GetAvailableModifiers(
AZ::SceneAPI::Events::ManifestMetaInfo::ModifiersList& modifiers,
const AZ::SceneAPI::Containers::Scene& scene,
const AZ::SceneAPI::DataTypes::IManifestObject& target) override;
void InitializeObject(const AZ::SceneAPI::Containers::Scene& scene, AZ::SceneAPI::DataTypes::IManifestObject& target) override;

// AssetImportRequestBus overrides ...
AZ::SceneAPI::Events::ProcessingResult UpdateManifest(AZ::SceneAPI::Containers::Scene& scene, ManifestAction action,
RequestingApplication requester) override;
void GetPolicyName(AZStd::string& result) const override
Expand Down
17 changes: 16 additions & 1 deletion Gems/PhysX/Code/Source/Pipeline/MeshExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#include <SceneAPI/SceneCore/Events/ExportProductList.h>
#include <SceneAPI/SceneCore/Utilities/FileUtilities.h>
#include <SceneAPI/SceneCore/Utilities/Reporting.h>
#include <SceneAPI/SceneCore/Containers/Utilities/SceneUtilities.h>
#include <SceneAPI/SceneCore/Containers/Views/SceneGraphChildIterator.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IMaterialData.h>
#include <SceneAPI/SceneData/Rules/CoordinateSystemRule.h>

#include <PhysX/MeshAsset.h>
#include <Source/Pipeline/MeshAssetHandler.h>
Expand Down Expand Up @@ -810,6 +812,16 @@ namespace PhysX
totalExportData.reserve(selectedNodeCount);
}

// Get the coordinate system conversion rule.
AZ::SceneAPI::CoordinateSystemConverter coordSysConverter;
AZStd::shared_ptr<AZ::SceneAPI::SceneData::CoordinateSystemRule> coordinateSystemRule =
pxMeshGroup.GetRuleContainerConst().FindFirstByType<AZ::SceneAPI::SceneData::CoordinateSystemRule>();
if (coordinateSystemRule)
{
coordinateSystemRule->UpdateCoordinateSystemConverter();
coordSysConverter = coordinateSystemRule->GetCoordinateSystemConverter();
}

for (size_t index = 0; index < selectedNodeCount; index++)
{
AZ::SceneAPI::Containers::SceneGraph::NodeIndex nodeIndex = graph.Find(sceneNodeSelectionList.GetSelectedNode(index));
Expand All @@ -822,7 +834,10 @@ namespace PhysX

const AZ::SceneAPI::Containers::SceneGraph::Name& nodeName = graph.GetNodeName(nodeIndex);

const AZ::SceneAPI::DataTypes::MatrixType worldTransform = SceneUtil::BuildWorldTransform(graph, nodeIndex);
// CoordinateSystemConverter covers the simple transformations of CoordinateSystemRule and
// DetermineWorldTransform function covers the advanced mode of CoordinateSystemRule.
const AZ::SceneAPI::DataTypes::MatrixType worldTransform = coordSysConverter.ConvertMatrix3x4(
AZ::SceneAPI::Utilities::DetermineWorldTransform(scene, nodeIndex, pxMeshGroup.GetRuleContainerConst()));

NodeCollisionGeomExportData nodeExportData;
nodeExportData.m_nodeName = nodeName.GetName();
Expand Down

0 comments on commit d0bf5e2

Please sign in to comment.