Exemplo n.º 1
0
	void AddConvexElemsToRigidActor_AssumesLocked() const
	{
		float ContactOffsetFactor, MaxContactOffset;
		GetContactOffsetParams(ContactOffsetFactor, MaxContactOffset);

		for (int32 i = 0; i < BodySetup->AggGeom.ConvexElems.Num(); i++)
		{
			const FKConvexElem& ConvexElem = BodySetup->AggGeom.ConvexElems[i];

			if (ConvexElem.ConvexMesh)
			{
				PxTransform PLocalPose;
				bool bUseNegX = CalcMeshNegScaleCompensation(Scale3D, PLocalPose);

				PxConvexMeshGeometry PConvexGeom;
				PConvexGeom.convexMesh = bUseNegX ? ConvexElem.ConvexMeshNegX : ConvexElem.ConvexMesh;
				PConvexGeom.scale.scale = U2PVector(Scale3DAbs * ConvexElem.GetTransform().GetScale3D().GetAbs());
				FTransform ConvexTransform = ConvexElem.GetTransform();
				if (ConvexTransform.GetScale3D().X < 0 || ConvexTransform.GetScale3D().Y < 0 || ConvexTransform.GetScale3D().Z < 0)
				{
					UE_LOG(LogPhysics, Warning, TEXT("AddConvexElemsToRigidActor: [%s] ConvexElem[%d] has negative scale. Not currently supported"), *GetPathNameSafe(BodySetup->GetOuter()), i);
				}
				if (ConvexTransform.IsValid())
				{
					PxTransform PElementTransform = U2PTransform(ConvexTransform * RelativeTM);
					PLocalPose.q *= PElementTransform.q;
					PLocalPose.p = PElementTransform.p;
					PLocalPose.p.x *= Scale3D.X;
					PLocalPose.p.y *= Scale3D.Y;
					PLocalPose.p.z *= Scale3D.Z;

					if (PConvexGeom.isValid())
					{
						PxVec3 PBoundsExtents = PConvexGeom.convexMesh->getLocalBounds().getExtents();

						ensure(PLocalPose.isValid());
						{
							const float ContactOffset = FMath::Min(MaxContactOffset, ContactOffsetFactor * PBoundsExtents.minElement());
							AttachShape_AssumesLocked(PConvexGeom, PLocalPose, ContactOffset);
						}
					}
					else
					{
						UE_LOG(LogPhysics, Warning, TEXT("AddConvexElemsToRigidActor: [%s] ConvexElem[%d] invalid"), *GetPathNameSafe(BodySetup->GetOuter()), i);
					}
				}
				else
				{
					UE_LOG(LogPhysics, Warning, TEXT("AddConvexElemsToRigidActor: [%s] ConvexElem[%d] has invalid transform"), *GetPathNameSafe(BodySetup->GetOuter()), i);
				}
			}
			else
			{
				UE_LOG(LogPhysics, Warning, TEXT("AddConvexElemsToRigidActor: ConvexElem is missing ConvexMesh (%d: %s)"), i, *BodySetup->GetPathName());
			}
		}
	}
Exemplo n.º 2
0
	void AddBoxesToRigidActor_AssumesLocked() const
	{
		float ContactOffsetFactor, MaxContactOffset;
		GetContactOffsetParams(ContactOffsetFactor, MaxContactOffset);

		for (int32 i = 0; i < BodySetup->AggGeom.BoxElems.Num(); i++)
		{
			const FKBoxElem& BoxElem = BodySetup->AggGeom.BoxElems[i];

			PxBoxGeometry PBoxGeom;
			PBoxGeom.halfExtents.x = (0.5f * BoxElem.X * Scale3DAbs.X);
			PBoxGeom.halfExtents.y = (0.5f * BoxElem.Y * Scale3DAbs.Y);
			PBoxGeom.halfExtents.z = (0.5f * BoxElem.Z * Scale3DAbs.Z);

			FTransform BoxTransform = BoxElem.GetTransform() * RelativeTM;
			if (PBoxGeom.isValid() && BoxTransform.IsValid())
			{
				PxTransform PLocalPose(U2PTransform(BoxTransform));
				PLocalPose.p.x *= Scale3D.X;
				PLocalPose.p.y *= Scale3D.Y;
				PLocalPose.p.z *= Scale3D.Z;

				ensure(PLocalPose.isValid());
				{
					const float ContactOffset = FMath::Min(MaxContactOffset, ContactOffsetFactor * PBoxGeom.halfExtents.minElement());
					AttachShape_AssumesLocked(PBoxGeom, PLocalPose, ContactOffset);
				}
			}
			else
			{
				UE_LOG(LogPhysics, Warning, TEXT("AddBoxesToRigidActor: [%s] BoxElems[%d] invalid or has invalid transform"), *GetPathNameSafe(BodySetup->GetOuter()), i);
			}
		}
	}
