Fixing TAB by SPACES

This commit is contained in:
bernat 2019-12-09 19:12:19 +01:00
parent 76b4133a5c
commit d3696d6b1e
5 changed files with 259 additions and 259 deletions

View File

@ -8,56 +8,56 @@ using UnrealBuildTool;
public class CarlaExporter : ModuleRules public class CarlaExporter : ModuleRules
{ {
public CarlaExporter(ReadOnlyTargetRules Target) : base(Target) public CarlaExporter(ReadOnlyTargetRules Target) : base(Target)
{ {
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
PublicIncludePaths.AddRange( PublicIncludePaths.AddRange(
new string[] { new string[] {
// ... add public include paths required here ... // ... add public include paths required here ...
} }
); );
PrivateIncludePaths.AddRange( PrivateIncludePaths.AddRange(
new string[] { new string[] {
// ... add other private include paths required here ... // ... add other private include paths required here ...
} }
); );
PublicDependencyModuleNames.AddRange( PublicDependencyModuleNames.AddRange(
new string[] new string[]
{ {
"Core", "Core",
// ... add other public dependencies that you statically link with here ... // ... add other public dependencies that you statically link with here ...
} }
); );
PrivateDependencyModuleNames.AddRange( PrivateDependencyModuleNames.AddRange(
new string[] new string[]
{ {
"Projects", "Projects",
"InputCore", "InputCore",
"UnrealEd", "UnrealEd",
"LevelEditor", "LevelEditor",
"CoreUObject", "CoreUObject",
"Engine", "Engine",
"Slate", "Slate",
"SlateCore", "SlateCore",
"Physx", "Physx",
"EditorStyle" "EditorStyle"
// ... add private dependencies that you statically link with here ... // ... add private dependencies that you statically link with here ...
} }
); );
DynamicallyLoadedModuleNames.AddRange( DynamicallyLoadedModuleNames.AddRange(
new string[] new string[]
{ {
// ... add any modules that your module loads dynamically here ... // ... add any modules that your module loads dynamically here ...
} }
); );
} }
} }

View File

