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

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

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

@ -264,7 +264,11 @@ namespace PhysX
case Physics::ShapeType::CookedMesh: case Physics::ShapeType::CookedMesh:
{ {
const auto& cookedMeshConfig = static_cast<const Physics::CookedMeshShapeConfiguration&>(shapeConfig); 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)
{ {
if (meshData->is<physx::PxTriangleMesh>()) if (meshData->is<physx::PxTriangleMesh>())

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

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

@ -67,7 +67,7 @@ namespace PhysX
} }
void CreatePxGeometryFromHeightfield( void CreatePxGeometryFromHeightfield(
const Physics::HeightfieldShapeConfiguration& heightfieldConfig, physx::PxGeometryHolder& pxGeometry) Physics::HeightfieldShapeConfiguration& heightfieldConfig, physx::PxGeometryHolder& pxGeometry)
{ {
physx::PxHeightField* heightfield = nullptr; physx::PxHeightField* heightfield = nullptr;
@ -264,9 +264,14 @@ namespace PhysX
} }
case Physics::ShapeType::CookedMesh: case Physics::ShapeType::CookedMesh:
{ {
const Physics::CookedMeshShapeConfiguration& cookedMeshShapeConfig = const Physics::CookedMeshShapeConfiguration& constCookedMeshShapeConfig =
static_cast<const Physics::CookedMeshShapeConfiguration&>(shapeConfiguration); 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; physx::PxBase* nativeMeshObject = nullptr;
// Use the cached mesh object if it is there, otherwise create one and save in the shape configuration // Use the cached mesh object if it is there, otherwise create one and save in the shape configuration
@ -304,9 +309,14 @@ namespace PhysX
} }
case Physics::ShapeType::Heightfield: case Physics::ShapeType::Heightfield:
{ {
const Physics::HeightfieldShapeConfiguration& heightfieldConfig = const Physics::HeightfieldShapeConfiguration& constHeightfieldConfig =
static_cast<const Physics::HeightfieldShapeConfiguration&>(shapeConfiguration); static_cast<const Physics::HeightfieldShapeConfiguration&>(shapeConfiguration);
// 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); CreatePxGeometryFromHeightfield(heightfieldConfig, pxGeometry);
break; break;
} }
@ -1518,9 +1528,9 @@ namespace PhysX
return entityWorldTransformWithoutScale * jointLocalTransformWithoutScale; 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); AZ::Vector2 gridSpacing(1.0f);
Physics::HeightfieldProviderRequestsBus::EventResult( Physics::HeightfieldProviderRequestsBus::EventResult(
@ -1549,6 +1559,8 @@ namespace PhysX
samples, entityId, &Physics::HeightfieldProviderRequestsBus::Events::GetHeightsAndMaterials); samples, entityId, &Physics::HeightfieldProviderRequestsBus::Events::GetHeightsAndMaterials);
configuration.SetSamples(samples); configuration.SetSamples(samples);
return configuration;
} }
} // namespace Utils } // namespace Utils

@ -188,7 +188,7 @@ namespace PhysX
//! Returns defaultValue if the input is infinite or NaN, otherwise returns the input unchanged. //! 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()); 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 namespace Geometry
{ {

Loading…
Cancel
Save