Commit cc9791ea by Kai Westerkamp

assimp reworlk broken

parent 9d3ced97
// Fill out your copyright notice in the Description page of Project Settings.
#include "MasterTestProject.h"
#include "GLTFDownloader.h"
void UGLTFDownloader::GetGLTF(AProceduralEntity * Reference, FString & baseUrl, FString & Url)
{
reference = Reference;
DownloadFile(ResolveRealativeURL(baseUrl, Url));
}
void UGLTFDownloader::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
reference->loadModel(Response->GetContent());
UE_LOG(GLTF, Error, TEXT("GLTF Loaded: %s "), *Request->GetURL());
//loadModel(Response);
}
\ No newline at end of file
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "HttpDownloader.h"
#include "ue4-assimp/ProceduralEntity.h"
#include "GLTFDownloader.generated.h"
/**
*
*/
UCLASS()
class MASTERTESTPROJECT_API UGLTFDownloader : public UHttpDownloader
{
GENERATED_BODY()
private:
AProceduralEntity* reference;
public:
void GetGLTF(AProceduralEntity* Reference, FString &baseUrl, FString &Url);
virtual void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
};
...@@ -8,6 +8,8 @@ void UImageDownloader::GetTextureForMaterial(UMaterialInstanceDynamic *Material, ...@@ -8,6 +8,8 @@ void UImageDownloader::GetTextureForMaterial(UMaterialInstanceDynamic *Material,
_Material = Material; _Material = Material;
_TextureName = TextureName; _TextureName = TextureName;
DownloadFile(ResolveRealativeURL(baseUrl, Url));
} }
void UImageDownloader::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) void UImageDownloader::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ProceduralEntity.h" #include "ProceduralEntity.h"
#include "ImageDownloader.h" #include "ImageDownloader.h"
#include "GLTFDownloader.h"
#include <assimp/DefaultLogger.hpp> #include <assimp/DefaultLogger.hpp>
#include <assimp/Logger.hpp> #include <assimp/Logger.hpp>
...@@ -33,7 +34,7 @@ AProceduralEntity::AProceduralEntity() ...@@ -33,7 +34,7 @@ AProceduralEntity::AProceduralEntity()
/*if (!IsTemplate(RF_Transient)) { /*if (!IsTemplate(RF_Transient)) {
std::string filename(TCHAR_TO_UTF8(*_filePath)); std::string filename(TCHAR_TO_UTF8(*_filePath));
loadModel(filename); loadModel(filename);UGLTFDownloader
}*/ }*/
} }
...@@ -41,6 +42,12 @@ AProceduralEntity::AProceduralEntity() ...@@ -41,6 +42,12 @@ AProceduralEntity::AProceduralEntity()
void AProceduralEntity::BeginPlay() void AProceduralEntity::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
UGLTFDownloader *downloader = NewObject<UGLTFDownloader>(UGLTFDownloader::StaticClass());
FString base = FString(TEXT(""));
downloader->GetGLTF(this, base, _filePath);
UE_LOG(GLTF, Error, TEXT("Loading Path: %s"), *_filePath);
} }
void AProceduralEntity::PostActorCreated() { void AProceduralEntity::PostActorCreated() {
...@@ -58,40 +65,41 @@ void AProceduralEntity::Tick(float DeltaTime) ...@@ -58,40 +65,41 @@ void AProceduralEntity::Tick(float DeltaTime)
{ {
Super::Tick( DeltaTime ); Super::Tick( DeltaTime );
struct _stat buf; //struct _stat buf;
int result; //int result;
std::string sfilename(TCHAR_TO_UTF8(*_filePath)); //std::string sfilename(TCHAR_TO_UTF8(*_filePath));
// 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(GLTF, Warning, TEXT("Problem getting info")); // UE_LOG(GLTF, Warning, TEXT("Problem getting info"));
switch (errno) { // switch (errno) {
case ENOENT: // case ENOENT:
UE_LOG(GLTF, Warning, TEXT("File not found.")); // UE_LOG(GLTF, Warning, TEXT("File not found."));
break; // break;
case EINVAL: // case EINVAL:
UE_LOG(GLTF, Warning, TEXT("Invalid parameter to _stat.")); // UE_LOG(GLTF, Warning, TEXT("Invalid parameter to _stat."));
break; // break;
default: // default:
UE_LOG(GLTF, Warning, TEXT("Unexpected error.")); // UE_LOG(GLTF, Warning, TEXT("Unexpected error."));
} // }
} //}
else { //else {
if (_lastModifiedTime == 0 || (int)buf.st_mtime > _lastModifiedTime) { // if (_lastModifiedTime == 0 || (int)buf.st_mtime > _lastModifiedTime) {
_lastModifiedTime = (int)buf.st_mtime; // _lastModifiedTime = (int)buf.st_mtime;
//
UE_LOG(GLTF, Warning, TEXT("Reloading model. %s"), *_filePath); // UE_LOG(GLTF, Warning, TEXT("Reloading model. %s"), *_filePath);
//loadModel(filename); // //loadModel(filename);
} // }
} //}
} }
void AProceduralEntity::loadModelFromBlueprint() { void AProceduralEntity::loadModelFromBlueprint() {
std::string filename(TCHAR_TO_UTF8(*_filePath)); std::string filename(TCHAR_TO_UTF8(*_filePath));
loadModel(filename); //FIXME
//loadModel(filename);
} }
/* ASSIMP IMPORT */ /* ASSIMP IMPORT */
...@@ -239,15 +247,11 @@ void AProceduralEntity::processNode(aiNode* node, const aiScene* scene, FMatrix ...@@ -239,15 +247,11 @@ void AProceduralEntity::processNode(aiNode* node, const aiScene* scene, FMatrix
} }
} }
void AProceduralEntity::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
loadModel(Response.GetContent());
}
void AProceduralEntity::loadModel(TArray<uint8> data) { void AProceduralEntity::loadModel(TArray<uint8> data) {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene* scene = importer.ReadFileFromMemory(data.GetData(), data.Num(), path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals); const aiScene* scene = importer.ReadFileFromMemory(data.GetData(), data.Num(), aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals);
//UE_LOG(GLTF, Warning, TEXT("START LOGGING")); //UE_LOG(GLTF, Warning, TEXT("START LOGGING"));
//const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals); //const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals);
...@@ -259,9 +263,9 @@ void AProceduralEntity::loadModel(TArray<uint8> data) { ...@@ -259,9 +263,9 @@ void AProceduralEntity::loadModel(TArray<uint8> data) {
importer.GetExtensionList(extensions); importer.GetExtensionList(extensions);
UE_LOG(GLTF, Error, TEXT("Extension list: %s"), *FString(extensions.c_str())); UE_LOG(GLTF, Error, TEXT("Extension list: %s"), *FString(extensions.c_str()));
wchar_t buffer[260]; //swchar_t buffer[260];
// GetModuleFileName(NULL, buffer, 260); //GetModuleFileName(NULL, buffer, 260);
UE_LOG(GLTF, Error, TEXT("Curretn Path: %s"), *FString(buffer)); //UE_LOG(GLTF, Error, TEXT("Curretn Path: %s"), *FString(buffer));
return; return;
} }
......
...@@ -10,13 +10,12 @@ ...@@ -10,13 +10,12 @@
#include "ImageUtils.h" #include "ImageUtils.h"
#include "ImageWrapper.h" //requires "ImageWrapper" in public dependencies in build CS #include "ImageWrapper.h" //requires "ImageWrapper" in public dependencies in build CS
#include "HttpDownloader.h"
#include "GameFramework/Actor.h" #include "GameFramework/Actor.h"
#include "ProceduralMeshComponent.h" #include "ProceduralMeshComponent.h"
#include "ProceduralEntity.generated.h" #include "ProceduralEntity.generated.h"
UCLASS() UCLASS()
class AProceduralEntity : public AActor, public UHttpDownloader class AProceduralEntity : public AActor
{ {
GENERATED_BODY() GENERATED_BODY()
...@@ -53,7 +52,7 @@ public: ...@@ -53,7 +52,7 @@ public:
//UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Materials") //UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Materials")
//UTexture2D* diffTexture; //UTexture2D* diffTexture;
virtual void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful); void loadModel(TArray<uint8> data);
private: private:
int32 _selectedVertex; int32 _selectedVertex;
...@@ -86,8 +85,6 @@ private: ...@@ -86,8 +85,6 @@ private:
void processMesh(aiMesh* mesh, const aiScene* scene, FMatrix modelTransform); void processMesh(aiMesh* mesh, const aiScene* scene, FMatrix modelTransform);
void processNode(aiNode* node, const aiScene* scene, FMatrix modelTransform); void processNode(aiNode* node, const aiScene* scene, FMatrix modelTransform);
void loadModel(TArray<uint8> data);
UMaterialInterface *GetMaterialForIndex(unsigned int index, const aiScene* scene); UMaterialInterface *GetMaterialForIndex(unsigned int index, const aiScene* scene);
}; };
\ No newline at end of file
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