Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Source/StreetMapImporting/Private/StreetMapActorFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

#include "StreetMapActorFactory.h"
#include "StreetMapImporting.h"

#ifndef __has_include
#include "AssetData.h"
#else
#if __has_include("AssetData.h")
#include "AssetData.h"
#endif
#endif

#include "StreetMapActor.h"
#include "StreetMapComponent.h"
Expand Down Expand Up @@ -33,6 +40,12 @@ void UStreetMapActorFactory::PostSpawnActor(UObject* Asset, AActor* NewActor)
}
}

#if ENGINE_MAJOR_VERSION > 4 && ENGINE_MINOR_VERSION > 3
void UStreetMapActorFactory::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
unimplemented();
}
#else
void UStreetMapActorFactory::PostCreateBlueprint(UObject* Asset, AActor* CDO)
{
if (Asset != nullptr && CDO != nullptr)
Expand All @@ -43,6 +56,7 @@ void UStreetMapActorFactory::PostCreateBlueprint(UObject* Asset, AActor* CDO)
StreetMapComponent->SetStreetMap(StreetMapAsset, true, false);
}
}
#endif

bool UStreetMapActorFactory::CanCreateActorFrom(const FAssetData& AssetData, FText& OutErrorMsg)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
#include "StreetMapImporting.h"

#include "StreetMap.h"

#ifndef __has_include
#include "AssetData.h"
#else
#if __has_include("AssetData.h")
#include "AssetData.h"
#endif
#endif



#define LOCTEXT_NAMESPACE "StreetMapImporting"
Expand Down
54 changes: 45 additions & 9 deletions Source/StreetMapImporting/Private/StreetMapComponentDetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include "StreetMapComponentDetails.h"
#include "StreetMapImporting.h"



#include "SlateBasics.h"
#include "RawMesh.h"
#include "PropertyEditorModule.h"
Expand All @@ -14,16 +12,30 @@
#include "PropertyCustomizationHelpers.h"
#include "IDetailsView.h"
#include "IDetailCustomization.h"
#include "AssetRegistryModule.h"
#include "Dialogs/DlgPickAssetPath.h"
#include "IDetailCustomization.h"
#include "Widgets/Notifications/SNotificationList.h"
#include "Framework/Notifications/NotificationManager.h"
#include "Misc/AssertionMacros.h"
#include "AssetToolsModule.h"

#if ENGINE_MAJOR_VERSION < 5
#include "AssetRegistryModule.h"
#else
#include "AssetRegistry/AssetRegistryModule.h"
#endif


#include "StreetMapComponent.h"

#if ENGINE_MAJOR_VERSION > 4
using V2 = FVector2f;
using V3 = FVector3f;
#else
using V2 = FVector2D;
using V3 = FVector3D;
#endif


#define LOCTEXT_NAMESPACE "StreetMapComponentDetails"

Expand Down Expand Up @@ -242,7 +254,7 @@ FReply FStreetMapComponentDetails::OnCreateStaticMeshAssetClicked()
// Copy verts
for (int32 VertIndex = 0; VertIndex < RawMeshVertices.Num();VertIndex++)
{
RawMesh.VertexPositions.Add(RawMeshVertices[VertIndex].Position);
RawMesh.VertexPositions.Add(V3(RawMeshVertices[VertIndex].Position));
}

// Copy 'wedge' info
Expand All @@ -255,15 +267,15 @@ FReply FStreetMapComponentDetails::OnCreateStaticMeshAssetClicked()

const FStreetMapVertex& StreetMapVertex = RawMeshVertices[VertexIndex];

FVector TangentX = StreetMapVertex.TangentX;
FVector TangentZ = StreetMapVertex.TangentZ;
FVector TangentY = (TangentX ^ TangentZ).GetSafeNormal();
auto TangentX = V3(StreetMapVertex.TangentX);
auto TangentZ = V3(StreetMapVertex.TangentZ);
auto TangentY = V3((TangentX ^ TangentZ).GetSafeNormal());

RawMesh.WedgeTangentX.Add(TangentX);
RawMesh.WedgeTangentY.Add(TangentY);
RawMesh.WedgeTangentZ.Add(TangentZ);

RawMesh.WedgeTexCoords[0].Add(StreetMapVertex.TextureCoordinate);
RawMesh.WedgeTexCoords[0].Add(V2(StreetMapVertex.TextureCoordinate));
RawMesh.WedgeColors.Add(StreetMapVertex.Color);
}

