Removed unnecessary comments. Added vehicle light and door ingestion to the pipeline

This commit is contained in:
Axel 2023-04-12 17:20:06 +02:00 committed by bernat
parent 359806f9b0
commit 13358263c6
7 changed files with 209 additions and 17 deletions

View File

@ -1097,3 +1097,15 @@ void ACarlaWheeledVehicle::RemoveReferenceToManager()
return;
}
}
FRotator ACarlaWheeledVehicle::GetPhysicsConstraintAngle(
UPhysicsConstraintComponent* Component)
{
return Component->ConstraintInstance.AngularRotationOffset;
}
void ACarlaWheeledVehicle::SetPhysicsConstraintAngle(
UPhysicsConstraintComponent* Component, const FRotator &NewAngle)
{
Component->ConstraintInstance.AngularRotationOffset = NewAngle;
}

View File

@ -420,6 +420,12 @@ public:
carla::rpc::VehicleFailureState GetFailureState() const;
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
static FRotator GetPhysicsConstraintAngle(UPhysicsConstraintComponent* Component);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
static void SetPhysicsConstraintAngle(
UPhysicsConstraintComponent*Component, const FRotator &NewAngle);
private:
UPROPERTY(Category="CARLA Wheeled Vehicle", VisibleAnywhere)

View File

