Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
glTFLoader
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kai Westerkamp
glTFLoader
Commits
6c3f8ba7
Commit
6c3f8ba7
authored
Jan 30, 2017
by
Kai Westerkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compile and execute
parent
e838ab2a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
55 deletions
+77
-55
UE4Editor-GLTFLoader.dll
Binaries/Win64/UE4Editor-GLTFLoader.dll
+0
-0
UE4Editor.modules
Binaries/Win64/UE4Editor.modules
+3
-2
GLTFFactory.cpp
Source/GLTFLoader/Private/GLTFFactory.cpp
+2
-2
GLTFLoader.cpp
Source/GLTFLoader/Private/GLTFLoader.cpp
+7
-3
GLTFMeshBuilder.cpp
Source/GLTFLoader/Private/GLTFMeshBuilder.cpp
+63
-46
GLTFMeshBuilder.h
Source/GLTFLoader/Private/GLTFMeshBuilder.h
+2
-2
No files found.
Binaries/Win64/UE4Editor-GLTFLoader.dll
View file @
6c3f8ba7
No preview for this file type
Binaries/Win64/UE4Editor.modules
View file @
6c3f8ba7
{
{
"Changelist" : 3013449,
"Changelist" : 3249277,
"BuildId" : "521bff43-3bc1-4230-8558-29af88fc728e",
"CompatibleChangelist" : 3195953,
"BuildId" : "afcfff98-97a3-4269-9c38-2ec2156cd5a3",
"Modules" :
"Modules" :
{
{
"GLTFLoader" : "UE4Editor-GLTFLoader.dll"
"GLTFLoader" : "UE4Editor-GLTFLoader.dll"
...
...
Source/GLTFLoader/Private/GLTFFactory.cpp
View file @
6c3f8ba7
...
@@ -32,7 +32,7 @@ UGLTFFactory::UGLTFFactory(const FObjectInitializer& ObjectInitializer)
...
@@ -32,7 +32,7 @@ UGLTFFactory::UGLTFFactory(const FObjectInitializer& ObjectInitializer)
bDetectImportTypeOnImport
=
false
;
bDetectImportTypeOnImport
=
false
;
}
}
//This function is adapted from
UFbxFactory
::CreateBinary()
//This function is adapted from
::CreateBinary()
UObject
*
UGLTFFactory
::
FactoryCreateBinary
UObject
*
UGLTFFactory
::
FactoryCreateBinary
(
(
UClass
*
Class
,
UClass
*
Class
,
...
@@ -123,7 +123,7 @@ UObject* UGLTFFactory::FactoryCreateBinary
...
@@ -123,7 +123,7 @@ UObject* UGLTFFactory::FactoryCreateBinary
int32
NodeIndex
=
0
;
int32
NodeIndex
=
0
;
int32
ImportedMeshCount
=
0
;
int32
ImportedMeshCount
=
0
;
UStaticMesh
*
NewStaticMesh
=
NULL
;
UStaticMesh
Component
*
NewStaticMesh
=
NULL
;
if
(
bCombineMeshes
)
if
(
bCombineMeshes
)
{
{
...
...
Source/GLTFLoader/Private/GLTFLoader.cpp
View file @
6c3f8ba7
...
@@ -216,7 +216,8 @@ TSharedRef<SDockTab> FGLTFLoaderModule::OnSpawnPluginTab(const FSpawnTabArgs& Sp
...
@@ -216,7 +216,8 @@ TSharedRef<SDockTab> FGLTFLoaderModule::OnSpawnPluginTab(const FSpawnTabArgs& Sp
void
FGLTFLoaderModule
::
OpenImportWindow
()
void
FGLTFLoaderModule
::
OpenImportWindow
()
{
{
TArray
<
FString
>
Filenames
;
/*
//TArray<FString> Filenames;
if (FDesktopPlatformModule::Get()->OpenFileDialog(nullptr,
if (FDesktopPlatformModule::Get()->OpenFileDialog(nullptr,
TEXT("Choose a GLTF file to import"),
TEXT("Choose a GLTF file to import"),
...
@@ -230,11 +231,14 @@ void FGLTFLoaderModule::OpenImportWindow()
...
@@ -230,11 +231,14 @@ void FGLTFLoaderModule::OpenImportWindow()
{
{
UE_LOG(LogTemp, Log, TEXT("File: %s"), *File);
UE_LOG(LogTemp, Log, TEXT("File: %s"), *File);
}
}
*/
FAssetToolsModule
&
AssetToolsModule
=
FModuleManager
::
Get
().
LoadModuleChecked
<
FAssetToolsModule
>
(
"AssetTools"
);
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"
));
AssetToolsModule
.
Get
().
ImportAssets
(
Filenames
,
FString
(
"/Game/Content"
));
}
//
}
}
}
void
FGLTFLoaderModule
::
PluginButtonClicked
()
void
FGLTFLoaderModule
::
PluginButtonClicked
()
...
...
Source/GLTFLoader/Private/GLTFMeshBuilder.cpp
View file @
6c3f8ba7
...
@@ -317,7 +317,7 @@ TArray<FString> GLTFMeshBuilder::GetMeshNames(FString NodeName, bool GetChildren
...
@@ -317,7 +317,7 @@ TArray<FString> GLTFMeshBuilder::GetMeshNames(FString NodeName, bool GetChildren
return
MeshNameArray
;
return
MeshNameArray
;
}
}
UStaticMesh
*
GLTFMeshBuilder
::
ImportStaticMeshAsSingle
(
UObject
*
InParent
,
TArray
<
FString
>&
MeshNameArray
,
const
FName
InName
,
EObjectFlags
Flags
,
UStaticMesh
*
InStaticMesh
)
UStaticMesh
Component
*
GLTFMeshBuilder
::
ImportStaticMeshAsSingle
(
UObject
*
InParent
,
TArray
<
FString
>&
MeshNameArray
,
const
FName
InName
,
EObjectFlags
Flags
,
UStaticMeshComponent
*
InStaticMesh
)
{
{
auto
ImportOptions
=
FGLTFLoaderModule
::
ImportOptions
;
auto
ImportOptions
=
FGLTFLoaderModule
::
ImportOptions
;
...
@@ -341,9 +341,9 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
...
@@ -341,9 +341,9 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
UPackage
*
Package
=
NULL
;
UPackage
*
Package
=
NULL
;
// create empty mesh
// create empty mesh
UStaticMesh
*
StaticMesh
=
NULL
;
UStaticMesh
Component
*
StaticMeshComponent
=
NULL
;
UStaticMesh
*
ExistingMesh
=
NULL
;
UStaticMesh
Component
*
ExistingMesh
=
NULL
;
UObject
*
ExistingObject
=
NULL
;
UObject
*
ExistingObject
=
NULL
;
// A mapping of vertex positions to their color in the existing static mesh
// A mapping of vertex positions to their color in the existing static mesh
...
@@ -358,7 +358,7 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
...
@@ -358,7 +358,7 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
NewPackageName
=
PackageTools
::
SanitizePackageName
(
NewPackageName
);
NewPackageName
=
PackageTools
::
SanitizePackageName
(
NewPackageName
);
Package
=
CreatePackage
(
NULL
,
*
NewPackageName
);
Package
=
CreatePackage
(
NULL
,
*
NewPackageName
);
ExistingMesh
=
FindObject
<
UStaticMesh
>
(
Package
,
*
MeshName
);
ExistingMesh
=
FindObject
<
UStaticMesh
Component
>
(
Package
,
*
MeshName
);
ExistingObject
=
FindObject
<
UObject
>
(
Package
,
*
MeshName
);
ExistingObject
=
FindObject
<
UObject
>
(
Package
,
*
MeshName
);
}
}
...
@@ -395,24 +395,35 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
...
@@ -395,24 +395,35 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
if
(
InStaticMesh
!=
NULL
&&
LODIndex
>
0
)
if
(
InStaticMesh
!=
NULL
&&
LODIndex
>
0
)
{
{
StaticMesh
=
InStaticMesh
;
StaticMesh
Component
=
InStaticMesh
;
}
}
else
else
{
{
StaticMesh
=
NewObject
<
UStaticMesh
>
(
Package
,
FName
(
*
MeshName
),
Flags
|
RF_Public
);
StaticMesh
Component
=
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
// 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
(
StaticMesh
Component
->
GetStaticMesh
()
->
SourceModels
.
Num
()
<
LODIndex
+
1
)
{
{
LODIndex
=
StaticMesh
->
SourceModels
.
Num
()
-
1
;
LODIndex
=
StaticMesh
Component
->
GetStaticMesh
()
->
SourceModels
.
Num
()
-
1
;
}
}
}
}
FStaticMeshSourceModel
&
SrcModel
=
StaticMesh
->
SourceModels
[
LODIndex
];
FStaticMeshSourceModel
&
SrcModel
=
StaticMeshComponent
->
GetStaticMesh
()
->
SourceModels
[
LODIndex
];
if
(
InStaticMesh
!=
NULL
&&
LODIndex
>
0
&&
!
SrcModel
.
RawMeshBulkData
->
IsEmpty
()
)
if
(
InStaticMesh
!=
NULL
&&
LODIndex
>
0
&&
!
SrcModel
.
RawMeshBulkData
->
IsEmpty
()
)
{
{
// clear out the old mesh data
// clear out the old mesh data
...
@@ -421,17 +432,20 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
...
@@ -421,17 +432,20 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
}
}
// make sure it has a new lighting guid
// make sure it has a new lighting guid
StaticMesh
->
LightingGuid
=
FGuid
::
NewGuid
();
StaticMesh
Component
->
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).
// 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
Component
->
GetStaticMesh
()
->
LightMapResolution
=
64
;
StaticMesh
->
LightMapCoordinateIndex
=
1
;
StaticMesh
Component
->
GetStaticMesh
()
->
LightMapCoordinateIndex
=
1
;
FRawMesh
NewRawMesh
;
FRawMesh
NewRawMesh
;
SrcModel
.
RawMeshBulkData
->
LoadRawMesh
(
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
)];
tinygltf
::
Mesh
*
Mesh
=
&
Scene
->
meshes
[
ToStdString
(
Name
)];
if
(
Mesh
)
if
(
Mesh
)
...
@@ -443,13 +457,13 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
...
@@ -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
)];
tinygltf
::
Mesh
*
Mesh
=
&
Scene
->
meshes
[
ToStdString
(
Name
)];
if
(
Mesh
)
if
(
Mesh
)
{
{
if
(
!
BuildStaticMeshFromGeometry
(
Mesh
,
StaticMesh
,
LODIndex
,
NewRawMesh
))
if
(
!
BuildStaticMeshFromGeometry
(
Mesh
,
StaticMesh
Component
,
LODIndex
,
NewRawMesh
))
{
{
bBuildStatus
=
false
;
bBuildStatus
=
false
;
break
;
break
;
...
@@ -605,7 +619,10 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
...
@@ -605,7 +619,10 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
// Setup per-section info and the materials array.
// Setup per-section info and the materials array.
if
(
LODIndex
==
0
)
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
// Build a new map of sections with the unique material set
...
@@ -613,17 +630,17 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
...
@@ -613,17 +630,17 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
int32
NumMaterials
=
FMath
::
Min
(
SortedMaterials
.
Num
(),
MaxMaterialIndex
+
1
);
int32
NumMaterials
=
FMath
::
Min
(
SortedMaterials
.
Num
(),
MaxMaterialIndex
+
1
);
for
(
int32
MaterialIndex
=
0
;
MaterialIndex
<
NumMaterials
;
++
MaterialIndex
)
for
(
int32
MaterialIndex
=
0
;
MaterialIndex
<
NumMaterials
;
++
MaterialIndex
)
{
{
FMeshSectionInfo
Info
=
StaticMesh
->
SectionInfoMap
.
Get
(
LODIndex
,
MaterialIndex
);
FMeshSectionInfo
Info
=
StaticMesh
Component
->
GetStaticMesh
()
->
SectionInfoMap
.
Get
(
LODIndex
,
MaterialIndex
);
//FIXME
int32
Index
=
StaticMesh
->
Materials
.
Add
(
ToUMaterial
(
SortedMaterials
[
MaterialIndex
]));
//int32 Index = StaticMeshComponent
->Materials.Add(ToUMaterial(SortedMaterials[MaterialIndex]));
Info
.
MaterialIndex
=
Index
;
//
Info.MaterialIndex = Index;
NewMap
.
Set
(
LODIndex
,
MaterialIndex
,
Info
);
//
NewMap.Set( LODIndex, MaterialIndex, Info);
}
}
// Copy the final section map into the static mesh
// Copy the final section map into the static mesh
StaticMesh
->
SectionInfoMap
.
Clear
();
StaticMesh
Component
->
GetStaticMesh
()
->
SectionInfoMap
.
Clear
();
StaticMesh
->
SectionInfoMap
.
CopyFrom
(
NewMap
);
StaticMesh
Component
->
GetStaticMesh
()
->
SectionInfoMap
.
CopyFrom
(
NewMap
);
FRawMesh
LocalRawMesh
;
FRawMesh
LocalRawMesh
;
SrcModel
.
RawMeshBulkData
->
LoadRawMesh
(
LocalRawMesh
);
SrcModel
.
RawMeshBulkData
->
LoadRawMesh
(
LocalRawMesh
);
...
@@ -635,15 +652,15 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
...
@@ -635,15 +652,15 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
check
(
CurrentPlatform
);
check
(
CurrentPlatform
);
const
FStaticMeshLODGroup
&
LODGroup
=
CurrentPlatform
->
GetStaticMeshLODSettings
().
GetLODGroup
(
ImportOptions
.
StaticMeshLODGroup
);
const
FStaticMeshLODGroup
&
LODGroup
=
CurrentPlatform
->
GetStaticMeshLODSettings
().
GetLODGroup
(
ImportOptions
.
StaticMeshLODGroup
);
int32
NumLODs
=
LODGroup
.
GetDefaultNumLODs
();
int32
NumLODs
=
LODGroup
.
GetDefaultNumLODs
();
while
(
StaticMesh
->
SourceModels
.
Num
()
<
NumLODs
)
while
(
StaticMesh
Component
->
GetStaticMesh
()
->
SourceModels
.
Num
()
<
NumLODs
)
{
{
new
(
StaticMesh
->
SourceModels
)
FStaticMeshSourceModel
();
new
(
StaticMesh
Component
->
GetStaticMesh
()
->
SourceModels
)
FStaticMeshSourceModel
();
}
}
for
(
int32
ModelLODIndex
=
0
;
ModelLODIndex
<
NumLODs
;
++
ModelLODIndex
)
for
(
int32
ModelLODIndex
=
0
;
ModelLODIndex
<
NumLODs
;
++
ModelLODIndex
)
{
{
StaticMesh
->
SourceModels
[
ModelLODIndex
].
ReductionSettings
=
LODGroup
.
GetDefaultSettings
(
ModelLODIndex
);
StaticMesh
Component
->
GetStaticMesh
()
->
SourceModels
[
ModelLODIndex
].
ReductionSettings
=
LODGroup
.
GetDefaultSettings
(
ModelLODIndex
);
}
}
StaticMesh
->
LightMapResolution
=
LODGroup
.
GetDefaultLightMapResolution
();
StaticMesh
Component
->
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.
// @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
...
@@ -656,7 +673,7 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
{
{
SrcModel
.
BuildSettings
.
bGenerateLightmapUVs
=
true
;
SrcModel
.
BuildSettings
.
bGenerateLightmapUVs
=
true
;
SrcModel
.
BuildSettings
.
DstLightmapIndex
=
FirstOpenUVChannel
;
SrcModel
.
BuildSettings
.
DstLightmapIndex
=
FirstOpenUVChannel
;
StaticMesh
->
LightMapCoordinateIndex
=
FirstOpenUVChannel
;
StaticMesh
Component
->
GetStaticMesh
()
->
LightMapCoordinateIndex
=
FirstOpenUVChannel
;
}
}
else
else
{
{
...
@@ -664,8 +681,8 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
...
@@ -664,8 +681,8 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
}
}
TArray
<
FText
>
BuildErrors
;
TArray
<
FText
>
BuildErrors
;
StaticMesh
->
LODGroup
=
ImportOptions
.
StaticMeshLODGroup
;
StaticMesh
Component
->
GetStaticMesh
()
->
LODGroup
=
ImportOptions
.
StaticMeshLODGroup
;
StaticMesh
->
Build
(
false
,
&
BuildErrors
);
StaticMesh
Component
->
GetStaticMesh
()
->
Build
(
false
,
&
BuildErrors
);
for
(
FText
&
Error
:
BuildErrors
)
for
(
FText
&
Error
:
BuildErrors
)
{
{
...
@@ -674,29 +691,29 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
...
@@ -674,29 +691,29 @@ UStaticMesh* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray
// this is damage control. After build, we'd like to absolutely sure that
// 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
// all index is pointing correctly and they're all used. Otherwise we remove them
FMeshSectionInfoMap
OldSectionInfoMap
=
StaticMesh
->
SectionInfoMap
;
FMeshSectionInfoMap
OldSectionInfoMap
=
StaticMesh
Component
->
GetStaticMesh
()
->
SectionInfoMap
;
StaticMesh
->
SectionInfoMap
.
Clear
();
StaticMesh
Component
->
GetStaticMesh
()
->
SectionInfoMap
.
Clear
();
// fix up section data
// fix up section data
for
(
int32
LODResourceIndex
=
0
;
LODResourceIndex
<
StaticMesh
->
RenderData
->
LODResources
.
Num
();
++
LODResourceIndex
)
for
(
int32
LODResourceIndex
=
0
;
LODResourceIndex
<
StaticMesh
Component
->
GetStaticMesh
()
->
RenderData
->
LODResources
.
Num
();
++
LODResourceIndex
)
{
{
FStaticMeshLODResources
&
LOD
=
StaticMesh
->
RenderData
->
LODResources
[
LODResourceIndex
];
FStaticMeshLODResources
&
LOD
=
StaticMesh
Component
->
GetStaticMesh
()
->
RenderData
->
LODResources
[
LODResourceIndex
];
int32
NumSections
=
LOD
.
Sections
.
Num
();
int32
NumSections
=
LOD
.
Sections
.
Num
();
for
(
int32
SectionIndex
=
0
;
SectionIndex
<
NumSections
;
++
SectionIndex
)
for
(
int32
SectionIndex
=
0
;
SectionIndex
<
NumSections
;
++
SectionIndex
)
{
{
FMeshSectionInfo
Info
=
OldSectionInfoMap
.
Get
(
LODResourceIndex
,
SectionIndex
);
FMeshSectionInfo
Info
=
OldSectionInfoMap
.
Get
(
LODResourceIndex
,
SectionIndex
);
if
(
StaticMesh
->
Materials
.
IsValidIndex
(
Info
.
MaterialIndex
))
if
(
StaticMesh
Component
->
GetMaterials
()
.
IsValidIndex
(
Info
.
MaterialIndex
))
{
{
StaticMesh
->
SectionInfoMap
.
Set
(
LODResourceIndex
,
SectionIndex
,
Info
);
StaticMesh
Component
->
GetStaticMesh
()
->
SectionInfoMap
.
Set
(
LODResourceIndex
,
SectionIndex
,
Info
);
}
}
}
}
}
}
}
}
else
else
{
{
StaticMesh
=
NULL
;
StaticMesh
Component
=
NULL
;
}
}
return
StaticMesh
;
return
StaticMesh
Component
;
}
}
// Reverse the winding order for triangle indices
// Reverse the winding order for triangle indices
...
@@ -711,14 +728,14 @@ void GLTFMeshBuilder::ReverseTriDirection(TArray<T>& OutArray)
...
@@ -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
,
UStaticMesh
Component
*
StaticMeshComponent
,
int
LODIndex
,
FRawMesh
&
RawMesh
)
{
{
check
(
StaticMesh
->
SourceModels
.
IsValidIndex
(
LODIndex
));
check
(
StaticMesh
Component
->
GetStaticMesh
()
->
SourceModels
.
IsValidIndex
(
LODIndex
));
auto
ImportOptions
=
FGLTFLoaderModule
::
ImportOptions
;
auto
ImportOptions
=
FGLTFLoaderModule
::
ImportOptions
;
tinygltf
::
Node
*
Node
=
GetMeshParentNode
(
Mesh
);
tinygltf
::
Node
*
Node
=
GetMeshParentNode
(
Mesh
);
FStaticMeshSourceModel
&
SrcModel
=
StaticMesh
->
SourceModels
[
LODIndex
];
FStaticMeshSourceModel
&
SrcModel
=
StaticMesh
Component
->
GetStaticMesh
()
->
SourceModels
[
LODIndex
];
tinygltf
::
Primitive
*
BaseLayer
=
&
Mesh
->
primitives
[
0
];
tinygltf
::
Primitive
*
BaseLayer
=
&
Mesh
->
primitives
[
0
];
if
(
BaseLayer
==
NULL
)
if
(
BaseLayer
==
NULL
)
...
@@ -763,7 +780,7 @@ bool GLTFMeshBuilder::BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticM
...
@@ -763,7 +780,7 @@ bool GLTFMeshBuilder::BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticM
else
else
{
{
FString
MaterialFullName
=
ObjectTools
::
SanitizeObjectName
(
ToFString
(
GLTFMaterial
->
name
));
FString
MaterialFullName
=
ObjectTools
::
SanitizeObjectName
(
ToFString
(
GLTFMaterial
->
name
));
FString
BasePackageName
=
PackageTools
::
SanitizePackageName
(
FPackageName
::
GetLongPackagePath
(
StaticMesh
->
GetOutermost
()
->
GetName
())
/
MaterialFullName
);
FString
BasePackageName
=
PackageTools
::
SanitizePackageName
(
FPackageName
::
GetLongPackagePath
(
StaticMesh
Component
->
GetOutermost
()
->
GetName
())
/
MaterialFullName
);
UMaterialInterface
*
UnrealMaterialInterface
=
FindObject
<
UMaterialInterface
>
(
NULL
,
*
(
BasePackageName
+
TEXT
(
"."
)
+
MaterialFullName
));
UMaterialInterface
*
UnrealMaterialInterface
=
FindObject
<
UMaterialInterface
>
(
NULL
,
*
(
BasePackageName
+
TEXT
(
"."
)
+
MaterialFullName
));
if
(
UnrealMaterialInterface
==
NULL
)
if
(
UnrealMaterialInterface
==
NULL
)
{
{
...
@@ -795,9 +812,9 @@ bool GLTFMeshBuilder::BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticM
...
@@ -795,9 +812,9 @@ bool GLTFMeshBuilder::BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticM
bool
bEnableCollision
=
bImportedCollision
||
(
/*GBuildStaticMeshCollision*/
true
&&
LODIndex
==
0
&&
ImportOptions
.
bRemoveDegenerates
);
bool
bEnableCollision
=
bImportedCollision
||
(
/*GBuildStaticMeshCollision*/
true
&&
LODIndex
==
0
&&
ImportOptions
.
bRemoveDegenerates
);
for
(
int32
SectionIndex
=
MaterialIndexOffset
;
SectionIndex
<
MaterialIndexOffset
+
FoundMaterials
.
Num
();
SectionIndex
++
)
for
(
int32
SectionIndex
=
MaterialIndexOffset
;
SectionIndex
<
MaterialIndexOffset
+
FoundMaterials
.
Num
();
SectionIndex
++
)
{
{
FMeshSectionInfo
Info
=
StaticMesh
->
SectionInfoMap
.
Get
(
LODIndex
,
SectionIndex
);
FMeshSectionInfo
Info
=
StaticMesh
Component
->
GetStaticMesh
()
->
SectionInfoMap
.
Get
(
LODIndex
,
SectionIndex
);
Info
.
bEnableCollision
=
bEnableCollision
;
Info
.
bEnableCollision
=
bEnableCollision
;
StaticMesh
->
SectionInfoMap
.
Set
(
LODIndex
,
SectionIndex
,
Info
);
StaticMesh
Component
->
GetStaticMesh
()
->
SectionInfoMap
.
Set
(
LODIndex
,
SectionIndex
,
Info
);
}
}
//
//
...
...
Source/GLTFLoader/Private/GLTFMeshBuilder.h
View file @
6c3f8ba7
...
@@ -56,7 +56,7 @@ public:
...
@@ -56,7 +56,7 @@ public:
/// @param InName The name of the package to be saved.
/// @param InName The name of the package to be saved.
/// @param Flags Metadata used for the creation of the new package.
/// @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.
/// @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
);
UStaticMesh
Component
*
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.
/// 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.
/// This function mirrors that in FFbxImporter of the same name.
...
@@ -65,7 +65,7 @@ public:
...
@@ -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 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 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.
/// @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
,
UStaticMesh
Component
*
StaticMesh
,
int
LODIndex
,
FRawMesh
&
RawMesh
);
/// Material/texture system does nothing currently.
/// Material/texture system does nothing currently.
UMaterialInterface
*
ToUMaterial
(
tinygltf
::
Material
*
Material
);
UMaterialInterface
*
ToUMaterial
(
tinygltf
::
Material
*
Material
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment