Commit 6cdeb206 by wester

testing fpr exposing API

parent 110727d8
......@@ -55,7 +55,7 @@ template<> struct GLTFType <TINYGLTF_TYPE_VEC4> { typedef FVector4 Type; }
/// @endcond
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))
{
......@@ -179,7 +179,7 @@ bool GLTFMeshBuilder::ConvertAttrib(TArray<T> &OutArray, tinygltf::Mesh* Mesh, s
// 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
template <typename T> T GLTFMeshBuilder::BufferValue(void* Data/*, uint8 Size*/)
template <typename T> T UGLTFMeshBuilder::BufferValue(void* Data/*, uint8 Size*/)
{
T Ret = T(0);
......@@ -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
template <> float GLTFMeshBuilder::BufferValue(void* Data)
template <> float UGLTFMeshBuilder::BufferValue(void* Data)
{
assert(sizeof(float) == sizeof(int32));
......@@ -212,7 +212,7 @@ template <> float GLTFMeshBuilder::BufferValue(void* Data)
return Ret;
}
template <> double GLTFMeshBuilder::BufferValue(void* Data)
template <> double UGLTFMeshBuilder::BufferValue(void* Data)
{
assert(sizeof(float) == sizeof(int64));
......@@ -240,7 +240,13 @@ struct MaterialPair
};
/// @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;
Scene = new tinygltf::Scene;
......@@ -250,18 +256,18 @@ GLTFMeshBuilder::GLTFMeshBuilder(FString FilePath)
Error = ToFString(TempError);
}
GLTFMeshBuilder::~GLTFMeshBuilder()
UGLTFMeshBuilder::~UGLTFMeshBuilder()
{
delete Loader;
delete Scene;
}
int32 GLTFMeshBuilder::GetMeshCount(FString NodeName)
int32 UGLTFMeshBuilder::GetMeshCount(FString NodeName)
{
return (int32)Scene->nodes[ToStdString(NodeName)].meshes.size();
}
FString GLTFMeshBuilder::GetRootNode()
FString UGLTFMeshBuilder::GetRootNode()
{
for (auto ThisNode : Scene->nodes)
{
......@@ -282,7 +288,7 @@ FString GLTFMeshBuilder::GetRootNode()
return FString("");
}
tinygltf::Node* GLTFMeshBuilder::GetMeshParentNode(tinygltf::Mesh* InMesh)
tinygltf::Node* UGLTFMeshBuilder::GetMeshParentNode(tinygltf::Mesh* InMesh)
{
for (auto &Node : Scene->nodes)
{
......@@ -297,7 +303,7 @@ tinygltf::Node* GLTFMeshBuilder::GetMeshParentNode(tinygltf::Mesh* InMesh)
return NULL;
}
TArray<FString> GLTFMeshBuilder::GetMeshNames(FString NodeName, bool GetChildren)
TArray<FString> UGLTFMeshBuilder::GetMeshNames(FString NodeName, bool GetChildren)
{
TArray<FString> MeshNameArray;
......@@ -317,7 +323,7 @@ TArray<FString> GLTFMeshBuilder::GetMeshNames(FString NodeName, bool GetChildren
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;
......@@ -718,7 +724,7 @@ UStaticMeshComponent* GLTFMeshBuilder::ImportStaticMeshAsSingle(UObject* InParen
// Reverse the winding order for triangle indices
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)
{
......@@ -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));
......@@ -957,22 +963,22 @@ bool GLTFMeshBuilder::BuildStaticMeshFromGeometry(tinygltf::Mesh* Mesh, UStaticM
return true;
}
UMaterialInterface* GLTFMeshBuilder::ToUMaterial(tinygltf::Material* Material)
UMaterialInterface* UGLTFMeshBuilder::ToUMaterial(tinygltf::Material* Material)
{
return UMaterial::GetDefaultMaterial(MD_Surface);
}
FString GLTFMeshBuilder::GetError()
FString UGLTFMeshBuilder::GetError()
{
return Error;
}
FString GLTFMeshBuilder::ToFString(std::string InString)
FString UGLTFMeshBuilder::ToFString(std::string InString)
{
return FString(InString.c_str());
}
std::string GLTFMeshBuilder::ToStdString(FString InString)
std::string UGLTFMeshBuilder::ToStdString(FString InString)
{
auto CharArray = InString.GetCharArray();
......@@ -982,7 +988,7 @@ std::string GLTFMeshBuilder::ToStdString(FString InString)
}
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)
{
......@@ -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
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)
{
......@@ -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
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)
{
......@@ -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
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)
{
......@@ -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
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)
{
......@@ -1285,7 +1291,7 @@ bool GLTFMeshBuilder::GetBufferData(TArray<FColor> &OutArray, tinygltf::Accessor
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)
{
......@@ -1300,7 +1306,7 @@ bool GLTFMeshBuilder::HasAttribute(tinygltf::Mesh* Mesh, std::string AttribName)
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)
{
......@@ -1313,7 +1319,7 @@ template <typename T> int32 GLTFMeshBuilder::FindInStdVector(const std::vector<T
return -1;
}
FMatrix GLTFMeshBuilder::GetNodeTransform(tinygltf::Node* Node)
FMatrix UGLTFMeshBuilder::GetNodeTransform(tinygltf::Node* Node)
{
if (Node->matrix.size() == 16)
{
......@@ -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)
{
......@@ -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)
{
......@@ -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)
{
......@@ -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)
{
......@@ -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)
{
......@@ -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)
{
......@@ -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)
{
......@@ -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)
{
......@@ -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()));
}
\ No newline at end of file
......@@ -9,6 +9,8 @@
#include <string>
#include <vector>
#include "GLTFMeshBuilder.generated.h"
class UStaticMesh;
class UMaterialInterface;
struct FRawMesh;
......@@ -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.
class GLTFMeshBuilder
UCLASS()
class GLTFLOADER_API UGLTFMeshBuilder : public UObject
{
GENERATED_BODY()
public:
GLTFMeshBuilder(FString FilePath);
~GLTFMeshBuilder();
UGLTFMeshBuilder();
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.
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