@ -19,13 +19,14 @@
#include "EditorAssetLibrary.h"
#include <unordered_map>
#include <string>
#include "Components/PointLightComponent.h"
void UUSDImporterWidget::ImportUSDProp(
const FString& USDPath, const FString& DestinationAssetPath, bool bAsBlueprint)
{
#ifdef WITH_OMNIVERSE
FUSDCARLAInterface::ImportUSD(USDPath, DestinationAssetPath, false, bAsBlueprint);
UUSDCARLAInterface::ImportUSD(USDPath, DestinationAssetPath, false, bAsBlueprint);
#else
UE_LOG(LogCarlaTools, Error, TEXT("Omniverse Plugin is not enabled"));
#endif
@ -33,9 +34,23 @@ void UUSDImporterWidget::ImportUSDProp(
}
void UUSDImporterWidget::ImportUSDVehicle(
const FString& USDPath, const FString& DestinationAssetPath, bool bAsBlueprint)
const FString& USDPath,
const FString& DestinationAssetPath,
TArray<FVehicleLight>& LightList,
bool bAsBlueprint)
{
#ifdef WITH_OMNIVERSE
UUSDCARLAInterface::ImportUSD(USDPath, DestinationAssetPath, false, bAsBlueprint);
TArray<FUSDCARLALight> USDLights = UUSDCARLAInterface::GetUSDLights(USDPath);
LightList.Empty();
for (const FUSDCARLALight& USDLight : USDLights)
{
FVehicleLight Light {USDLight.Name, USDLight.Location, USDLight.Color};
LightList.Add(Light);
}
#else
UE_LOG(LogCarlaTools, Error, TEXT("Omniverse Plugin is not enabled"));
#endif
}
AActor* UUSDImporterWidget::GetGeneratedBlueprint(UWorld* World, const FString& USDPath)
@ -112,9 +127,11 @@ bool IsChildrenOf(USceneComponent* Component, FString StringInParent)
return false;
}
FVehicleMeshParts UUSDImporterWidget::SplitVehicleParts(AActor* BlueprintActor)
FVehicleMeshParts UUSDImporterWidget::SplitVehicleParts(
AActor* BlueprintActor, const TArray<FVehicleLight>& LightList)
{
FVehicleMeshParts Result;
Result.Lights = LightList;
TArray<UStaticMeshComponent*> MeshComponents;
BlueprintActor->GetComponents(MeshComponents, false);
FVector BodyLocation = FVector(0,0,0);
@ -210,6 +227,10 @@ FVehicleMeshParts UUSDImporterWidget::SplitVehicleParts(AActor* BlueprintActor)
Result.Anchors.WheelRL -= BodyLocation;
Result.Anchors.Hood -= BodyLocation;
Result.Anchors.Trunk -= BodyLocation;
for (FVehicleLight& Light : Result.Lights)
{
Light.Location -= BodyLocation;
}
return Result;
}
@ -247,9 +268,72 @@ FMergedVehicleMeshParts UUSDImporterWidget::GenerateVehicleMeshes(
Result.WheelRL = MergePart(VehicleMeshParts.WheelRL, DestPath + "_wheel_rl");
Result.Body = MergePart(VehicleMeshParts.Body, DestPath + "_body");
Result.Anchors = VehicleMeshParts.Anchors;
Result.Lights = VehicleMeshParts.Lights;
return Result;
}
FString GetCarlaLightName(const FString &USDName)
{
FString LowerCaseUSDName = USDName.ToLower();
FString LightType = "";
if (LowerCaseUSDName.Contains("headlight"))
{
LightType = "low_beam";
}
else if (LowerCaseUSDName.Contains("brakelight"))
{
LightType = "brake";
}
else if (LowerCaseUSDName.Contains("blinker"))
{
LightType = "blinker";
}
else if (LowerCaseUSDName.Contains("night"))
{
LightType = "high_beam";
}
else if (LowerCaseUSDName.Contains("reverse"))
{
LightType = "reverse";
}
else if (LowerCaseUSDName.Contains("highbeamlight"))
{
LightType = "high_beam";
}
else if (LowerCaseUSDName.Contains("foglight"))
{
LightType = "fog";
}
else if (LowerCaseUSDName.Contains("TailLight"))
{
LightType = "position";
}
else
{
LightType = USDName;
}
FString FinalName = "-" + LightType + "-";
if (LowerCaseUSDName.EndsWith("_fr"))
{
FinalName = "front" + FinalName + "r-";
}
else if (LowerCaseUSDName.EndsWith("_fl"))
{
FinalName = "front" + FinalName + "l-";
}
else if (LowerCaseUSDName.EndsWith("_rr"))
{
FinalName = "back" + FinalName + "r-";
}
else if (LowerCaseUSDName.EndsWith("_rl"))
{
FinalName = "back" + FinalName + "l-";
}
return FinalName;
}
AActor* UUSDImporterWidget::GenerateNewVehicleBlueprint(
UWorld* World,
UClass* BaseClass,
@ -270,7 +354,7 @@ AActor* UUSDImporterWidget::GenerateNewVehicleBlueprint(
{"Wheel_RL", {VehicleMeshes.WheelRL, FVector(0,0,0)}},
{"Body", {VehicleMeshes.Body, FVector(0,0,0)}}
};
AActor* TemplateActor = World->SpawnActor<AActor>(BaseClass);
// Get an replace all static meshes with the appropiate mesh
TArray<UStaticMeshComponent*> MeshComponents;
@ -317,10 +401,23 @@ AActor* UUSDImporterWidget::GenerateNewVehicleBlueprint(
return nullptr;
}
SkeletalMeshComponent->SetSkeletalMesh(NewSkeletalMesh);
UE_LOG(LogCarlaTools, Log, TEXT("Num Lights %d"), VehicleMeshes.Lights.Num());
for (const FVehicleLight& Light : VehicleMeshes.Lights)
{
UPointLightComponent* PointLightComponent = NewObject<UPointLightComponent>(TemplateActor, FName(*GetCarlaLightName(Light.Name)));
PointLightComponent->RegisterComponent();
PointLightComponent->AttachToComponent(TemplateActor->GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);
PointLightComponent->SetRelativeLocation(Light.Location); // Set the position of the light relative to the actor
PointLightComponent->SetIntensity(5000.f); // Set the brightness of the light
PointLightComponent->SetLightColor(Light.Color);
TemplateActor->AddInstanceComponent(PointLightComponent);
UE_LOG(LogCarlaTools, Log, TEXT("Spawn Light %s, %s, %s"), *Light.Name, *Light.Location.ToString(), *Light.Color.ToString());
}
// Create the new blueprint vehicle
FKismetEditorUtilities::FCreateBlueprintFromActorParams Params;
Params.bReplaceActor = true;
Params.bReplaceActor = false;
Params.bKeepMobility = true;
Params.bDeferCompilation = false;
Params.bOpenBlueprint = false;
@ -355,11 +452,7 @@ bool UUSDImporterWidget::EditSkeletalMeshBones(
UE_LOG(LogCarlaTools, Log, TEXT("Bone %s corresponds to index %d"), *BoneName, BoneIdx);
SkeletonModifier.UpdateRefPoseTransform(BoneIdx, BoneTransform);
}
// UE_LOG(LogCarlaTools, Log, TEXT("Creating new skeletal mesh in path %s"), *PackagePath);
// UPackage* NewPackage = CreatePackage(nullptr, *PackagePath);
// UObject* NewObject = DuplicateObject(Skeleton, NewPackage);
// SavePackageHelper(NewPackage, *PackagePath);
NewSkeletalMesh->MarkPackageDirty();
UPackage* Package = NewSkeletalMesh->GetOutermost();
return UPackage::SavePackage(

View File

@ -8,6 +8,18 @@
#include "USDImporterWidget.generated.h"
USTRUCT(BlueprintType)
struct FVehicleLight
{
GENERATED_BODY()
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="USD Light")
FString Name;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="USD Light")
FVector Location;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="USD Light")
FLinearColor Color;
};
USTRUCT(BlueprintType)
struct CARLATOOLS_API FVehicleMeshAnchorPoints
{
@ -65,6 +77,8 @@ struct CARLATOOLS_API FVehicleMeshParts
TArray<UPrimitiveComponent*> Body;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="USD Importer")
FVehicleMeshAnchorPoints Anchors;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="USD Importer")
TArray<FVehicleLight> Lights;
};
USTRUCT(BlueprintType)
@ -96,6 +110,8 @@ struct CARLATOOLS_API FMergedVehicleMeshParts
UStaticMesh* Body;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="USD Importer")
FVehicleMeshAnchorPoints Anchors;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="USD Importer")
TArray<FVehicleLight> Lights;
};
UCLASS()
@ -108,7 +124,11 @@ public:
UFUNCTION(BlueprintCallable, Category="USD Importer")
void ImportUSDProp(const FString& USDPath, const FString& DestinationAssetPath, bool bAsBlueprint = true);
UFUNCTION(BlueprintCallable, Category="USD Importer")
void ImportUSDVehicle(const FString& USDPath, const FString& DestinationAssetPath, bool bAsBlueprint = true);
void ImportUSDVehicle(
const FString& USDPath,
const FString& DestinationAssetPath,
TArray<FVehicleLight>& LightList,
bool bAsBlueprint = true);
UFUNCTION(BlueprintCallable, Category="USD Importer")
static AActor* GetGeneratedBlueprint(UWorld* World, const FString& USDPath);
UFUNCTION(BlueprintCallable, Category="USD Importer")
@ -116,7 +136,8 @@ public:
UFUNCTION(BlueprintCallable, Category="USD Importer")
static TArray<UObject*> MergeMeshComponents(TArray<UPrimitiveComponent*> Components, const FString& DestMesh);
UFUNCTION(BlueprintCallable, Category="USD Importer")
static FVehicleMeshParts SplitVehicleParts(AActor* BlueprintActor);
static FVehicleMeshParts SplitVehicleParts(
AActor* BlueprintActor, const TArray<FVehicleLight>& LightList);
UFUNCTION(BlueprintCallable, Category="USD Importer")
static FMergedVehicleMeshParts GenerateVehicleMeshes(const FVehicleMeshParts& VehicleMeshParts, const FString& DestPath);
UFUNCTION(BlueprintCallable, Category="USD Importer")