Expand All @@ -279,17 +291,29 @@ FReply FStreetMapComponentDetails::OnCreateStaticMeshAssetClicked()
if (RawMesh.VertexPositions.Num() > 3 && RawMesh.WedgeIndices.Num() > 3)
{
// Then find/create it.
#if ENGINE_MAJOR_VERSION < 5
UPackage* Package = CreatePackage(NULL, *UserPackageName);
#else
UPackage* Package = CreatePackage(*UserPackageName);
#endif
check(Package);

// Create StaticMesh object
UStaticMesh* StaticMesh = NewObject<UStaticMesh>(Package, MeshName, RF_Public | RF_Standalone);
StaticMesh->InitResources();

#if ENGINE_MAJOR_VERSION < 5
StaticMesh->LightingGuid = FGuid::NewGuid();
#else
StaticMesh->SetLightingGuid(FGuid::NewGuid());
#endif

// Add source to new StaticMesh
#if ENGINE_MAJOR_VERSION < 5
FStaticMeshSourceModel* SrcModel = new (StaticMesh->SourceModels) FStaticMeshSourceModel();
#else
FStaticMeshSourceModel* SrcModel = &StaticMesh->AddSourceModel();
#endif
SrcModel->BuildSettings.bRecomputeNormals = false;
SrcModel->BuildSettings.bRecomputeTangents = false;
SrcModel->BuildSettings.bRemoveDegenerates = false;
Expand All @@ -303,7 +327,11 @@ FReply FStreetMapComponentDetails::OnCreateStaticMeshAssetClicked()
// Copy materials to new mesh
for (UMaterialInterface* Material : MeshMaterials)
{
#if ENGINE_MAJOR_VERSION < 5
StaticMesh->StaticMaterials.Add(FStaticMaterial(Material));
#else
StaticMesh->GetStaticMaterials().Add(FStaticMaterial(Material));
#endif
}

//Set the Imported version before calling the build
Expand All @@ -325,7 +353,15 @@ FReply FStreetMapComponentDetails::OnCreateStaticMeshAssetClicked()
FNotificationInfo Info(FText::Format(LOCTEXT("StreetMapMeshConverted", "Successfully Converted Mesh"), FText::FromString(StaticMesh->GetName())));
Info.ExpireDuration = 8.0f;
Info.bUseLargeFont = false;
Info.Hyperlink = FSimpleDelegate::CreateLambda([=]() { FAssetEditorManager::Get().OpenEditorForAssets(TArray<UObject*>({ StaticMesh })); });
Info.Hyperlink = FSimpleDelegate::CreateLambda([=]()
{
#if ENGINE_MAJOR_VERSION < 5
FAssetEditorManager::Get().OpenEditorForAssets(TArray<UObject*>({ StaticMesh }));
#else
GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->OpenEditorForAssets(
TArray<UObject*>({ StaticMesh }));
#endif
});
Info.HyperlinkText = FText::Format(LOCTEXT("OpenNewAnimationHyperlink", "Open {0}"), FText::FromString(StaticMesh->GetName()));
TSharedPtr<SNotificationItem> Notification = FSlateNotificationManager::Get().AddNotification(Info);
if (Notification.IsValid())
Expand Down
4 changes: 4 additions & 0 deletions Source/StreetMapImporting/Private/StreetMapFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ UObject* UStreetMapFactory::FactoryCreateText( UClass* Class, UObject* Parent, F

if( !bLoadedOkay )
{
#if ENGINE_MAJOR_VERSION < 5
StreetMap->MarkPendingKill();
#else
StreetMap->MarkAsGarbage();
#endif
StreetMap = nullptr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
#include "StreetMapImportBlueprintLibrary.h"
#include "StreetMapFactory.h"
#include "StreetMap.h"
#include "StreetMapImporting.h"
#include "Engine/AssetManager.h"
#include "AssetToolsModule.h"
#include "IAssetTools.h"

#if ENGINE_MAJOR_VERSION > 4
#include "AssetRegistry/IAssetRegistry.h"
#else
#include "AssetData.h"
#endif

UStreetMap* UStreetMapImportBlueprintLibrary::ImportStreetMap(FString Path, FString DestinationAssetPath, FVector2D OriginLatLon)
{
Expand All @@ -23,7 +31,8 @@ UStreetMap* UStreetMapImportBlueprintLibrary::ImportStreetMap(FString Path, FStr

FString FileName = FPaths::GetCleanFilename(Path);
FileName.RemoveFromEnd(".osm");
if( AssetRegistry.GetAssetsByClass(TEXT("StreetMap"), AssetData, false) ) {
FTopLevelAssetPath AssetClassPath = FTopLevelAssetPath(FName("/Script/StreetMapRuntime"), FName("StreetMap"));
if(AssetRegistry.GetAssetsByClass(AssetClassPath, AssetData, false)) {
for( auto Asset : AssetData ){
UE_LOG(LogStreetMapImporting, Log, TEXT("FileName %s, AssetName %s ."), *FileName,*(Asset.AssetName.ToString() ) );
if( FileName.Equals( Asset.AssetName.ToString() ) ){
Expand Down
6 changes: 5 additions & 1 deletion Source/StreetMapImporting/Public/StreetMapActorFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class UStreetMapActorFactory : public UActorFactory

//~ Begin UActorFactory Interface
virtual void PostSpawnActor(UObject* Asset, AActor* NewActor) override;
virtual void PostCreateBlueprint(UObject* Asset, AActor* CDO) override;
#if ENGINE_MAJOR_VERSION > 4 && ENGINE_MINOR_VERSION > 3
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
#else
virtual void PostCreateBlueprint(UObject* Asset, AActor* CDO) override;
#endif
virtual bool CanCreateActorFrom(const FAssetData& AssetData, FText& OutErrorMsg) override;
//~ End UActorFactory Interface
};
4 changes: 2 additions & 2 deletions Source/StreetMapImporting/StreetMapImporting.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public StreetMapImporting(ReadOnlyTargetRules Target)
: base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicDependencyModuleNames.AddRange(new string[] { "CarlaMeshGeneration" });
PrivateDependencyModuleNames.AddRange(
new string[] {
"Core",
Expand All @@ -34,7 +34,7 @@ public StreetMapImporting(ReadOnlyTargetRules Target)
}
);

PrivateIncludePaths.AddRange(new string[]{"StreetMapImporting/Private"});
PrivateIncludePaths.AddRange(new string[]{"StreetMapImporting/Private" });
}
}
}
14 changes: 10 additions & 4 deletions Source/StreetMapRuntime/Private/PolygonTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
#include "PolygonTools.h"
#include "StreetMapRuntime.h"
#include "CompGeom/PolygonTriangulation.h"

#if ENGINE_MAJOR_VERSION > 4
#include "IndexTypes.h"
using UE::Geometry::FIndex3i;
using V2 = FVector2f;
#else
using V2 = FVector2D;
#endif

// Based off "Efficient Polygon Triangulation" algorithm by John W. Ratcliff (http://flipcode.net/archives/Efficient_Polygon_Triangulation.shtml)
bool FPolygonTools::TriangulatePolygon( const TArray<FVector2D>& Polygon, TArray<int32>& TempIndices, TArray<int32>& TriangulatedIndices, bool& OutWindsClockwise )
Expand Down Expand Up @@ -38,20 +44,20 @@ bool FPolygonTools::TriangulatePolygon( const TArray<FVector2D>& Polygon, TArray
VertexIndices[ PointIndex ] = ( NumVertices - 1 ) - PointIndex;
}
}
TArray<FVector2<float>> InputVertices;
TArray<V2> InputVertices;
TArray<FIndex3i> OutTriangles;
if(OutWindsClockwise){
for( int32 PointIndex = 0; PointIndex < NumVertices; PointIndex++ )
{
InputVertices.Add(FVector2<float>(Polygon[PointIndex].X, Polygon[PointIndex].Y));
InputVertices.Add(V2(Polygon[PointIndex].X, Polygon[PointIndex].Y));
}
}
else
{
for( int32 PointIndex = 0; PointIndex < NumVertices; PointIndex++ )
{
int RealIndex = ( NumVertices - 1 ) - PointIndex;
InputVertices.Add(FVector2<float>(Polygon[RealIndex].X, Polygon[RealIndex].Y));
InputVertices.Add(V2(Polygon[RealIndex].X, Polygon[RealIndex].Y));
}
}

Expand Down
19 changes: 15 additions & 4 deletions Source/StreetMapRuntime/Private/StreetMapComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,25 @@

#include "PhysicsEngine/BodySetup.h"
#include "ProceduralMeshComponent.h"
#include "Carla/OpenDrive/OpenDriveGenerator.h"
#include "Carla/BlueprintLibary/MapGenFunctionLibrary.h"

#include "Generation/MapGenFunctionLibrary.h"


#if WITH_EDITOR
#include "Modules/ModuleManager.h"
#include "PropertyEditorModule.h"
#endif //WITH_EDITOR

#if ENGINE_MAJOR_VERSION > 4
#include "IndexTypes.h"
using UE::Geometry::FIndex3i;
using V3 = FVector3f;
using V2 = FVector2f;
#else
using V3 = FVector;
using V2 = FVector2D;
#endif

DEFINE_LOG_CATEGORY(LogNoriega);

UStreetMapComponent::UStreetMapComponent(const FObjectInitializer& ObjectInitializer)
Expand Down Expand Up @@ -107,7 +118,7 @@ bool UStreetMapComponent::GetPhysicsTriMeshData(struct FTriMeshCollisionData* Co

for (int32 VertexIndex = 0; VertexIndex < NumVertices; VertexIndex++)
{
CollisionData->Vertices[VertexIndex] = Vertices[VertexIndex].Position;
CollisionData->Vertices[VertexIndex] = V3(Vertices[VertexIndex].Position);
}

// Copy indices data
Expand Down Expand Up @@ -704,7 +715,7 @@ AActor* UStreetMapComponent::GenerateTopOfBuilding(int Index, FString MapName, U
TempPoints[ PointIndex ] = FVector( Building.BuildingPoints[ ( Building.BuildingPoints.Num() - PointIndex ) - 1 ], BuildingFillZ );
}

if(WindsClockwise){
if(!WindsClockwise){
for( int32 PointIndex = 0; PointIndex < Building.BuildingPoints.Num(); PointIndex++ )
{
BPositions.Add( FVector(Building.BuildingPoints[PointIndex], BuildingFillZ) );
Expand Down
37 changes: 32 additions & 5 deletions Source/StreetMapRuntime/Private/StreetMapSceneProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
#include "Runtime/Renderer/Public/MeshPassProcessor.h"
#include "Runtime/Renderer/Public/PrimitiveSceneInfo.h"

#if ENGINE_MAJOR_VERSION < 5
using V2 = FVector2D;
using V3 = FVector;
#else
#include "Materials/MaterialRenderProxy.h"
using V2 = FVector2f;
using V3 = FVector3f;
#endif

FStreetMapSceneProxy::FStreetMapSceneProxy(const UStreetMapComponent* InComponent)
: FPrimitiveSceneProxy(InComponent),
Expand Down Expand Up @@ -35,11 +43,11 @@ void FStreetMapSceneProxy::Init(const UStreetMapComponent* InComponent, const TA
{
const FStreetMapVertex& StreetMapVert = Vertices[VertIdx];
FDynamicMeshVertex& Vert = DynamicVertices[VertIdx];
Vert.Position = StreetMapVert.Position;
Vert.Position = V3(StreetMapVert.Position);
Vert.Color = StreetMapVert.Color;
Vert.TextureCoordinate[0] = StreetMapVert.TextureCoordinate;
Vert.TangentX = StreetMapVert.TangentX;
Vert.TangentZ = StreetMapVert.TangentZ;
Vert.TextureCoordinate[0] = V2(StreetMapVert.TextureCoordinate);
Vert.TangentX = V3(StreetMapVert.TangentX);
Vert.TangentZ = V3(StreetMapVert.TangentZ);
}

VertexBuffer.InitFromDynamicVertex(&VertexFactory, DynamicVertices);
Expand Down Expand Up @@ -152,7 +160,26 @@ void FStreetMapSceneProxy::MakeMeshBatch( FMeshBatch& Mesh, class FMeshElementCo
// BatchElement.PrimitiveUniformBuffer = CreatePrimitiveUniformBufferImmediate(GetLocalToWorld(), GetBounds(), GetLocalBounds(), true, UseEditorDepthTest());

FDynamicPrimitiveUniformBuffer& DynamicPrimitiveUniformBuffer = Collector.AllocateOneFrameResource<FDynamicPrimitiveUniformBuffer>();
DynamicPrimitiveUniformBuffer.Set(GetLocalToWorld(), GetLocalToWorld(), GetBounds(), GetLocalBounds(), true, false, DrawsVelocity(), false);
#if ENGINE_MAJOR_VERSION < 5
DynamicPrimitiveUniformBuffer.Set(
GetLocalToWorld(),
GetLocalToWorld(),
GetBounds(),
GetLocalBounds(),
true,
false,
DrawsVelocity(),
false);
#else
DynamicPrimitiveUniformBuffer.Set(
GetLocalToWorld(),
GetLocalToWorld(),
GetBounds(),
GetLocalBounds(),
true,
false,
DrawsVelocity());
#endif
BatchElement.PrimitiveUniformBufferResource = &DynamicPrimitiveUniformBuffer.UniformBuffer;

BatchElement.FirstIndex = 0;
Expand Down
Loading