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 "Kismet2/BlueprintEditorUtils.h"
|
||||||
#include "BlueprintEditor.h"
|
#include "BlueprintEditor.h"
|
||||||
#include "Carla/Vehicle/CarlaWheeledVehicle.h"
|
#include "Carla/Vehicle/CarlaWheeledVehicle.h"
|
||||||
|
#include "EditorStaticMeshLibrary.h"
|
||||||
|
|
||||||
|
|
||||||
void UUSDImporterWidget::ImportUSDProp(
|
void UUSDImporterWidget::ImportUSDProp(
|
||||||
|
@ -71,7 +72,7 @@ void UUSDImporterWidget::ImportUSDVehicle(
|
||||||
-> TSubclassOf<UVehicleWheel>
|
-> TSubclassOf<UVehicleWheel>
|
||||||
{
|
{
|
||||||
// Get a reference to the editor subsystem
|
// Get a reference to the editor subsystem
|
||||||
constexpr float MToCM = 0.01f;
|
constexpr float MToCM = 100.f;
|
||||||
constexpr float RadToDeg = 360.f/3.14159265359f;
|
constexpr float RadToDeg = 360.f/3.14159265359f;
|
||||||
FString BlueprintName = FPaths::GetBaseFilename(PackagePathName);
|
FString BlueprintName = FPaths::GetBaseFilename(PackagePathName);
|
||||||
FString BlueprintPath = FPaths::GetPath(PackagePathName);
|
FString BlueprintPath = FPaths::GetPath(PackagePathName);
|
||||||
|
@ -430,6 +431,7 @@ AActor* UUSDImporterWidget::GenerateNewVehicleBlueprint(
|
||||||
UWorld* World,
|
UWorld* World,
|
||||||
UClass* BaseClass,
|
UClass* BaseClass,
|
||||||
USkeletalMesh* NewSkeletalMesh,
|
USkeletalMesh* NewSkeletalMesh,
|
||||||
|
UPhysicsAsset* NewPhysicsAsset,
|
||||||
const FString &DestPath,
|
const FString &DestPath,
|
||||||
const FMergedVehicleMeshParts& VehicleMeshes,
|
const FMergedVehicleMeshParts& VehicleMeshes,
|
||||||
const FWheelTemplates& WheelTemplates)
|
const FWheelTemplates& WheelTemplates)
|
||||||
|
@ -538,6 +540,16 @@ AActor* UUSDImporterWidget::GenerateNewVehicleBlueprint(
|
||||||
TemplateActor->AddInstanceComponent(LightComponent);
|
TemplateActor->AddInstanceComponent(LightComponent);
|
||||||
UE_LOG(LogCarlaTools, Log, TEXT("Spawn Light %s, %s, %s"), *Light.Name, *Light.Location.ToString(), *Light.Color.ToString());
|
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
|
// assign generated wheel types
|
||||||
TArray<FWheelSetup> WheelSetups;
|
TArray<FWheelSetup> WheelSetups;
|
||||||
FWheelSetup Setup;
|
FWheelSetup Setup;
|
||||||
|
@ -566,7 +578,12 @@ AActor* UUSDImporterWidget::GenerateNewVehicleBlueprint(
|
||||||
{
|
{
|
||||||
UE_LOG(LogCarlaTools, Error, TEXT("Null CarlaVehicle"));
|
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
|
// Create the new blueprint vehicle
|
||||||
FKismetEditorUtilities::FCreateBlueprintFromActorParams Params;
|
FKismetEditorUtilities::FCreateBlueprintFromActorParams Params;
|
||||||
Params.bReplaceActor = false;
|
Params.bReplaceActor = false;
|
||||||
|
@ -612,3 +629,15 @@ bool UUSDImporterWidget::EditSkeletalMeshBones(
|
||||||
EObjectFlags::RF_Public | EObjectFlags::RF_Standalone,
|
EObjectFlags::RF_Public | EObjectFlags::RF_Standalone,
|
||||||
*(Package->GetName()), GError, nullptr, true, true, SAVE_NoError);
|
*(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 "Animation/Skeleton.h"
|
||||||
#include "VehicleWheel.h"
|
#include "VehicleWheel.h"
|
||||||
#include "Materials/MaterialInterface.h"
|
#include "Materials/MaterialInterface.h"
|
||||||
|
#include "PhysicsEngine/PhysicsAsset.h"
|
||||||
|
|
||||||
#include "USDImporterWidget.generated.h"
|
#include "USDImporterWidget.generated.h"
|
||||||
|
|
||||||
|
@ -165,6 +166,7 @@ public:
|
||||||
UWorld* World,
|
UWorld* World,
|
||||||
UClass* BaseClass,
|
UClass* BaseClass,
|
||||||
USkeletalMesh* NewSkeletalMesh,
|
USkeletalMesh* NewSkeletalMesh,
|
||||||
|
UPhysicsAsset* NewPhysicsAsset,
|
||||||
const FString &DestPath,
|
const FString &DestPath,
|
||||||
const FMergedVehicleMeshParts& VehicleMeshes,
|
const FMergedVehicleMeshParts& VehicleMeshes,
|
||||||
const FWheelTemplates& WheelTemplates);
|
const FWheelTemplates& WheelTemplates);
|
||||||
|
@ -172,5 +174,8 @@ public:
|
||||||
static bool EditSkeletalMeshBones(
|
static bool EditSkeletalMeshBones(
|
||||||
USkeletalMesh* Skeleton,
|
USkeletalMesh* Skeleton,
|
||||||
const TMap<FString, FTransform> &NewBoneTransforms);
|
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)
|
if(!WheelPrim)
|
||||||
{
|
{
|
||||||
UE_LOG(LogOmniverseUsd, Warning, TEXT("Wheel prim fail"));
|
UE_LOG(LogOmniverseUsd, Warning, TEXT("Wheel prim fail"));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
pxr::UsdRelationship WheelRelationship;
|
pxr::UsdRelationship WheelRelationship;
|
||||||
pxr::UsdRelationship TireRelationship;
|
pxr::UsdRelationship TireRelationship;
|
||||||
|
@ -155,7 +156,15 @@ TArray<FUSDCARLAWheelData> UUSDCARLAInterface::GetUSDWheelData(const FString& Pa
|
||||||
|
|
||||||
return true;
|
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_0", Wheel0);
|
||||||
ParseWheelData("wheel_1", Wheel1);
|
ParseWheelData("wheel_1", Wheel1);
|
||||||
ParseWheelData("wheel_2", Wheel2);
|
ParseWheelData("wheel_2", Wheel2);
|
||||||
|
|
Loading…
Reference in New Issue