diff --git a/Unreal/CarlaUE4/Plugins/CarlaTools/Content/USDImporter/UW_USDVehicleImporterEditorWidget.uasset b/Unreal/CarlaUE4/Plugins/CarlaTools/Content/USDImporter/UW_USDVehicleImporterEditorWidget.uasset index a19930ff0..07e711bbc 100644 Binary files a/Unreal/CarlaUE4/Plugins/CarlaTools/Content/USDImporter/UW_USDVehicleImporterEditorWidget.uasset and b/Unreal/CarlaUE4/Plugins/CarlaTools/Content/USDImporter/UW_USDVehicleImporterEditorWidget.uasset differ diff --git a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/USDImporterWidget.cpp b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/USDImporterWidget.cpp index b47302939..4f699e3cd 100644 --- a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/USDImporterWidget.cpp +++ b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/USDImporterWidget.cpp @@ -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 { // 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(); + WheelDefault->ShapeRadius = VehicleMeshes.WheelFL->GetBounds().SphereRadius; + WheelDefault = WheelTemplates.WheelFR->GetDefaultObject(); + WheelDefault->ShapeRadius = VehicleMeshes.WheelFR->GetBounds().SphereRadius; + WheelDefault = WheelTemplates.WheelRL->GetDefaultObject(); + WheelDefault->ShapeRadius = VehicleMeshes.WheelRL->GetBounds().SphereRadius; + WheelDefault = WheelTemplates.WheelRR->GetDefaultObject(); + WheelDefault->ShapeRadius = VehicleMeshes.WheelRR->GetBounds().SphereRadius; // assign generated wheel types TArray 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; + +} diff --git a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Public/USDImporterWidget.h b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Public/USDImporterWidget.h index 0e9aab595..a168544e0 100644 --- a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Public/USDImporterWidget.h +++ b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Public/USDImporterWidget.h @@ -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 &NewBoneTransforms); + UFUNCTION(BlueprintCallable, Category="USD Importer") + static void CopyCollisionToPhysicsAsset( + UPhysicsAsset* PhysicsAssetToEdit, UStaticMesh* StaticMesh); }; diff --git a/Util/Patches/omniverse_4.26/USDCARLAInterface.cpp b/Util/Patches/omniverse_4.26/USDCARLAInterface.cpp index 99b4bf259..e809151a4 100644 --- a/Util/Patches/omniverse_4.26/USDCARLAInterface.cpp +++ b/Util/Patches/omniverse_4.26/USDCARLAInterface.cpp @@ -91,6 +91,7 @@ TArray 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 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);