Get Location and Rotation of a chunk (Destructable Mesh)

Hello is it possible to get the rotation and location of a chunk?
Am trying to get a cylinder component to follow a peace that is broken off the destructable mesh.

Is this possible?

In code I would recommend start looking from:

NxDestructibleActor::getChunkPose

then look on this function:

void UDestructibleComponent::SetChunkVisible( int32 ChunkIndex, bool bVisible )
...
const physx::PxMat44 ChunkPoseRT = ApexDestructibleActor->getChunkPose(ChunkIndex);	// Unscaled
const physx::PxTransform Transform(ChunkPoseRT);
SetChunkWorldRT(ChunkIndex, P2UQuat(Transform.q), P2UVector(Transform.p));

Chunk location is copied in SetChunkWorldRT to SpaceBases array which contains UNREAL chunk transforms.

Then You should be able to use:

FVector USkinnedMeshComponent::GetBoneLocation( FName BoneName, int32 Space = 0 ) const; 

but I don’t know what is the BoneName for specific chunk

Regards

Pierdek

Thank you for this i will have a look at this right away.
Cheers!

Hello again been trying to get this to work and while i can find the decleration of the namespacees physx::apex in the header file “DestructableComponent.h”
But the class NxDestructibleActor i can`t see to find any header for it.

Am using the binary build in 4.4.3

Engine\Source\ThirdParty\PhysX\APEX-1.3\module\destructible\public\

Yes i was just about to edit the comment.
I added the headers and library directorys in the Project Propertys and it did the trick.

Now lets see if i can get the rest to work as well.
Thanks for your continues help. :slight_smile:
Cheers!

#Compiling PhysX Code?

I have a related question that it seems like the two of you have solved?

How do I actually compile PhysX code using just the Engine without any external libraries/SDKs ?

I tried including the module PhysX to no avail.

My question in full detail:

The only header i have included is:
#include “PhysXIncludes.h”
#include “ApexDestructibleAssetImport.h”
Also make sure both modules are added “PhysX” and “APEX”
Then i added the include directorys for the headers and the library directorys in the Project Propertys in Visual Studio.

That did the trick, am just having truble with finding the two functions.

P2UQuat(Transform.q), P2UVector(Transform.p)

Removed some lines that may confuse.

PS: There will be a tutorial on this as soon as i figuer it out.
Right now am messing around half blind so my overview is not perfect.
I wish i could be of better help.

So am a bit stuck and am sure it be a easy fix.
If you know what you are doing :slight_smile: the code under shows where am at.

		if (GatheringNodeMesh->ApexDestructibleActor)
		{
			NxDestructibleActor* Temp = GatheringNodeMesh->ApexDestructibleActor;
			physx::PxMat44 ChunkLoc = Temp->getChunkPose(8); // 8
			physx::PxMat44 ChunkTrans = Temp->getChunkTM(8);

			if (TrunkSphereComponent)
			{
				const FVector NewLocation(ChunkLoc.getPosition().x, ChunkLoc.getPosition().y, ChunkLoc.getPosition().z);
				TrunkSphereComponent->SetWorldLocation(NewLocation, false);

				const FRotator NewRotation(ChunkLoc.rotate(ChunkLoc.getPosition()).x, ChunkLoc.rotate(ChunkLoc.getPosition()).y, ChunkLoc.rotate(ChunkLoc.getPosition()).z);
				TrunkSphereComponent->SetWorldRotation(NewRotation, false);
			}
		}

And this code gets the correct chunk for the mesh but the rotation is off.
Transformation is missing atm, the methods you use i can`t find.
Any ideas on what i can do?

Edit: So i found

/** Convert PhysX PxVec3 to Unreal FVector */
ENGINE_API FVector P2UVector(const PxVec3& PVec); 

it was located in “PhysicsPublic.h”
But i can not find P2UQuat(physx::PxQuat InQuat);

Re-Edit: I got it working now. :slight_smile:
I will document the hole thing and post it as a answer later on.

I have solved this issue i be back with details tomorrow after work.
Edit:

	if (DestructableMeshComp->ApexDestructibleActor)
	{
		const physx::PxMat44 ChunkPoseRT = DestructableMeshComp->ApexDestructibleActor->getChunkPose(8);    // Unscaled
		const physx::PxTransform Transform(ChunkPoseRT);

		if (SomeOtherComponent)
		{
			FQuat NewQuat(Transform.q.x, 
                          Transform.q.y,
                          Transform.q.z,
                          Transform.q.w);

			const FVector NewLocation(ChunkPoseRT.getPosition().x, 
                                      ChunkPoseRT.getPosition().y, 
                                      ChunkPoseRT.getPosition().z);

		    SomeOtherComponent->SetWorldLocationAndRotation(NewLocation, NewQuat, false);
		}
	}