Added asset loading and OBJ parsing, including indexing

This commit is contained in:
Grayson Riffe (Laptop) 2021-08-30 21:26:06 -05:00
parent 086f8a1670
commit 9fcd8240e4
16 changed files with 249 additions and 79 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -109,7 +109,7 @@
<AdditionalDependencies>nf.res;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" &amp;&amp; "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" &amp;&amp; del "$(OutDir)assets\" /Q /S &amp;&amp; copy "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
<Command>cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" &amp;&amp; "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" &amp;&amp; del "$(OutDir)assets\" /Q /S &amp;&amp; move "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -135,7 +135,7 @@
<AdditionalDependencies>nf.res;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" &amp;&amp; "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" &amp;&amp; del "$(OutDir)assets\" /Q /S &amp;&amp; copy "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
<Command>cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" &amp;&amp; "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" &amp;&amp; del "$(OutDir)assets\" /Q /S &amp;&amp; move "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -157,7 +157,7 @@
<AdditionalDependencies>nf.res;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" &amp;&amp; "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" &amp;&amp; del "$(OutDir)assets\" /Q /S &amp;&amp; copy "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
<Command>cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" &amp;&amp; "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" &amp;&amp; del "$(OutDir)assets\" /Q /S &amp;&amp; move "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -183,7 +183,7 @@
<AdditionalDependencies>nf.res;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" &amp;&amp; "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" &amp;&amp; del "$(OutDir)assets\" /Q /S &amp;&amp; copy "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
<Command>cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" &amp;&amp; "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" &amp;&amp; del "$(OutDir)assets\" /Q /S &amp;&amp; move "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
@ -203,7 +203,7 @@
</ImportGroup>
<Target Name="AfterClean">
<ItemGroup>
<_delete Include="$(OutDir)**\*"/>
<_delete Include="$(OutDir)**\*" />
</ItemGroup>
<Delete Files="@(_delete)" />
</Target>

View File

@ -6,7 +6,6 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>-h</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>

View File

