render obj file
This commit is contained in:
@@ -1,16 +1,85 @@
|
||||
#include "pch.hpp"
|
||||
|
||||
#include "Object.h"
|
||||
#include "utils/Objects/Body.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
Body readOBJ(std::string path, Shader shader) {
|
||||
|
||||
std::ifstream file(path);
|
||||
|
||||
if(!file.is_open()) return Body();
|
||||
|
||||
std::string s;
|
||||
|
||||
std::vector<float> verticies;
|
||||
std::vector<unsigned int> indicies;
|
||||
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
|
||||
float point;
|
||||
unsigned int idx;
|
||||
|
||||
while(!file.eof()) {
|
||||
getline(file, s, ' ');
|
||||
|
||||
//std::cout << "\nline start: " << s << std::endl;
|
||||
|
||||
if(s == "v") {
|
||||
file >> point;
|
||||
verticies.push_back(point);
|
||||
//std::cout << "point1: " << point << std::endl;
|
||||
|
||||
file >> point;
|
||||
verticies.push_back(point);
|
||||
//std::cout << "point2: " << point << std::endl;
|
||||
|
||||
file >> point;
|
||||
verticies.push_back(point);
|
||||
//std::cout << "point3: " << point << std::endl;
|
||||
|
||||
//std::cout << "index: " << j << std::endl;
|
||||
|
||||
getline(file, s);
|
||||
//file.ignore();
|
||||
} else if(s == "f") {
|
||||
|
||||
file >> idx;
|
||||
indicies.push_back(--idx);
|
||||
file.ignore(5, ' ');
|
||||
|
||||
file >> idx;
|
||||
indicies.push_back(--idx);
|
||||
file.ignore(5, ' ');
|
||||
|
||||
file >> idx;
|
||||
indicies.push_back(--idx);
|
||||
getline(file, s);
|
||||
|
||||
} else {
|
||||
getline(file, s);
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
return Body(
|
||||
VertexBuffer(verticies),
|
||||
IndexArray(indicies),
|
||||
VertexLayout(),
|
||||
shader
|
||||
);
|
||||
}
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
class JObject {
|
||||
|
||||
public:
|
||||
JObject(std::string path) {
|
||||
JObject() {}
|
||||
|
||||
void load(std::string path) {
|
||||
std::ifstream file(path);
|
||||
if (!file.is_open()) goodJSON = false;
|
||||
document = json::parse(file);
|
||||
@@ -25,9 +94,41 @@ namespace Archimedes {
|
||||
|
||||
bool isValid() const { return goodJSON; }
|
||||
|
||||
std::vector<Object> buildObjects() {
|
||||
Body createCircle(json& element, std::string name) {
|
||||
std::vector<float> v;
|
||||
std::vector<unsigned int> i;
|
||||
|
||||
std::vector<Object> v;
|
||||
for(int it = 0; it < resolution; it++) {
|
||||
v.push_back(glm::cos(2.0f * glm::pi<float>() / resolution));
|
||||
v.push_back(glm::sin(2.0f * glm::pi<float>() / resolution));
|
||||
v.push_back(0.0f);
|
||||
|
||||
i.push_back(it);
|
||||
}
|
||||
|
||||
return Body(
|
||||
VertexBuffer(v),
|
||||
IndexArray(i),
|
||||
VertexLayout(),
|
||||
shader
|
||||
);
|
||||
}
|
||||
|
||||
Body createRect(json& element, std::string name) {
|
||||
return Body();
|
||||
}
|
||||
|
||||
Body createPoly(json& element, std::string name) {
|
||||
return Body();
|
||||
}
|
||||
|
||||
Body createText(json& element, std::string name) {
|
||||
return Body();
|
||||
}
|
||||
|
||||
std::vector<Body> buildObjects() {
|
||||
|
||||
std::vector<Body> v;
|
||||
|
||||
|
||||
for (json::const_iterator it = templates.cbegin(); it != templates.cend(); it++)
|
||||
@@ -35,7 +136,9 @@ namespace Archimedes {
|
||||
json element = *it;
|
||||
std::string name = element["name"];
|
||||
std::string type = element["type"];
|
||||
if (type == "CIRCLE") {}
|
||||
if (type == "CIRCLE") {
|
||||
objectMap[name] = createCircle(element, name);
|
||||
}
|
||||
if (type == "SQUARE") {}
|
||||
if (type == "RECTANGLE") {}
|
||||
if (type == "POLYGON") {}
|
||||
@@ -47,8 +150,16 @@ namespace Archimedes {
|
||||
|
||||
private:
|
||||
|
||||
std::unordered_map<std::string, Body> objectMap;
|
||||
|
||||
std::unordered_map<std::string, Body> templateMap;
|
||||
|
||||
bool goodJSON = true;
|
||||
|
||||
Shader shader;
|
||||
|
||||
unsigned int resolution = 50;
|
||||
|
||||
json document, templates, objects, setup, cameras, lights, actions;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user