Skip to content

Commit

Permalink
マテリアル分けLib実装 (#221)
Browse files Browse the repository at this point in the history
* LOD4 Import 用 library update

* temp update (build error)

* temp update (crash)

* temp update (軸変換未対応)

* Lib update (座標変換)

* 動作(LOD3 Road以外)

* const value fix

* lib update (mac build)

* lib update (mac crash fixed)

* LOD3 Road

* Debug処理

* Heightmap書き換え処理変更

* Refactoring

* save aligned image for debug
set results at once

* fix for mac

* cosnt added

* lib update( align invert whiite out fix )

* type/attr convert from model

* comment removed

* comment removed

* gml id children interation

* error fix

* Terrainメッシュ化処理 (#222)

* Terrain Mesh 生成

* icon 変更

* lib update

* mac build fix

* Tab文言変更

---------

Co-authored-by: COREI5\taka <seventhdim@gmail.com>
  • Loading branch information
sevendev and seventhX authored Jul 25, 2024
1 parent 2e4ce1f commit 9006f0a
Show file tree
Hide file tree
Showing 59 changed files with 778 additions and 149 deletions.
4 changes: 2 additions & 2 deletions Content/EUW/ModelAdjustmentTab.uasset
Git LFS file not shown
4 changes: 2 additions & 2 deletions Content/EUW/ModelLandscapeTab.uasset
Git LFS file not shown
4 changes: 2 additions & 2 deletions Content/EUW/ModelReconstructSetTab.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 Expand Up @@ -383,9 +383,19 @@ void UPLATEAUCityObjectGroup::SerializeCityObject(const std::string& InNodeName,
FJsonSerializer::Serialize(JsonRootObject.ToSharedRef(), Writer);
}

void UPLATEAUCityObjectGroup::SerializeCityObject(const plateau::polygonMesh::Node& InNode, const FPLATEAUCityObject& InCityObject, const plateau::polygonMesh::MeshGranularity& Granularity) {
void UPLATEAUCityObjectGroup::SerializeCityObject(const plateau::polygonMesh::Node& InNode, const FPLATEAUCityObject& InCityObject, const plateau::granularityConvert::ConvertGranularity& Granularity) {
SetConvertGranularity(Granularity);
SerializeCityObject(InNode, InCityObject);
}

void UPLATEAUCityObjectGroup::SerializeCityObject(const plateau::polygonMesh::Node& InNode, const FPLATEAUCityObject& InCityObject, const plateau::polygonMesh::MeshGranularity& Granularity) {
SetMeshGranularity(Granularity);
SerializeCityObject(InNode, InCityObject);
}

void UPLATEAUCityObjectGroup::SerializeCityObject(const plateau::polygonMesh::Node& InNode, const FPLATEAUCityObject& InCityObject) {


const TSharedPtr<FJsonObject> JsonRootObject = MakeShareable(new FJsonObject);
// 親はなし
JsonRootObject->SetStringField(plateau::CityObjectGroup::OutsideParentFieldName, "");
Expand All @@ -407,9 +417,21 @@ void UPLATEAUCityObjectGroup::SerializeCityObject(const plateau::polygonMesh::No
FJsonSerializer::Serialize(JsonRootObject.ToSharedRef(), Writer);
}

void UPLATEAUCityObjectGroup::SerializeCityObject(const FString& InNodeName, const plateau::polygonMesh::Mesh& InMesh, const plateau::polygonMesh::MeshGranularity& Granularity, TMap<FString, FPLATEAUCityObject> CityObjMap) {

void UPLATEAUCityObjectGroup::SerializeCityObject(const FString& InNodeName, const plateau::polygonMesh::Mesh& InMesh,
const plateau::granularityConvert::ConvertGranularity& Granularity, TMap<FString, FPLATEAUCityObject> CityObjMap) {
SetConvertGranularity(Granularity);
const plateau::polygonMesh::MeshGranularity MeshGranularity = (const plateau::polygonMesh::MeshGranularity)Granularity;
SerializeCityObjectInner(InNodeName, InMesh, MeshGranularity, CityObjMap);
}
void UPLATEAUCityObjectGroup::SerializeCityObject(const FString& InNodeName, const plateau::polygonMesh::Mesh& InMesh,
const plateau::polygonMesh::MeshGranularity& Granularity, TMap<FString, FPLATEAUCityObject> CityObjMap) {
SetMeshGranularity(Granularity);
SerializeCityObjectInner(InNodeName, InMesh, Granularity, CityObjMap);
}

void UPLATEAUCityObjectGroup::SerializeCityObjectInner(const FString& InNodeName, const plateau::polygonMesh::Mesh& InMesh,
const plateau::polygonMesh::MeshGranularity& Granularity, TMap<FString, FPLATEAUCityObject> CityObjMap) {

const auto& CityObjectList = InMesh.getCityObjectList();
const std::vector<plateau::polygonMesh::CityObjectIndex> CityObjectIndices = *CityObjectList.getAllKeys();
const TSharedPtr<FJsonObject> JsonRootObject = MakeShareable(new FJsonObject);
Expand Down Expand Up @@ -592,10 +614,21 @@ TArray<FPLATEAUCityObject> UPLATEAUCityObjectGroup::GetAllRootCityObjects() {
return RootCityObjects;
}

const plateau::granularityConvert::ConvertGranularity UPLATEAUCityObjectGroup::GetConvertGranularity() {
return static_cast<plateau::granularityConvert::ConvertGranularity>(MeshGranularityIntValue);
}
/*
const plateau::polygonMesh::MeshGranularity UPLATEAUCityObjectGroup::GetMeshGranularity() {
if (MeshGranularityIntValue >= 4)
return plateau::polygonMesh::MeshGranularity::PerAtomicFeatureObject;
return static_cast<plateau::polygonMesh::MeshGranularity>(MeshGranularityIntValue);
}
*/

void UPLATEAUCityObjectGroup::SetMeshGranularity(plateau::polygonMesh::MeshGranularity Granularity) {
void UPLATEAUCityObjectGroup::SetConvertGranularity(const plateau::granularityConvert::ConvertGranularity Granularity) {
MeshGranularityIntValue = (int)Granularity;
}

void UPLATEAUCityObjectGroup::SetMeshGranularity(const plateau::polygonMesh::MeshGranularity Granularity) {
MeshGranularityIntValue = (int)Granularity;
}
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
54 changes: 33 additions & 21 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 @@ -476,7 +476,7 @@ TTask<TArray<USceneComponent*>> APLATEAUInstancedCityModel::ReconstructModel(con

UE_LOG(LogTemp, Log, TEXT("ReconstructModel: %d %d %s"), TargetComponents.Num(), static_cast<int>(ReconstructType), bDestroyOriginal ? TEXT("True") : TEXT("False"));
TTask<TArray<USceneComponent*>> ReconstructModelTask = Launch(TEXT("ReconstructModelTask"), [this, TargetComponents, ReconstructType, bDestroyOriginal] {
FPLATEAUModelReconstruct ModelReconstruct(this, FPLATEAUModelReconstruct::GetMeshGranularityFromReconstructType(ReconstructType));
FPLATEAUModelReconstruct ModelReconstruct(this, FPLATEAUModelReconstruct::GetConvertGranularityFromReconstructType(ReconstructType));
const auto& TargetCityObjects = ModelReconstruct.GetUPLATEAUCityObjectGroupsFromSceneComponents(TargetComponents);
auto Task = ReconstructTask(ModelReconstruct, TargetCityObjects, bDestroyOriginal);
AddNested(Task);
Expand Down Expand Up @@ -541,14 +541,17 @@ UE::Tasks::TTask<TArray<USceneComponent*>> APLATEAUInstancedCityModel::ClassifyT

//粒度ごとにターゲットを取得して実行
TArray<USceneComponent*> JoinedResults;
TArray<plateau::polygonMesh::MeshGranularity> GranularityList{ plateau::polygonMesh::MeshGranularity::PerAtomicFeatureObject,
plateau::polygonMesh::MeshGranularity::PerPrimaryFeatureObject ,
plateau::polygonMesh::MeshGranularity::PerCityModelArea };
TArray<ConvertGranularity> GranularityList{
ConvertGranularity::PerAtomicFeatureObject,
ConvertGranularity::PerPrimaryFeatureObject,
ConvertGranularity::PerCityModelArea,
ConvertGranularity::MaterialInPrimary
};

for (const auto& Granularity : GranularityList) {
const auto& Targets = ModelClassification.FilterComponentsByMeshGranularity(TargetCityObjects, Granularity);
const auto& Targets = ModelClassification.FilterComponentsByConvertGranularity(TargetCityObjects, Granularity);
if (Targets.Num() > 0) {
ModelClassification.SetMeshGranularity(Granularity);
ModelClassification.SetConvertGranularity(Granularity);
auto GranularityTask = ReconstructTask(ModelClassification, Targets, bDestroyOriginal);
AddNested(GranularityTask);
GranularityTask.Wait();
Expand All @@ -558,8 +561,8 @@ UE::Tasks::TTask<TArray<USceneComponent*>> APLATEAUInstancedCityModel::ClassifyT
return JoinedResults;
}
else {
const auto& MeshGranularity = FPLATEAUModelReconstruct::GetMeshGranularityFromReconstructType(ReconstructType);
ModelClassification.SetMeshGranularity(MeshGranularity);
const auto& ConvertGranularity = FPLATEAUModelReconstruct::GetConvertGranularityFromReconstructType(ReconstructType);
ModelClassification.SetConvertGranularity(ConvertGranularity);
auto Task = ReconstructTask(ModelClassification, TargetCityObjects, bDestroyOriginal);
return Task.GetResult();
}
Expand Down Expand Up @@ -614,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;
}
Loading

0 comments on commit 9006f0a

Please sign in to comment.