Commit 6cdeb206 by wester

testing fpr exposing API

parent 110727d8
...@@ -55,7 +55,7 @@ template<> struct GLTFType <TINYGLTF_TYPE_VEC4> { typedef FVector4 Type; } ...@@ -55,7 +55,7 @@ template<> struct GLTFType <TINYGLTF_TYPE_VEC4> { typedef FVector4 Type; }
/// @endcond /// @endcond
template <typename T> template <typename T>
bool GLTFMeshBuilder::ConvertAttrib(TArray<T> &OutArray, tinygltf::Mesh* Mesh, std::string AttribName, bool UseWedgeIndices, bool AutoSetArraySize) bool UUGLTFMeshBuilder::ConvertAttrib(TArray<T> &OutArray, tinygltf::Mesh* Mesh, std::string AttribName, bool UseWedgeIndices, bool AutoSetArraySize)
{ {
if (AttribName != "__WedgeIndices" && !HasAttribute(Mesh, AttribName)) if (AttribName != "__WedgeIndices" && !HasAttribute(Mesh, AttribName))
{ {
...@@ -179,7 +179,7 @@ bool GLTFMeshBuilder::ConvertAttrib(TArray<T> &OutArray, tinygltf::Mesh* Mesh, s ...@@ -179,7 +179,7 @@ bool GLTFMeshBuilder::ConvertAttrib(TArray<T> &OutArray, tinygltf::Mesh* Mesh, s
// Retrieve a value from the buffer, implicitly accounting for endianness // Retrieve a value from the buffer, implicitly accounting for endianness
// Adapted from http://stackoverflow.com/questions/13001183/how-to-read-little-endian-integers-from-file-in-c // Adapted from http://stackoverflow.com/questions/13001183/how-to-read-little-endian-integers-from-file-in-c
template <typename T> T GLTFMeshBuilder::BufferValue(void* Data/*, uint8 Size*/) template <typename T> T UGLTFMeshBuilder::BufferValue(void* Data/*, uint8 Size*/)
{ {
T Ret = T(0); T Ret = T(0);
...@@ -192,7 +192,7 @@ template <typename T> T GLTFMeshBuilder::BufferValue(void* Data/*, uint8 Size*/) ...@@ -192,7 +192,7 @@ template <typename T> T GLTFMeshBuilder::BufferValue(void* Data/*, uint8 Size*/)
} }
// Use unions for floats and doubles since they don't have a bitwise OR operator // Use unions for floats and doubles since they don't have a bitwise OR operator
template <> float GLTFMeshBuilder::BufferValue(void* Data) template <> float UGLTFMeshBuilder::BufferValue(void* Data)
{ {
assert(sizeof(float) == sizeof(int32)); assert(sizeof(float) == sizeof(int32));
...@@ -212,7 +212,7 @@ template <> float GLTFMeshBuilder::BufferValue(void* Data) ...@@ -212,7 +212,7 @@ template <> float GLTFMeshBuilder::BufferValue(void* Data)
return Ret; return Ret;
} }
template <> double GLTFMeshBuilder::BufferValue(void* Data) template <> double UGLTFMeshBuilder::BufferValue(void* Data)
{ {
assert(sizeof(float) == sizeof(int64)); assert(sizeof(float) == sizeof(int64));
...@@ -240,7 +240,13 @@ struct MaterialPair ...@@ -240,7 +240,13 @@ struct MaterialPair
}; };
/// @endcond /// @endcond
GLTFMeshBuilder::GLTFMeshBuilder(FString FilePath) UGLTFMeshBuilder::UGLTFMeshBuilder()
: UGLTFMeshBuilder(TEXT("H:/Repositories/MasterArbeit/glTF-Sample-Models/1.0/Duck/glTF/Duck.gltf"))
{
} //DO NOT USE
UGLTFMeshBuilder::UGLTFMeshBuilder(FString FilePath)
{ {
Loader = new tinygltf::TinyGLTFLoader; Loader = new tinygltf::TinyGLTFLoader;
Scene = new tinygltf::Scene; Scene = new tinygltf::Scene;
...@@ -250,18 +256,18 @@ GLTFMeshBuilder::GLTFMeshBuilder(FString FilePath) ...@@ -250,18 +256,18 @@ GLTFMeshBuilder::GLTFMeshBuilder(FString FilePath)
Error = ToFString(TempError); Error = ToFString(TempError);
} }
GLTFMeshBuilder::~GLTFMeshBuilder() UGLTFMeshBuilder::~UGLTFMeshBuilder()
{ {
delete Loader; delete Loader;
delete Scene; delete Scene;
} }
int32 GLTFMeshBuilder::GetMeshCount(FString NodeName) int32 UGLTFMeshBuilder::GetMeshCount(FString NodeName)
{ {
return (int32)Scene->nodes[ToStdString(NodeName)].meshes.size(); return (int32)Scene->nodes[ToStdString(NodeName)].meshes.size();
} }
FString GLTFMeshBuilder::GetRootNode() FString UGLTFMeshBuilder::GetRootNode()
{ {
for (auto ThisNode : Scene->nodes) for (auto ThisNode : Scene->nodes)
{ {
...@@ -282,7 +288,7 @@ FString GLTFMeshBuilder::GetRootNode() ...@@ -282,7 +288,7 @@ FString GLTFMeshBuilder::GetRootNode()
return FString(""); return FString("");
} }
tinygltf::Node* GLTFMeshBuilder::GetMeshParentNode(tinygltf::Mesh* InMesh) tinygltf::Node* UGLTFMeshBuilder::GetMeshParentNode(tinygltf::Mesh* InMesh)
{ {
for (auto &Node : Scene->nodes) for (auto &Node : Scene->nodes)
{ {
...@@ -297,7 +303,7 @@ tinygltf::Node* GLTFMeshBuilder::GetMeshParentNode(tinygltf::Mesh* InMesh) ...@@ -297,7 +303,7 @@ tinygltf::Node* GLTFMeshBuilder::GetMeshParentNode(tinygltf::Mesh* InMesh)
return NULL; return NULL;
} }
TArray<FString> GLTFMeshBuilder::GetMeshNames(FString NodeName, bool GetChildren) TArray<FString> UGLTFMeshBuilder::GetMeshNames(FString NodeName, bool GetChildren)
{ {
TArray<FString> MeshNameArray; TArray<FString> MeshNameArray;
...@@ -317,7 +323,7 @@ TArray<FString> GLTFMeshBuilder::GetMeshNames(FString NodeName, bool GetChildren ...@@ -317,7 +323,7 @@ TArray<FString> GLTFMeshBuilder::GetMeshNames(FString NodeName, bool GetChildren
return MeshNameArray; return MeshNameArray;
} }
UStaticMeshComponent* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray<FString>& MeshNameArray, const FName InName, EObjectFlags Flags, UStaticMeshComponent* InStaticMesh) UStaticMeshComponent* UGLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParent, TArray<FString>& MeshNameArray, const FName InName, EObjectFlags Flags, UStaticMeshComponent* InStaticMesh)
{ {
auto ImportOptions = FGLTFLoaderModule::ImportOptions; auto ImportOptions = FGLTFLoaderModule::ImportOptions;
...@@ -718,7 +724,7 @@ UStaticMeshComponent* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParen ...@@ -718,7 +724,7 @@ UStaticMeshComponent* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParen
// Reverse the winding order for triangle indices // Reverse the winding order for triangle indices
template <typename T> template <typename T>
void GLTFMeshBuilder::ReverseTriDirection(TArray<T>& OutArray) void UGLTFMeshBuilder::ReverseTriDirection(TArray<T>& OutArray)
{ {
for (int i = 0; i < OutArray.Num() - 2; i += 3) for (int i = 0; i < OutArray.Num() - 2; i += 3)
{ {
...@@ -728,7 +734,7 @@ void GLTFMeshBuilder::ReverseTriDirection(TArray<T>& OutArray) ...@@ -728,7 +734,7 @@ void GLTFMeshBuilder::ReverseTriDirection(TArray<T>& OutArray)
} }
} }
bool GLTFMeshBuilder::BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticMeshComponent* StaticMeshComponent, int LODIndex, FRawMesh& RawMesh) bool UGLTFMeshBuilder::BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticMeshComponent* StaticMeshComponent, int LODIndex, FRawMesh& RawMesh)
{ {
check(StaticMeshComponent->GetStaticMesh()->SourceModels.IsValidIndex(LODIndex)); check(StaticMeshComponent->GetStaticMesh()->SourceModels.IsValidIndex(LODIndex));
...@@ -957,22 +963,22 @@ bool GLTFMeshBuilder::BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticM ...@@ -957,22 +963,22 @@ bool GLTFMeshBuilder::BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticM
return true; return true;
} }
UMaterialInterface* GLTFMeshBuilder::ToUMaterial(tinygltf::Material* Material) UMaterialInterface* UGLTFMeshBuilder::ToUMaterial(tinygltf::Material* Material)
{ {
return UMaterial::GetDefaultMaterial(MD_Surface); return UMaterial::GetDefaultMaterial(MD_Surface);
} }
FString GLTFMeshBuilder::GetError() FString UGLTFMeshBuilder::GetError()
{ {
return Error; return Error;
} }
FString GLTFMeshBuilder::ToFString(std::string InString) FString UGLTFMeshBuilder::ToFString(std::string InString)
{ {
return FString(InString.c_str()); return FString(InString.c_str());
} }
std::string GLTFMeshBuilder::ToStdString(FString InString) std::string UGLTFMeshBuilder::ToStdString(FString InString)
{ {
auto CharArray = InString.GetCharArray(); auto CharArray = InString.GetCharArray();
...@@ -982,7 +988,7 @@ std::string GLTFMeshBuilder::ToStdString(FString InString) ...@@ -982,7 +988,7 @@ std::string GLTFMeshBuilder::ToStdString(FString InString)
} }
template <typename T> template <typename T>
bool GLTFMeshBuilder::GetBufferData(TArray<T> &OutArray, tinygltf::Accessor* Accessor, bool Append) bool UGLTFMeshBuilder::GetBufferData(TArray<T> &OutArray, tinygltf::Accessor* Accessor, bool Append)
{ {
if (Accessor->type != TINYGLTF_TYPE_SCALAR) if (Accessor->type != TINYGLTF_TYPE_SCALAR)
{ {
...@@ -1043,7 +1049,7 @@ bool GLTFMeshBuilder::GetBufferData(TArray<T> &OutArray, tinygltf::Accessor* Acc ...@@ -1043,7 +1049,7 @@ bool GLTFMeshBuilder::GetBufferData(TArray<T> &OutArray, tinygltf::Accessor* Acc
// This specialization is almost the same, but checks for the VEC2 GLTF type and uses the overloaded BufferCopy function for FVector2D // This specialization is almost the same, but checks for the VEC2 GLTF type and uses the overloaded BufferCopy function for FVector2D
template <> template <>
bool GLTFMeshBuilder::GetBufferData(TArray<FVector2D> &OutArray, tinygltf::Accessor* Accessor, bool Append) bool UGLTFMeshBuilder::GetBufferData(TArray<FVector2D> &OutArray, tinygltf::Accessor* Accessor, bool Append)
{ {
if (Accessor->type != TINYGLTF_TYPE_VEC2) if (Accessor->type != TINYGLTF_TYPE_VEC2)
{ {
...@@ -1104,7 +1110,7 @@ bool GLTFMeshBuilder::GetBufferData(TArray<FVector2D> &OutArray, tinygltf::Acces ...@@ -1104,7 +1110,7 @@ bool GLTFMeshBuilder::GetBufferData(TArray<FVector2D> &OutArray, tinygltf::Acces
// This specialization is almost the same, but checks for the VEC3 GLTF type and uses the overloaded BufferCopy function for FVector // This specialization is almost the same, but checks for the VEC3 GLTF type and uses the overloaded BufferCopy function for FVector
template <> template <>
bool GLTFMeshBuilder::GetBufferData(TArray<FVector> &OutArray, tinygltf::Accessor* Accessor, bool Append) bool UGLTFMeshBuilder::GetBufferData(TArray<FVector> &OutArray, tinygltf::Accessor* Accessor, bool Append)
{ {
if (Accessor->type != TINYGLTF_TYPE_VEC3) if (Accessor->type != TINYGLTF_TYPE_VEC3)
{ {
...@@ -1165,7 +1171,7 @@ bool GLTFMeshBuilder::GetBufferData(TArray<FVector> &OutArray, tinygltf::Accesso ...@@ -1165,7 +1171,7 @@ bool GLTFMeshBuilder::GetBufferData(TArray<FVector> &OutArray, tinygltf::Accesso
// This specialization is almost the same, but checks for the VEC4 GLTF type and uses the overloaded BufferCopy function for FVector4 // This specialization is almost the same, but checks for the VEC4 GLTF type and uses the overloaded BufferCopy function for FVector4
template <> template <>
bool GLTFMeshBuilder::GetBufferData(TArray<FVector4> &OutArray, tinygltf::Accessor* Accessor, bool Append) bool UGLTFMeshBuilder::GetBufferData(TArray<FVector4> &OutArray, tinygltf::Accessor* Accessor, bool Append)
{ {
if (Accessor->type != TINYGLTF_TYPE_VEC4) if (Accessor->type != TINYGLTF_TYPE_VEC4)
{ {
...@@ -1226,7 +1232,7 @@ bool GLTFMeshBuilder::GetBufferData(TArray<FVector4> &OutArray, tinygltf::Access ...@@ -1226,7 +1232,7 @@ bool GLTFMeshBuilder::GetBufferData(TArray<FVector4> &OutArray, tinygltf::Access
// This specialization is almost the same, but checks for a VEC3 or VEC4 GLTF type and uses the overloaded BufferCopy function for FColor // This specialization is almost the same, but checks for a VEC3 or VEC4 GLTF type and uses the overloaded BufferCopy function for FColor
template <> template <>
bool GLTFMeshBuilder::GetBufferData(TArray<FColor> &OutArray, tinygltf::Accessor* Accessor, bool Append) bool UGLTFMeshBuilder::GetBufferData(TArray<FColor> &OutArray, tinygltf::Accessor* Accessor, bool Append)
{ {
if (Accessor->type != TINYGLTF_TYPE_VEC3 && Accessor->type != TINYGLTF_TYPE_VEC4) if (Accessor->type != TINYGLTF_TYPE_VEC3 && Accessor->type != TINYGLTF_TYPE_VEC4)
{ {
...@@ -1285,7 +1291,7 @@ bool GLTFMeshBuilder::GetBufferData(TArray<FColor> &OutArray, tinygltf::Accessor ...@@ -1285,7 +1291,7 @@ bool GLTFMeshBuilder::GetBufferData(TArray<FColor> &OutArray, tinygltf::Accessor
return true; return true;
} }
bool GLTFMeshBuilder::HasAttribute(tinygltf::Mesh* Mesh, std::string AttribName) const bool UGLTFMeshBuilder::HasAttribute(tinygltf::Mesh* Mesh, std::string AttribName) const
{ {
for (auto Prim : Mesh->primitives) for (auto Prim : Mesh->primitives)
{ {
...@@ -1300,7 +1306,7 @@ bool GLTFMeshBuilder::HasAttribute(tinygltf::Mesh* Mesh, std::string AttribName) ...@@ -1300,7 +1306,7 @@ bool GLTFMeshBuilder::HasAttribute(tinygltf::Mesh* Mesh, std::string AttribName)
return false; return false;
} }
template <typename T> int32 GLTFMeshBuilder::FindInStdVector(const std::vector<T> &InVector, const T &InElement) const template <typename T> int32 UGLTFMeshBuilder::FindInStdVector(const std::vector<T> &InVector, const T &InElement) const
{ {
for (int32 i = 0; i < InVector.size(); ++i) for (int32 i = 0; i < InVector.size(); ++i)
{ {
...@@ -1313,7 +1319,7 @@ template <typename T> int32 GLTFMeshBuilder::FindInStdVector(const std::vector<T ...@@ -1313,7 +1319,7 @@ template <typename T> int32 GLTFMeshBuilder::FindInStdVector(const std::vector<T
return -1; return -1;
} }
FMatrix GLTFMeshBuilder::GetNodeTransform(tinygltf::Node* Node) FMatrix UGLTFMeshBuilder::GetNodeTransform(tinygltf::Node* Node)
{ {
if (Node->matrix.size() == 16) if (Node->matrix.size() == 16)
{ {
...@@ -1341,7 +1347,7 @@ FMatrix GLTFMeshBuilder::GetNodeTransform(tinygltf::Node* Node) ...@@ -1341,7 +1347,7 @@ FMatrix GLTFMeshBuilder::GetNodeTransform(tinygltf::Node* Node)
} }
} }
size_t GLTFMeshBuilder::TypeSize(int Type) const size_t UGLTFMeshBuilder::TypeSize(int Type) const
{ {
switch (Type) switch (Type)
{ {
...@@ -1368,7 +1374,7 @@ size_t GLTFMeshBuilder::TypeSize(int Type) const ...@@ -1368,7 +1374,7 @@ size_t GLTFMeshBuilder::TypeSize(int Type) const
} }
} }
int32 GLTFMeshBuilder::GetNumWedges(tinygltf::Primitive* Prim) const int32 UGLTFMeshBuilder::GetNumWedges(tinygltf::Primitive* Prim) const
{ {
switch (Prim->mode) switch (Prim->mode)
{ {
...@@ -1384,7 +1390,7 @@ int32 GLTFMeshBuilder::GetNumWedges(tinygltf::Primitive* Prim) const ...@@ -1384,7 +1390,7 @@ int32 GLTFMeshBuilder::GetNumWedges(tinygltf::Primitive* Prim) const
} }
} }
void GLTFMeshBuilder::GetMaterialIndices(TArray<int32>& OutArray, tinygltf::Mesh& Mesh) void UGLTFMeshBuilder::GetMaterialIndices(TArray<int32>& OutArray, tinygltf::Mesh& Mesh)
{ {
for (auto Prim : Mesh.primitives) for (auto Prim : Mesh.primitives)
{ {
...@@ -1396,7 +1402,7 @@ void GLTFMeshBuilder::GetMaterialIndices(TArray<int32>& OutArray, tinygltf::Mesh ...@@ -1396,7 +1402,7 @@ void GLTFMeshBuilder::GetMaterialIndices(TArray<int32>& OutArray, tinygltf::Mesh
} }
} }
template <typename SrcType, typename DstType> void GLTFMeshBuilder::BufferCopy(TArray<DstType>& OutArray, unsigned char* Data, int32 Count, size_t Stride) template <typename SrcType, typename DstType> void UGLTFMeshBuilder::BufferCopy(TArray<DstType>& OutArray, unsigned char* Data, int32 Count, size_t Stride)
{ {
for (int32 i = 0; i < Count; ++i) for (int32 i = 0; i < Count; ++i)
{ {
...@@ -1406,7 +1412,7 @@ template <typename SrcType, typename DstType> void GLTFMeshBuilder::BufferCopy(T ...@@ -1406,7 +1412,7 @@ template <typename SrcType, typename DstType> void GLTFMeshBuilder::BufferCopy(T
} }
} }
template <typename SrcType> void GLTFMeshBuilder::BufferCopy(TArray<FVector2D> &OutArray, unsigned char* Data, int32 Count, size_t Stride) template <typename SrcType> void UGLTFMeshBuilder::BufferCopy(TArray<FVector2D> &OutArray, unsigned char* Data, int32 Count, size_t Stride)
{ {
for (int32 i = 0; i < Count; ++i) for (int32 i = 0; i < Count; ++i)
{ {
...@@ -1416,7 +1422,7 @@ template <typename SrcType> void GLTFMeshBuilder::BufferCopy(TArray<FVector2D> & ...@@ -1416,7 +1422,7 @@ template <typename SrcType> void GLTFMeshBuilder::BufferCopy(TArray<FVector2D> &
} }
} }
template <typename SrcType> void GLTFMeshBuilder::BufferCopy(TArray<FVector> &OutArray, unsigned char* Data, int32 Count, size_t Stride) template <typename SrcType> void UGLTFMeshBuilder::BufferCopy(TArray<FVector> &OutArray, unsigned char* Data, int32 Count, size_t Stride)
{ {
for (int32 i = 0; i < Count; ++i) for (int32 i = 0; i < Count; ++i)
{ {
...@@ -1426,7 +1432,7 @@ template <typename SrcType> void GLTFMeshBuilder::BufferCopy(TArray<FVector> &Ou ...@@ -1426,7 +1432,7 @@ template <typename SrcType> void GLTFMeshBuilder::BufferCopy(TArray<FVector> &Ou
} }
} }
template <typename SrcType> void GLTFMeshBuilder::BufferCopy(TArray<FVector4> &OutArray, unsigned char* Data, int32 Count, size_t Stride) template <typename SrcType> void UGLTFMeshBuilder::BufferCopy(TArray<FVector4> &OutArray, unsigned char* Data, int32 Count, size_t Stride)
{ {
for (int32 i = 0; i < Count; ++i) for (int32 i = 0; i < Count; ++i)
{ {
...@@ -1436,7 +1442,7 @@ template <typename SrcType> void GLTFMeshBuilder::BufferCopy(TArray<FVector4> &O ...@@ -1436,7 +1442,7 @@ template <typename SrcType> void GLTFMeshBuilder::BufferCopy(TArray<FVector4> &O
} }
} }
template <typename SrcType> void GLTFMeshBuilder::BufferCopy(TArray<FColor> &OutArray, int InType, unsigned char* Data, int32 Count, size_t Stride) template <typename SrcType> void UGLTFMeshBuilder::BufferCopy(TArray<FColor> &OutArray, int InType, unsigned char* Data, int32 Count, size_t Stride)
{ {
switch (InType) switch (InType)
{ {
...@@ -1460,7 +1466,7 @@ template <typename SrcType> void GLTFMeshBuilder::BufferCopy(TArray<FColor> &Out ...@@ -1460,7 +1466,7 @@ template <typename SrcType> void GLTFMeshBuilder::BufferCopy(TArray<FColor> &Out
} }
} }
void GLTFMeshBuilder::AddTokenizedErrorMessage(TSharedRef<FTokenizedMessage> Error, FName ErrorName) void UGLTFMeshBuilder::AddTokenizedErrorMessage(TSharedRef<FTokenizedMessage> Error, FName ErrorName)
{ {
UE_LOG(LogTemp, Warning, TEXT("%s"), *(Error->ToText().ToString())); UE_LOG(LogTemp, Warning, TEXT("%s"), *(Error->ToText().ToString()));
} }
\ No newline at end of file
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "GLTFMeshBuilder.generated.h"
class UStaticMesh; class UStaticMesh;
class UMaterialInterface; class UMaterialInterface;
struct FRawMesh; struct FRawMesh;
...@@ -31,11 +33,14 @@ namespace tinygltf ...@@ -31,11 +33,14 @@ namespace tinygltf
} }
/// Works in conjunction with TinyGLTF and Unreal's Static Mesh build system to return a UStaticMesh to the factory. This class is adapted from FbxImporter. /// Works in conjunction with TinyGLTF and Unreal's Static Mesh build system to return a UStaticMesh to the factory. This class is adapted from FbxImporter.
class GLTFMeshBuilder UCLASS()
class GLTFLOADER_API UGLTFMeshBuilder : public UObject
{ {
GENERATED_BODY()
public: public:
GLTFMeshBuilder(FString FilePath); UGLTFMeshBuilder();
~GLTFMeshBuilder(); UGLTFMeshBuilder(FString FilePath);
~UGLTFMeshBuilder();
/// Returns whether we have a valid glTF scene loaded up. For a new MeshBuilder, this should always be queried before calling other functions. /// Returns whether we have a valid glTF scene loaded up. For a new MeshBuilder, this should always be queried before calling other functions.
bool LoadedSuccessfully() { return LoadSuccess; } bool LoadedSuccessfully() { return LoadSuccess; }
......
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