diff --git a/Plugins/KawaiiPhysics/Source/KawaiiPhysics/Private/AnimNode_KawaiiPhysics.cpp b/Plugins/KawaiiPhysics/Source/KawaiiPhysics/Private/AnimNode_KawaiiPhysics.cpp index 79cc406..8d3e364 100644 --- a/Plugins/KawaiiPhysics/Source/KawaiiPhysics/Private/AnimNode_KawaiiPhysics.cpp +++ b/Plugins/KawaiiPhysics/Source/KawaiiPhysics/Private/AnimNode_KawaiiPhysics.cpp @@ -428,8 +428,8 @@ void FAnimNode_KawaiiPhysics::UpdateSphericalLimits(TArray& Lim for (auto& Sphere : Limits) { SCOPE_CYCLE_COUNTER(STAT_KawaiiPhysics_UpdateSphericalLimit); - - if (Sphere.DrivingBone.BoneIndex >= 0) + + if (Sphere.DrivingBone.IsValidToEvaluate(BoneContainer)) { const FCompactPoseBoneIndex CompactPoseIndex = Sphere.DrivingBone.GetCompactPoseIndex(BoneContainer); FTransform BoneTransform = Output.Pose.GetComponentSpaceTransform(CompactPoseIndex); @@ -441,10 +441,12 @@ void FAnimNode_KawaiiPhysics::UpdateSphericalLimits(TArray& Lim FAnimationRuntime::ConvertBoneSpaceTransformToCS(ComponentTransform, Output.Pose, BoneTransform, CompactPoseIndex, BCS_BoneSpace); Sphere.Location = BoneTransform.GetLocation(); Sphere.Rotation = BoneTransform.GetRotation(); + + Sphere.bEnable = true; } else { - Sphere.Location = Sphere.OffsetLocation; + Sphere.bEnable = false; } } } @@ -457,7 +459,7 @@ void FAnimNode_KawaiiPhysics::UpdateCapsuleLimits(TArray& Limits, { SCOPE_CYCLE_COUNTER(STAT_KawaiiPhysics_UpdateCapsuleLimit); - if (Capsule.DrivingBone.BoneIndex >= 0) + if (Capsule.DrivingBone.IsValidToEvaluate(BoneContainer)) { const FCompactPoseBoneIndex CompactPoseIndex = Capsule.DrivingBone.GetCompactPoseIndex(BoneContainer); FTransform BoneTransform = Output.Pose.GetComponentSpaceTransform(CompactPoseIndex); @@ -469,11 +471,12 @@ void FAnimNode_KawaiiPhysics::UpdateCapsuleLimits(TArray& Limits, FAnimationRuntime::ConvertBoneSpaceTransformToCS(ComponentTransform, Output.Pose, BoneTransform, CompactPoseIndex, BCS_BoneSpace); Capsule.Location = BoneTransform.GetLocation(); Capsule.Rotation = BoneTransform.GetRotation(); + + Capsule.bEnable = true; } else { - Capsule.Location = Capsule.OffsetLocation; - Capsule.Rotation = Capsule.OffsetRotation.Quaternion(); + Capsule.bEnable = false; } } } @@ -486,7 +489,7 @@ void FAnimNode_KawaiiPhysics::UpdatePlanerLimits(TArray& Limits, F { SCOPE_CYCLE_COUNTER(STAT_KawaiiPhysics_UpdatePlanerLimit); - if (Planar.DrivingBone.BoneIndex >= 0) + if (Planar.DrivingBone.IsValidToEvaluate(BoneContainer)) { const FCompactPoseBoneIndex CompactPoseIndex = Planar.DrivingBone.GetCompactPoseIndex(BoneContainer); FTransform BoneTransform = Output.Pose.GetComponentSpaceTransform(CompactPoseIndex); @@ -500,13 +503,12 @@ void FAnimNode_KawaiiPhysics::UpdatePlanerLimits(TArray& Limits, F Planar.Rotation = BoneTransform.GetRotation(); Planar.Rotation.Normalize(); Planar.Plane = FPlane(Planar.Location, Planar.Rotation.GetUpVector()); + + Planar.bEnable = true; } else { - Planar.Location = Planar.OffsetLocation; - Planar.Rotation = Planar.OffsetRotation.Quaternion(); - Planar.Rotation.Normalize(); - Planar.Plane = FPlane(Planar.Location, Planar.Rotation.GetUpVector()); + Planar.bEnable = false; } } } @@ -740,7 +742,7 @@ void FAnimNode_KawaiiPhysics::AdjustBySphereCollision(FKawaiiPhysicsModifyBone& { for (auto& Sphere : Limits) { - if (Sphere.Radius <= 0.0f) + if (!Sphere.bEnable || Sphere.Radius <= 0.0f) { continue; } @@ -783,7 +785,7 @@ void FAnimNode_KawaiiPhysics::AdjustByCapsuleCollision(FKawaiiPhysicsModifyBone& { for (auto& Capsule : Limits) { - if (Capsule.Radius <= 0 || Capsule.Length <= 0) + if (!Capsule.bEnable || Capsule.Radius <= 0 || Capsule.Length <= 0) { continue; } @@ -805,6 +807,10 @@ void FAnimNode_KawaiiPhysics::AdjustByPlanerCollision(FKawaiiPhysicsModifyBone& { for (auto& Planar : Limits) { + if(!Planar.bEnable) + { + continue; + } FVector PointOnPlane = FVector::PointPlaneProject(Bone.Location, Planar.Plane); const float DistSquared = (Bone.Location - PointOnPlane).SizeSquared(); diff --git a/Plugins/KawaiiPhysics/Source/KawaiiPhysics/Public/AnimNode_KawaiiPhysics.h b/Plugins/KawaiiPhysics/Source/KawaiiPhysics/Public/AnimNode_KawaiiPhysics.h index 3754545..ba080c7 100644 --- a/Plugins/KawaiiPhysics/Source/KawaiiPhysics/Public/AnimNode_KawaiiPhysics.h +++ b/Plugins/KawaiiPhysics/Source/KawaiiPhysics/Public/AnimNode_KawaiiPhysics.h @@ -58,6 +58,9 @@ struct FCollisionLimitBase UPROPERTY() FQuat Rotation = FQuat::Identity; + + UPROPERTY() + bool bEnable = true; #if WITH_EDITORONLY_DATA diff --git a/Plugins/KawaiiPhysics/Source/KawaiiPhysicsEd/Private/KawaiiPhysicsEditMode.cpp b/Plugins/KawaiiPhysics/Source/KawaiiPhysicsEd/Private/KawaiiPhysicsEditMode.cpp index 0b7e333..167cf1b 100644 --- a/Plugins/KawaiiPhysics/Source/KawaiiPhysicsEd/Private/KawaiiPhysicsEditMode.cpp +++ b/Plugins/KawaiiPhysics/Source/KawaiiPhysicsEd/Private/KawaiiPhysicsEditMode.cpp @@ -128,7 +128,7 @@ void FKawaiiPhysicsEditMode::RenderSphericalLimits(FPrimitiveDrawInterface* PDI) for( int32 i=0; i< RuntimeNode->SphericalLimits.Num(); i++) { auto& Sphere = RuntimeNode->SphericalLimits[i]; - if (Sphere.Radius > 0) + if (Sphere.bEnable && Sphere.Radius > 0) { PDI->SetHitProxy(new HKawaiiPhysicsHitProxy(ECollisionLimitType::Spherical, i)); DrawSphere(PDI, Sphere.Location, FRotator::ZeroRotator, FVector(Sphere.Radius), 24, 6, @@ -141,7 +141,7 @@ void FKawaiiPhysicsEditMode::RenderSphericalLimits(FPrimitiveDrawInterface* PDI) for (int32 i = 0; i < RuntimeNode->SphericalLimitsData.Num(); i++) { auto& Sphere = RuntimeNode->SphericalLimitsData[i]; - if (Sphere.Radius > 0) + if (Sphere.bEnable && Sphere.Radius > 0) { PDI->SetHitProxy(new HKawaiiPhysicsHitProxy(ECollisionLimitType::Spherical, i, true)); DrawSphere(PDI, Sphere.Location, FRotator::ZeroRotator, FVector(Sphere.Radius), 24, 6, @@ -160,7 +160,7 @@ void FKawaiiPhysicsEditMode::RenderCapsuleLimit(FPrimitiveDrawInterface* PDI) co for (int32 i = 0; i < RuntimeNode->CapsuleLimits.Num(); i++) { auto& Capsule = RuntimeNode->CapsuleLimits[i]; - if (Capsule.Radius > 0 && Capsule.Length > 0) + if (Capsule.bEnable && Capsule.Radius > 0 && Capsule.Length > 0) { FVector XAxis = Capsule.Rotation.GetAxisX(); FVector YAxis = Capsule.Rotation.GetAxisY(); @@ -185,7 +185,7 @@ void FKawaiiPhysicsEditMode::RenderCapsuleLimit(FPrimitiveDrawInterface* PDI) co for (int32 i = 0; i < RuntimeNode->CapsuleLimitsData.Num(); i++) { auto& Capsule = RuntimeNode->CapsuleLimitsData[i]; - if (Capsule.Radius > 0 && Capsule.Length > 0) + if (Capsule.bEnable && Capsule.Radius > 0 && Capsule.Length > 0) { FVector XAxis = Capsule.Rotation.GetAxisX(); FVector YAxis = Capsule.Rotation.GetAxisY(); @@ -216,6 +216,10 @@ void FKawaiiPhysicsEditMode::RenderPlanerLimit(FPrimitiveDrawInterface* PDI) for (int32 i = 0; i < RuntimeNode->PlanarLimits.Num(); i++) { auto& Plane = RuntimeNode->PlanarLimits[i]; + if(!Plane.bEnable) + { + continue; + } FTransform PlaneTransform = FTransform(Plane.Rotation, Plane.Location); PlaneTransform.NormalizeRotation(); @@ -228,7 +232,11 @@ void FKawaiiPhysicsEditMode::RenderPlanerLimit(FPrimitiveDrawInterface* PDI) for (int32 i = 0; i < RuntimeNode->PlanarLimitsData.Num(); i++) { auto& Plane = RuntimeNode->PlanarLimitsData[i]; - + if(!Plane.bEnable) + { + continue; + } + FTransform PlaneTransform = FTransform(Plane.Rotation, Plane.Location); PlaneTransform.NormalizeRotation();