Added asset loading and OBJ parsing, including indexing
This commit is contained in:
1 parent
086f8a1670
commit
9fcd8240e4
16 files changed
+249
-79
No files matched your search
@@ -1,21 +1,25 @@
|
||||
#pragma once
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace nf {
|
||||
class Model;
|
||||
|
||||
struct Asset {
|
||||
virtual ~Asset();
|
||||
};
|
||||
|
||||
struct AGeometry : Asset {
|
||||
const float* m_vertexBufferData;
|
||||
const unsigned int* m_indexBufferData;
|
||||
const float* m_textureCoordinatesBufferData;
|
||||
~AGeometry() override;
|
||||
struct AModel : Asset {
|
||||
char* data;
|
||||
bool alreadyLoaded;
|
||||
Model* loadedModel;
|
||||
|
||||
~AModel() override;
|
||||
};
|
||||
|
||||
struct ATexture : Asset {
|
||||
const void* m_data;
|
||||
unsigned char* data;
|
||||
size_t size;
|
||||
|
||||
~ATexture() override;
|
||||
};
|
||||
|
||||
@@ -24,6 +28,8 @@ namespace nf {
|
||||
AssetPack();
|
||||
|
||||
void load(const char* packName);
|
||||
Asset* operator[](const char* in);
|
||||
Asset* operator[](std::string& in);
|
||||
|
||||
~AssetPack();
|
||||
private:
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
#pragma once
|
||||
#include "Model.h"
|
||||
#include "Assets.h"
|
||||
|
||||
namespace nf {
|
||||
class Entity {
|
||||
struct Vec3 {
|
||||
Vec3(float x1) : x(x1), y(x1), z(x1) {}
|
||||
Vec3(float x1, float y1, float z1) : x(x1), y(y1), z(z1) {}
|
||||
float x, y, z;
|
||||
Vec3(double x1) : x(x1), y(x1), z(x1) {}
|
||||
Vec3(double x1, double y1, double z1) : x(x1), y(y1), z(z1) {}
|
||||
double x, y, z;
|
||||
};
|
||||
public:
|
||||
Entity();
|
||||
|
||||
void create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinatesBufferData = nullptr, size_t textureCoordinatesBufferSize = 0, const char* textureName = nullptr);
|
||||
//TODO: Do this using loaded assets somehow
|
||||
void setPosition(float x, float y, float z);
|
||||
void setRotation(float x, float y, float z);
|
||||
void setScale(float x);
|
||||
void setScale(float x, float y, float z);
|
||||
void create(Asset* modelAsset, Asset* textureAsset = nullptr);
|
||||
|
||||
void setPosition(double x, double y, double z);
|
||||
void setRotation(double x, double y, double z);
|
||||
void setScale(double x);
|
||||
void setScale(double x, double y, double z);
|
||||
|
||||
void bind(Shader* shader);
|
||||
Model* getModel() const;
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace nf {
|
||||
public:
|
||||
Model();
|
||||
|
||||
void create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinates = nullptr, size_t textureCoordinatesBufferSize = 0, const char* textureName = nullptr);
|
||||
void create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinates, size_t textureCoordinatesBufferSize, const unsigned char* textureData, size_t textureSize);
|
||||
void bind() override;
|
||||
|
||||
~Model();
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "Config.h"
|
||||
#include "IntroGamestate.h"
|
||||
#include "Assets.h"
|
||||
|
||||
namespace nf {
|
||||
class Drawable;
|
||||
@@ -15,19 +16,19 @@ namespace nf {
|
||||
|
||||
class Entity {
|
||||
struct Vec3 {
|
||||
Vec3(float x1) : x(x1), y(x1), z(x1) {}
|
||||
Vec3(float x1, float y1, float z1) : x(x1), y(y1), z(z1) {}
|
||||
float x, y, z;
|
||||
Vec3(double x1) : x(x1), y(x1), z(x1) {}
|
||||
Vec3(double x1, double y1, double z1) : x(x1), y(y1), z(z1) {}
|
||||
double x, y, z;
|
||||
};
|
||||
public:
|
||||
Entity();
|
||||
|
||||
void create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinatesBufferData = nullptr, size_t textureCoordinatesBufferSize = 0, const char* textureName = nullptr);
|
||||
//TODO: Do this using loaded assets somehow
|
||||
void setPosition(float x, float y, float z);
|
||||
void setRotation(float x, float y, float z);
|
||||
void setScale(float x);
|
||||
void setScale(float x, float y, float z);
|
||||
void create(Asset* modelAsset, Asset* textureAsset = nullptr);
|
||||
|
||||
void setPosition(double x, double y, double z);
|
||||
void setRotation(double x, double y, double z);
|
||||
void setScale(double x);
|
||||
void setScale(double x, double y, double z);
|
||||
|
||||
void bind(Shader* shader);
|
||||
Model* getModel() const;
|
||||
@@ -131,6 +132,5 @@ namespace nf {
|
||||
Renderer* m_renderer;
|
||||
};
|
||||
}
|
||||
#include "Assets.h"
|
||||
#include "Input.h"
|
||||
#include "Utility.h"
|
||||
@@ -5,7 +5,7 @@ namespace nf {
|
||||
public:
|
||||
Texture();
|
||||
|
||||
void create(const char* textureName);
|
||||
void create(const unsigned char* textureData, size_t textureSize);
|
||||
void bind();
|
||||
|
||||
~Texture();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <Windows.h>
|
||||
|
||||
namespace nf {
|
||||
@@ -49,4 +50,5 @@ std::exit(-1);}
|
||||
void writeFile(const std::string& filename, const std::string& in, bool encrypted = false);
|
||||
std::string readFile(const std::string& filename);
|
||||
|
||||
void parseOBJ(std::string& in, std::vector<float>& vbOut, std::vector<unsigned int>& ibOut, size_t& ibCountOut, std::vector<float>& tcOut);
|
||||
}
|
||||
Reference in new issue
Block a user