@ -29,232 +29,232 @@ static const FName CarlaExporterTabName("CarlaExporter");
void FCarlaExporterModule::StartupModule() void FCarlaExporterModule::StartupModule()
{ {
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
FCarlaExporterCommands::Register(); FCarlaExporterCommands::Register();
PluginCommands = MakeShareable(new FUICommandList); PluginCommands = MakeShareable(new FUICommandList);
PluginCommands->MapAction( PluginCommands->MapAction(
FCarlaExporterCommands::Get().PluginActionExportAll, FCarlaExporterCommands::Get().PluginActionExportAll,
FExecuteAction::CreateRaw(this, &FCarlaExporterModule::PluginButtonClicked), FExecuteAction::CreateRaw(this, &FCarlaExporterModule::PluginButtonClicked),
FCanExecuteAction()); FCanExecuteAction());
FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor"); FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
{ {
TSharedPtr<FExtender> MenuExtender = MakeShareable(new FExtender()); TSharedPtr<FExtender> MenuExtender = MakeShareable(new FExtender());
MenuExtender->AddMenuExtension("FileActors", EExtensionHook::After, PluginCommands, FMenuExtensionDelegate::CreateRaw(this, &FCarlaExporterModule::AddMenuExtension)); MenuExtender->AddMenuExtension("FileActors", EExtensionHook::After, PluginCommands, FMenuExtensionDelegate::CreateRaw(this, &FCarlaExporterModule::AddMenuExtension));
LevelEditorModule.GetMenuExtensibilityManager()->AddExtender(MenuExtender); LevelEditorModule.GetMenuExtensibilityManager()->AddExtender(MenuExtender);
} }
{ {
TSharedPtr<FExtender> ToolbarExtender = MakeShareable(new FExtender); TSharedPtr<FExtender> ToolbarExtender = MakeShareable(new FExtender);
ToolbarExtender->AddToolBarExtension("Settings", EExtensionHook::After, PluginCommands, FToolBarExtensionDelegate::CreateRaw(this, &FCarlaExporterModule::AddToolbarExtension)); ToolbarExtender->AddToolBarExtension("Settings", EExtensionHook::After, PluginCommands, FToolBarExtensionDelegate::CreateRaw(this, &FCarlaExporterModule::AddToolbarExtension));
LevelEditorModule.GetToolBarExtensibilityManager()->AddExtender(ToolbarExtender); LevelEditorModule.GetToolBarExtensibilityManager()->AddExtender(ToolbarExtender);
} }
} }
void FCarlaExporterModule::ShutdownModule() void FCarlaExporterModule::ShutdownModule()
{ {
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module. // we call this function before unloading the module.
FCarlaExporterCommands::Unregister(); FCarlaExporterCommands::Unregister();
} }
void FCarlaExporterModule::PluginButtonClicked() void FCarlaExporterModule::PluginButtonClicked()
{ {
UWorld* World = GEditor->GetEditorWorldContext().World(); UWorld* World = GEditor->GetEditorWorldContext().World();
if (!World) return; if (!World) return;
// get all selected objects (if any) // get all selected objects (if any)
TArray<UObject*> BP_Actors; TArray<UObject*> BP_Actors;
USelection* CurrentSelection = GEditor->GetSelectedActors(); USelection* CurrentSelection = GEditor->GetSelectedActors();
int32 SelectionNum = CurrentSelection->GetSelectedObjects(AActor::StaticClass(), BP_Actors); int32 SelectionNum = CurrentSelection->GetSelectedObjects(AActor::StaticClass(), BP_Actors);
// if no selection, then get all objects // if no selection, then get all objects
if (SelectionNum == 0) if (SelectionNum == 0)
{ {
// for (TObjectIterator<UStaticMeshComponent> it; it; ++it) // for (TObjectIterator<UStaticMeshComponent> it; it; ++it)
for (TActorIterator<AActor> it(World); it; ++it) for (TActorIterator<AActor> it(World); it; ++it)
BP_Actors.Add(Cast<UObject>(*it)); BP_Actors.Add(Cast<UObject>(*it));
} }
// get target path // get target path
FString Path = FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir()); FString Path = FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir());
// build final name // build final name
std::ostringstream name; std::ostringstream name;
name << TCHAR_TO_UTF8(*Path) << "/" << TCHAR_TO_UTF8(*World->GetMapName()) << ".obj"; name << TCHAR_TO_UTF8(*Path) << "/" << TCHAR_TO_UTF8(*World->GetMapName()) << ".obj";
// create the file // create the file
std::ofstream f(name.str()); std::ofstream f(name.str());
// define the rounds // define the rounds
int rounds; int rounds;
rounds = 5; rounds = 5;
int offset = 1; int offset = 1;
std::string type; std::string type;
for (int round = 0; round < rounds; ++round) for (int round = 0; round < rounds; ++round)
{ {
for (UObject* SelectedObject : BP_Actors) for (UObject* SelectedObject : BP_Actors)
{ {
AActor* TempActor = Cast<AActor>(SelectedObject); AActor* TempActor = Cast<AActor>(SelectedObject);
if (!TempActor) continue; if (!TempActor) continue;
// check the TAG (NoExport) // check the TAG (NoExport)
if (TempActor->ActorHasTag(FName("NoExport"))) continue; if (TempActor->ActorHasTag(FName("NoExport"))) continue;
FString ActorName = TempActor->GetName(); FString ActorName = TempActor->GetName();
// check type by nomenclature // check type by nomenclature
if (ActorName.StartsWith("Road_Road")) if (ActorName.StartsWith("Road_Road"))
type = "road"; type = "road";
else if (ActorName.StartsWith("Road_Marking")) else if (ActorName.StartsWith("Road_Marking"))
type = "road"; type = "road";
else if (ActorName.StartsWith("Road_Curb")) else if (ActorName.StartsWith("Road_Curb"))
type = "road"; type = "road";
else if (ActorName.StartsWith("Road_Gutter")) else if (ActorName.StartsWith("Road_Gutter"))
type = "road"; type = "road";
else if (ActorName.StartsWith("Road_Sidewalk")) else if (ActorName.StartsWith("Road_Sidewalk"))
type = "sidewalk"; type = "sidewalk";
else if (ActorName.StartsWith("Road_Crosswalk")) else if (ActorName.StartsWith("Road_Crosswalk"))
type = "crosswalk"; type = "crosswalk";
else if (ActorName.StartsWith("Road_Grass")) else if (ActorName.StartsWith("Road_Grass"))
type = "grass"; type = "grass";
else else
type = "block"; type = "block";
// check to export in this round or not // check to export in this round or not
if (rounds > 1) if (rounds > 1)
{ {
if (type == "block" && round != 0) if (type == "block" && round != 0)
continue; continue;
else if (type == "road" && round != 1) else if (type == "road" && round != 1)
continue; continue;
else if (type == "grass" && round != 2) else if (type == "grass" && round != 2)
continue; continue;
else if (type == "sidewalk" && round != 3) else if (type == "sidewalk" && round != 3)
continue; continue;
else if (type == "crosswalk" && round != 4) else if (type == "crosswalk" && round != 4)
continue; continue;
} }
f << "o " << TCHAR_TO_ANSI(*(ActorName)) << "\n"; f << "o " << TCHAR_TO_ANSI(*(ActorName)) << "\n";
TArray<UActorComponent*> Components = TempActor->GetComponentsByClass(UStaticMeshComponent::StaticClass()); TArray<UActorComponent*> Components = TempActor->GetComponentsByClass(UStaticMeshComponent::StaticClass());
for (auto *Component : Components) for (auto *Component : Components)
{ {
// check if is an instanced static mesh // check if is an instanced static mesh
UInstancedStaticMeshComponent* comp2 = Cast<UInstancedStaticMeshComponent>(Component); UInstancedStaticMeshComponent* comp2 = Cast<UInstancedStaticMeshComponent>(Component);
if (comp2) if (comp2)
{ {
UBodySetup *body = comp2->GetBodySetup(); UBodySetup *body = comp2->GetBodySetup();
if (!body) continue; if (!body) continue;
for (int i=0; i<comp2->GetInstanceCount(); ++i) for (int i=0; i<comp2->GetInstanceCount(); ++i)
{ {
f << "g instance_" << i << "\n"; f << "g instance_" << i << "\n";
// get the component position and transform // get the component position and transform
FTransform InstanceTransform; FTransform InstanceTransform;
comp2->GetInstanceTransform(i, InstanceTransform, true); comp2->GetInstanceTransform(i, InstanceTransform, true);
FVector InstanceLocation = InstanceTransform.GetTranslation(); FVector InstanceLocation = InstanceTransform.GetTranslation();
// through all convex elements // through all convex elements
for (const auto &mesh : body->TriMeshes) for (const auto &mesh : body->TriMeshes)
{ {
// get data // get data
PxU32 nbVerts = mesh->getNbVertices(); PxU32 nbVerts = mesh->getNbVertices();
const PxVec3* convexVerts = mesh->getVertices(); const PxVec3* convexVerts = mesh->getVertices();
const PxU16* indexBuffer = (PxU16 *) mesh->getTriangles(); const PxU16* indexBuffer = (PxU16 *) mesh->getTriangles();
// write all vertex // write all vertex
for(PxU32 j=0;j<nbVerts;j++) for(PxU32 j=0;j<nbVerts;j++)
{ {
const PxVec3 &v = convexVerts[j]; const PxVec3 &v = convexVerts[j];
FVector vec(v.x, v.y, v.z); FVector vec(v.x, v.y, v.z);
FVector vec3 = InstanceTransform.TransformVector(vec); FVector vec3 = InstanceTransform.TransformVector(vec);
FVector world(vec3.X, vec3.Y, vec3.Z); FVector world(vec3.X, vec3.Y, vec3.Z);
f << "v " << std::fixed << (InstanceLocation.X + world.X) * 0.01f << " " << (InstanceLocation.Z + world.Z) * 0.01f << " " << (InstanceLocation.Y + world.Y) * 0.01f << "\n"; f << "v " << std::fixed << (InstanceLocation.X + world.X) * 0.01f << " " << (InstanceLocation.Z + world.Z) * 0.01f << " " << (InstanceLocation.Y + world.Y) * 0.01f << "\n";
} }
// write all faces // write all faces
f << "usemtl " << type << "\n"; f << "usemtl " << type << "\n";
for (unsigned int k=0; k<mesh->getNbTriangles()*3;k+=3) for (unsigned int k=0; k<mesh->getNbTriangles()*3;k+=3)
{ {
// inverse order for left hand // inverse order for left hand
f << "f " << offset + indexBuffer[k+2] << " " << offset + indexBuffer[k+1] << " " << offset + indexBuffer[k] << "\n"; f << "f " << offset + indexBuffer[k+2] << " " << offset + indexBuffer[k+1] << " " << offset + indexBuffer[k] << "\n";
} }
offset += nbVerts; offset += nbVerts;
} }
} }
} }
else else
{ {
// try as static mesh // try as static mesh
UStaticMeshComponent* comp = Cast<UStaticMeshComponent>(Component); UStaticMeshComponent* comp = Cast<UStaticMeshComponent>(Component);
if (!comp) continue; if (!comp) continue;
UBodySetup *body = comp->GetBodySetup(); UBodySetup *body = comp->GetBodySetup();
if (!body) if (!body)
continue; continue;
f << "g " << TCHAR_TO_ANSI(*(comp->GetName())) << "\n"; f << "g " << TCHAR_TO_ANSI(*(comp->GetName())) << "\n";
// get the component position and transform // get the component position and transform
FTransform CompTransform = comp->GetComponentTransform(); FTransform CompTransform = comp->GetComponentTransform();
FVector CompLocation = CompTransform.GetTranslation(); FVector CompLocation = CompTransform.GetTranslation();
// through all convex elements // through all convex elements
for (const auto &mesh : body->TriMeshes) for (const auto &mesh : body->TriMeshes)
{ {
// get data // get data
PxU32 nbVerts = mesh->getNbVertices(); PxU32 nbVerts = mesh->getNbVertices();
const PxVec3* convexVerts = mesh->getVertices(); const PxVec3* convexVerts = mesh->getVertices();
const PxU16* indexBuffer = (PxU16 *) mesh->getTriangles(); const PxU16* indexBuffer = (PxU16 *) mesh->getTriangles();
// write all vertex // write all vertex
for(PxU32 j=0;j<nbVerts;j++) for(PxU32 j=0;j<nbVerts;j++)
{ {
const PxVec3 &v = convexVerts[j]; const PxVec3 &v = convexVerts[j];
FVector vec(v.x, v.y, v.z); FVector vec(v.x, v.y, v.z);
FVector vec3 = CompTransform.TransformVector(vec); FVector vec3 = CompTransform.TransformVector(vec);
FVector world(CompLocation.X + vec3.X, CompLocation.Y + vec3.Y, CompLocation.Z + vec3.Z); FVector world(CompLocation.X + vec3.X, CompLocation.Y + vec3.Y, CompLocation.Z + vec3.Z);
f << "v " << std::fixed << world.X * 0.01f << " " << world.Z * 0.01f << " " << world.Y * 0.01f << "\n"; f << "v " << std::fixed << world.X * 0.01f << " " << world.Z * 0.01f << " " << world.Y * 0.01f << "\n";
} }
// write all faces // write all faces
f << "usemtl " << type << "\n"; f << "usemtl " << type << "\n";
int k = 0; int k = 0;
for (PxU32 i=0; i<mesh->getNbTriangles(); ++i) for (PxU32 i=0; i<mesh->getNbTriangles(); ++i)
{ {
// inverse order for left hand // inverse order for left hand
f << "f " << offset + indexBuffer[k+2] << " " << offset + indexBuffer[k+1] << " " << offset + indexBuffer[k] << "\n"; f << "f " << offset + indexBuffer[k+2] << " " << offset + indexBuffer[k+1] << " " << offset + indexBuffer[k] << "\n";
k += 3; k += 3;
} }
offset += nbVerts; offset += nbVerts;
} }
} }
} }
} }
} }
f.close(); f.close();
} }
void FCarlaExporterModule::AddMenuExtension(FMenuBuilder& Builder) void FCarlaExporterModule::AddMenuExtension(FMenuBuilder& Builder)
{ {
Builder.AddMenuEntry(FCarlaExporterCommands::Get().PluginActionExportAll); Builder.AddMenuEntry(FCarlaExporterCommands::Get().PluginActionExportAll);
} }
void FCarlaExporterModule::AddToolbarExtension(FToolBarBuilder& Builder) void FCarlaExporterModule::AddToolbarExtension(FToolBarBuilder& Builder)
{ {
//Builder.AddToolBarButton(FCarlaExporterCommands::Get().PluginAction); //Builder.AddToolBarButton(FCarlaExporterCommands::Get().PluginAction);
} }
#undef LOCTEXT_NAMESPACE #undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FCarlaExporterModule, CarlaExporter) IMPLEMENT_MODULE(FCarlaExporterModule, CarlaExporter)