View File

@ -1,9 +1,11 @@
#include "USDCARLAInterface.h"
#include "OmniversePxr.h"
#include "OmniverseUSDImporter.h"
#include "OmniverseUSDHelper.h"
bool FUSDCARLAInterface::ImportUSD(
bool UUSDCARLAInterface::ImportUSD(
const FString& Path, const FString& Dest,
bool bImportUnusedReferences, bool bImportAsBlueprint)
{
@ -12,3 +14,39 @@ bool FUSDCARLAInterface::ImportUSD(
Settings.bImportAsBlueprint = bImportAsBlueprint;
return FOmniverseUSDImporter::LoadUSD(Path, Dest, Settings);
}
TArray<FUSDCARLALight> UUSDCARLAInterface::GetUSDLights(const FString& Path)
{
TArray<FUSDCARLALight> Result;
pxr::UsdStageRefPtr Stage = FOmniverseUSDHelper::LoadUSDStageFromPath(Path);
std::vector<pxr::UsdPrim> LightPrims;
const auto& PrimRange = Stage->Traverse();
for (const auto& Prim : PrimRange) {
if (Prim.IsA<pxr::UsdLuxLight>()) {
LightPrims.push_back(Prim);
}
}
for (pxr::UsdPrim& LightPrim : LightPrims)
{
pxr::UsdLuxLight Light(LightPrim);
std::string StdName = LightPrim.GetName();
pxr::GfVec3f PxColor;
pxr::VtValue vtValue;
if (Light.GetColorAttr().Get(&vtValue)) {
PxColor = vtValue.Get<pxr::GfVec3f>();
}
pxr::UsdGeomXformCache Cache;
pxr::GfMatrix4d Transform = Cache.GetLocalToWorldTransform(LightPrim);
pxr::GfVec3d PxLocation = Transform.ExtractTranslation();
FString Name(StdName.size(), UTF8_TO_TCHAR(StdName.c_str()));
FLinearColor Color(PxColor[0], PxColor[1], PxColor[2]);
FVector Location(PxLocation[0], -PxLocation[1], PxLocation[2]);
Location *= 100.f;
FUSDCARLALight LightParams {Name, Location, Color};
Result.Add(LightParams);
}
return Result;
}

View File

@ -1,10 +1,32 @@
#pragma once
#include "UObject/Object.h"
#include "CoreMinimal.h"
#include "USDCARLAInterface.generated.h"
class OMNIVERSEUSD_API FUSDCARLAInterface
USTRUCT(BlueprintType)
struct FUSDCARLALight
{
public:
static bool ImportUSD(const FString& Path, const FString& Dest, bool bImportUnusedReferences, bool bImportAsBlueprint);
GENERATED_BODY()
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="USD Light")
FString Name;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="USD Light")
FVector Location;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="USD Light")
FLinearColor Color;
};
UCLASS()
class OMNIVERSEUSD_API UUSDCARLAInterface : public UObject
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category="USD Carla Interface")
static bool ImportUSD(
const FString& Path, const FString& Dest,
bool bImportUnusedReferences, bool bImportAsBlueprint);
UFUNCTION(BlueprintCallable, Category="USD Carla Interface")
static TArray<FUSDCARLALight> GetUSDLights(const FString& Path);
};