render from json
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
// This only works with opengl!!!!
|
||||
|
||||
#ifndef JOBJECT_H
|
||||
#define JOBJECT_H
|
||||
|
||||
#include "Archimedes.h"
|
||||
|
||||
@@ -9,6 +11,8 @@
|
||||
#include "utils/Objects/Body.h"
|
||||
#include "utils/Objects/Camera.h"
|
||||
|
||||
#include "JObject.h"
|
||||
|
||||
class Sandbox : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
@@ -50,10 +54,13 @@ class Sandbox : public Archimedes::Module {
|
||||
" FragColor = color;\n"
|
||||
"}\n\0";
|
||||
|
||||
Archimedes::JObject jObject;
|
||||
|
||||
Archimedes::Shader cubeShader, gridShader;
|
||||
Archimedes::Body cube, grid, hexagon;
|
||||
|
||||
Archimedes::Camera camera;
|
||||
|
||||
std::vector<float> gridVertices = {
|
||||
-1.0f, 0.0f, 1.0f,
|
||||
1.0f, 0.0f, 1.0f,
|
||||
@@ -133,6 +140,77 @@ class Sandbox : public Archimedes::Module {
|
||||
1,
|
||||
|
||||
};
|
||||
|
||||
Archimedes::Body readOBJ(std::string path, Archimedes::Shader shader) {
|
||||
|
||||
std::ifstream file(path);
|
||||
|
||||
if(!file.is_open()) return Archimedes::Body();
|
||||
|
||||
std::string s;
|
||||
|
||||
std::vector<float> verticies;
|
||||
std::vector<unsigned int> indicies;
|
||||
|
||||
verticies.reserve(3 * 100);
|
||||
indicies.reserve(100);
|
||||
|
||||
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 Archimedes::Body(
|
||||
Archimedes::VertexBuffer(verticies),
|
||||
Archimedes::IndexArray(indicies),
|
||||
Archimedes::VertexLayout(),
|
||||
shader
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -140,3 +218,5 @@ class Sandbox : public Archimedes::Module {
|
||||
typedef Sandbox mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user