Skip to content

Commit d58a663

Browse files
committed
Updated Debug from Temp Fix to Perm Fix, Using Only Component Space.
Updated Simulation to remove ActorToBody offset. So the COM will be whatever the component location is for that component.
1 parent 1595cec commit d58a663

File tree

6 files changed

+19
-32
lines changed

6 files changed

+19
-32
lines changed
-1.53 KB
Binary file not shown.
Binary file not shown.
59.7 KB
Binary file not shown.

Plugins/LocalPhysics/Source/LocalPhysics/Private/LocalPhysicsSimulation.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,8 @@ uint32 FLocalSimulation:: CreateActor(PxRigidActor* RigidActor, const FTransform
216216
NewRigidBodyData->maxDepenetrationVelocity = RigidDynamic ? RigidDynamic->getMaxDepenetrationVelocity() : PX_MAX_F32;
217217
NewRigidBodyData->invInertia = RigidDynamic ? RigidDynamic->getMassSpaceInvInertiaTensor() : PxVec3(PxZero);
218218
NewRigidBodyData->maxContactImpulse = RigidBody ? RigidBody->getMaxContactImpulse() : PX_MAX_F32;
219-
220-
NewActorHandle->ActorToBody = RigidBody ? P2UTransform(RigidBody->getCMassLocalPose()) : FTransform::Identity; //TODO: Why is this an unreal transform?
221-
//UE_LOG(LogTemp, Warning, L"ActorToBody: %s", *NewActorHandle->ActorToBody.ToHumanReadableString())
222-
NewActorHandle->ActorScale3D = WorldTM.GetScale3D();
219+
220+
NewActorHandle->ActorToBody = /*RigidBody ? P2UTransform(RigidBody->getCMassLocalPose()) : */FTransform::Identity; //TODO: Why is this an unreal transform?
223221
NewRigidBodyData->body2World = U2PTransform(NewActorHandle->ActorToBody * WorldTM);
224222

225223
NewRigidBodyData->linearDamping = RigidDynamic ? RigidDynamic->getLinearDamping() : 0.f;

Plugins/LocalPhysics/Source/LocalPhysics/Private/LocalSimulationVolume.cpp

+9-19
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,7 @@ void ALocalSimulationVolume::UpdateMeshVisuals()
222222
// dereference pointers to pointers, and set references
223223
UStaticMeshComponent& Mesh = *MeshData->InVisualMesh;
224224
LocalPhysics::FActorHandle& Handle = *MeshData->InHandle;
225-
//FTransform HandleTransform = Handle.GetWorldTransform();
226-
//HandleTransform.SetScale3D(Mesh.GetComponentTransform().GetScale3D());
227-
//const FTransform& BodyTransform = LocalSpace->GetComponentTransform().GetRelativeTransformReverse(Handle.GetWorldTransform());;
228225
const FTransform& BodyTransform = Handle.GetWorldTransform() * LocalSpace->GetComponentTransform();
229-
//UE_LOG(LocalSimulationLog, Warning, L"New transform: %s is %s", *Mesh.GetStaticMesh()->GetName(), *BodyTransform.ToHumanReadableString());
230226

231227
switch (MeshData->InBodyType)
232228
{
@@ -235,8 +231,6 @@ void ALocalSimulationVolume::UpdateMeshVisuals()
235231
{
236232
// update meshes back in 'world' space
237233
Mesh.SetWorldTransform(BodyTransform, false, nullptr, ETeleportType::TeleportPhysics);
238-
//Mesh.SetWorldLocation(BodyTransform.GetLocation(), false, nullptr, ETeleportType::TeleportPhysics);
239-
//Mesh.SetWorldRotation(BodyTransform.GetRotation().Rotator(), false, nullptr, ETeleportType::TeleportPhysics);
240234
}
241235
break;
242236
case ELocalPhysicsBodyType::Kinematic:
@@ -249,9 +243,10 @@ void ALocalSimulationVolume::UpdateMeshVisuals()
249243

250244
// let's show everything in simulation.
251245
if (bShowDebugPhyics)
252-
{ // temporary fix to show local transforms correctly.
253-
const FTransform& DebugTransform = (bDebugInWorldSpace ? FTransform(BodyTransform.Rotator(), Mesh.Bounds.Origin, BodyTransform.GetScale3D()) : FTransform(Handle.GetWorldTransform().Rotator(), FTransform(BodyTransform.Rotator(), Mesh.Bounds.Origin, BodyTransform.GetScale3D()).GetRelativeTransform(LocalSpace->ComponentToWorld).GetLocation(), Handle.GetWorldTransform().GetScale3D()));
254-
UKismetSystemLibrary::DrawDebugBox(GetWorld(), DebugTransform.GetLocation(), Mesh.GetStaticMesh()->GetBounds().BoxExtent * Handle.ActorScale3D, DebugSimulatedColor, DebugTransform.Rotator(), DebugTick, DebugThickness);
246+
{
247+
const FTransform& DebugTransform = (bDebugInWorldSpace ? FTransform(BodyTransform.Rotator(), Mesh.Bounds.Origin, BodyTransform.GetScale3D()) : Handle.GetWorldTransform());
248+
const FVector& DebugExtent = Mesh.GetStaticMesh()->GetBounds().BoxExtent * Handle.ActorScale3D;
249+
UKismetSystemLibrary::DrawDebugBox(GetWorld(), DebugTransform.GetLocation(), DebugExtent, DebugSimulatedColor, DebugTransform.Rotator(), DebugTick, DebugThickness);
255250
}
256251
}
257252
}
@@ -308,7 +303,7 @@ void ALocalSimulationVolume::TransformUpdated(USceneComponent* InRootComponent,
308303
// let's show everything in simulation.
309304
if (bShowDebugPhyics)
310305
{
311-
const FTransform& BodyTransform = bDebugInWorldSpace ? WorldBodyTransform : Handle.GetWorldTransform();
306+
const FTransform& BodyTransform = bDebugInWorldSpace ? WorldBodyTransform : Handle.GetBodyTransform();
312307

313308
UKismetSystemLibrary::DrawDebugBox(GetWorld(), BodyTransform.GetLocation(), Mesh.GetStaticMesh()->GetBounds().BoxExtent * Handle.ActorScale3D, DebugKinematicColor, BodyTransform.Rotator(), DebugTick, DebugKinematicThickness);
314309
}
@@ -381,7 +376,7 @@ bool ALocalSimulationVolume::AddStaticMeshToSimulation(UStaticMeshComponent* Mes
381376
// if we don't find this mesh in Simulated or Kinematic arrays
382377
if (IsInSimulation(Mesh) == false)
383378
{
384-
//UE_LOG(LocalSimulationLog, Warning, L"Current transform: %s is %s", *Mesh->GetStaticMesh()->GetName(), *Mesh->GetComponentTransform().ToHumanReadableString());
379+
//UE_LOG(LocalSimulationLog, Warning, L"Current transform: %s is %s", *Mesh->GetStaticMesh()->GetName(), *Mesh->K2_GetComponentScale().ToString());
385380
/*
386381
* messy check for static, kinematic, dynamic
387382
*/
@@ -412,15 +407,10 @@ bool ALocalSimulationVolume::AddStaticMeshToSimulation(UStaticMeshComponent* Mes
412407
FBodyInstance& BodyInstance = Mesh->BodyInstance;
413408

414409
// create copy of new relative transform
415-
FTransform BodyTransform = BodyInstance.GetUnrealWorldTransform_AssumesLocked(false).GetRelativeTransform(LocalSpace->GetComponentTransform());
416-
//BodyTransform.SetScale3D(Mesh->GetComponentTransform().GetScale3D());
417-
//FTransform BodyTransform = FTransform(Mesh->GetComponentTransform().Rotator(), Mesh->Bounds.Origin, Mesh->GetComponentTransform().GetScale3D()).GetRelativeTransform(LocalSpace->GetComponentTransform());
418-
//FTransform BodyTransform = Mesh->GetComponentTransform();
419-
//BodyTransform.SetScale3D(FVector(1.f));
420-
//BodyTransform = BodyTransform.GetRelativeTransform(LocalSpace->GetComponentTransform());
421-
410+
const FTransform& BodyTransform = Mesh->GetComponentTransform().GetRelativeTransform(LocalSpace->GetComponentTransform());
422411

423412
UStaticMeshComponent* DynamicMesh = NewMeshData->InPhysicsMesh;
413+
424414
if(ShouldExistInBothScenes)
425415
{
426416
// by default, we create clones for kinematic components.
@@ -504,7 +494,7 @@ bool ALocalSimulationVolume::AddStaticMeshToSimulation(UStaticMeshComponent* Mes
504494
}
505495

506496
// store scale so that Unreal component gets returned the correct scale / debug looks percise.
507-
NewMeshData->InHandle->ActorScale3D = Mesh->GetComponentTransform().GetScale3D();
497+
NewMeshData->InHandle->ActorScale3D = Mesh->K2_GetComponentScale();
508498

509499
// create new pair in kinematic meshses array (we don't update on tick)
510500
haveWeAddedMesh = (SimulatedActors.Add(NewMeshData) > -1);

Plugins/LocalPhysics/Source/LocalPhysics/Public/LocalPhysicsActorHandle.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ struct LOCALPHYSICS_API FActorHandle
1616
{
1717

1818
private:
19-
/** Converts from actor space (i.e. the transform in world space as the client gives us) to body space (body with its origin at the COM and oriented to inertia tensor) */
20-
FTransform ActorToBody;
2119
FLocalSimulation& OwningSimulation;
22-
int32 ActorDataIndex;
23-
int rigidBodyType = -1;
24-
2520

2621
public:
2722
FVector ActorScale3D;
23+
/** Converts from actor space (i.e. the transform in world space as the client gives us) to body space (body with its origin at the COM and oriented to inertia tensor) */
24+
FTransform ActorToBody;
25+
int32 ActorDataIndex;
26+
int rigidBodyType = -1;
2827

2928
/** Sets the world transform.*/
3029
void SetWorldTransform(const FTransform& WorldTM)
@@ -45,9 +44,9 @@ struct LOCALPHYSICS_API FActorHandle
4544
FTransform GetWorldTransform() const
4645
{
4746
#if WITH_PHYSX
48-
auto Transform = ActorToBody.GetRelativeTransformReverse( P2UTransform(OwningSimulation.GetLowLevelBody(ActorDataIndex).body2World) );
49-
Transform.SetScale3D(ActorScale3D);
50-
return Transform;
47+
auto WorldT = ActorToBody.GetRelativeTransformReverse(P2UTransform(OwningSimulation.GetLowLevelBody(ActorDataIndex).body2World));
48+
WorldT.SetScale3D(ActorScale3D);
49+
return WorldT;
5150
#else
5251
return FTransform::Identity;
5352
#endif
@@ -57,7 +56,7 @@ struct LOCALPHYSICS_API FActorHandle
5756
FTransform GetBodyTransform() const
5857
{
5958
#if WITH_PHYSX
60-
return P2UTransform(OwningSimulation.GetLowLevelBody(ActorDataIndex).body2World);
59+
return FTransform().GetRelativeTransformReverse(P2UTransform(OwningSimulation.GetLowLevelBody(ActorDataIndex).body2World));
6160
#else
6261
return FTransform::Identity;
6362
#endif

0 commit comments

Comments
 (0)