Just pushing what I have.
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 14s
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 14s
This commit is contained in:
46
assets/models/cube.amo
Normal file
46
assets/models/cube.amo
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
ao Cube 1
|
||||||
|
v 8
|
||||||
|
1.000000 1.000000 1.000000
|
||||||
|
1.000000 1.000000 -1.000000
|
||||||
|
1.000000 -1.000000 1.000000
|
||||||
|
1.000000 -1.000000 -1.000000
|
||||||
|
-1.000000 1.000000 1.000000
|
||||||
|
-1.000000 1.000000 -1.000000
|
||||||
|
-1.000000 -1.000000 1.000000
|
||||||
|
-1.000000 -1.000000 -1.000000
|
||||||
|
vt 14
|
||||||
|
0.625000 0.500000
|
||||||
|
0.875000 0.500000
|
||||||
|
0.875000 0.750000
|
||||||
|
0.625000 0.750000
|
||||||
|
0.375000 0.750000
|
||||||
|
0.625000 1.000000
|
||||||
|
0.375000 1.000000
|
||||||
|
0.375000 0.000000
|
||||||
|
0.625000 0.000000
|
||||||
|
0.625000 0.250000
|
||||||
|
0.375000 0.250000
|
||||||
|
0.125000 0.500000
|
||||||
|
0.375000 0.500000
|
||||||
|
0.125000 0.750000
|
||||||
|
vn 6
|
||||||
|
0.000000 0.000000 1.000000
|
||||||
|
0.000000 -1.000000 0.000000
|
||||||
|
-1.000000 0.000000 0.000000
|
||||||
|
0.000000 0.000000 -1.000000
|
||||||
|
1.000000 0.000000 0.000000
|
||||||
|
0.000000 1.000000 0.000000
|
||||||
|
f 12
|
||||||
|
2 0 0 0 1 0 4 2 0
|
||||||
|
7 3 1 3 4 1 2 3 1
|
||||||
|
5 5 2 7 6 2 6 7 2
|
||||||
|
7 8 3 5 9 3 1 10 3
|
||||||
|
3 11 4 1 12 4 0 4 4
|
||||||
|
1 13 5 5 12 5 4 0 5
|
||||||
|
2 0 0 4 1 0 6 2 0
|
||||||
|
7 3 1 2 4 1 6 3 1
|
||||||
|
5 5 2 6 6 2 4 7 2
|
||||||
|
7 8 3 1 9 3 3 10 3
|
||||||
|
3 11 4 0 12 4 2 4 4
|
||||||
|
1 13 5 4 12 5 0 0 5
|
||||||
|
end
|
@@ -93,6 +93,7 @@ public:
|
|||||||
const std::vector<Normal>& vertex_normals = {}, const std::vector<TextureCoordinate>& texture_coordinates = {});
|
const std::vector<Normal>& vertex_normals = {}, const std::vector<TextureCoordinate>& texture_coordinates = {});
|
||||||
|
|
||||||
static VertexArray LoadWavefrontOBJ(const std::string& file_text);
|
static VertexArray LoadWavefrontOBJ(const std::string& file_text);
|
||||||
|
static VertexArray LoadAMO(const std::string& file_text);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
6
main.cpp
6
main.cpp
@@ -317,7 +317,7 @@ int main(int argc, char** argv) {
|
|||||||
window->SetResizable(true);
|
window->SetResizable(true);
|
||||||
window->SetVsyncEnabled(true);
|
window->SetVsyncEnabled(true);
|
||||||
|
|
||||||
std::ifstream file("assets/models/cube.obj");
|
std::ifstream file("assets/models/cube.amo");
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -325,9 +325,9 @@ int main(int argc, char** argv) {
|
|||||||
buffer << file.rdbuf();
|
buffer << file.rdbuf();
|
||||||
std::string file_text = buffer.str();
|
std::string file_text = buffer.str();
|
||||||
file.close();
|
file.close();
|
||||||
//std::cout << "File contents:\n" << file_text << std::endl;
|
std::cout << file_text << std::endl;
|
||||||
|
|
||||||
auto result = VertexArray::LoadWavefrontOBJ(file_text);
|
auto result = VertexArray::LoadAMO(file_text);
|
||||||
|
|
||||||
ReWindow::Logger::Error.EnableConsole(false);
|
ReWindow::Logger::Error.EnableConsole(false);
|
||||||
ReWindow::Logger::Warning.EnableConsole(false);
|
ReWindow::Logger::Warning.EnableConsole(false);
|
||||||
|
9
src/internals/include/AMO.h
Normal file
9
src/internals/include/AMO.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace JGL {
|
||||||
|
class VertexArray;
|
||||||
|
/*
|
||||||
|
VertexArray LoadAMO(const std::string& file_text);
|
||||||
|
*/
|
||||||
|
}
|
@@ -3,5 +3,7 @@
|
|||||||
|
|
||||||
namespace JGL {
|
namespace JGL {
|
||||||
class VertexArray;
|
class VertexArray;
|
||||||
|
// Currently requires "Triangulate Mesh" ticked in Blender.
|
||||||
|
// TODO use the number of slashes in the first "face-line" to detect quads.
|
||||||
VertexArray LoadWavefrontOBJ(const std::string& file_text);
|
VertexArray LoadWavefrontOBJ(const std::string& file_text);
|
||||||
}
|
}
|
@@ -1,4 +1,5 @@
|
|||||||
#include "../include/WavefrontOBJ.h"
|
#include "../include/WavefrontOBJ.h"
|
||||||
|
#include "../include/AMO.h"
|
||||||
#include <JGL/types/VertexArray.h>
|
#include <JGL/types/VertexArray.h>
|
||||||
#include <JGL/logger/logger.h>
|
#include <JGL/logger/logger.h>
|
||||||
|
|
||||||
@@ -61,7 +62,19 @@ std::pair<Vector3, unsigned long> ParseVector3(const std::string& file_text, con
|
|||||||
return {Vector3(x_result.first, y_result.first, z_result.first), z_result.second + 1};
|
return {Vector3(x_result.first, y_result.first, z_result.first), z_result.second + 1};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::array<Vector3, 3>, unsigned long> ParseFaceData(const std::string& file_text, const unsigned long& offset) {
|
std::pair<Vector4, unsigned long> ParseVector4(const std::string& file_text, const unsigned long& offset) {
|
||||||
|
auto x_result = ParseNumber(file_text, offset);
|
||||||
|
auto y_result = ParseNumber(file_text, x_result.second + 1);
|
||||||
|
auto z_result = ParseNumber(file_text, y_result.second + 1);
|
||||||
|
auto w_result = ParseNumber(file_text, z_result.second + 1);
|
||||||
|
|
||||||
|
if (x_result.second == offset || y_result.second == x_result.second || z_result.second == y_result.second || w_result.second == z_result.second)
|
||||||
|
return {Vector4(0, 0, 0, 0), offset};
|
||||||
|
|
||||||
|
return {Vector4(x_result.first, y_result.first, z_result.first, w_result.first), w_result.second + 1};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<std::array<Vector3, 3>, unsigned long> ParseWavefrontFaceData(const std::string& file_text, const unsigned long& offset) {
|
||||||
unsigned long new_offset = offset;
|
unsigned long new_offset = offset;
|
||||||
std::array<Vector3, 3> face_data;
|
std::array<Vector3, 3> face_data;
|
||||||
|
|
||||||
@@ -111,7 +124,6 @@ VertexArray JGL::LoadWavefrontOBJ(const std::string &file_text) {
|
|||||||
std::vector<Vertex> temp_vertices;
|
std::vector<Vertex> temp_vertices;
|
||||||
|
|
||||||
unsigned long offset = 0;
|
unsigned long offset = 0;
|
||||||
|
|
||||||
while (offset < file_text.size()) {
|
while (offset < file_text.size()) {
|
||||||
char c = file_text[offset];
|
char c = file_text[offset];
|
||||||
|
|
||||||
@@ -161,7 +173,7 @@ VertexArray JGL::LoadWavefrontOBJ(const std::string &file_text) {
|
|||||||
else if (c == 'f' && offset + 1 < file_text.size() && file_text[offset + 1] == ' ') {
|
else if (c == 'f' && offset + 1 < file_text.size() && file_text[offset + 1] == ' ') {
|
||||||
offset += 2;
|
offset += 2;
|
||||||
|
|
||||||
auto faceline_result = ParseFaceData(file_text, offset);
|
auto faceline_result = ParseWavefrontFaceData(file_text, offset);
|
||||||
if (faceline_result.second != offset) {
|
if (faceline_result.second != offset) {
|
||||||
faceline_data.push_back(faceline_result.first);
|
faceline_data.push_back(faceline_result.first);
|
||||||
offset = faceline_result.second;
|
offset = faceline_result.second;
|
||||||
@@ -200,4 +212,125 @@ VertexArray JGL::LoadWavefrontOBJ(const std::string &file_text) {
|
|||||||
final_indices.data(), final_indices.size(),
|
final_indices.data(), final_indices.size(),
|
||||||
final_normals.data(), final_normals.size(),
|
final_normals.data(), final_normals.size(),
|
||||||
final_uvs.data(), final_uvs.size());
|
final_uvs.data(), final_uvs.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
VertexArray JGL::LoadAMO(const std::string& file_text) {
|
||||||
|
std::vector<Vector3> temp_vertices;
|
||||||
|
std::vector<Vector3> temp_normals;
|
||||||
|
std::vector<Vector2> temp_uvs;
|
||||||
|
std::vector<std::array<Vector3, 3>> faceline_data;
|
||||||
|
std::string name;
|
||||||
|
|
||||||
|
unsigned long offset = 0;
|
||||||
|
while (offset < file_text.size()) {
|
||||||
|
char c = file_text[offset];
|
||||||
|
|
||||||
|
// If we've dropped on a newline character somehow then just skip passed it.
|
||||||
|
if (c == '\n' || c == '\r') {
|
||||||
|
offset++; continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// File name.
|
||||||
|
else if (offset + 2 < file_text.size() && c == 'a' && file_text[offset + 1] == 'o' && file_text[offset + 2] == ' ') {
|
||||||
|
offset += 3;
|
||||||
|
while (offset < file_text.size()) {
|
||||||
|
if (file_text[offset] != '\n' && file_text[offset] != '\r')
|
||||||
|
name.push_back(file_text[offset]), offset++;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vertices
|
||||||
|
else if (offset + 1 < file_text.size() && c == 'v' && file_text[offset + 1] == ' ') {
|
||||||
|
offset += 2; auto parsed_number = ParseNumber(file_text, offset);
|
||||||
|
|
||||||
|
if (parsed_number.second == offset)
|
||||||
|
Logger::Fatal("We couldn't interpret the Vertex count at: " + std::to_string(offset));
|
||||||
|
|
||||||
|
unsigned long vertex_count = parsed_number.first;
|
||||||
|
offset = parsed_number.second;
|
||||||
|
|
||||||
|
for (unsigned long i = 0; i < vertex_count; i++) {
|
||||||
|
// Skip by newlines.
|
||||||
|
while (file_text[offset] == '\n' || file_text[offset] == '\r')
|
||||||
|
offset++;
|
||||||
|
|
||||||
|
auto parsed_vector3 = ParseVector3(file_text, offset);
|
||||||
|
if (parsed_vector3.second == offset)
|
||||||
|
Logger::Fatal("We couldn't interpret the Vertex at: " + std::to_string(offset));
|
||||||
|
|
||||||
|
temp_vertices.push_back(parsed_vector3.first);
|
||||||
|
offset = parsed_vector3.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UVs
|
||||||
|
else if (offset + 2 < file_text.size() && c == 'v' && file_text[offset + 1] == 't' && file_text[offset + 2] == ' ') {
|
||||||
|
offset += 3; auto parsed_number = ParseNumber(file_text, offset);
|
||||||
|
|
||||||
|
if (parsed_number.second == offset)
|
||||||
|
Logger::Fatal("We couldn't interpret the UV count at: " + std::to_string(offset));
|
||||||
|
|
||||||
|
unsigned long uv_count = parsed_number.first;
|
||||||
|
offset = parsed_number.second;
|
||||||
|
|
||||||
|
for (unsigned long i = 0; i < uv_count; i++) {
|
||||||
|
// Skip by newlines.
|
||||||
|
while (file_text[offset] == '\n' || file_text[offset] == '\r')
|
||||||
|
offset++;
|
||||||
|
|
||||||
|
auto parsed_vector2 = ParseVector2(file_text, offset);
|
||||||
|
if (parsed_vector2.second == offset)
|
||||||
|
Logger::Fatal("We couldn't interpret the UV at: " + std::to_string(offset));
|
||||||
|
|
||||||
|
temp_uvs.push_back(parsed_vector2.first);
|
||||||
|
offset = parsed_vector2.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normals
|
||||||
|
else if (offset + 2 < file_text.size() && c == 'v' && file_text[offset + 1] == 'n' && file_text[offset + 2] == ' ') {
|
||||||
|
offset += 3; auto parsed_number = ParseNumber(file_text, offset);
|
||||||
|
|
||||||
|
if (parsed_number.second == offset)
|
||||||
|
Logger::Fatal("We couldn't interpret the Normal count at: " + std::to_string(offset));
|
||||||
|
|
||||||
|
unsigned long uv_count = parsed_number.first;
|
||||||
|
offset = parsed_number.second;
|
||||||
|
|
||||||
|
for (unsigned long i = 0; i < uv_count; i++) {
|
||||||
|
// Skip by newlines.
|
||||||
|
while (file_text[offset] == '\n' || file_text[offset] == '\r')
|
||||||
|
offset++;
|
||||||
|
|
||||||
|
auto parsed_vector3 = ParseVector3(file_text, offset);
|
||||||
|
if (parsed_vector3.second == offset)
|
||||||
|
Logger::Fatal("We couldn't interpret the Normal at: " + std::to_string(offset));
|
||||||
|
|
||||||
|
temp_normals.push_back(parsed_vector3.first);
|
||||||
|
offset = parsed_vector3.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Face Lines
|
||||||
|
else if (offset + 1 < file_text.size() && c == 'f' && file_text[offset + 1] == ' ') {
|
||||||
|
offset += 2; auto parsed_number = ParseNumber(file_text, offset);
|
||||||
|
|
||||||
|
if (parsed_number.second == offset)
|
||||||
|
Logger::Fatal("We couldn't interpret the Face Line count at: " + std::to_string(offset));
|
||||||
|
|
||||||
|
unsigned long faceline_count = parsed_number.first;
|
||||||
|
for (unsigned long i = 0; i < faceline_count; i++) {
|
||||||
|
// Skip by newlines.
|
||||||
|
while (file_text[offset] == '\n' || file_text[offset] == '\r')
|
||||||
|
offset++;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
@@ -116,7 +116,7 @@ void JGL::J2D::End() {
|
|||||||
if (!OpenGLState::wasBlendEnabled)
|
if (!OpenGLState::wasBlendEnabled)
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
//Select whatever texture mapper was selected before.
|
// Select whatever texture mapper was selected before.
|
||||||
glActiveTexture(GL_TEXTURE0 + OpenGLState::activeTextureUnit);
|
glActiveTexture(GL_TEXTURE0 + OpenGLState::activeTextureUnit);
|
||||||
glClientActiveTexture(GL_TEXTURE0 + OpenGLState::activeTextureUnit);
|
glClientActiveTexture(GL_TEXTURE0 + OpenGLState::activeTextureUnit);
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#include <JGL/types/VertexArray.h>
|
#include <JGL/types/VertexArray.h>
|
||||||
#include <JGL/logger/logger.h>
|
#include <JGL/logger/logger.h>
|
||||||
#include "../internals/include/WavefrontOBJ.h"
|
#include "../internals/include/WavefrontOBJ.h"
|
||||||
|
#include "../internals/include/AMO.h"
|
||||||
|
|
||||||
using namespace JGL;
|
using namespace JGL;
|
||||||
|
|
||||||
@@ -182,3 +183,7 @@ bool VertexArray::Static() {
|
|||||||
VertexArray VertexArray::LoadWavefrontOBJ(const std::string& file_text) {
|
VertexArray VertexArray::LoadWavefrontOBJ(const std::string& file_text) {
|
||||||
return JGL::LoadWavefrontOBJ(file_text);
|
return JGL::LoadWavefrontOBJ(file_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VertexArray VertexArray::LoadAMO(const std::string& file_text) {
|
||||||
|
//return JGL::LoadAMO(file_text);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user