Vehicle usd collisions (#6459)
* Added collision shape generation for vehicles * Fixed wrong physics asset assignment to skeletal mesh * Fixed long line * Fixed crash with missing optional data from USD --------- Co-authored-by: Antonio Peris Sanchez <perissanchezantonio@gmail.com> Co-authored-by: Blyron <53337103+Blyron@users.noreply.github.com>
This commit is contained in:
parent
80d3471171
commit
f7dbdf8189
Binary file not shown.
|
@ -30,6 +30,7 @@
|
|||
#include "Kismet2/BlueprintEditorUtils.h"
|
||||
#include "BlueprintEditor.h"
|
||||
#include "Carla/Vehicle/CarlaWheeledVehicle.h"
|
||||
#include "EditorStaticMeshLibrary.h"
|
||||
|
||||
|
||||
void UUSDImporterWidget::ImportUSDProp(
|
||||
|
@ -71,7 +72,7 @@ void UUSDImporterWidget::ImportUSDVehicle(
|
|||
-> TSubclassOf<UVehicleWheel>
|
||||
{
|
||||
// Get a reference to the editor subsystem
|
||||
constexpr float MToCM = 0.01f;
|
||||
constexpr float MToCM = 100.f;
|
||||
constexpr float RadToDeg = 360.f/3.14159265359f;
|
||||
FString BlueprintName = FPaths::GetBaseFilename(PackagePathName);
|
||||
FString BlueprintPath = FPaths::GetPath(PackagePathName);
|
||||
|
@ -430,7 +431,8 @@ AActor* UUSDImporterWidget::GenerateNewVehicleBlueprint(
|
|||
UWorld* World,
|
||||
UClass* BaseClass,
|
||||
USkeletalMesh* NewSkeletalMesh,
|
||||
const FString &DestPath,
|
||||
UPhysicsAsset* NewPhysicsAsset,
|
||||
const FString &DestPath,
|
||||
const FMergedVehicleMeshParts& VehicleMeshes,
|
||||
const FWheelTemplates& WheelTemplates)
|
||||
{
|
||||
|
@ -538,6 +540,16 @@ AActor* UUSDImporterWidget::GenerateNewVehicleBlueprint(
|
|||
TemplateActor->AddInstanceComponent(LightComponent);
|
||||
UE_LOG(LogCarlaTools, Log, TEXT("Spawn Light %s, %s, %s"), *Light.Name, *Light.Location.ToString(), *Light.Color.ToString());
|
||||
}
|
||||
// set the wheel radius
|
||||
UVehicleWheel* WheelDefault;
|
||||
WheelDefault = WheelTemplates.WheelFL->GetDefaultObject<UVehicleWheel>();
|
||||
WheelDefault->ShapeRadius = VehicleMeshes.WheelFL->GetBounds().SphereRadius;
|
||||
WheelDefault = WheelTemplates.WheelFR->GetDefaultObject<UVehicleWheel>();
|
||||
WheelDefault->ShapeRadius = VehicleMeshes.WheelFR->GetBounds().SphereRadius;
|
||||
WheelDefault = WheelTemplates.WheelRL->GetDefaultObject<UVehicleWheel>();
|
||||
WheelDefault->ShapeRadius = VehicleMeshes.WheelRL->GetBounds().SphereRadius;
|
||||
WheelDefault = WheelTemplates.WheelRR->GetDefaultObject<UVehicleWheel>();
|
||||
WheelDefault->ShapeRadius = VehicleMeshes.WheelRR->GetBounds().SphereRadius;
|
||||
// assign generated wheel types
|
||||
TArray<FWheelSetup> WheelSetups;
|
||||
FWheelSetup Setup;
|
||||
|
@ -566,7 +578,12 @@ AActor* UUSDImporterWidget::GenerateNewVehicleBlueprint(
|
|||
{
|
||||
UE_LOG(LogCarlaTools, Error, TEXT("Null CarlaVehicle"));
|
||||
}
|
||||
|
||||
// Set the vehicle collision in the new physicsasset object
|
||||
UEditorStaticMeshLibrary::AddSimpleCollisions(
|
||||
VehicleMeshes.Body, EScriptingCollisionShapeType::NDOP26);
|
||||
CopyCollisionToPhysicsAsset(NewPhysicsAsset, VehicleMeshes.Body);
|
||||
// assign the physics asset to the skeletal mesh
|
||||
NewSkeletalMesh->PhysicsAsset = NewPhysicsAsset;
|
||||
// Create the new blueprint vehicle
|
||||
FKismetEditorUtilities::FCreateBlueprintFromActorParams Params;
|
||||
Params.bReplaceActor = false;
|
||||
|
@ -612,3 +629,15 @@ bool UUSDImporterWidget::EditSkeletalMeshBones(
|
|||
EObjectFlags::RF_Public | EObjectFlags::RF_Standalone,
|
||||
*(Package->GetName()), GError, nullptr, true, true, SAVE_NoError);
|
||||
}
|
||||
|
||||
void UUSDImporterWidget::CopyCollisionToPhysicsAsset(
|
||||
UPhysicsAsset* PhysicsAssetToEdit, UStaticMesh* StaticMesh)
|
||||
{
|
||||
UE_LOG(LogCarlaTools, Log, TEXT("Num bodysetups %d"), PhysicsAssetToEdit->SkeletalBodySetups.Num());
|
||||
UBodySetup* BodySetupPhysicsAsset =
|
||||
PhysicsAssetToEdit->SkeletalBodySetups[
|
||||
PhysicsAssetToEdit->FindBodyIndex(FName("Vehicle_Base"))];
|
||||
UBodySetup* BodySetupStaticMesh = StaticMesh->BodySetup;
|
||||
BodySetupPhysicsAsset->AggGeom = BodySetupStaticMesh->AggGeom;
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "Animation/Skeleton.h"
|
||||
#include "VehicleWheel.h"
|
||||
#include "Materials/MaterialInterface.h"
|
||||
#include "PhysicsEngine/PhysicsAsset.h"
|
||||
|
||||
#include "USDImporterWidget.generated.h"
|
||||
|
||||
|
@ -165,6 +166,7 @@ public:
|
|||
UWorld* World,
|
||||
UClass* BaseClass,
|
||||
USkeletalMesh* NewSkeletalMesh,
|
||||
UPhysicsAsset* NewPhysicsAsset,
|
||||
const FString &DestPath,
|
||||
const FMergedVehicleMeshParts& VehicleMeshes,
|
||||
const FWheelTemplates& WheelTemplates);
|
||||
|
@ -172,5 +174,8 @@ public:
|
|||
static bool EditSkeletalMeshBones(
|
||||
USkeletalMesh* Skeleton,
|
||||
const TMap<FString, FTransform> &NewBoneTransforms);
|
||||
UFUNCTION(BlueprintCallable, Category="USD Importer")
|
||||
static void CopyCollisionToPhysicsAsset(
|
||||
UPhysicsAsset* PhysicsAssetToEdit, UStaticMesh* StaticMesh);
|
||||
|
||||
};
|
||||
|
|
|
@ -91,6 +91,7 @@ TArray<FUSDCARLAWheelData> UUSDCARLAInterface::GetUSDWheelData(const FString& Pa
|
|||
if(!WheelPrim)
|
||||
{
|
||||
UE_LOG(LogOmniverseUsd, Warning, TEXT("Wheel prim fail"));
|
||||
return false;
|
||||
}
|
||||
pxr::UsdRelationship WheelRelationship;
|
||||
pxr::UsdRelationship TireRelationship;
|
||||
|
@ -155,7 +156,15 @@ TArray<FUSDCARLAWheelData> UUSDCARLAInterface::GetUSDWheelData(const FString& Pa
|
|||
|
||||
return true;
|
||||
};
|
||||
FUSDCARLAWheelData Wheel0, Wheel1, Wheel2, Wheel3;
|
||||
// default wheel values, overriden by ParseWheelData if physx data is present
|
||||
FUSDCARLAWheelData Wheel0 =
|
||||
{8.f, 16.f, 0.61f, 0.f, 0.f, 0.1f, 0.f, 20.f, 3000.f}; // front left
|
||||
FUSDCARLAWheelData Wheel1 =
|
||||
{8.f, 16.f, 0.61f, 0.f, 0.f, 0.1f, 0.f, 20.f, 3000.f}; // front right
|
||||
FUSDCARLAWheelData Wheel2 =
|
||||
{8.f, 16.f, 0.f, 0.f, 5.f, 0.1f, 0.f, 20.f, 3000.f}; // rear left
|
||||
FUSDCARLAWheelData Wheel3 =
|
||||
{8.f, 16.f, 0.f, 0.f, 5.f, 0.1f, 0.f, 20.f, 3000.f}; // rear right
|
||||
ParseWheelData("wheel_0", Wheel0);
|
||||
ParseWheelData("wheel_1", Wheel1);
|
||||
ParseWheelData("wheel_2", Wheel2);
|
||||
|
|
Loading…
Reference in New Issue