Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
MasterTestProjekt
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
MasterTestProjekt
Commits
113e3ce1
Commit
113e3ce1
authored
Feb 17, 2017
by
Kai Westerkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
material
parent
f105761f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
168 additions
and
5 deletions
+168
-5
Minimal_Default.umap
Content/MobileStarterContent/Maps/Minimal_Default.umap
+0
-0
Minimal_Default_BuiltData.uasset
...obileStarterContent/Maps/Minimal_Default_BuiltData.uasset
+0
-0
UnrealGLTFLoader
Plugins/UnrealGLTFLoader
+0
-1
ProceduralEntity.cpp
Source/MasterTestProject/ue4-assimp/ProceduralEntity.cpp
+163
-4
ProceduralEntity.h
Source/MasterTestProject/ue4-assimp/ProceduralEntity.h
+5
-0
No files found.
Content/MobileStarterContent/Maps/Minimal_Default.umap
View file @
113e3ce1
No preview for this file type
Content/MobileStarterContent/Maps/Minimal_Default_BuiltData.uasset
View file @
113e3ce1
No preview for this file type
UnrealGLTFLoader
@
110727d8
Subproject commit 110727d81d3f44dc58f8b2c09c8c27e4c1b6a3dd
Source/MasterTestProject/ue4-assimp/ProceduralEntity.cpp
View file @
113e3ce1
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include "ProceduralEntity.h"
#include "ProceduralEntity.h"
#include "Runtime/Engine/Public/DDSLoader.h"
#include <assimp/DefaultLogger.hpp>
#include <assimp/DefaultLogger.hpp>
#include <assimp/Logger.hpp>
#include <assimp/Logger.hpp>
...
@@ -63,6 +64,7 @@ void AProceduralEntity::Tick(float DeltaTime)
...
@@ -63,6 +64,7 @@ void AProceduralEntity::Tick(float DeltaTime)
// quick C++11 trick to get a char * from a std::string
// quick C++11 trick to get a char * from a std::string
char
*
filename
=
&
sfilename
[
0
];
char
*
filename
=
&
sfilename
[
0
];
result
=
_stat
(
filename
,
&
buf
);
result
=
_stat
(
filename
,
&
buf
);
if
(
result
!=
0
)
{
if
(
result
!=
0
)
{
UE_LOG
(
LogTemp
,
Warning
,
TEXT
(
"Problem getting info"
));
UE_LOG
(
LogTemp
,
Warning
,
TEXT
(
"Problem getting info"
));
...
@@ -167,6 +169,12 @@ void AProceduralEntity::processMesh(aiMesh* mesh, const aiScene* scene) {
...
@@ -167,6 +169,12 @@ void AProceduralEntity::processMesh(aiMesh* mesh, const aiScene* scene) {
_mesh
->
UpdateMeshSection
(
_meshCurrentlyProcessed
,
_vertices
[
_meshCurrentlyProcessed
],
_normals
[
_meshCurrentlyProcessed
],
_uvs
[
_meshCurrentlyProcessed
],
_vertexColors
[
_meshCurrentlyProcessed
],
_tangents
[
_meshCurrentlyProcessed
]);
_mesh
->
UpdateMeshSection
(
_meshCurrentlyProcessed
,
_vertices
[
_meshCurrentlyProcessed
],
_normals
[
_meshCurrentlyProcessed
],
_uvs
[
_meshCurrentlyProcessed
],
_vertexColors
[
_meshCurrentlyProcessed
],
_tangents
[
_meshCurrentlyProcessed
]);
}
}
//load material
UMaterial
*
material
=
GetMaterialForIndex
(
mesh
->
mMaterialIndex
,
scene
);
_mesh
->
SetMaterial
(
_meshCurrentlyProcessed
,
material
);
UE_LOG
(
LogTemp
,
Warning
,
TEXT
(
"Done creating the mesh"
));
UE_LOG
(
LogTemp
,
Warning
,
TEXT
(
"Done creating the mesh"
));
_requiresFullRecreation
=
false
;
_requiresFullRecreation
=
false
;
...
@@ -196,18 +204,168 @@ void AProceduralEntity::loadModel(std::string path) {
...
@@ -196,18 +204,168 @@ void AProceduralEntity::loadModel(std::string path) {
const
aiScene
*
scene
=
importer
.
ReadFile
(
path
,
aiProcess_Triangulate
|
aiProcess_FlipUVs
|
aiProcess_GenNormals
);
const
aiScene
*
scene
=
importer
.
ReadFile
(
path
,
aiProcess_Triangulate
|
aiProcess_FlipUVs
|
aiProcess_GenNormals
);
if
(
!
scene
)
{
if
(
!
scene
)
{
UE_LOG
(
LogTemp
,
Error
,
TEXT
(
"Failed, Scene is empty: %s"
),
*
FString
(
importer
.
GetErrorString
()));
UE_LOG
(
LogTemp
,
Error
,
TEXT
(
"Failed, Scene is empty: %s"
),
*
FString
(
importer
.
GetErrorString
()));
std
::
string
extensions
;
std
::
string
extensions
;
importer
.
GetExtensionList
(
extensions
);
importer
.
GetExtensionList
(
extensions
);
UE_LOG
(
LogTemp
,
Error
,
TEXT
(
"Extension list: %s"
),
*
FString
(
extensions
.
c_str
()));
UE_LOG
(
LogTemp
,
Error
,
TEXT
(
"Extension list: %s"
),
*
FString
(
extensions
.
c_str
()));
return
;
wchar_t
buffer
[
260
];
GetModuleFileName
(
NULL
,
buffer
,
MAX_PATH
);
UE_LOG
(
LogTemp
,
Error
,
TEXT
(
"Curretn PAth: %s"
),
*
FString
(
buffer
));
return
;
}
}
UE_LOG
(
LogTemp
,
Warning
,
TEXT
(
"Has MAterials: %s"
),
scene
->
HasMaterials
()
?
TEXT
(
"True"
)
:
TEXT
(
"False"
));
_meshCurrentlyProcessed
=
0
;
_meshCurrentlyProcessed
=
0
;
processNode
(
scene
->
mRootNode
,
scene
);
processNode
(
scene
->
mRootNode
,
scene
);
}
UMaterial
*
AProceduralEntity
::
GetMaterialForIndex
(
unsigned
int
index
,
const
aiScene
*
scene
){
if
(
MaterialMap
.
Contains
(
index
))
{
return
*
MaterialMap
.
Find
(
index
);
}
else
{
UE_LOG
(
LogTemp
,
Warning
,
TEXT
(
"Parsing Material %d"
),
index
);
UMaterial
*
newMaterial
=
UMaterial
::
GetDefaultMaterial
(
EMaterialDomain
::
MD_Surface
);
aiMaterial
*
AMat
=
scene
->
mMaterials
[
index
];
aiColor3D
color
(
0.
f
,
0.
f
,
0.
f
);
if
(
AI_SUCCESS
==
AMat
->
Get
(
AI_MATKEY_COLOR_DIFFUSE
,
color
))
{
UE_LOG
(
LogTemp
,
Warning
,
TEXT
(
"Material Property: %s, %d %d %d"
),
TEXT
(
"AI_MATKEY_COLOR_DIFFUSE"
),
color
.
r
,
color
.
g
,
color
.
b
);
}
else
{
UE_LOG
(
LogTemp
,
Warning
,
TEXT
(
"Material Property: %s, Failed"
),
TEXT
(
"AI_MATKEY_COLOR_DIFFUSE"
));
}
if
(
AMat
->
GetTextureCount
(
aiTextureType_DIFFUSE
)
>
0
)
{
aiString
Path
;
if
(
AMat
->
GetTexture
(
aiTextureType_DIFFUSE
,
0
,
&
Path
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
)
==
AI_SUCCESS
)
{
FString
fileName
=
FString
(
Path
.
C_Str
());
FString
dirPath
,
temp
,
right
;
_filePath
.
Split
(
TEXT
(
"
\\
"
),
&
temp
,
&
right
,
ESearchCase
::
IgnoreCase
,
ESearchDir
::
FromEnd
);
temp
.
Split
(
TEXT
(
"/"
),
&
dirPath
,
&
right
,
ESearchCase
::
IgnoreCase
,
ESearchDir
::
FromEnd
);
UE_LOG
(
LogTemp
,
Warning
,
TEXT
(
"Diffuse Texture: %s %s"
),
*
dirPath
,
*
fileName
);
UTexture2D
*
diffTexture
=
LoadTexture
(
dirPath
,
fileName
);
}
else
{
UE_LOG
(
LogTemp
,
Warning
,
TEXT
(
"No Diffuse Texture"
));
}
}
return
newMaterial
;
}
}
/** Loads a texture from the data path */
//https://drive.google.com/file/d/0BzqpBc4MrAMXLXN1ZGNzUEJZc1k/edit
//https://forums.unrealengine.com/showthread.php?33446-Creating-UTexture-from-data-in-code-making-it-a-material-and-adding-it-to-a-mesh
UTexture2D
*
AProceduralEntity
::
LoadTexture
(
FString
Folder
,
FString
FileName
)
{
FString
TexturePath
=
Folder
+
"
\\
"
+
FileName
;
UTexture2D
*
Texture
=
NULL
;
TArray
<
uint8
>
FileData
;
/* Load DDS texture */
if
(
FFileHelper
::
LoadFileToArray
(
FileData
,
*
TexturePath
,
0
))
{
FDDSLoadHelper
DDSLoadHelper
(
&
FileData
[
0
],
FileData
.
Num
());
if
(
DDSLoadHelper
.
IsValid2DTexture
())
{
int32
NumMips
=
DDSLoadHelper
.
ComputeMipMapCount
();
EPixelFormat
Format
=
DDSLoadHelper
.
ComputePixelFormat
();
int32
BlockSize
=
16
;
if
(
NumMips
==
0
)
{
NumMips
=
1
;
}
if
(
Format
==
PF_DXT1
)
{
BlockSize
=
8
;
}
/* Create transient texture */
Texture
=
UTexture2D
::
CreateTransient
(
DDSLoadHelper
.
DDSHeader
->
dwWidth
,
DDSLoadHelper
.
DDSHeader
->
dwHeight
,
Format
);
Texture
->
MipGenSettings
=
TMGS_LeaveExistingMips
;
Texture
->
PlatformData
->
NumSlices
=
1
;
Texture
->
NeverStream
=
true
;
Texture
->
Rename
(
*
FileName
);
/* Get pointer to actual data */
uint8
*
DataPtr
=
(
uint8
*
)
DDSLoadHelper
.
GetDDSDataPointer
();
uint32
CurrentWidth
=
DDSLoadHelper
.
DDSHeader
->
dwWidth
;
uint32
CurrentHeight
=
DDSLoadHelper
.
DDSHeader
->
dwHeight
;
/* Iterate through mips */
for
(
int32
i
=
0
;
i
<
NumMips
;
i
++
)
{
/* Lock to 1x1 as smallest size */
CurrentWidth
=
(
CurrentWidth
<
1
)
?
1
:
CurrentWidth
;
CurrentHeight
=
(
CurrentHeight
<
1
)
?
1
:
CurrentHeight
;
/* Get number of bytes to read */
int32
NumBytes
=
CurrentWidth
*
CurrentHeight
*
4
;
if
(
Format
==
PF_DXT1
||
Format
==
PF_DXT3
||
Format
==
PF_DXT5
)
{
/* Compressed formats */
NumBytes
=
((
CurrentWidth
+
3
)
/
4
)
*
((
CurrentHeight
+
3
)
/
4
)
*
BlockSize
;
}
/* Write to existing mip */
if
(
i
<
Texture
->
PlatformData
->
Mips
.
Num
())
{
FTexture2DMipMap
&
Mip
=
Texture
->
PlatformData
->
Mips
[
i
];
void
*
Data
=
Mip
.
BulkData
.
Lock
(
LOCK_READ_WRITE
);
FMemory
::
Memcpy
(
Data
,
DataPtr
,
NumBytes
);
Mip
.
BulkData
.
Unlock
();
}
/* Add new mip */
else
{
FTexture2DMipMap
*
Mip
=
new
(
Texture
->
PlatformData
->
Mips
)
FTexture2DMipMap
();
Mip
->
SizeX
=
CurrentWidth
;
Mip
->
SizeY
=
CurrentHeight
;
Mip
->
BulkData
.
Lock
(
LOCK_READ_WRITE
);
Mip
->
BulkData
.
Realloc
(
NumBytes
);
Mip
->
BulkData
.
Unlock
();
void
*
Data
=
Mip
->
BulkData
.
Lock
(
LOCK_READ_WRITE
);
FMemory
::
Memcpy
(
Data
,
DataPtr
,
NumBytes
);
Mip
->
BulkData
.
Unlock
();
}
/* Set next mip level */
CurrentWidth
/=
2
;
CurrentHeight
/=
2
;
DataPtr
+=
NumBytes
;
}
Texture
->
UpdateResource
();
}
}
return
Texture
;
}
}
\ No newline at end of file
Source/MasterTestProject/ue4-assimp/ProceduralEntity.h
View file @
113e3ce1
...
@@ -50,6 +50,8 @@ private:
...
@@ -50,6 +50,8 @@ private:
TArray
<
TArray
<
FVector2D
>>
_uvs
;
TArray
<
TArray
<
FVector2D
>>
_uvs
;
TArray
<
TArray
<
FProcMeshTangent
>>
_tangents
;
TArray
<
TArray
<
FProcMeshTangent
>>
_tangents
;
TArray
<
TArray
<
FColor
>>
_vertexColors
;
TArray
<
TArray
<
FColor
>>
_vertexColors
;
TMap
<
int32
,
UMaterial
*>
MaterialMap
;
//USceneComponent* _rootComp;
//USceneComponent* _rootComp;
...
@@ -66,4 +68,6 @@ private:
...
@@ -66,4 +68,6 @@ private:
void
processMesh
(
aiMesh
*
mesh
,
const
aiScene
*
scene
);
void
processMesh
(
aiMesh
*
mesh
,
const
aiScene
*
scene
);
void
processNode
(
aiNode
*
node
,
const
aiScene
*
scene
);
void
processNode
(
aiNode
*
node
,
const
aiScene
*
scene
);
void
loadModel
(
std
::
string
path
);
void
loadModel
(
std
::
string
path
);
UMaterial
*
GetMaterialForIndex
(
unsigned
int
index
,
const
aiScene
*
scene
);
UTexture2D
*
LoadTexture
(
FString
Folder
,
FString
FileName
);
};
};
\ No newline at end of file
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