Exemplo n.º 3
0
	void AddSphylsToRigidActor_AssumesLocked() const
	{
		float ContactOffsetFactor, MaxContactOffset;
		GetContactOffsetParams(ContactOffsetFactor, MaxContactOffset);

		float ScaleRadius = FMath::Max(Scale3DAbs.X, Scale3DAbs.Y);
		float ScaleLength = Scale3DAbs.Z;

		for (int32 i = 0; i < BodySetup->AggGeom.SphylElems.Num(); i++)
		{
			const FKSphylElem& SphylElem = BodySetup->AggGeom.SphylElems[i];

			// this is a bit confusing since radius and height is scaled
			// first apply the scale first 
			float Radius = FMath::Max(SphylElem.Radius * ScaleRadius, 0.1f);
			float Length = SphylElem.Length + SphylElem.Radius * 2.f;
			float HalfLength = Length * ScaleLength * 0.5f;
			Radius = FMath::Clamp(Radius, 0.1f, HalfLength);	//radius is capped by half length
			float HalfHeight = HalfLength - Radius;
			HalfHeight = FMath::Max(0.1f, HalfHeight);

			PxCapsuleGeometry PCapsuleGeom;
			PCapsuleGeom.halfHeight = HalfHeight;
			PCapsuleGeom.radius = Radius;

			if (PCapsuleGeom.isValid())
			{
				// The stored sphyl transform assumes the sphyl axis is down Z. In PhysX, it points down X, so we twiddle the matrix a bit here (swap X and Z and negate Y).
				PxTransform PLocalPose(U2PVector(RelativeTM.TransformPosition(SphylElem.Center)), U2PQuat(SphylElem.Orientation) * U2PSphylBasis);
				PLocalPose.p.x *= Scale3D.X;
				PLocalPose.p.y *= Scale3D.Y;
				PLocalPose.p.z *= Scale3D.Z;

				ensure(PLocalPose.isValid());
				{
					const float ContactOffset = FMath::Min(MaxContactOffset, ContactOffsetFactor * PCapsuleGeom.radius);
					AttachShape_AssumesLocked(PCapsuleGeom, PLocalPose, ContactOffset);
				}
			}
			else
			{
				UE_LOG(LogPhysics, Warning, TEXT("AddSphylsToRigidActor: [%s] SphylElems[%d] invalid"), *GetPathNameSafe(BodySetup->GetOuter()), i);
			}
		}
	}
Exemplo n.º 4
0
	void AddSpheresToRigidActor_AssumesLocked() const
	{
		float ContactOffsetFactor, MaxContactOffset;
		GetContactOffsetParams(ContactOffsetFactor, MaxContactOffset);

		for (int32 i = 0; i < BodySetup->AggGeom.SphereElems.Num(); i++)
		{
			const FKSphereElem& SphereElem = BodySetup->AggGeom.SphereElems[i];

			PxSphereGeometry PSphereGeom;
			PSphereGeom.radius = (SphereElem.Radius * MinScaleAbs);

			if (ensure(PSphereGeom.isValid()))
			{
				FVector LocalOrigin = RelativeTM.TransformPosition(SphereElem.Center);
				PxTransform PLocalPose(U2PVector(LocalOrigin));
				PLocalPose.p *= MinScale;

				ensure(PLocalPose.isValid());
				{
					const float ContactOffset = FMath::Min(MaxContactOffset, ContactOffsetFactor * PSphereGeom.radius);
					AttachShape_AssumesLocked(PSphereGeom, PLocalPose, ContactOffset);
				}
			}
			else
			{
				UE_LOG(LogPhysics, Warning, TEXT("AddSpheresToRigidActor: [%s] SphereElem[%d] invalid"), *GetPathNameSafe(BodySetup->GetOuter()), i);
			}
		}
	}