Commit 6c3f8ba7 by Kai Westerkamp

compile and execute

parent e838ab2a
{
"Changelist" : 3013449,
"BuildId" : "521bff43-3bc1-4230-8558-29af88fc728e",
"Changelist" : 3249277,
"CompatibleChangelist" : 3195953,
"BuildId" : "afcfff98-97a3-4269-9c38-2ec2156cd5a3",
"Modules" :
{
"GLTFLoader" : "UE4Editor-GLTFLoader.dll"
......
......@@ -32,7 +32,7 @@ UGLTFFactory::UGLTFFactory(const FObjectInitializer& ObjectInitializer)
bDetectImportTypeOnImport = false;
}
//This function is adapted from UFbxFactory::CreateBinary()
//This function is adapted from ::CreateBinary()
UObject* UGLTFFactory::FactoryCreateBinary
(
UClass* Class,
......@@ -123,7 +123,7 @@ UObject* UGLTFFactory::FactoryCreateBinary
int32 NodeIndex = 0;
int32 ImportedMeshCount = 0;
UStaticMesh* NewStaticMesh = NULL;
UStaticMeshComponent* NewStaticMesh = NULL;
if (bCombineMeshes)
{
......
......@@ -216,7 +216,8 @@ TSharedRef<SDockTab> FGLTFLoaderModule::OnSpawnPluginTab(const FSpawnTabArgs& Sp
void FGLTFLoaderModule::OpenImportWindow()
{
TArray<FString> Filenames;
/*
//TArray<FString> Filenames;
if (FDesktopPlatformModule::Get()->OpenFileDialog(nullptr,
TEXT("Choose a GLTF file to import"),
......@@ -230,11 +231,14 @@ void FGLTFLoaderModule::OpenImportWindow()
{
UE_LOG(LogTemp, Log, TEXT("File: %s"), *File);
}
*/
FAssetToolsModule& AssetToolsModule = FModuleManager::Get().LoadModuleChecked<FAssetToolsModule>("AssetTools");
TArray<FString> Filenames;
Filenames.Add("D:/Dropbox/Studium/MasterArbeit/glTF-Sample-Models/1.0/Box/glTF/Box.gltf");
AssetToolsModule.Get().ImportAssets(Filenames, FString("/Game/Content"));
}
//}
}
void FGLTFLoaderModule::PluginButtonClicked()
......
......@@ -317,7 +317,7 @@ TArray<FString> GLTFMeshBuilder::GetMeshNames(FString NodeName, bool GetChildren
return MeshNameArray;
}
UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray<FString>& MeshNameArray, const FName InName, EObjectFlags Flags, UStaticMesh* InStaticMesh)
UStaticMeshComponent* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray<FString>& MeshNameArray, const FName InName, EObjectFlags Flags, UStaticMeshComponent* InStaticMesh)
{
auto ImportOptions = FGLTFLoaderModule::ImportOptions;
......@@ -341,9 +341,9 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
UPackage* Package = NULL;
// create empty mesh
UStaticMesh* StaticMesh = NULL;
UStaticMeshComponent* StaticMeshComponent = NULL;
UStaticMesh* ExistingMesh = NULL;
UStaticMeshComponent* ExistingMesh = NULL;
UObject* ExistingObject = NULL;
// A mapping of vertex positions to their color in the existing static mesh
......@@ -358,7 +358,7 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
NewPackageName = PackageTools::SanitizePackageName(NewPackageName);
Package = CreatePackage(NULL, *NewPackageName);
ExistingMesh = FindObject<UStaticMesh>( Package, *MeshName );
ExistingMesh = FindObject<UStaticMeshComponent>( Package, *MeshName );
ExistingObject = FindObject<UObject>( Package, *MeshName );
}
......@@ -395,24 +395,35 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
if( InStaticMesh != NULL && LODIndex > 0 )
{
StaticMesh = InStaticMesh;
StaticMeshComponent = InStaticMesh;
}
else
{
StaticMesh = NewObject<UStaticMesh>(Package, FName(*MeshName), Flags | RF_Public);
StaticMeshComponent = NewObject<UStaticMeshComponent>(Package, FName(*MeshName), Flags | RF_Public);
}
if (StaticMesh->SourceModels.Num() < LODIndex+1)
verify(StaticMeshComponent != NULL);
if (StaticMeshComponent->GetStaticMesh() == NULL ) {
UStaticMesh *mesh = NewObject<UStaticMesh>(Package);
StaticMeshComponent->SetStaticMesh(mesh);
}
verify(StaticMeshComponent->GetStaticMesh() != NULL);
if (StaticMeshComponent->GetStaticMesh()->SourceModels.Num() < LODIndex+1)
{
// Add one LOD
new(StaticMesh->SourceModels) FStaticMeshSourceModel();
//StaticMeshComponent->GetStaticMesh()->SourceModels.AddUninitialized();
//StaticMeshComponent->GetStaticMesh()->SourceModels = new FStaticMeshSourceModel();
new(StaticMeshComponent->GetStaticMesh()->SourceModels) FStaticMeshSourceModel();
if (StaticMesh->SourceModels.Num() < LODIndex+1)
if (StaticMeshComponent->GetStaticMesh()->SourceModels.Num() < LODIndex+1)
{
LODIndex = StaticMesh->SourceModels.Num() - 1;
LODIndex = StaticMeshComponent->GetStaticMesh()->SourceModels.Num() - 1;
}
}
FStaticMeshSourceModel& SrcModel = StaticMesh->SourceModels[LODIndex];
FStaticMeshSourceModel& SrcModel = StaticMeshComponent->GetStaticMesh()->SourceModels[LODIndex];
if( InStaticMesh != NULL && LODIndex > 0 && !SrcModel.RawMeshBulkData->IsEmpty() )
{
// clear out the old mesh data
......@@ -421,17 +432,20 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
}
// make sure it has a new lighting guid
StaticMesh->LightingGuid = FGuid::NewGuid();
StaticMeshComponent->GetStaticMesh()->LightingGuid = FGuid::NewGuid();
// Set it to use textured lightmaps. Note that Build Lighting will do the error-checking (texcoordindex exists for all LODs, etc).
StaticMesh->LightMapResolution = 64;
StaticMesh->LightMapCoordinateIndex = 1;
StaticMeshComponent->GetStaticMesh()->LightMapResolution = 64;
StaticMeshComponent->GetStaticMesh()->LightMapCoordinateIndex = 1;
FRawMesh NewRawMesh;
SrcModel.RawMeshBulkData->LoadRawMesh(NewRawMesh);
for (auto Name : MeshNameArray)
//for (FString Name : MeshNameArray)
for(int i = 0; i < MeshNameArray.Num(); i++)
{
FString Name = MeshNameArray[i];
tinygltf::Mesh* Mesh = &Scene->meshes[ToStdString(Name)];
if (Mesh)
......@@ -443,13 +457,13 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
}
}
for (auto Name : MeshNameArray)
for (FString Name : MeshNameArray)
{
tinygltf::Mesh* Mesh = &Scene->meshes[ToStdString(Name)];
if (Mesh)
{
if (!BuildStaticMeshFromGeometry(Mesh, StaticMesh, LODIndex, NewRawMesh))
if (!BuildStaticMeshFromGeometry(Mesh, StaticMeshComponent, LODIndex, NewRawMesh))
{
bBuildStatus = false;
break;
......@@ -605,7 +619,10 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
// Setup per-section info and the materials array.
if (LODIndex == 0)
{
StaticMesh->Materials.Empty();
StaticMeshComponent->GetMaterial(0);
//TODO check if right
//StaticMeshComponent->Materials.Empty();
StaticMeshComponent->GetNumMaterials();
}
// Build a new map of sections with the unique material set
......@@ -613,17 +630,17 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
int32 NumMaterials = FMath::Min(SortedMaterials.Num(),MaxMaterialIndex+1);
for (int32 MaterialIndex = 0; MaterialIndex < NumMaterials; ++MaterialIndex)
{
FMeshSectionInfo Info = StaticMesh->SectionInfoMap.Get(LODIndex, MaterialIndex);
int32 Index = StaticMesh->Materials.Add(ToUMaterial(SortedMaterials[MaterialIndex]));
FMeshSectionInfo Info = StaticMeshComponent->GetStaticMesh()->SectionInfoMap.Get(LODIndex, MaterialIndex);
//FIXME
//int32 Index = StaticMeshComponent->Materials.Add(ToUMaterial(SortedMaterials[MaterialIndex]));
Info.MaterialIndex = Index;
NewMap.Set( LODIndex, MaterialIndex, Info);
//Info.MaterialIndex = Index;
//NewMap.Set( LODIndex, MaterialIndex, Info);
}
// Copy the final section map into the static mesh
StaticMesh->SectionInfoMap.Clear();
StaticMesh->SectionInfoMap.CopyFrom(NewMap);
StaticMeshComponent->GetStaticMesh()->SectionInfoMap.Clear();
StaticMeshComponent->GetStaticMesh()->SectionInfoMap.CopyFrom(NewMap);
FRawMesh LocalRawMesh;
SrcModel.RawMeshBulkData->LoadRawMesh(LocalRawMesh);
......@@ -635,15 +652,15 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
check(CurrentPlatform);
const FStaticMeshLODGroup& LODGroup = CurrentPlatform->GetStaticMeshLODSettings().GetLODGroup(ImportOptions.StaticMeshLODGroup);
int32 NumLODs = LODGroup.GetDefaultNumLODs();
while (StaticMesh->SourceModels.Num() < NumLODs)
while (StaticMeshComponent->GetStaticMesh()->SourceModels.Num() < NumLODs)
{
new (StaticMesh->SourceModels) FStaticMeshSourceModel();
new (StaticMeshComponent->GetStaticMesh()->SourceModels) FStaticMeshSourceModel();
}
for (int32 ModelLODIndex = 0; ModelLODIndex < NumLODs; ++ModelLODIndex)
{
StaticMesh->SourceModels[ModelLODIndex].ReductionSettings = LODGroup.GetDefaultSettings(ModelLODIndex);
StaticMeshComponent->GetStaticMesh()->SourceModels[ModelLODIndex].ReductionSettings = LODGroup.GetDefaultSettings(ModelLODIndex);
}
StaticMesh->LightMapResolution = LODGroup.GetDefaultLightMapResolution();
StaticMeshComponent->GetStaticMesh()->LightMapResolution = LODGroup.GetDefaultLightMapResolution();
}
// @todo This overrides restored values currently but we need to be able to import over the existing settings if the user chose to do so.
......@@ -656,7 +673,7 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
{
SrcModel.BuildSettings.bGenerateLightmapUVs = true;
SrcModel.BuildSettings.DstLightmapIndex = FirstOpenUVChannel;
StaticMesh->LightMapCoordinateIndex = FirstOpenUVChannel;
StaticMeshComponent->GetStaticMesh()->LightMapCoordinateIndex = FirstOpenUVChannel;
}
else
{
......@@ -664,8 +681,8 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
}
TArray<FText> BuildErrors;
StaticMesh->LODGroup = ImportOptions.StaticMeshLODGroup;
StaticMesh->Build(false, &BuildErrors);
StaticMeshComponent->GetStaticMesh()->LODGroup = ImportOptions.StaticMeshLODGroup;
StaticMeshComponent->GetStaticMesh()->Build(false, &BuildErrors);
for( FText& Error : BuildErrors )
{
......@@ -674,29 +691,29 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
// this is damage control. After build, we'd like to absolutely sure that
// all index is pointing correctly and they're all used. Otherwise we remove them
FMeshSectionInfoMap OldSectionInfoMap = StaticMesh->SectionInfoMap;
StaticMesh->SectionInfoMap.Clear();
FMeshSectionInfoMap OldSectionInfoMap = StaticMeshComponent->GetStaticMesh()->SectionInfoMap;
StaticMeshComponent->GetStaticMesh()->SectionInfoMap.Clear();
// fix up section data
for (int32 LODResourceIndex = 0; LODResourceIndex < StaticMesh->RenderData->LODResources.Num(); ++LODResourceIndex)
for (int32 LODResourceIndex = 0; LODResourceIndex < StaticMeshComponent->GetStaticMesh()->RenderData->LODResources.Num(); ++LODResourceIndex)
{
FStaticMeshLODResources& LOD = StaticMesh->RenderData->LODResources[LODResourceIndex];
FStaticMeshLODResources& LOD = StaticMeshComponent->GetStaticMesh()->RenderData->LODResources[LODResourceIndex];
int32 NumSections = LOD.Sections.Num();
for(int32 SectionIndex = 0; SectionIndex < NumSections; ++SectionIndex)
{
FMeshSectionInfo Info = OldSectionInfoMap.Get(LODResourceIndex, SectionIndex);
if (StaticMesh->Materials.IsValidIndex(Info.MaterialIndex))
if (StaticMeshComponent->GetMaterials().IsValidIndex(Info.MaterialIndex))
{
StaticMesh->SectionInfoMap.Set(LODResourceIndex, SectionIndex, Info);
StaticMeshComponent->GetStaticMesh()->SectionInfoMap.Set(LODResourceIndex, SectionIndex, Info);
}
}
}
}
else
{
StaticMesh = NULL;
StaticMeshComponent = NULL;
}
return StaticMesh;
return StaticMeshComponent;
}
// Reverse the winding order for triangle indices
......@@ -711,14 +728,14 @@ void GLTFMeshBuilder::ReverseTriDirection(TArray<T>& OutArray)
}
}
bool GLTFMeshBuilder::BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticMesh* StaticMesh, int LODIndex, FRawMesh& RawMesh)
bool GLTFMeshBuilder::BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticMeshComponent* StaticMeshComponent, int LODIndex, FRawMesh& RawMesh)
{
check(StaticMesh->SourceModels.IsValidIndex(LODIndex));
check(StaticMeshComponent->GetStaticMesh()->SourceModels.IsValidIndex(LODIndex));
auto ImportOptions = FGLTFLoaderModule::ImportOptions;
tinygltf::Node* Node = GetMeshParentNode(Mesh);
FStaticMeshSourceModel& SrcModel = StaticMesh->SourceModels[LODIndex];
FStaticMeshSourceModel& SrcModel = StaticMeshComponent->GetStaticMesh()->SourceModels[LODIndex];
tinygltf::Primitive* BaseLayer = &Mesh->primitives[0];
if (BaseLayer == NULL)
......@@ -763,7 +780,7 @@ bool GLTFMeshBuilder::BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticM
else
{
FString MaterialFullName = ObjectTools::SanitizeObjectName(ToFString(GLTFMaterial->name));
FString BasePackageName = PackageTools::SanitizePackageName(FPackageName::GetLongPackagePath(StaticMesh->GetOutermost()->GetName()) / MaterialFullName);
FString BasePackageName = PackageTools::SanitizePackageName(FPackageName::GetLongPackagePath(StaticMeshComponent->GetOutermost()->GetName()) / MaterialFullName);
UMaterialInterface* UnrealMaterialInterface = FindObject<UMaterialInterface>(NULL, *(BasePackageName + TEXT(".") + MaterialFullName));
if (UnrealMaterialInterface == NULL)
{
......@@ -795,9 +812,9 @@ bool GLTFMeshBuilder::BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticM
bool bEnableCollision = bImportedCollision || (/*GBuildStaticMeshCollision*/true && LODIndex == 0 && ImportOptions.bRemoveDegenerates);
for (int32 SectionIndex = MaterialIndexOffset; SectionIndex<MaterialIndexOffset + FoundMaterials.Num(); SectionIndex++)
{
FMeshSectionInfo Info = StaticMesh->SectionInfoMap.Get(LODIndex, SectionIndex);
FMeshSectionInfo Info = StaticMeshComponent->GetStaticMesh()->SectionInfoMap.Get(LODIndex, SectionIndex);
Info.bEnableCollision = bEnableCollision;
StaticMesh->SectionInfoMap.Set(LODIndex, SectionIndex, Info);
StaticMeshComponent->GetStaticMesh()->SectionInfoMap.Set(LODIndex, SectionIndex, Info);
}
//
......
......@@ -56,7 +56,7 @@ public:
/// @param InName The name of the package to be saved.
/// @param Flags Metadata used for the creation of the new package.
/// @param InStaticMesh A pointer to the StaticMesh to be built and have this new geometry added to it.
UStaticMesh* ImportStaticMeshAsSingle(UObject* InParent, TArray<FString>& MeshNameArray, const FName InName, EObjectFlags Flags, UStaticMesh* InStaticMesh);
UStaticMeshComponent* ImportStaticMeshAsSingle(UObject* InParent, TArray<FString>& MeshNameArray, const FName InName, EObjectFlags Flags, UStaticMeshComponent* InStaticMesh);
/// Obtains the geometry data from the file and adds it to the RawMesh ready to be built for the StaticMesh.
/// This function mirrors that in FFbxImporter of the same name.
......@@ -65,7 +65,7 @@ public:
/// @param MeshMaterials An array of materials to convert to those used by the engine and send to the build process.
/// @param LODIndex Level of detail for this mesh - currently unused i.e. always 0.
/// @param RawMesh The intermediate container for the data between the external format (glTF in our case) and the built StaticMesh.
bool BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticMesh* StaticMesh, int LODIndex, FRawMesh& RawMesh);
bool BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticMeshComponent* StaticMesh, int LODIndex, FRawMesh& RawMesh);
/// Material/texture system does nothing currently.
UMaterialInterface* ToUMaterial(tinygltf::Material* Material);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment