本文整理汇总了C++中FBodyInstance::IsValidBodyInstance方法的典型用法代码示例。如果您正苦于以下问题:C++ FBodyInstance::IsValidBodyInstance方法的具体用法?C++ FBodyInstance::IsValidBodyInstance怎么用?C++ FBodyInstance::IsValidBodyInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FBodyInstance
的用法示例。
在下文中一共展示了FBodyInstance::IsValidBodyInstance方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadConfig
bool UCollisionProfile::ReadConfig(FName ProfileName, FBodyInstance& BodyInstance) const
{
FCollisionResponseTemplate Template;
// first check redirect
// if that fails, just get profile
if ( CheckRedirect(ProfileName, BodyInstance, Template) ||
GetProfileTemplate(ProfileName, Template) )
{
// note that this can be called during loading or run-time (because of the function)
// from property, it just uses property handle to set all data
// but we can't use functions - i.e. SetCollisionEnabled -
// which will reset ProfileName by default
BodyInstance.CollisionEnabled = Template.CollisionEnabled;
BodyInstance.ObjectType = Template.ObjectType;
BodyInstance.CollisionResponses.SetCollisionResponseContainer(Template.ResponseToChannels);
BodyInstance.ResponseToChannels_DEPRECATED = Template.ResponseToChannels;
// if valid instance, make sure to update physics filter data
if (BodyInstance.IsValidBodyInstance())
{
BodyInstance.UpdatePhysicsFilterData();
}
return true;
}
return false;
}
示例2: GetVelocityAtPoint
FVector UTKMathFunctionLibrary::GetVelocityAtPoint(UPrimitiveComponent* Target, FVector Point, FName BoneName, bool DrawDebugInfo)
{
//FTransform Transform = Target->GetComponentTransform();
//FVector LocalLinearVelocity = Transform.InverseTransformVectorNoScale(Target->GetPhysicsLinearVelocity());
//FVector LocalAngularVelocity = Transform.InverseTransformVectorNoScale(Target->GetPhysicsAngularVelocity());
//FVector ResultPointVelocity = LocalLinearVelocity + FVector::CrossProduct(FVector::DegreesToRadians(LocalAngularVelocity), Transform.InverseTransformVectorNoScale(Point - Target->GetCenterOfMass()));
if (!Target) return FVector::ZeroVector;
//You can actually get it from the physx body instance instead.
FBodyInstance* BI = Target->GetBodyInstance(BoneName);
if (BI && BI->IsValidBodyInstance())
{
FVector PointVelocity = BI->GetUnrealWorldVelocityAtPoint(Point);
UWorld* TheWorld = Target->GetWorld();
if (DrawDebugInfo && TheWorld)
{
FColor DefaultColor(255,200,0);
DrawDebugPoint(TheWorld, Point, 10, DefaultColor);
DrawDebugString(TheWorld, Point, FString::SanitizeFloat(PointVelocity.Size()), NULL, FColor::White, 0.0f);
}
return PointVelocity;
}
return FVector::ZeroVector;
}
示例3: GetClosestCollidingRigidBodyLocation
FVector USkeletalMeshComponent::GetClosestCollidingRigidBodyLocation(const FVector& TestLocation) const
{
float BestDistSq = BIG_NUMBER;
FVector Best = TestLocation;
UPhysicsAsset* PhysicsAsset = GetPhysicsAsset();
if( PhysicsAsset )
{
for (int32 i=0; i<Bodies.Num(); i++)
{
FBodyInstance* BodyInstance = Bodies[i];
if( BodyInstance && BodyInstance->IsValidBodyInstance() && (BodyInstance->GetCollisionEnabled() != ECollisionEnabled::NoCollision) )
{
const FVector BodyLocation = BodyInstance->GetUnrealWorldTransform().GetTranslation();
const float DistSq = (BodyLocation - TestLocation).SizeSquared();
if( DistSq < BestDistSq )
{
Best = BodyLocation;
BestDistSq = DistSq;
}
}
}
}
return Best;
}
示例4: GetVelocityAtPoint
FVector UBuoyancyComponent::GetVelocityAtPoint(UPrimitiveComponent* Target, FVector Point, FName BoneName)
{
FBodyInstance* BI = Target->GetBodyInstance(BoneName);
if (BI != NULL && BI->IsValidBodyInstance())
{
return BI->GetUnrealWorldVelocityAtPoint(Point);
}
return FVector::ZeroVector;
}
示例5: SetCenterOfMassOffset
void UTKMathFunctionLibrary::SetCenterOfMassOffset(UPrimitiveComponent* Target, FVector Offset, FName BoneName)
{
if (!Target) return;
FBodyInstance* BI = Target->GetBodyInstance(BoneName);
if (BI && BI->IsValidBodyInstance())
{
BI->COMNudge = Offset;
BI->UpdateMassProperties();
}
}
示例6: SyncComponentToRBPhysics
void UPrimitiveComponent::SyncComponentToRBPhysics()
{
if(!IsRegistered())
{
UE_LOG(LogPhysics, Log, TEXT("SyncComponentToRBPhysics : Component not registered (%s)"), *GetPathName());
return;
}
// BodyInstance we are going to sync the component to
FBodyInstance* UseBI = GetBodyInstance();
if(UseBI == NULL || !UseBI->IsValidBodyInstance())
{
UE_LOG(LogPhysics, Log, TEXT("SyncComponentToRBPhysics : Missing or invalid BodyInstance (%s)"), *GetPathName());
return;
}
AActor* Owner = GetOwner();
if(Owner != NULL)
{
if (Owner->IsPendingKill() || !Owner->CheckStillInWorld())
{
return;
}
}
if (IsPendingKill() || !IsSimulatingPhysics())
{
return;
}
// See if the transform is actually different, and if so, move the component to match physics
const FTransform NewTransform = GetComponentTransformFromBodyInstance(UseBI);
if(!NewTransform.EqualsNoScale(ComponentToWorld))
{
const FVector MoveBy = NewTransform.GetLocation() - ComponentToWorld.GetLocation();
const FQuat NewRotation = NewTransform.GetRotation();
//@warning: do not reference BodyInstance again after calling MoveComponent() - events from the move could have made it unusable (destroying the actor, SetPhysics(), etc)
MoveComponent(MoveBy, NewRotation, false, NULL, MOVECOMP_SkipPhysicsMove);
}
}
示例7: TickComponent
void UBuoyancyForceComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// If disabled or we are not attached to a parent component, return.
if (!bIsActive || !GetAttachParent()) return;
if (!OceanManager) return;
UPrimitiveComponent* BasePrimComp = Cast<UPrimitiveComponent>(GetAttachParent());
if (!BasePrimComp) return;
if (!BasePrimComp->IsSimulatingPhysics())
{
if (!SnapToSurfaceIfNoPhysics) return;
UE_LOG(LogTemp, Warning, TEXT("Running in no physics mode.."));
float waveHeight = OceanManager->GetWaveHeightValue(BasePrimComp->GetComponentLocation(), World, true, TwoGerstnerIterations).Z;
BasePrimComp->SetWorldLocation(FVector(BasePrimComp->GetComponentLocation().X, BasePrimComp->GetComponentLocation().Y, waveHeight));
return;
}
//Get gravity
float Gravity = BasePrimComp->GetPhysicsVolume()->GetGravityZ();
//--------------- If Skeletal ---------------
USkeletalMeshComponent* SkeletalComp = Cast<USkeletalMeshComponent>(GetAttachParent());
if (SkeletalComp && ApplyForceToBones)
{
TArray<FName> BoneNames;
SkeletalComp->GetBoneNames(BoneNames);
for (int32 Itr = 0; Itr < BoneNames.Num(); Itr++)
{
FBodyInstance* BI = SkeletalComp->GetBodyInstance(BoneNames[Itr], false);
if (BI && BI->IsValidBodyInstance()
&& BI->bEnableGravity) //Buoyancy doesn't exist without gravity
{
bool isUnderwater = false;
//FVector worldBoneLoc = SkeletalComp->GetBoneLocation(BoneNames[Itr]);
FVector worldBoneLoc = BI->GetCOMPosition(); //Use center of mass of the bone's physics body instead of bone's location
FVector waveHeight = OceanManager->GetWaveHeightValue(worldBoneLoc, World, true, TwoGerstnerIterations);
float BoneDensity = MeshDensity;
float BoneTestRadius = FMath::Abs(TestPointRadius);
float SignedBoneRadius = FMath::Sign(Gravity) * TestPointRadius; //Direction of radius (test radius is actually a Z offset, should probably rename it!). Just in case we need an upside down world.
//Get density & radius from the override array, if available.
for (int pointIndex = 0; pointIndex < BoneOverride.Num(); pointIndex++)
{
FStructBoneOverride Override = BoneOverride[pointIndex];
if (Override.BoneName.IsEqual(BoneNames[Itr]))
{
BoneDensity = Override.Density;
BoneTestRadius = FMath::Abs(Override.TestRadius);
SignedBoneRadius = FMath::Sign(Gravity) * BoneTestRadius;
}
}
//If test point radius is below water surface, add buoyancy force.
if (waveHeight.Z > (worldBoneLoc.Z + SignedBoneRadius))
{
isUnderwater = true;
float DepthMultiplier = (waveHeight.Z - (worldBoneLoc.Z + SignedBoneRadius)) / (BoneTestRadius * 2);
DepthMultiplier = FMath::Clamp(DepthMultiplier, 0.f, 1.f);
float Mass = SkeletalComp->CalculateMass(BoneNames[Itr]); //Mass of this specific bone's physics body
/**
* --------
* Buoyancy force formula: (Volume(Mass / Density) * Fluid Density * -Gravity) / Total Points * Depth Multiplier
* --------
*/
float BuoyancyForceZ = Mass / BoneDensity * FluidDensity * -Gravity * DepthMultiplier;
//Velocity damping.
FVector DampingForce = -BI->GetUnrealWorldVelocity() * VelocityDamper * Mass * DepthMultiplier;
//Experimental xy wave force
if (EnableWaveForces)
{
float waveVelocity = FMath::Clamp(BI->GetUnrealWorldVelocity().Z, -20.f, 150.f) * (1 - DepthMultiplier);
DampingForce += FVector(OceanManager->GlobalWaveDirection.X, OceanManager->GlobalWaveDirection.Y, 0) * Mass * waveVelocity * WaveForceMultiplier;
}
//Add force to this bone
BI->AddForce(FVector(DampingForce.X, DampingForce.Y, DampingForce.Z + BuoyancyForceZ));
//BasePrimComp->AddForceAtLocation(FVector(DampingForce.X, DampingForce.Y, DampingForce.Z + BuoyancyForceZ), worldBoneLoc, BoneNames[Itr]);
}
//Apply fluid damping & clamp velocity
if (isUnderwater)
{
BI->SetLinearVelocity(-BI->GetUnrealWorldVelocity() * (FluidLinearDamping / 10), true);
BI->SetAngularVelocity(-BI->GetUnrealWorldAngularVelocity() * (FluidAngularDamping / 10), true);
//Clamp the velocity to MaxUnderwaterVelocity
//.........这里部分代码省略.........
示例8: UnWeldFromParent
void UPrimitiveComponent::UnWeldFromParent()
{
FBodyInstance* NewRootBI = GetBodyInstance(NAME_None, false);
UWorld* CurrentWorld = GetWorld();
if (NewRootBI == NULL || NewRootBI->bWelded == false || CurrentWorld == nullptr || IsPendingKill())
{
return;
}
FName SocketName;
UPrimitiveComponent * RootComponent = GetRootWelded(this, AttachSocketName, &SocketName);
if (RootComponent)
{
if (FBodyInstance* RootBI = RootComponent->GetBodyInstance(SocketName, false))
{
bool bRootIsBeingDeleted = RootComponent->HasAnyFlags(RF_PendingKill) || RootComponent->HasAnyFlags(RF_Unreachable);
if (!bRootIsBeingDeleted)
{
//create new root
RootBI->UnWeld(NewRootBI); //don't bother fixing up shapes if RootComponent is about to be deleted
}
NewRootBI->bWelded = false;
const FBodyInstance* PrevWeldParent = NewRootBI->WeldParent;
NewRootBI->WeldParent = nullptr;
bool bHasBodySetup = GetBodySetup() != nullptr;
//if BodyInstance hasn't already been created we need to initialize it
if (bHasBodySetup && NewRootBI->IsValidBodyInstance() == false)
{
bool bPrevAutoWeld = NewRootBI->bAutoWeld;
NewRootBI->bAutoWeld = false;
NewRootBI->InitBody(GetBodySetup(), GetComponentToWorld(), this, CurrentWorld->GetPhysicsScene());
NewRootBI->bAutoWeld = bPrevAutoWeld;
}
if(PrevWeldParent == nullptr) //our parent is kinematic so no need to do any unwelding/rewelding of children
{
return;
}
//now weld its children to it
TArray<FBodyInstance*> ChildrenBodies;
TArray<FName> ChildrenLabels;
GetWeldedBodies(ChildrenBodies, ChildrenLabels);
for (int32 ChildIdx = 0; ChildIdx < ChildrenBodies.Num(); ++ChildIdx)
{
FBodyInstance* ChildBI = ChildrenBodies[ChildIdx];
if (ChildBI != NewRootBI)
{
if (!bRootIsBeingDeleted)
{
RootBI->UnWeld(ChildBI);
}
//At this point, NewRootBI must be kinematic because it's being unwelded. It's up to the code that simulates to call Weld on the children as needed
ChildBI->WeldParent = nullptr; //null because we are currently kinematic
}
}
}
}
}
示例9: UpdateKinematicBonesToAnim
void USkeletalMeshComponent::UpdateKinematicBonesToAnim(const TArray<FTransform>& InSpaceBases, ETeleportType Teleport, bool bNeedsSkinning)
{
SCOPE_CYCLE_COUNTER(STAT_UpdateRBBones);
// This below code produces some interesting result here
// - below codes update physics data, so if you don't update pose, the physics won't have the right result
// - but if we just update physics bone without update current pose, it will have stale data
// If desired, pass the animation data to the physics joints so they can be used by motors.
// See if we are going to need to update kinematics
const bool bUpdateKinematics = (KinematicBonesUpdateType != EKinematicBonesUpdateToPhysics::SkipAllBones);
const bool bTeleport = Teleport == ETeleportType::TeleportPhysics;
// If desired, update physics bodies associated with skeletal mesh component to match.
if(!bUpdateKinematics && !(bTeleport && IsAnySimulatingPhysics()))
{
// nothing to do
return;
}
// Get the scene, and do nothing if we can't get one.
FPhysScene* PhysScene = nullptr;
if (GetWorld() != nullptr)
{
PhysScene = GetWorld()->GetPhysicsScene();
}
if(PhysScene == nullptr)
{
return;
}
const FTransform& CurrentLocalToWorld = ComponentToWorld;
// Gracefully handle NaN
if(CurrentLocalToWorld.ContainsNaN())
{
return;
}
// If desired, draw the skeleton at the point where we pass it to the physics.
if (bShowPrePhysBones && SkeletalMesh && InSpaceBases.Num() == SkeletalMesh->RefSkeleton.GetNum())
{
for (int32 i = 1; i<InSpaceBases.Num(); i++)
{
FVector ThisPos = CurrentLocalToWorld.TransformPosition(InSpaceBases[i].GetLocation());
int32 ParentIndex = SkeletalMesh->RefSkeleton.GetParentIndex(i);
FVector ParentPos = CurrentLocalToWorld.TransformPosition(InSpaceBases[ParentIndex].GetLocation());
GetWorld()->LineBatcher->DrawLine(ThisPos, ParentPos, AnimSkelDrawColor, SDPG_Foreground);
}
}
// warn if it has non-uniform scale
const FVector& MeshScale3D = CurrentLocalToWorld.GetScale3D();
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
if( !MeshScale3D.IsUniform() )
{
UE_LOG(LogPhysics, Log, TEXT("USkeletalMeshComponent::UpdateKinematicBonesToAnim : Non-uniform scale factor (%s) can cause physics to mismatch for %s SkelMesh: %s"), *MeshScale3D.ToString(), *GetFullName(), SkeletalMesh ? *SkeletalMesh->GetFullName() : TEXT("NULL"));
}
#endif
if (bEnablePerPolyCollision == false)
{
const UPhysicsAsset* const PhysicsAsset = GetPhysicsAsset();
if (PhysicsAsset && SkeletalMesh && Bodies.Num() > 0)
{
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
if (!ensure(PhysicsAsset->BodySetup.Num() == Bodies.Num()))
{
// related to TTP 280315
UE_LOG(LogPhysics, Warning, TEXT("Mesh (%s) has PhysicsAsset(%s), and BodySetup(%d) and Bodies(%d) don't match"),
*SkeletalMesh->GetName(), *PhysicsAsset->GetName(), PhysicsAsset->BodySetup.Num(), Bodies.Num());
return;
}
#endif
#if WITH_PHYSX
// Lock the scenes we need (flags set in InitArticulated)
if(bHasBodiesInSyncScene)
{
SCENE_LOCK_WRITE(PhysScene->GetPhysXScene(PST_Sync))
}
if (bHasBodiesInAsyncScene)
{
SCENE_LOCK_WRITE(PhysScene->GetPhysXScene(PST_Async))
}
#endif
// Iterate over each body
for (int32 i = 0; i < Bodies.Num(); i++)
{
// If we have a physics body, and its kinematic...
FBodyInstance* BodyInst = Bodies[i];
check(BodyInst);
if (bTeleport || (BodyInst->IsValidBodyInstance() && !BodyInst->IsInstanceSimulatingPhysics()))
{
const int32 BoneIndex = BodyInst->InstanceBoneIndex;
//.........这里部分代码省略.........