Skip to content

Commit

Permalink
Terrainメッシュ化処理 (#222)
Browse files Browse the repository at this point in the history
* Terrain Mesh 生成

* icon 変更

* lib update

* mac build fix
  • Loading branch information
sevendev authored Jul 25, 2024
1 parent 4c0ec1c commit 6a11444
Show file tree
Hide file tree
Showing 40 changed files with 438 additions and 64 deletions.
4 changes: 2 additions & 2 deletions Content/EUW/ModelLandscapeTab.uasset
Git LFS file not shown
4 changes: 2 additions & 2 deletions Content/dark_icon_adjust.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Content/dark_icon_adjust.uasset
Git LFS file not shown
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright © 2023 Ministry of Land, Infrastructure and Transport
#include "PLATEAUCityObjectGroupDetails.h"
#include "PLATEAUCityObjectGroup.h"
#include "Component/PLATEAUCityObjectGroup.h"
#include "SlateOptMacros.h"
#include "DetailLayoutBuilder.h"
#include "Widgets/Input/SNumericEntryBox.h"
Expand Down
2 changes: 1 addition & 1 deletion Source/PLATEAUEditor/Private/PLATEAUEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "PLATEAUEditor.h"
#include "PLATEAUCityModelLoader.h"
#include "PLATEAUCityObjectGroup.h"
#include "Component/PLATEAUCityObjectGroup.h"
#include "PLATEAUCityObjectGroupDetails.h"
#include "PLATEAUInstancedCityModel.h"
#include "PLATEAUEditorStyle.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2023 Ministry of Land, Infrastructure and Transport

#include "AttrInfo/PLATEAUAttrInfoDrawGizmo.h"
#include "PLATEAUCityObjectGroup.h"
#include "Component/PLATEAUCityObjectGroup.h"
#include "MeshDescription.h"
#include "Components/LineBatchComponent.h"
#include "Kismet/KismetMathLibrary.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright © 2023 Ministry of Land, Infrastructure and Transport
#include "CityGML/PLATEAUAttributeValue.h"
#include "PLATEAUCityObjectGroup.h"
#include "Component/PLATEAUCityObjectGroup.h"

namespace {
constexpr TCHAR EPLATEAUAttributeTypePath[] = TEXT("/Script/PLATEAURuntime.EPLATEAUAttributeType");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 Ministry of Land, Infrastructure and Transport
#include "PLATEAUCityObjectGroup.h"
#include "Component/PLATEAUCityObjectGroup.h"
#include "PLATEAUMeshExporter.h"
#include "PLATEAUCityModelLoader.h"
#include "CityGML/PLATEAUCityObject.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023 Ministry of Land, Infrastructure and Transport


#include "Component/PLATEAULandscapeRefComponent.h"

UPLATEAULandscapeRefComponent::UPLATEAULandscapeRefComponent()
{
PrimaryComponentTick.bCanEverTick = true;
}

void UPLATEAULandscapeRefComponent::BeginPlay()
{
Super::BeginPlay();
}

void UPLATEAULandscapeRefComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023 Ministry of Land, Infrastructure and Transport


#include "PLATEAUSceneComponent.h"
#include "Component/PLATEAUSceneComponent.h"

UPLATEAUSceneComponent::UPLATEAUSceneComponent()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 Ministry of Land, Infrastructure and Transport


#include "PLATEAUStaticMeshComponent.h"
#include "Component/PLATEAUStaticMeshComponent.h"

4 changes: 2 additions & 2 deletions Source/PLATEAURuntime/Private/PLATEAUCityModelLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include "PLATEAUMeshLoader.h"
#include "citygml/citygml.h"
#include "Kismet/GameplayStatics.h"
#include <Reconstruct/PLATEAUMeshLoaderForLandscape.h>
#include <PLATEAUSceneComponent.h>
#include "Reconstruct/PLATEAUMeshLoaderForLandscape.h"
#include "Component/PLATEAUSceneComponent.h"


#define LOCTEXT_NAMESPACE "PLATEAUCityModelLoader"
Expand Down
35 changes: 22 additions & 13 deletions Source/PLATEAURuntime/Private/PLATEAUInstancedCityModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <Reconstruct/PLATEAUModelClassificationByType.h>
#include <Reconstruct/PLATEAUModelClassificationByAttribute.h>
#include <Reconstruct/PLATEAUModelLandscape.h>
#include <Reconstruct/PLATEAUMeshLoaderForLandscape.h>
#include <Reconstruct/PLATEAUMeshLoaderForLandscapeMesh.h>
#include <Reconstruct/PLATEAUModelAlignLand.h>
#include "Tasks/Pipe.h"

Expand Down Expand Up @@ -617,24 +617,33 @@ UE::Tasks::FTask APLATEAUInstancedCityModel::CreateLandscape(const TArray<UScene
}

for (const auto Result : Results) {
//Landscape生成
if (Param.CreateLandscape) {
TArray<uint16> HeightData(Result.Data->data(), Result.Data->size());
//LandScape
FFunctionGraphTask::CreateAndDispatchWhenReady(
[&, HeightData, Result, Param] {
Landscape.CreateLandScape(GetWorld(), Param.NumSubsections, Param.SubsectionSizeQuads,
Param.ComponentCountX, Param.ComponentCountY,
Param.TextureWidth, Param.TextureHeight,
Result.Min, Result.Max, Result.MinUV, Result.MaxUV, Result.TexturePath, HeightData, Result.NodeName);
}, TStatId(), nullptr, ENamedThreads::GameThread)->Wait();
// 平滑化Mesh / Landscape生成
if (Param.ConvertTerrain) {
if (!Param.ConvertToLandscape) {
//平滑化Mesh生成
FPLATEAUMeshLoaderForLandscapeMesh MeshLoader;
MeshLoader.CreateMeshFromHeightMap(*this, Param.TextureWidth, Param.TextureHeight, Result.Min, Result.Max, Result.MinUV, Result.MaxUV, Result.Data->data(), Result.NodeName);
}
else {
//Landscape生成
TArray<uint16> HeightData(Result.Data->data(), Result.Data->size());
//LandScape
FFunctionGraphTask::CreateAndDispatchWhenReady(
[&, HeightData, Result, Param ] {
auto LandActor = Landscape.CreateLandScape(GetWorld(), Param.NumSubsections, Param.SubsectionSizeQuads,
Param.ComponentCountX, Param.ComponentCountY,
Param.TextureWidth, Param.TextureHeight,
Result.Min, Result.Max, Result.MinUV, Result.MaxUV, Result.TexturePath, HeightData, Result.NodeName);
Landscape.CreateLandScapeReference(LandActor, this, Result.NodeName);
}, TStatId(), nullptr, ENamedThreads::GameThread)->Wait();
}
}
}

FFunctionGraphTask::CreateAndDispatchWhenReady([&, TargetCityObjects, bDestroyOriginal, Results]() {

// Landscape コンポーネント削除
if (Param.CreateLandscape)
if (Param.ConvertTerrain)
DestroyOrHideComponents(TargetCityObjects, bDestroyOriginal);

//終了イベント通知
Expand Down
18 changes: 13 additions & 5 deletions Source/PLATEAURuntime/Private/PLATEAUMeshLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#include "StaticMeshResources.h"
#include "MeshElementRemappings.h"
#include "PLATEAUCityModelLoader.h"
#include "PLATEAUCityObjectGroup.h"
#include "Component/PLATEAUCityObjectGroup.h"
#include "PLATEAUInstancedCityModel.h"
#include "StaticMeshAttributes.h"
#include "Materials/Material.h"
#include "Materials/MaterialInstanceDynamic.h"
#include "PLATEAUStaticMeshComponent.h"
#include "Component/PLATEAUStaticMeshComponent.h"

#if WITH_EDITOR
#include "EditorFramework/AssetImportData.h"
Expand Down Expand Up @@ -126,7 +126,7 @@ namespace {
}

bool ConvertMesh(const plateau::polygonMesh::Mesh& InMesh, FMeshDescription& OutMeshDescription,
TArray<FSubMeshMaterialSet>& SubMeshMaterialSets, bool InvertNormal) {
TArray<FSubMeshMaterialSet>& SubMeshMaterialSets, bool InvertNormal, bool MergeTriangles) {
FStaticMeshAttributes Attributes(OutMeshDescription);

// UVチャンネル数を3に設定
Expand Down Expand Up @@ -202,7 +202,7 @@ namespace {
auto VertexID = InIndices[InIndexIndex];

// 頂点が使用済みの場合は複製
if (UsedVertexIDs.Contains(VertexID)) {
if (UsedVertexIDs.Contains(VertexID) && !MergeTriangles) {
const auto NewVertexID = OutMeshDescription.CreateVertex();
VertexPositions[NewVertexID] = VertexPositions[VertexID];
VertexID = NewVertexID;
Expand Down Expand Up @@ -376,7 +376,8 @@ UStaticMeshComponent* FPLATEAUMeshLoader::CreateStaticMeshComponent(AActor& Acto
}, TStatId(), nullptr, ENamedThreads::GameThread)->Wait();
}

ConvertMesh(InMesh, *MeshDescription, SubMeshMaterialSets, InvertMeshNormal());
ConvertMesh(InMesh, *MeshDescription, SubMeshMaterialSets, InvertMeshNormal(), MergeTriangles());
ModifyMeshDescription(*MeshDescription);

#if WITH_EDITOR
FFunctionGraphTask::CreateAndDispatchWhenReady(
Expand Down Expand Up @@ -625,6 +626,9 @@ USceneComponent* FPLATEAUMeshLoader::LoadNode(USceneComponent* ParentComponent,
Node.getName());
}

void FPLATEAUMeshLoader::ModifyMeshDescription(FMeshDescription& MeshDescription) {
}

TArray<USceneComponent*> FPLATEAUMeshLoader::GetLastCreatedComponents() {
return LastCreatedComponents;
}
Expand All @@ -637,6 +641,10 @@ bool FPLATEAUMeshLoader::InvertMeshNormal() {
return true;
}

bool FPLATEAUMeshLoader::MergeTriangles() {
return false;
}

bool FPLATEAUMeshLoader::OverwriteTexture() {
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@

#include "Reconstruct/PLATEAUMeshLoaderCloneComponent.h"
#include "PLATEAUCityModelLoader.h"
#include "PLATEAUCityObjectGroup.h"
#include "Component/PLATEAUCityObjectGroup.h"
#include "PLATEAUInstancedCityModel.h"
#include "MeshDescription.h"
#include "StaticMeshOperations.h"
#include "StaticMeshAttributes.h"

FPLATEAUMeshLoaderCloneComponent::FPLATEAUMeshLoaderCloneComponent() {}

FPLATEAUMeshLoaderCloneComponent::FPLATEAUMeshLoaderCloneComponent(const bool InbAutomationTest){
bAutomationTest = InbAutomationTest;
}

void FPLATEAUMeshLoaderCloneComponent::SetSmoothing(bool bSmooth) {
IsSmooth = bSmooth;
}

TMap<FString, UPLATEAUCityObjectGroup*> FPLATEAUMeshLoaderCloneComponent::CreateComponentsMap(const TArray<UPLATEAUCityObjectGroup*> TargetCityObjects) {
TMap<FString, UPLATEAUCityObjectGroup*> Map;
for (auto Comp : TargetCityObjects) {
Expand Down Expand Up @@ -102,3 +109,22 @@ USceneComponent* FPLATEAUMeshLoaderCloneComponent::ReloadNode(USceneComponent* P
return nullptr;
}

bool FPLATEAUMeshLoaderCloneComponent::MergeTriangles() {
return IsSmooth;
}

void FPLATEAUMeshLoaderCloneComponent::ModifyMeshDescription(FMeshDescription& MeshDescription) {

if (!IsSmooth) return;

FStaticMeshOperations::DetermineEdgeHardnessesFromVertexInstanceNormals(MeshDescription);

TEdgeAttributesRef<bool> EdgeHardness =
MeshDescription.EdgeAttributes().GetAttributesRef<bool>(MeshAttribute::Edge::IsHard);
for (FEdgeID EdgeID : MeshDescription.Edges().GetElementIDs()) {
EdgeHardness.Set(EdgeID, 0, false);
}

FStaticMeshOperations::ComputeTriangleTangentsAndNormals(MeshDescription, FMathf::Epsilon);
FStaticMeshOperations::RecomputeNormalsAndTangentsIfNeeded(MeshDescription, EComputeNTBsFlags::WeightedNTBs | EComputeNTBsFlags::Normals | EComputeNTBsFlags::Tangents | EComputeNTBsFlags::BlendOverlappingNormals);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "Reconstruct/PLATEAUMeshLoaderForClassification.h"
#include "PLATEAUMeshLoader.h"
#include "PLATEAUCityObjectGroup.h"
#include "Component/PLATEAUCityObjectGroup.h"

FPLATEAUMeshLoaderForClassification::FPLATEAUMeshLoaderForClassification(const TMap<int, UMaterialInterface*> Materials) {
ClassificationMaterials = Materials;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@

#include "Reconstruct/PLATEAUMeshLoaderForLandscape.h"
#include "PLATEAUCityModelLoader.h"
#include "PLATEAUCityObjectGroup.h"
#include "Component/PLATEAUCityObjectGroup.h"
#include "plateau/polygon_mesh/mesh_extractor.h"
#include <plateau/height_map_generator/heightmap_generator.h>
#include "plateau/height_map_generator/heightmap_mesh_generator.h"
#include "MeshDescription.h"
#include "StaticMeshOperations.h"
#include "StaticMeshAttributes.h"
#include "Component/PLATEAULandscapeRefComponent.h"
#include "Landscape.h"


FPLATEAUMeshLoaderForLandscape::FPLATEAUMeshLoaderForLandscape() {}

Expand Down Expand Up @@ -86,6 +93,60 @@ HeightmapCreationResult FPLATEAUMeshLoaderForLandscape::CreateHeightMapFromMesh(
return Result;
}

bool FPLATEAUMeshLoaderForLandscape::OverwriteTexture() {
return false;

void FPLATEAUMeshLoaderForLandscape::CreateReference(ALandscape* Landscape, AActor* Actor, const FString NodeName) {
const FString ReplacedNodeName = NodeName.Replace(*FString("Mesh_"), *FString()); //Mesh Prefix ����
auto OriginalComponent = GetOriginalComponent(Actor, ReplacedNodeName);
if (OriginalComponent) {
const auto& OriginalParentComponent = OriginalComponent->GetAttachParent();
auto RefComponent = (UPLATEAULandscapeRefComponent*)Actor->AddComponentByClass(UPLATEAULandscapeRefComponent::StaticClass(), false, FTransform(), false);

// Original�R���|�[�l���g�̑�������̂܂ܗ��p
if (OriginalComponent) {
RefComponent->SerializedCityObjects = OriginalComponent->SerializedCityObjects;
RefComponent->OutsideChildren = OriginalComponent->OutsideChildren;
RefComponent->OutsideParent = OriginalComponent->OutsideParent;
RefComponent->MeshGranularityIntValue = OriginalComponent->MeshGranularityIntValue;
}

RefComponent->LandscapeReference = Landscape;
RefComponent->SetMobility(EComponentMobility::Type::Static);

auto NewName = "Ref_" + NodeName;
RefComponent->Rename(*NewName, nullptr, REN_DontCreateRedirectors);
Actor->AddInstanceComponent(RefComponent);
RefComponent->RegisterComponent();
RefComponent->AttachToComponent(OriginalParentComponent, FAttachmentTransformRules::KeepWorldTransform);

#if WITH_EDITOR
RefComponent->PostEditChange();
#endif
}
}

TArray<USceneComponent*> FPLATEAUMeshLoaderForLandscape::FindComponentsByName(const AActor* ModelActor, const FString Name) {
const FRegexPattern pattern = FRegexPattern(FString::Format(*FString(TEXT("^{0}__([0-9]+)")), { Name }));
TArray<USceneComponent*> Result;
const auto Components = ModelActor->GetComponents();
for (auto Component : Components) {
if (Component->IsA<USceneComponent>()) {
FRegexMatcher matcher(pattern, Component->GetName());
if (matcher.FindNext()) {
Result.Add((USceneComponent*)Component);
}
}
}
return Result;
}

UPLATEAUCityObjectGroup* FPLATEAUMeshLoaderForLandscape::GetOriginalComponent(const AActor* ModelActor, const FString Name) {
const auto BaseComponents = FindComponentsByName(ModelActor, Name);
if (BaseComponents.Num() > 0) {
UPLATEAUCityObjectGroup* FoundItem;
int32 ItemIndex;
if (BaseComponents.FindItemByClass<UPLATEAUCityObjectGroup>(&FoundItem, &ItemIndex)) {
return FoundItem;
}
}
return nullptr;
}
Loading

0 comments on commit 6a11444

Please sign in to comment.