View File

@ -10,7 +10,7 @@
void FCarlaExporterCommands::RegisterCommands() void FCarlaExporterCommands::RegisterCommands()
{ {
UI_COMMAND(PluginActionExportAll, "Carla Exporter", "Export all or selected meshes into an .OBJ file to be used by Carla (in /saved/ folder)", EUserInterfaceActionType::Button, FInputGesture()); UI_COMMAND(PluginActionExportAll, "Carla Exporter", "Export all or selected meshes into an .OBJ file to be used by Carla (in /saved/ folder)", EUserInterfaceActionType::Button, FInputGesture());
} }
#undef LOCTEXT_NAMESPACE #undef LOCTEXT_NAMESPACE

View File

@ -17,18 +17,18 @@ class FCarlaExporterModule : public IModuleInterface
{ {
public: public:
/** IModuleInterface implementation */ /** IModuleInterface implementation */
virtual void StartupModule() override; virtual void StartupModule() override;
virtual void ShutdownModule() override; virtual void ShutdownModule() override;
/** This function will be bound to Command. */ /** This function will be bound to Command. */
void PluginButtonClicked(); void PluginButtonClicked();
private: private:
void AddToolbarExtension(FToolBarBuilder& Builder); void AddToolbarExtension(FToolBarBuilder& Builder);
void AddMenuExtension(FMenuBuilder& Builder); void AddMenuExtension(FMenuBuilder& Builder);
private: private:
TSharedPtr<class FUICommandList> PluginCommands; TSharedPtr<class FUICommandList> PluginCommands;
}; };

View File

@ -14,18 +14,18 @@ class FCarlaExporterCommands : public TCommands<FCarlaExporterCommands>
{ {
public: public:
FCarlaExporterCommands() FCarlaExporterCommands()
: TCommands<FCarlaExporterCommands>( : TCommands<FCarlaExporterCommands>(
TEXT("CarlaExporter"), TEXT("CarlaExporter"),
NSLOCTEXT("Contexts", "CarlaExporter", "CarlaExporter Plugin"), NSLOCTEXT("Contexts", "CarlaExporter", "CarlaExporter Plugin"),
NAME_None, NAME_None,
FEditorStyle::GetStyleSetName()) FEditorStyle::GetStyleSetName())
{ {
} }
// TCommands<> interface // TCommands<> interface
virtual void RegisterCommands() override; virtual void RegisterCommands() override;
public: public:
TSharedPtr< FUICommandInfo > PluginActionExportAll; TSharedPtr< FUICommandInfo > PluginActionExportAll;
}; };