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,
_Material = Material;
_TextureName = TextureName;
DownloadFile(ResolveRealativeURL(baseUrl, Url));
}
void UImageDownloader::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
......
......@@ -4,6 +4,7 @@
#include "ProceduralEntity.h"
#include "ImageDownloader.h"
#include "GLTFDownloader.h"
#include <assimp/DefaultLogger.hpp>
#include <assimp/Logger.hpp>
......@@ -33,7 +34,7 @@ AProceduralEntity::AProceduralEntity()
/*if (!IsTemplate(RF_Transient)) {
std::string filename(TCHAR_TO_UTF8(*_filePath));
loadModel(filename);
loadModel(filename);UGLTFDownloader
}*/
}
......@@ -41,6 +42,12 @@ AProceduralEntity::AProceduralEntity()
void AProceduralEntity::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() {
......@@ -58,40 +65,41 @@ void AProceduralEntity::Tick(float DeltaTime)
{
Super::Tick( DeltaTime );
struct _stat buf;
int result;
std::string sfilename(TCHAR_TO_UTF8(*_filePath));
// quick C++11 trick to get a char * from a std::string
char* filename = &sfilename[0];
result = _stat(filename, &buf);
if (result != 0) {
UE_LOG(GLTF, Warning, TEXT("Problem getting info"));
switch (errno) {
case ENOENT:
UE_LOG(GLTF, Warning, TEXT("File not found."));
break;
case EINVAL:
UE_LOG(GLTF, Warning, TEXT("Invalid parameter to _stat."));
break;
default:
UE_LOG(GLTF, Warning, TEXT("Unexpected error."));
}
}
else {
if (_lastModifiedTime == 0 || (int)buf.st_mtime > _lastModifiedTime) {
_lastModifiedTime = (int)buf.st_mtime;
UE_LOG(GLTF, Warning, TEXT("Reloading model. %s"), *_filePath);
//loadModel(filename);
}
}
//struct _stat buf;
//int result;
//std::string sfilename(TCHAR_TO_UTF8(*_filePath));
//// quick C++11 trick to get a char * from a std::string
//char* filename = &sfilename[0];
//result = _stat(filename, &buf);
//if (result != 0) {
// UE_LOG(GLTF, Warning, TEXT("Problem getting info"));
// switch (errno) {
// case ENOENT:
// UE_LOG(GLTF, Warning, TEXT("File not found."));
// break;
// case EINVAL:
// UE_LOG(GLTF, Warning, TEXT("Invalid parameter to _stat."));
// break;
// default:
// UE_LOG(GLTF, Warning, TEXT("Unexpected error."));
// }
//}
//else {
// if (_lastModifiedTime == 0 || (int)buf.st_mtime > _lastModifiedTime) {
// _lastModifiedTime = (int)buf.st_mtime;
//
// UE_LOG(GLTF, Warning, TEXT("Reloading model. %s"), *_filePath);
// //loadModel(filename);
// }
//}
}
void AProceduralEntity::loadModelFromBlueprint() {
std::string filename(TCHAR_TO_UTF8(*_filePath));
loadModel(filename);
//FIXME
//loadModel(filename);
}
/* ASSIMP IMPORT */
......@@ -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) {
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"));
//const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals);
......@@ -259,9 +263,9 @@ void AProceduralEntity::loadModel(TArray<uint8> data) {
importer.GetExtensionList(extensions);
UE_LOG(GLTF, Error, TEXT("Extension list: %s"), *FString(extensions.c_str()));
wchar_t buffer[260];
// GetModuleFileName(NULL, buffer, 260);
UE_LOG(GLTF, Error, TEXT("Curretn Path: %s"), *FString(buffer));
//swchar_t buffer[260];
//GetModuleFileName(NULL, buffer, 260);
//UE_LOG(GLTF, Error, TEXT("Curretn Path: %s"), *FString(buffer));
return;
}
......
......@@ -10,13 +10,12 @@
#include "ImageUtils.h"
#include "ImageWrapper.h" //requires "ImageWrapper" in public dependencies in build CS
#include "HttpDownloader.h"
#include "GameFramework/Actor.h"
#include "ProceduralMeshComponent.h"
#include "ProceduralEntity.generated.h"
UCLASS()
class AProceduralEntity : public AActor, public UHttpDownloader
class AProceduralEntity : public AActor
{
GENERATED_BODY()
......@@ -53,7 +52,7 @@ public:
//UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Materials")
//UTexture2D* diffTexture;
virtual void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void loadModel(TArray<uint8> data);
private:
int32 _selectedVertex;
......@@ -86,8 +85,6 @@ private:
void processMesh(aiMesh* mesh, 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);
};
\ 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