Addressed feedback from PR 4874. (#4915)

* Addressed feedback from PR 4874.
* Removed second copy of HeightfieldProviderBus.h from cmake file
* Changed CookedMeshShapeConfiguration and HeightfieldShapeConfiguration to have less messy implementations, instead opting for the slightly less messy const_cast inside of Utils.cpp and DebugDraw.cpp.
* Changed InitHeightfieldShapeConfiguraiton to CreateHeightfieldShapeConfiguration with a better API signature.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Fixed indentation

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
monroegm-disable-blank-issue-2
Mike Balfour 4 years ago committed by GitHub
parent 2fe4524458
commit 243532c5de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -286,12 +286,17 @@ namespace Physics
return m_type;
}
void* CookedMeshShapeConfiguration::GetCachedNativeMesh() const
const void* CookedMeshShapeConfiguration::GetCachedNativeMesh() const
{
return m_cachedNativeMesh;
}
void CookedMeshShapeConfiguration::SetCachedNativeMesh(void* cachedNativeMesh) const
void* CookedMeshShapeConfiguration::GetCachedNativeMesh()
{
return m_cachedNativeMesh;
}
void CookedMeshShapeConfiguration::SetCachedNativeMesh(void* cachedNativeMesh)
{
m_cachedNativeMesh = cachedNativeMesh;
}
@ -353,12 +358,17 @@ namespace Physics
return *this;
}
void* HeightfieldShapeConfiguration::GetCachedNativeHeightfield() const
const void* HeightfieldShapeConfiguration::GetCachedNativeHeightfield() const
{
return m_cachedNativeHeightfield;
}
void HeightfieldShapeConfiguration::SetCachedNativeHeightfield(void* cachedNativeHeightfield) const
void* HeightfieldShapeConfiguration::GetCachedNativeHeightfield()
{
return m_cachedNativeHeightfield;
}
void HeightfieldShapeConfiguration::SetCachedNativeHeightfield(void* cachedNativeHeightfield)
{
if (m_cachedNativeHeightfield)
{
@ -427,4 +437,5 @@ namespace Physics
{
m_maxHeightBounds = maxBounds;
}
}
} // namespace Physics

@ -187,8 +187,9 @@ namespace Physics
MeshType GetMeshType() const;
void* GetCachedNativeMesh() const;
void SetCachedNativeMesh(void* cachedNativeMesh) const;
void* GetCachedNativeMesh();
const void* GetCachedNativeMesh() const;
void SetCachedNativeMesh(void* cachedNativeMesh);
private:
void ReleaseCachedNativeMesh();
@ -197,7 +198,7 @@ namespace Physics
MeshType m_type = MeshType::TriangleMesh;
//! Cached native mesh object (e.g. PxConvexMesh or PxTriangleMesh). This data is not serialized.
mutable void* m_cachedNativeMesh = nullptr;
void* m_cachedNativeMesh = nullptr;
};
class HeightfieldShapeConfiguration
@ -217,8 +218,9 @@ namespace Physics
return ShapeType::Heightfield;
}
void* GetCachedNativeHeightfield() const;
void SetCachedNativeHeightfield(void* cachedNativeHeightfield) const;
const void* GetCachedNativeHeightfield() const;
void* GetCachedNativeHeightfield();
void SetCachedNativeHeightfield(void* cachedNativeHeightfield);
AZ::Vector2 GetGridResolution() const;
void SetGridResolution(const AZ::Vector2& gridSpacing);
int32_t GetNumColumns() const;
@ -246,6 +248,6 @@ namespace Physics
//! The grid of sample points for the heightfield.
AZStd::vector<Physics::HeightMaterialPoint> m_samples;
//! An optional storage pointer for the physics system to cache its native heightfield representation.
mutable void* m_cachedNativeHeightfield{ nullptr };
void* m_cachedNativeHeightfield{ nullptr };
};
} // namespace Physics

