StaticGLTFComponent.h 1.93 KB
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Components/StaticMeshComponent.h"

#include <string>
#include <vector>

#include "StaticGLTFComponent.generated.h"

struct FRawMesh;

/// Forward-declared TinyGLTF types since its header can only be #included in one source file.
/// This also means that we must use pointers to these types outside of GLTFMeshBuilder.cpp.
namespace tinygltf
{
	class TinyGLTFLoader;
	class Scene;
	class Node;
	struct ACCESSOR;
	typedef struct ACCESSOR Accessor;
	struct PRIMITIVE;
	typedef struct PRIMITIVE Primitive;
	struct MESH;
	typedef struct MESH Mesh;
	struct MATERIAL;
	typedef struct MATERIAL Material;
}

/**
 * 
 */
UCLASS()
class MASTERTESTPROJECT_API UStaticGLTFComponent : public UStaticMeshComponent
{
	GENERATED_BODY()

public:

	UStaticGLTFComponent();
	~UStaticGLTFComponent();


	UPROPERTY(Category = GLTF, EditAnywhere, BlueprintReadWrite)
	FString GLTFPath;



	virtual void OnRegister() override;

private:
	tinygltf::TinyGLTFLoader* Loader;
	tinygltf::Scene* Scene;
	bool tinygltfLoadSuccess;
	FString tinygltfError;


	void ImportNodes(std::vector<std::string> nodes, FRawMesh& RawMesh, FMatrix ModelTransform);


	/// @name String Conversion
	///@{
	/// Helper functions for converting between Unreal's and STL's strings.
	static FString ToFString(std::string InString);
	static std::string ToStdString(FString InString);
	///@}

	/// Returns the transform of a node relative to its parent.
	FMatrix GetNodeTransform(tinygltf::Node* Node);

	//Copy methods

	/// @name Level 1: BufferValue
	///@{
	/// Obtains a single value from the geometry data buffer, accounting for endianness.
	/// Adapted from http://stackoverflow.com/questions/13001183/how-to-read-little-endian-integers-from-file-in-c
	/// @param Data A pointer to the raw data to cast to the desired type.
	/// @return The typed data value.
	template <typename T> T BufferValue(void* Data);
	///@}

	
};