diff --git a/Source/Engine/Physics/Actors/Cloth.cpp b/Source/Engine/Physics/Actors/Cloth.cpp index 3b9c1cf1c..23f7633e1 100644 --- a/Source/Engine/Physics/Actors/Cloth.cpp +++ b/Source/Engine/Physics/Actors/Cloth.cpp @@ -507,6 +507,16 @@ bool Cloth::CreateCloth() #if WITH_CLOTH PROFILE_CPU(); + // Skip if all vertices are fixed so cloth sim doesn't make sense + if (_paint.HasItems()) + { + bool allZero = true; + for (int32 i = 0; i < _paint.Count() && allZero; i++) + allZero = _paint[i] <= ZeroTolerance; + if (allZero) + return false; + } + // Get mesh data // TODO: consider making it via async task so physics can wait on the cloth setup from mesh data just before next fixed update which gives more time when loading scene const ModelInstanceActor::MeshReference mesh = GetMesh(); diff --git a/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp b/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp index a1072f540..88a123be9 100644 --- a/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp +++ b/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp @@ -3332,21 +3332,21 @@ void* PhysicsBackend::CreateCloth(const PhysicsClothDesc& desc) { // Sanity check bool allValid = true; - for (int32 i = 0; i < desc.VerticesCount; i++) + for (uint32 i = 0; i < desc.VerticesCount; i++) allValid &= !(*(Float3*)((byte*)desc.VerticesData + i * desc.VerticesStride)).IsNanOrInfinity(); if (desc.InvMassesData) { - for (int32 i = 0; i < desc.VerticesCount; i++) + for (uint32 i = 0; i < desc.VerticesCount; i++) { - float v = *(float*)((byte*)desc.InvMassesData + i * desc.InvMassesStride); + const float v = *(float*)((byte*)desc.InvMassesData + i * desc.InvMassesStride); allValid &= !isnan(v) && !isinf(v); } } if (desc.MaxDistancesData) { - for (int32 i = 0; i < desc.VerticesCount; i++) + for (uint32 i = 0; i < desc.VerticesCount; i++) { - float v = *(float*)((byte*)desc.MaxDistancesData + i * desc.MaxDistancesStride); + const float v = *(float*)((byte*)desc.MaxDistancesData + i * desc.MaxDistancesStride); allValid &= !isnan(v) && !isinf(v); } }