@ -252,7 +252,6 @@ set(FILES
Physics/Shape.h
Physics/ShapeConfiguration.h
Physics/ShapeConfiguration.cpp
Physics/HeightfieldProviderBus.h
Physics/SystemBus.h
Physics/ColliderComponentBus.h
Physics/RagdollPhysicsBus.h

@ -264,7 +264,11 @@ namespace PhysX
case Physics::ShapeType::CookedMesh:
{
const auto& cookedMeshConfig = static_cast<const Physics::CookedMeshShapeConfiguration&>(shapeConfig);
physx::PxBase* meshData = static_cast<physx::PxBase*>(cookedMeshConfig.GetCachedNativeMesh());
const physx::PxBase* constMeshData = static_cast<const physx::PxBase*>(cookedMeshConfig.GetCachedNativeMesh());
// Specifically removing the const from the meshData pointer because the physx APIs expect this pointer to be non-const.
physx::PxBase* meshData = const_cast<physx::PxBase*>(constMeshData);
if (meshData)
{
if (meshData->is<physx::PxTriangleMesh>())

@ -201,9 +201,7 @@ namespace PhysX
void EditorHeightfieldColliderComponent::InitHeightfieldShapeConfiguration()
{
Physics::HeightfieldShapeConfiguration& configuration = static_cast<Physics::HeightfieldShapeConfiguration&>(*m_shapeConfig);
Utils::InitHeightfieldShapeConfiguration(GetEntityId(), configuration);
*m_shapeConfig = Utils::CreateHeightfieldShapeConfiguration(GetEntityId());
}
void EditorHeightfieldColliderComponent::RefreshHeightfield()

@ -139,7 +139,7 @@ namespace PhysX
{
Physics::HeightfieldShapeConfiguration& configuration = static_cast<Physics::HeightfieldShapeConfiguration&>(*m_shapeConfig.second);
Utils::InitHeightfieldShapeConfiguration(GetEntityId(), configuration);
configuration = Utils::CreateHeightfieldShapeConfiguration(GetEntityId());
}
void HeightfieldColliderComponent::RefreshHeightfield()

@ -67,7 +67,7 @@ namespace PhysX
}
void CreatePxGeometryFromHeightfield(
const Physics::HeightfieldShapeConfiguration& heightfieldConfig, physx::PxGeometryHolder& pxGeometry)
Physics::HeightfieldShapeConfiguration& heightfieldConfig, physx::PxGeometryHolder& pxGeometry)
{
physx::PxHeightField* heightfield = nullptr;
@ -264,9 +264,14 @@ namespace PhysX
}
case Physics::ShapeType::CookedMesh:
{
const Physics::CookedMeshShapeConfiguration& cookedMeshShapeConfig =
const Physics::CookedMeshShapeConfiguration& constCookedMeshShapeConfig =
static_cast<const Physics::CookedMeshShapeConfiguration&>(shapeConfiguration);
// We are deliberately removing the const off of the ShapeConfiguration here because we're going to change the cached
// native mesh pointer that gets stored in the configuration.
Physics::CookedMeshShapeConfiguration& cookedMeshShapeConfig =
const_cast<Physics::CookedMeshShapeConfiguration&>(constCookedMeshShapeConfig);
physx::PxBase* nativeMeshObject = nullptr;
// Use the cached mesh object if it is there, otherwise create one and save in the shape configuration
@ -303,13 +308,18 @@ namespace PhysX
return false;
}
case Physics::ShapeType::Heightfield:
{
const Physics::HeightfieldShapeConfiguration& heightfieldConfig =
static_cast<const Physics::HeightfieldShapeConfiguration&>(shapeConfiguration);
{
const Physics::HeightfieldShapeConfiguration& constHeightfieldConfig =
static_cast<const Physics::HeightfieldShapeConfiguration&>(shapeConfiguration);
CreatePxGeometryFromHeightfield(heightfieldConfig, pxGeometry);
break;
}
// We are deliberately removing the const off of the ShapeConfiguration here because we're going to change the cached
// native heightfield pointer that gets stored in the configuration.
Physics::HeightfieldShapeConfiguration& heightfieldConfig =
const_cast<Physics::HeightfieldShapeConfiguration&>(constHeightfieldConfig);
CreatePxGeometryFromHeightfield(heightfieldConfig, pxGeometry);
break;
}
default:
AZ_Warning("PhysX Rigid Body", false, "Shape not supported in PhysX. Shape Type: %d", shapeType);
return false;
@ -1518,9 +1528,9 @@ namespace PhysX
return entityWorldTransformWithoutScale * jointLocalTransformWithoutScale;
}
void InitHeightfieldShapeConfiguration(AZ::EntityId entityId, Physics::HeightfieldShapeConfiguration& configuration)
Physics::HeightfieldShapeConfiguration CreateHeightfieldShapeConfiguration(AZ::EntityId entityId)
{
configuration = Physics::HeightfieldShapeConfiguration();
Physics::HeightfieldShapeConfiguration configuration;
AZ::Vector2 gridSpacing(1.0f);
Physics::HeightfieldProviderRequestsBus::EventResult(
@ -1549,6 +1559,8 @@ namespace PhysX
samples, entityId, &Physics::HeightfieldProviderRequestsBus::Events::GetHeightsAndMaterials);
configuration.SetSamples(samples);
return configuration;
}
} // namespace Utils

@ -188,7 +188,7 @@ namespace PhysX
//! Returns defaultValue if the input is infinite or NaN, otherwise returns the input unchanged.
const AZ::Vector3& Sanitize(const AZ::Vector3& input, const AZ::Vector3& defaultValue = AZ::Vector3::CreateZero());
void InitHeightfieldShapeConfiguration(AZ::EntityId entityId, Physics::HeightfieldShapeConfiguration& configuration);
Physics::HeightfieldShapeConfiguration CreateHeightfieldShapeConfiguration(AZ::EntityId entityId);
namespace Geometry
{

Loading…
Cancel
Save