Added Carla To CarlaExporter plugin and changes to Tesselation code
This commit is contained in:
parent
728e1155fa
commit
181718ef9b
|
@ -1349,8 +1349,8 @@ namespace road {
|
|||
std::vector<geom::Mesh> Map::GetAllCrosswalkMeshesTesselated() const {
|
||||
std::vector<geom::Mesh> out_meshes;
|
||||
|
||||
const size_t NumVertexWidthTessCrosswalk = 30;
|
||||
const size_t NumVertexLenghtTessCrosswalk = 200;
|
||||
const size_t NumVertexWidthTessCrosswalk = 2;
|
||||
const size_t NumVertexLenghtTessCrosswalk = 2;
|
||||
|
||||
// Get the crosswalk vertices for the current map
|
||||
const std::vector<std::vector<geom::Location>> crosswalks_vertices = GetAllCrosswalkZonesListed();
|
||||
|
@ -1370,28 +1370,31 @@ namespace road {
|
|||
geom::Location forwardvector = current_crosswalk[2] - current_crosswalk[0];
|
||||
|
||||
geom::Vector3D first_left_edge = current_crosswalk[0];
|
||||
geom::Vector3D first_right_edge = current_crosswalk[0];
|
||||
geom::Vector3D first_right_edge = current_crosswalk[1];
|
||||
size_t current_vertex_length = 0;
|
||||
|
||||
std::vector<geom::Vector3D> vertices;
|
||||
// Ensure minimum vertices in width are two
|
||||
const int vertices_in_width = NumVertexWidthTessCrosswalk;
|
||||
const int segments_number = vertices_in_width - 1;
|
||||
const geom::Location segments_length_size = forwardvector/NumVertexLenghtTessCrosswalk;
|
||||
|
||||
do {
|
||||
const geom::Vector3D left_edge = first_left_edge + (forwardvector * current_vertex_length);
|
||||
const geom::Vector3D right_edge = first_right_edge + (forwardvector * current_vertex_length);
|
||||
const geom::Vector3D left_edge = first_left_edge + (segments_length_size * current_vertex_length);
|
||||
const geom::Vector3D right_edge = first_right_edge + (segments_length_size * current_vertex_length);
|
||||
|
||||
const geom::Vector3D segments_size = ( right_edge - left_edge ) / segments_number;
|
||||
geom::Vector3D current_vertex = left_edge;
|
||||
for (int i = 0; i < vertices_in_width; ++i) {
|
||||
current_vertex = current_vertex + segments_size * i;
|
||||
vertices.push_back(current_vertex);
|
||||
current_vertex = current_vertex + segments_size;
|
||||
}
|
||||
// Update the current waypoint's "s"
|
||||
current_vertex_length++;
|
||||
} while (current_vertex_length < NumVertexLenghtTessCrosswalk);
|
||||
|
||||
|
||||
out_mesh.AddVertices(vertices);
|
||||
|
||||
for (size_t i = 0; i < (NumVertexLenghtTessCrosswalk - 1); ++i) {
|
||||
for (size_t j = 0; j < NumVertexWidthTessCrosswalk - 1; ++j) {
|
||||
out_mesh.AddIndex( j + ( i * NumVertexWidthTessCrosswalk ) + 1);
|
||||
|
|
|
@ -295,6 +295,12 @@ foreach (DEF_FILE ${CARLA_UNREAL_DEF_FILES})
|
|||
-E create_symlink
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${DEF_FILE}
|
||||
${CARLA_UE_CARLA_TOOLS_PATH}/${DEF_FILE}
|
||||
COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
ARGS
|
||||
-E create_symlink
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${DEF_FILE}
|
||||
${CARLA_UE_CARLA_EXPORTER_PATH}/${DEF_FILE}
|
||||
)
|
||||
endforeach ()
|
||||
|
||||
|
|
|
@ -19,5 +19,11 @@
|
|||
"Type": "Editor",
|
||||
"LoadingPhase": "Default"
|
||||
}
|
||||
],
|
||||
"Plugins": [
|
||||
{
|
||||
"Name": "Carla",
|
||||
"Enabled": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
C:/CarlaUE5/Build/Unreal/Definitions.def
|
|
@ -0,0 +1 @@
|
|||
C:/CarlaUE5/Build/Unreal/Includes.def
|
|
@ -0,0 +1 @@
|
|||
C:/CarlaUE5/Build/Unreal/Libraries.def
|
|
@ -0,0 +1 @@
|
|||
C:/CarlaUE5/Build/Unreal/Options.def
|
|
@ -4,7 +4,9 @@
|
|||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
using System;
|
||||
using UnrealBuildTool;
|
||||
using System.IO;
|
||||
|
||||
public class CarlaExporter :
|
||||
ModuleRules
|
||||
|
@ -13,8 +15,12 @@ public class CarlaExporter :
|
|||
base(Target)
|
||||
{
|
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
bEnableExceptions = true;
|
||||
|
||||
|
||||
|
||||
PublicDependencyModuleNames.Add("Core");
|
||||
PublicDependencyModuleNames.Add("Carla");
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[]
|
||||
{
|
||||
|
@ -29,5 +35,27 @@ public class CarlaExporter :
|
|||
"Chaos",
|
||||
"EditorStyle",
|
||||
});
|
||||
|
||||
PublicDefinitions.AddRange(new string[]
|
||||
{
|
||||
"ASIO_NO_EXCEPTIONS",
|
||||
"BOOST_NO_EXCEPTIONS",
|
||||
"LIBCARLA_NO_EXCEPTIONS",
|
||||
"PUGIXML_NO_EXCEPTIONS",
|
||||
"BOOST_DISABLE_ABI_HEADERS",
|
||||
"BOOST_NO_RTTI",
|
||||
"BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY",
|
||||
});
|
||||
|
||||
foreach (var Definition in File.ReadAllText(Path.Combine(PluginDirectory, "Definitions.def")).Split(';'))
|
||||
PrivateDefinitions.Add(Definition.Trim());
|
||||
|
||||
foreach (var Path in File.ReadAllText(Path.Combine(PluginDirectory, "Includes.def")).Split(';'))
|
||||
if (Path.Length != 0)
|
||||
PublicIncludePaths.Add(Path.Trim());
|
||||
|
||||
foreach (var Path in File.ReadAllText(Path.Combine(PluginDirectory, "Libraries.def")).Split(';'))
|
||||
if (Path.Length != 0)
|
||||
PublicAdditionalLibraries.Add(Path.Trim());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,20 @@
|
|||
#include "Chaos/TriangleMeshImplicitObject.h"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <exception>
|
||||
|
||||
#include "OpenDrive/OpenDriveGenerator.h"
|
||||
#include <compiler/disable-ue4-macros.h>
|
||||
#include <carla/opendrive/OpenDriveParser.h>
|
||||
#include <carla/road/Map.h>
|
||||
#include <carla/rpc/String.h>
|
||||
#include <carla/Exception.h>
|
||||
#include <compiler/enable-ue4-macros.h>
|
||||
|
||||
static const FName CarlaExporterTabName("CarlaExporter");
|
||||
DEFINE_LOG_CATEGORY(LogCarlaExporter);
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FCarlaExporterModule"
|
||||
|
||||
|
@ -163,7 +175,7 @@ void FCarlaExporterModule::PluginButtonClicked()
|
|||
comp2->GetInstanceTransform(i, InstanceTransform, true);
|
||||
FVector InstanceLocation = InstanceTransform.GetTranslation();
|
||||
|
||||
offset += WriteObjectGeom(f, ObjectName, body, InstanceTransform, areaType, offset);
|
||||
//offset += WriteObjectGeom(f, ObjectName, body, InstanceTransform, areaType, offset);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -183,14 +195,59 @@ void FCarlaExporterModule::PluginButtonClicked()
|
|||
FTransform CompTransform = comp->GetComponentTransform();
|
||||
FVector CompLocation = CompTransform.GetTranslation();
|
||||
|
||||
offset += WriteObjectGeom(f, ObjectName, body, CompTransform, areaType, offset);
|
||||
//offset += WriteObjectGeom(f, ObjectName, body, CompTransform, areaType, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
offset += WriteCrosswalks(f, offset);
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
int32 FCarlaExporterModule::WriteCrosswalks(std::ofstream &f, int32 Offset){
|
||||
|
||||
FString FilePath = FString("C:/CarlaUE5/Unreal/CarlaUnreal/Content/Carla/Maps/OpenDrive/Town10HD_Opt.xodr");
|
||||
FString FileContent;
|
||||
FFileHelper::LoadFileToString(FileContent, *FilePath);
|
||||
std::string opendrive_xml = carla::rpc::FromLongFString(FileContent);
|
||||
std::optional<carla::road::Map> CarlaMap = carla::opendrive::OpenDriveParser::Load(opendrive_xml);
|
||||
if (!CarlaMap.has_value())
|
||||
{
|
||||
//UE_LOG(LogCarlaToolsMapGenerator, Error, TEXT("Invalid Map"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<carla::geom::Mesh> crosswalk_meshes = CarlaMap->GetAllCrosswalkMeshesTesselated();
|
||||
|
||||
constexpr float TO_METERS = 0.01f;
|
||||
int TotalVerticesAdded = 0;
|
||||
|
||||
for(int i = 0; i < crosswalk_meshes.size(); i++){
|
||||
|
||||
f << "o crosswalk_" << TCHAR_TO_ANSI(*FString::FromInt(i)) << "\n";
|
||||
|
||||
std::vector<carla::geom::Vector3D> crosswalk_vertices = crosswalk_meshes[i].GetVertices();
|
||||
std::vector<size_t> crosswalk_indexes = crosswalk_meshes[i].GetIndexes();
|
||||
|
||||
for(int j = 0; j < crosswalk_vertices.size(); ++j){
|
||||
f << "v " << std::fixed << crosswalk_vertices[j].x << " " << crosswalk_vertices[j].z << " " << crosswalk_vertices[j].y << "\n";
|
||||
}
|
||||
|
||||
f << "usemtl crosswalk" << "\n";
|
||||
|
||||
for(int j = 0; j < crosswalk_indexes.size(); j+=3){
|
||||
f << "f " << Offset + crosswalk_indexes[j] << " " << Offset + crosswalk_indexes[j+1] << " " << Offset + crosswalk_indexes[j+2] << "\n";
|
||||
}
|
||||
|
||||
Offset += crosswalk_vertices.size();
|
||||
TotalVerticesAdded = crosswalk_vertices.size();
|
||||
}
|
||||
|
||||
return TotalVerticesAdded;
|
||||
}
|
||||
|
||||
int32 FCarlaExporterModule::WriteObjectGeom(std::ofstream &f, FString ObjectName, UBodySetup *body, FTransform &CompTransform, AreaType Area, int32 Offset)
|
||||
{
|
||||
if (!body) return 0;
|
||||
|
@ -404,9 +461,6 @@ int32 FCarlaExporterModule::WriteObjectGeom(std::ofstream &f, FString ObjectName
|
|||
}
|
||||
|
||||
return TotalVerticesAdded;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void FCarlaExporterModule::AddMenuExtension(FMenuBuilder& Builder)
|
||||
|
@ -417,3 +471,24 @@ void FCarlaExporterModule::AddMenuExtension(FMenuBuilder& Builder)
|
|||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
IMPLEMENT_MODULE(FCarlaExporterModule, CarlaExporter)
|
||||
|
||||
// =============================================================================
|
||||
// -- Implement carla throw_exception ------------------------------------------
|
||||
// =============================================================================
|
||||
|
||||
#ifdef LIBCARLA_NO_EXCEPTIONS
|
||||
#include <compiler/disable-ue4-macros.h>
|
||||
#include <carla/Exception.h>
|
||||
#include <compiler/enable-ue4-macros.h>
|
||||
|
||||
#include <exception>
|
||||
namespace carla {
|
||||
|
||||
void throw_exception(const std::exception &e) {
|
||||
UE_LOG(LogCarlaExporter, Fatal, TEXT("Exception thrown: %s"), UTF8_TO_TCHAR(e.what()));
|
||||
// It should never reach this part.
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
} // namespace carla
|
||||
#endif
|
|
@ -10,6 +10,8 @@
|
|||
#include "Modules/ModuleManager.h"
|
||||
#include <string>
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogCarlaExporter, Log, All);
|
||||
|
||||
class FToolBarBuilder;
|
||||
class FMenuBuilder;
|
||||
|
||||
|
@ -36,6 +38,7 @@ public:
|
|||
private:
|
||||
|
||||
void AddMenuExtension(FMenuBuilder& Builder);
|
||||
int32 WriteCrosswalks(std::ofstream &f, int32 Offset);
|
||||
int32 WriteObjectGeom(std::ofstream &f, FString ObjectName, UBodySetup *body, FTransform &CompTransform, AreaType Area, int32 Offset);
|
||||
|
||||
private:
|
||||
|
|
|
@ -125,14 +125,6 @@ public class CarlaTools :
|
|||
PrivateDefinitions.Add("WIN32_LEAN_AND_MEAN");
|
||||
}
|
||||
|
||||
PublicDefinitions.Add("BOOST_DISABLE_ABI_HEADERS");
|
||||
PublicDefinitions.Add("BOOST_NO_RTTI");
|
||||
PublicDefinitions.Add("BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY");
|
||||
PublicDefinitions.Add("ASIO_NO_EXCEPTIONS");
|
||||
PublicDefinitions.Add("BOOST_NO_EXCEPTIONS");
|
||||
PublicDefinitions.Add("LIBCARLA_NO_EXCEPTIONS");
|
||||
PublicDefinitions.Add("PUGIXML_NO_EXCEPTIONS");
|
||||
|
||||
if (EnableOSM2ODR)
|
||||
{
|
||||
// @TODO
|
||||
|
|
Loading…
Reference in New Issue