Merge branch 'main' into dev
This commit is contained in:
@@ -88,8 +88,8 @@ CPMAddPackage(
|
||||
|
||||
#https://github.com/assimp/assimp/blob/master/LICENSE
|
||||
CPMAddPackage(
|
||||
NAME ASSIMP
|
||||
URL https://github.com/assimp/assimp/archive/refs/tags/v5.3.1.zip
|
||||
NAME Collage
|
||||
URL https://git.redacted.cc/Redacted/Collage/archive/v0.3.zip
|
||||
)
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ include_directories(
|
||||
${ASSIMP_SOURCE_DIR}/include
|
||||
${archive_SOURCE_DIR}/include
|
||||
${PROJECT_BINARY_DIR}/glu/include
|
||||
#${JGL_SOURCE_DIR}/include
|
||||
${Collage_SOURCE_DIR}/include
|
||||
${Event_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -15,15 +15,9 @@ using J3ML::LinearAlgebra::Vector2;
|
||||
typedef Vector3 Vertex;
|
||||
typedef Vector2 TextureCoordinate;
|
||||
|
||||
struct FaceIndices {
|
||||
unsigned int vertexIndex[3];
|
||||
unsigned int texCoordIndex[3];
|
||||
};
|
||||
|
||||
class VertexArray {
|
||||
private:
|
||||
std::vector<Vertex> boundingVolume;
|
||||
void mapfaces(const FaceIndices& facedata, const std::vector<Vector3>& positions, const std::vector<Vector2>& uvs);
|
||||
public:
|
||||
std::string name;
|
||||
std::vector<Vertex> vertices;
|
||||
|
@@ -6,9 +6,9 @@ set_target_properties(Re3D-RuntimeTest PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib")
|
||||
|
||||
# TODO: Link all applicable dependencies to Re3D directly
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(Re3D-RuntimeTest PUBLIC Re3D ReWindowLibrary ReHardwareID J3ML soil uuid_v4 GL glad assimp archive ${PROJECT_BINARY_DIR}/lib/libGLU.so)
|
||||
target_link_libraries(Re3D-RuntimeTest PUBLIC Re3D ReWindowLibrary ReHardwareID J3ML soil uuid_v4 GL glad Collage archive ${PROJECT_BINARY_DIR}/lib/libGLU.so)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(Re3D-RuntimeTest PUBLIC Re3D ReWindowLibrary ReHardwareID J3ML soil uuid_v4 GL GLU glad assimp archive)
|
||||
target_link_libraries(Re3D-RuntimeTest PUBLIC Re3D ReWindowLibrary ReHardwareID J3ML soil uuid_v4 GL GLU Collage glad archive)
|
||||
endif()
|
||||
|
@@ -2,132 +2,28 @@
|
||||
#include <types/vertex.h>
|
||||
#include <engine/collision.h>
|
||||
#include <cmath>
|
||||
#include <tuple>
|
||||
|
||||
/// Reads a single Vertex Coordinate Attribute from an OBJ format text file.
|
||||
// v = vertex
|
||||
Vector3 ParseVertexCoordinates(std::istringstream& stream) {
|
||||
|
||||
float x, y, z;
|
||||
stream >> x >> y >> z;
|
||||
return {x,y,z};
|
||||
}
|
||||
|
||||
/// Reads a single Texture Coordinate Attribute from an OBJ format text file.
|
||||
// vt = vertex texture coordinates
|
||||
Vector2 ParseVertexTextureCoordinates(std::istringstream& stream) {
|
||||
float u, v;
|
||||
stream >> u >> v;
|
||||
return {u,v};
|
||||
}
|
||||
|
||||
|
||||
/// Reads a single Face Index Attribute from an OBJ format text file.
|
||||
/// This tells us what order to place our list of vertices and texcoords to create
|
||||
/// our model.
|
||||
// f = face
|
||||
FaceIndices ParseFaceIndices(std::istringstream& stream) {
|
||||
//unsigned int vertexIndex[3], texCoordIndex[3];
|
||||
FaceIndices face;
|
||||
char slash;
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
unsigned int vI;
|
||||
unsigned int tCI;
|
||||
|
||||
// Get vertexIndex value seperated by slash and get texcoordindex value
|
||||
stream >> vI >> slash >> tCI;
|
||||
|
||||
face.vertexIndex[i] = vI;
|
||||
face.texCoordIndex[i] = tCI;
|
||||
|
||||
// Shift vertexindex by 1
|
||||
face.vertexIndex[i]--;
|
||||
// shift texcoordindex by 1
|
||||
face.texCoordIndex[i]--;
|
||||
}
|
||||
|
||||
return face;
|
||||
}
|
||||
|
||||
|
||||
// map face of model to positions and texture coords
|
||||
void VertexArray::mapfaces(const FaceIndices& facedata, const std::vector<Vector3>& positions, const std::vector<Vector2>& uvs) {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
Vertex vertex;
|
||||
TextureCoordinate textureCoordinate;
|
||||
vertex = positions[facedata.vertexIndex[i]];
|
||||
textureCoordinate = uvs[facedata.texCoordIndex[i]];
|
||||
|
||||
vertices.push_back(vertex);
|
||||
texCoords.push_back(textureCoordinate);
|
||||
indices.push_back(static_cast<unsigned int>(indices.size()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#include <types/model.h>
|
||||
void VertexArray::load (const std::string& filename) {
|
||||
std::ifstream file(filename);
|
||||
if (!file.is_open())
|
||||
engine->setError(ENGINE_ERROR_CODE::MODEL_NOT_FOUND, true);
|
||||
Model m(filename);
|
||||
vertices = m.getVertices();
|
||||
indices = m.getIndices();
|
||||
texCoords = m.getTextureInformation()[0].textureCoordinates;
|
||||
|
||||
std::vector<Vector3> positions;
|
||||
std::vector<Vector2> uvs;
|
||||
std::string line;
|
||||
|
||||
// First: We read every (unique) vertex entry and textureCoord entry from the file.
|
||||
// Then: Use Face data to map the bulk data into correct locations.
|
||||
|
||||
// TODO: Check the assumption that we can **always** read all "v", "vt" etc. tokens first,
|
||||
// allowing us to perform a second-pass to reconstruct faces?
|
||||
|
||||
while (std::getline(file, line)) {
|
||||
std::istringstream stream(line);
|
||||
std::string prefix;
|
||||
stream >> prefix;
|
||||
|
||||
|
||||
if (prefix == "v") {
|
||||
auto result = ParseVertexCoordinates(stream);
|
||||
positions.emplace_back(result);
|
||||
} else if (prefix == "vt") {
|
||||
auto result = ParseVertexTextureCoordinates(stream);
|
||||
uvs.emplace_back(result);
|
||||
} else if (prefix == "f") {
|
||||
auto result = ParseFaceIndices(stream);
|
||||
mapfaces(result, positions, uvs);
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
|
||||
//Copy verts to vram.
|
||||
if (engine->useVBO) {
|
||||
if (vbo == 0) {
|
||||
//This breaks stuff if the model is *very* big.
|
||||
GLfloat verts[vertices.size() * 3];
|
||||
size_t index = 0;
|
||||
for (const auto &vertex: vertices) {
|
||||
verts[index++] = vertex.x;
|
||||
verts[index++] = vertex.y;
|
||||
verts[index++] = vertex.z;
|
||||
}
|
||||
//Copy Vertices to vram.
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), &verts, GL_STATIC_DRAW); //GL_STATIC_DRAW means the VBO won't be changed atall.
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*vertices.size()*3, vertices.data(), GL_STATIC_DRAW); //GL_STATIC_DRAW means the VBO won't be changed atall.
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
//Copy Texture Coordinates to vram.
|
||||
GLfloat textureCoordinates[texCoords.size() * 2];
|
||||
index = 0;
|
||||
for (const auto &tCoord: texCoords) {
|
||||
textureCoordinates[index++] = tCoord.x;
|
||||
textureCoordinates[index++] = tCoord.y;
|
||||
}
|
||||
glGenBuffers(1, &tbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, tbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(textureCoordinates), &textureCoordinates, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*texCoords.size()*2, texCoords.data(), GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
//copy indices to vram.
|
||||
//copy Indices to vram.
|
||||
glGenBuffers(1, &ebo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (indices.size() * sizeof(GLuint)), indices.data(), GL_STATIC_DRAW);
|
||||
|
Reference in New Issue
Block a user