Commit 0906751a by wester

GLTF start

parent e958cca2
// Fill out your copyright notice in the Description page of Project Settings.
#include "MasterTestProject.h"
#include <codecvt>
#define TINYGLTF_LOADER_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#include "tiny_gltf_loader.h"
#include "StaticGLTFComponent.h"
UStaticGLTFComponent::UStaticGLTFComponent()
{
GLTFPath = TEXT("H:/Repositories/MasterArbeit/glTF-Sample-Models/1.0/Duck/glTF/Duck.gltf");
Loader = new tinygltf::TinyGLTFLoader;
Scene = new tinygltf::Scene;
}
UStaticGLTFComponent::~UStaticGLTFComponent() {
delete Loader;
delete Scene;
}
void UStaticGLTFComponent::OnRegister()
{
Super::OnRegister();
std::string TempError;
tinygltfLoadSuccess = Loader->LoadFromFile((*Scene), TempError, ToStdString(GLTFPath));
tinygltfError = ToFString(TempError);
if(!tinygltfLoadSuccess){
UE_LOG(GLTF, Error, TEXT("GLTF loading Error: %s"), *tinygltfError);
return;
}
UE_LOG(GLTF, Log,TEXT("GLTF parsed %s"), *tinygltfError);
//get Default Scene and Root Nodes
if (Scene->defaultScene.empty()) {
UE_LOG(GLTF, Error, TEXT("Default Scene Empty"));
}
for (auto RootNode : Scene->scenes[Scene->defaultScene]) {
UE_LOG(GLTF, Log, TEXT("Root Node %s"), *ToFString(RootNode));
}
}
FString UStaticGLTFComponent::ToFString(std::string InString)
{
return FString(InString.c_str());
}
std::string UStaticGLTFComponent::ToStdString(FString InString)
{
auto CharArray = InString.GetCharArray();
std::wstring WideString(&CharArray[0]);
std::wstring_convert< std::codecvt_utf8<wchar_t> > Convert;
return Convert.to_bytes(WideString);
}
\ No newline at end of file
......@@ -3,8 +3,33 @@
#pragma once
#include "Components/StaticMeshComponent.h"
#include <string>
#include <vector>
#include "StaticGLTFComponent.generated.h"
/// 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;
}
/**
*
*/
......@@ -16,6 +41,7 @@ class MASTERTESTPROJECT_API UStaticGLTFComponent : public UStaticMeshComponent
public:
UStaticGLTFComponent();
~UStaticGLTFComponent();
UPROPERTY(Category = GLTF, EditAnywhere, BlueprintReadWrite)
......@@ -26,7 +52,17 @@ public:
virtual void OnRegister() override;
private:
//tinygltf::TinyGLTFLoader* Loader;
//tinygltf::Scene* Scene;
tinygltf::TinyGLTFLoader* Loader;
tinygltf::Scene* Scene;
bool tinygltfLoadSuccess;
FString tinygltfError;
/// @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);
///@}
};
This source diff could not be displayed because it is too large. You can view the blob instead.
Copyright (c) 2016, Syoyo Fujita
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
......@@ -51,9 +51,10 @@ void AGLTFDisplay::BeginPlay()
if (!StaticMeshComponentCopy->IsRegistered())
StaticMeshComponentCopy->RegisterComponent();
StaticMeshComponentCopy->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
StaticMeshComponentCopy->SetRelativeLocation(FVector(100.f));
StaticGLTFComponent->SetRelativeLocation(FVector(-100.f));
StaticMeshComponentCopy->SetRelativeLocation(FVector(100.f));
SetActorLocation(zero, false);
......
......@@ -3,7 +3,7 @@
#pragma once
#include "GameFramework/Actor.h"
#include "staticGLTFComponent.h"
#include "GLTF/StaticGLTFComponent.h"
#include "GLTFDisplay.generated.h"
UCLASS()
......
......@@ -7,10 +7,7 @@ public class MasterTestProject : ModuleRules
public MasterTestProject(TargetInfo Target)
{
PublicIncludePaths.AddRange(new string[] { "GLTFLoader/Public", "GLTFLoader/Classes" });
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "GLTFLoader" });
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", });
PrivateDependencyModuleNames.AddRange(new string[] { });
......
......@@ -3,3 +3,7 @@
#include "MasterTestProject.h"
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, MasterTestProject, "MasterTestProject" );
//General Log
DEFINE_LOG_CATEGORY(GLTF);
......@@ -4,3 +4,5 @@
#include "Engine.h"
//General Log
DECLARE_LOG_CATEGORY_EXTERN(GLTF, Log, All);
......@@ -4,5 +4,3 @@
#include "MasterTestProjectGameModeBase.h"
......@@ -5,6 +5,7 @@
#include "GameFramework/GameModeBase.h"
#include "MasterTestProjectGameModeBase.generated.h"
/**
*
*/
......@@ -13,7 +14,7 @@ class MASTERTESTPROJECT_API AMasterTestProjectGameModeBase : public AGameModeBas
{
GENERATED_BODY()
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "MasterTestProject.h"
#include "GLTFLoader/Public/GLTFMeshBuilder.h"
//#include "GLTF/GLTFMeshBuilder.h"
#include "StaticGLTFComponent.h"
UStaticGLTFComponent::UStaticGLTFComponent()
{
GLTFPath = TEXT("H:/Repositories/MasterArbeit/glTF-Sample-Models/1.0/Duck/glTF/Duck.gltf");
//Loader = new tinygltf::TinyGLTFLoader;
//Scene = new tinygltf::Scene;
}
void UStaticGLTFComponent::OnRegister()
{
UGLTFMeshBuilder Builder();
//std::string TempError;
//LoadSuccess = Loader->LoadFromFile((*Scene), TempError, ToStdString(FilePath));
//Error = ToFString(TempError);
//GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("Hello World, this is FPSGameMode!"));
}
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