fixing bug with subdivision level for runtime asset colliders and adding caching for collider aabbs
This commit is contained in:
@@ -142,6 +142,7 @@ namespace Physics
|
||||
->Field("PhysicsAsset", &PhysicsAssetShapeConfiguration::m_asset)
|
||||
->Field("AssetScale", &PhysicsAssetShapeConfiguration::m_assetScale)
|
||||
->Field("UseMaterialsFromAsset", &PhysicsAssetShapeConfiguration::m_useMaterialsFromAsset)
|
||||
->Field("SubdivisionLevel", &PhysicsAssetShapeConfiguration::m_subdivisionLevel)
|
||||
;
|
||||
|
||||
if (auto editContext = serializeContext->GetEditContext())
|
||||
|
||||
@@ -141,6 +141,7 @@ namespace Physics
|
||||
AZ::Data::Asset<AZ::Data::AssetData> m_asset{ AZ::Data::AssetLoadBehavior::PreLoad };
|
||||
AZ::Vector3 m_assetScale = AZ::Vector3::CreateOne();
|
||||
bool m_useMaterialsFromAsset = true;
|
||||
AZ::u8 m_subdivisionLevel = 4; ///< The level of subdivision if a primitive shape is replaced with a convex mesh due to scaling.
|
||||
};
|
||||
|
||||
class NativeShapeConfiguration : public ShapeConfiguration
|
||||
|
||||
@@ -330,10 +330,9 @@ namespace PhysX
|
||||
}
|
||||
|
||||
const bool hasNonUniformScale = (AZ::NonUniformScaleRequestBus::FindFirstHandler(GetEntityId()) != nullptr);
|
||||
// the value for the subdivision level doesn't matter in the runtime, because any approximation of primitives will already have
|
||||
// happened in the editor, so can pass an arbitrary value here
|
||||
AZ::u8 subdivisionLevel = 0;
|
||||
Utils::GetShapesFromAsset(physicsAssetConfiguration, componentColliderConfiguration, hasNonUniformScale, subdivisionLevel, m_shapes);
|
||||
AZ::u8 subdivisionLevel = physicsAssetConfiguration.m_subdivisionLevel;
|
||||
Utils::GetShapesFromAsset(physicsAssetConfiguration, componentColliderConfiguration, hasNonUniformScale,
|
||||
physicsAssetConfiguration.m_subdivisionLevel, m_shapes);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -513,6 +513,8 @@ namespace PhysX
|
||||
break;
|
||||
case Physics::ShapeType::PhysicsAsset:
|
||||
colliderComponent = gameEntity->CreateComponent<MeshColliderComponent>();
|
||||
|
||||
m_shapeConfiguration.m_physicsAsset.m_configuration.m_subdivisionLevel = m_shapeConfiguration.m_subdivisionLevel;
|
||||
colliderComponent->SetShapeConfigurationList({ AZStd::make_pair(sharedColliderConfig,
|
||||
AZStd::make_shared<Physics::PhysicsAssetShapeConfiguration>(m_shapeConfiguration.m_physicsAsset.m_configuration)) });
|
||||
|
||||
@@ -560,6 +562,8 @@ namespace PhysX
|
||||
|
||||
void EditorColliderComponent::CreateStaticEditorCollider()
|
||||
{
|
||||
m_cachedAabbDirty = true;
|
||||
|
||||
// Don't create static rigid body in the editor if current entity components
|
||||
// don't allow creation of runtime static rigid body component
|
||||
if (!StaticRigidBodyUtils::CanCreateRuntimeComponent(*GetEntity()))
|
||||
@@ -1014,11 +1018,17 @@ namespace PhysX
|
||||
// PhysX::ColliderShapeBus
|
||||
AZ::Aabb EditorColliderComponent::GetColliderShapeAabb()
|
||||
{
|
||||
return PhysX::Utils::GetColliderAabb(GetWorldTM()
|
||||
, m_hasNonUniformScale
|
||||
, m_shapeConfiguration.m_subdivisionLevel
|
||||
, m_shapeConfiguration.GetCurrent()
|
||||
, m_configuration);
|
||||
if (m_cachedAabbDirty)
|
||||
{
|
||||
m_cachedAabb = PhysX::Utils::GetColliderAabb(GetWorldTM()
|
||||
, m_hasNonUniformScale
|
||||
, m_shapeConfiguration.m_subdivisionLevel
|
||||
, m_shapeConfiguration.GetCurrent()
|
||||
, m_configuration);
|
||||
m_cachedAabbDirty = false;
|
||||
}
|
||||
|
||||
return m_cachedAabb;
|
||||
}
|
||||
|
||||
void EditorColliderComponent::UpdateShapeConfigurationScale()
|
||||
|
||||
@@ -261,6 +261,8 @@ namespace PhysX
|
||||
bool m_hasNonUniformScale = false; //!< Whether there is a non-uniform scale component on this entity.
|
||||
AZ::Vector3 m_cachedNonUniformScale = AZ::Vector3::CreateOne(); //!< Caches the current non-uniform scale.
|
||||
mutable AZStd::optional<Physics::CookedMeshShapeConfiguration> m_scaledPrimitive; //!< Approximation for non-uniformly scaled primitive.
|
||||
AZ::Aabb m_cachedAabb = AZ::Aabb::CreateNull(); //!< Cache the Aabb to avoid recalculating it.
|
||||
bool m_cachedAabbDirty = true; //!< Track whether the cached Aabb needs to be recomputed.
|
||||
|
||||
AZ::ComponentDescriptor::StringWarningArray m_componentWarnings;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user