@ -33,7 +33,7 @@ void Success(const std::string& in) {
std::string readFile(const std::string& filename) {
std::ifstream in;
in.open(filename);
in.open(filename, std::ios::binary);
if (!in)
Error("File \"" + (std::string)filename + (std::string)"\" could not be read!");
std::stringstream ss;
@ -49,13 +49,15 @@ std::string readFile(const std::string& filename) {
void writeFile(const std::string& filename, const std::string& in, bool encrypted) {
std::ofstream out;
out.open(filename);
out.open(filename, std::ios::binary);
if (!out)
Error("File \"" + (std::string)filename + (std::string)"\" could not be written!");
std::string write(in);
if (encrypted) {
for (unsigned int i = 0; i < write.size(); i++)
write[i] = write[i] + 100;
for (unsigned int i = 0; i < write.size(); i++) {
char temp = write[i] + 100;
write[i] = temp;
}
write.insert(0, "NFEF");
}
out << write;
@ -82,7 +84,7 @@ int main(int argc, char* argv[]) {
continue;
std::string filename = currDir.path().filename().string().append(".nfpack");
Log("Creating pack \"" + filename + (std::string)"\"");
std::ifstream in;
std::string currFileContents;
std::stringstream out;
unsigned int fileCount = 0;
for (const auto& curr : std::filesystem::recursive_directory_iterator(currDir)) {
@ -93,15 +95,12 @@ int main(int argc, char* argv[]) {
Error("File \"" + relative.string() + (std::string)"\" is not of supported type!");
Log("Current file: " + relative.string());
in.open(curr.path(), std::ios::binary);
if (!in)
Error("Couldn't open \"" + relative.string() + (std::string)"\"!");
currFileContents = readFile(curr.path().string());
if (out.rdbuf()->in_avail() != 0)
out << "\n";
out << "#NFASSET " + curr.path().filename().string();
out << "\n";
out << in.rdbuf();
in.close();
out << currFileContents;
fileCount++;
}
if (fileCount == 0) {
@ -114,6 +113,8 @@ int main(int argc, char* argv[]) {
}
if (dirCount > 0)
Log("Wrote " + std::to_string(dirCount) + (std::string)" asset pack(s).");
else
Log("No directories found!");
Log("Done");
std::this_thread::sleep_for(std::chrono::seconds(2));
return 0;

View File

@ -144,7 +144,7 @@ namespace nf {
RegisterClass(&wclass);
}
else
Error("Cannot run two NF applications at once!");
Error("Cannot run multiple NF applications concurrently!");
}
RECT Application::getWindowRect() const {

View File

@ -1,5 +1,6 @@
#include "Assets.h"
#include "Model.h"
#include "Utility.h"
namespace nf {
@ -7,14 +8,12 @@ namespace nf {
}
AGeometry::~AGeometry() {
delete[] m_vertexBufferData;
delete[] m_indexBufferData;
delete[] m_textureCoordinatesBufferData;
AModel::~AModel() {
delete[] data;
}
ATexture::~ATexture() {
delete[] m_data;
delete[] data;
}
AssetPack::AssetPack() {
@ -22,8 +21,59 @@ namespace nf {
}
void AssetPack::load(const char* packName) {
std::string path = "assets/" + (std::string)packName + ".nfpack";
std::string contents = readFile(path);
std::string path = "assets/" + (std::string)packName;
std::string packContents = readFile(path);
while (packContents.size()) {
unsigned int startingPos = packContents.find_first_of("#NFASSET ") + 9;
packContents = packContents.substr(9);
unsigned int endAssetNamePos = packContents.find_first_of('\n');
std::string assetName = packContents.substr(0, endAssetNamePos);
packContents = packContents.substr(endAssetNamePos + 1);
unsigned int extensionPos = assetName.find_first_of('.');
std::string extension = assetName.substr(extensionPos + 1);
std::string assetContents;
unsigned int nextAssetPos = packContents.find("#NFASSET ");
if (nextAssetPos != std::string::npos) {
assetContents = packContents.substr(0, nextAssetPos - 1);
packContents = packContents.substr(nextAssetPos);
}
else {
assetContents = packContents;
packContents = "";
}
size_t assetSize = assetContents.size();
if (extension == "obj") {
AModel* geometry = new AModel;
geometry->data = new char[assetSize + 1];
std::memcpy(geometry->data, &assetContents[0], assetSize);
geometry->data[assetSize] = '\0';
geometry->alreadyLoaded = false;
geometry->loadedModel = nullptr;
m_assets[assetName] = geometry;
continue;
}
if (extension == "png") {
ATexture* texture = new ATexture;
texture->data = new unsigned char[assetSize];
std::memcpy(texture->data, &assetContents[0], assetSize);
texture->size = assetSize;
m_assets[assetName] = texture;
continue;
}
Error("Invalid asset extention in pack \"" + (std::string)packName + (std::string)"\"!");
}
}
Asset* AssetPack::operator[](const char* in) {
if (m_assets.find(in) == m_assets.end())
Error("Could not find asset \"" + (std::string)in + (std::string)"\" in asset pack!");
return m_assets[in];
}
Asset* AssetPack::operator[](std::string& in) {
if (m_assets.find(in) == m_assets.end())
Error("Could not find asset \"" + in + (std::string)"\" in asset pack!");
return m_assets[in];
}
AssetPack::~AssetPack() {

View File

@ -1,5 +1,9 @@
#include "Entity.h"
#include<vector>
#include "Utility.h"
namespace nf {
Entity::Entity() :
m_model(nullptr),
@ -10,25 +14,40 @@ namespace nf {
}
void Entity::create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinatesBufferData, size_t textureCoordinatesBufferSize, const char* textureName) {
void Entity::create(Asset* modelAsset, Asset* textureAsset) {
AModel& model = *(AModel*)modelAsset;
if (model.alreadyLoaded) {
m_model = model.loadedModel;
return;
}
if (!textureAsset)
Error("No texture given to Entity create function on new model load!");
ATexture& texture = *(ATexture*)textureAsset;
std::string obj = model.data;
m_model = new Model;
m_model->create(vertexBufferData, vertexBufferSize, indexBufferData, indexBufferCount, textureCoordinatesBufferData, textureCoordinatesBufferSize, textureName);
//TODO: Replace this with getting the information from the AGeometry and ATexture structs
std::vector<float> vb;
std::vector<unsigned int> ib;
size_t ibCount = 0;
std::vector<float> tc;
parseOBJ(obj, vb, ib, ibCount, tc);
m_model->create(&vb[0], vb.size() * sizeof(float), &ib[0], ibCount, &tc[0], tc.size() * sizeof(float), texture.data, texture.size);
model.alreadyLoaded = true;
model.loadedModel = m_model;
}
void Entity::setPosition(float x, float y, float z) {
void Entity::setPosition(double x, double y, double z) {
m_position = { x, y, z };
}
void Entity::setRotation(float x, float y, float z) {
void Entity::setRotation(double x, double y, double z) {
m_rotation = { x, y, z };
}
void Entity::setScale(float x) {
void Entity::setScale(double x) {
m_rotation = { x, x, x };
}
void Entity::setScale(float x, float y, float z) {
void Entity::setScale(double x, double y, double z) {
m_scale = { x, y, z };
}
@ -45,9 +64,9 @@ namespace nf {
void Entity::setModelMatrix(Shader* shader) {
glm::mat4 model(1.0f);
model = glm::translate(model, glm::vec3(m_position.x, m_position.y, m_position.z));
model = glm::rotate(model, glm::radians(m_rotation.x), glm::vec3(1.0, 0.0, 0.0));
model = glm::rotate(model, glm::radians(m_rotation.y), glm::vec3(0.0, 1.0, 0.0));
model = glm::rotate(model, glm::radians(m_rotation.z), glm::vec3(0.0, 0.0, 1.0));
model = glm::rotate(model, glm::radians((float)m_rotation.x), glm::vec3(1.0, 0.0, 0.0));
model = glm::rotate(model, glm::radians((float)m_rotation.y), glm::vec3(0.0, 1.0, 0.0));
model = glm::rotate(model, glm::radians((float)m_rotation.z), glm::vec3(0.0, 0.0, 1.0));
model = glm::scale(model, glm::vec3(m_scale.x, m_scale.y, m_scale.z));
shader->setUniform("model", model);
}

View File

@ -6,18 +6,17 @@ namespace nf {
Model::Model() {
}
void Model::create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinatesBufferData, size_t textureCoordinatesBufferSize, const char* textureName) {
void Model::create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinatesBufferData, size_t textureCoordinatesBufferSize, const unsigned char* textureData, size_t textureSize) {
m_vao = new VertexArray;
m_vao->addBuffer(vertexBufferData, vertexBufferSize);
m_vao->push<float>(2);
//TODO: Change this to 3
m_vao->push<float>(3);
m_vao->finishBufferLayout();
if (textureCoordinatesBufferData && textureCoordinatesBufferSize && textureName) {
if (textureCoordinatesBufferData && textureCoordinatesBufferSize && textureData) {
m_vao->addBuffer(textureCoordinatesBufferData, textureCoordinatesBufferSize);
m_vao->push<float>(2);
m_vao->finishBufferLayout();
m_texture = new Texture;
m_texture->create(textureName);
m_texture->create(textureData, textureSize);
}
m_ib = new IndexBuffer(indexBufferData, indexBufferCount);
}

View File

@ -11,18 +11,17 @@ namespace nf {
glGenTextures(1, &m_id);
}
void Texture::create(const char* textureName) {
void Texture::create(const unsigned char* textureData, size_t textureSize) {
int width, height, nChannels;
stbi_set_flip_vertically_on_load(true);
unsigned char* texture = stbi_load(textureName, &width, &height, &nChannels, 0);
//TODO: Load from memory
unsigned char* texture = stbi_load_from_memory(textureData, textureSize, &width, &height, &nChannels, 0);
if (!texture)
Error("Texture \"" + (std::string)textureName + "\" failed to load from memory!");
Error("Texture failed to load from memory!");
glBindTexture(GL_TEXTURE_2D, m_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
//glGenerateMipmap(GL_TEXTURE_2D);
glGenerateMipmap(GL_TEXTURE_2D);
stbi_image_free(texture);
}

View File

@ -3,6 +3,7 @@
#include <iostream>
#include <sstream>
#include <fstream>
#include <map>
#include "Config.h"
@ -28,24 +29,22 @@ namespace nf {
std::chrono::duration<float> time = getCurrentTime();
std::printf("[%.4f] Debug: %.4f\n", time.count(), in);
}
//TODO: Test every Error in release mode
void Debug::ErrorImp(const char* in, const char* filename, int line) {
std::chrono::duration<float> time = getCurrentTime();
HANDLE cmd = GetStdHandle(STD_OUTPUT_HANDLE);
static HANDLE cmd = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(cmd, FOREGROUND_RED);
std::printf("[%.4f] Error (%s, %i): %s\n", time.count(), filename, line, in);
SetConsoleTextAttribute(cmd, 7);
FindClose(cmd);
}
void Debug::ErrorImp(const std::string& in, const char* filename, int line) {
std::chrono::duration<float> time = getCurrentTime();
HANDLE cmd = GetStdHandle(STD_OUTPUT_HANDLE);
static HANDLE cmd = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(cmd, FOREGROUND_RED);
std::printf("[%.4f] Error (%s, %i): ", time.count(), filename, line);
std::cout << in << "\n";
SetConsoleTextAttribute(cmd, 7);
FindClose(cmd);
}
std::chrono::duration<float> Debug::getCurrentTime() {
@ -96,7 +95,7 @@ namespace nf {
CreateDirectory(folders.c_str(), NULL);
}
std::ofstream out;
out.open(filename);
out.open(filename, std::ios::binary);
if (!out)
Error("File \"" + (std::string)filename + (std::string)"\" could not be written!");
std::string write(in);
@ -118,13 +117,108 @@ namespace nf {
std::stringstream ss;
ss << in.rdbuf();
std::string read(ss.str());
if (read.size() > 4 && read.substr(0, 4) == "NFEF" ){
if (read.size() > 4 && read.substr(0, 4) == "NFEF") {
read = read.substr(4);
for (unsigned int i = 0; i < read.size(); i++)
read[i] = read[i] - 100;
}
return read;
}
void parseOBJ(std::string& in, std::vector<float>& vbOut, std::vector<unsigned int>& ibOut, size_t& ibCountOut, std::vector<float>& tcOut) {
std::string file = in;
std::vector<float> vbRaw, tcRaw;
std::vector<unsigned int> vertexIndices, uvIndices, normalIndices;
std::vector<float> tempVertices;
std::vector<float> tempTC;
while (true) {
char line[500];
int remove = 0;
int result = sscanf_s(file.c_str(), "\n%s", line, (unsigned)_countof(line));
if (result == EOF)
break;
if (std::strcmp(line, "v") == 0) {
float x = 0.0, y = 0.0, z = 0.0;
sscanf_s(file.c_str(), "\nv %f %f %f\n", &x, &y, &z);
remove = 28;
tempVertices.push_back(x);
tempVertices.push_back(y);
tempVertices.push_back(z);
}
else if (std::strcmp(line, "vt") == 0) {
float u = 0.0, v = 0.0;
sscanf_s(file.c_str(), "\nvt %f %f\n", &u, &v);
remove = 18;
tempTC.push_back(u);
tempTC.push_back(v);
}
else if (std::strcmp(line, "f") == 0) {
unsigned int vertexIndex[3], uvIndex[3];
sscanf_s(file.c_str(), "\nf %d/%d %d/%d %d/%d\n", &vertexIndex[0], &uvIndex[0], &vertexIndex[1], &uvIndex[1], &vertexIndex[2], &uvIndex[2]);
remove = 12;
vertexIndices.push_back(vertexIndex[0]);
vertexIndices.push_back(vertexIndex[1]);
vertexIndices.push_back(vertexIndex[2]);
uvIndices.push_back(uvIndex[0]);
uvIndices.push_back(uvIndex[1]);
uvIndices.push_back(uvIndex[2]);
}
unsigned int pos = file.find(line) + strlen(line) + remove;
file = file.substr(pos);
}
for (unsigned int i = 0; i < vertexIndices.size(); i++) {
unsigned int vertexIndex = vertexIndices[i];
unsigned int uvIndex = uvIndices[i];
float vertexX = tempVertices[(vertexIndex - 1) * 3];
float vertexY = tempVertices[(vertexIndex - 1) * 3 + 1];
float vertexZ = tempVertices[(vertexIndex - 1) * 3 + 2];
float vertexU = tempTC[(uvIndex - 1) * 2];
float vertexV = tempTC[(uvIndex - 1) * 2 + 1];
vbRaw.push_back(vertexX);
vbRaw.push_back(vertexY);
vbRaw.push_back(vertexZ);
tcRaw.push_back(vertexU);
tcRaw.push_back(vertexV);
}
struct Vertex {
float x;
float y;
float z;
float u;
float v;
bool operator<(const Vertex other) const {
return std::memcmp((void*)this, (void*)&other, sizeof(Vertex)) > 0;
}
};
std::map<Vertex, unsigned int> vertexMap;
for (unsigned int i = 0; i * 3 < vbRaw.size(); i++) {
Vertex curr = { vbRaw[(i * 3)], vbRaw[(i * 3) + 1], vbRaw[(i * 3) + 2], tcRaw[(i * 2)], tcRaw[(i * 2) + 1] };
bool found = false;
found = vertexMap.find(curr) != vertexMap.end();
if (found) {
unsigned int index = vertexMap[curr];
ibOut.push_back(index);
ibCountOut++;
}
else {
vbOut.push_back(curr.x);
vbOut.push_back(curr.y);
vbOut.push_back(curr.z);
tcOut.push_back(curr.u);
tcOut.push_back(curr.v);
unsigned int index = (vbOut.size() / 3) - 1;
ibOut.push_back(index);
vertexMap[curr] = index;
ibCountOut++;
}
}
}
}
//Nvidia Optimius support

View File

@ -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:

View File

@ -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;

View File

@ -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();

View File

@ -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"

View File

@ -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();

View File

@ -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);
}