Added notes
This commit is contained in:
@@ -23,6 +23,7 @@ struct FaceIndices {
|
||||
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;
|
||||
@@ -30,7 +31,8 @@ public:
|
||||
std::vector<TextureCoordinate> texCoords;
|
||||
VertexArray getBoundingVolume(Vector3 angle);
|
||||
void rotate(const Vector3& angle);
|
||||
void mapfaces(const FaceIndices& facedata, const std::vector<Vector3>& positions, const std::vector<Vector2>& uvs);
|
||||
/// Loads data from an OBJ mesh file to populate the VertexArray
|
||||
/// @see LearnOpenGL::Mesh LearnOpenGL::Model J3ML::Geometry::TriangleMesh
|
||||
void load(const std::string& filename);
|
||||
static void erase(const VertexArray& vArray);
|
||||
virtual void draw();
|
||||
|
@@ -4,8 +4,6 @@ add_executable(Re3D-RuntimeTest "src/demo/RuntimeTest/main.cpp")
|
||||
#Link based on the relative path *so you can copy the game around*
|
||||
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)
|
||||
|
@@ -4,13 +4,16 @@
|
||||
#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;
|
||||
@@ -19,6 +22,9 @@ Vector2 ParseVertexTextureCoordinates(std::istringstream& stream) {
|
||||
}
|
||||
|
||||
|
||||
/// 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];
|
||||
@@ -68,55 +74,29 @@ void VertexArray::load (const std::string& filename) {
|
||||
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") {
|
||||
float x, y, z;
|
||||
stream >> x >> y >> z;
|
||||
positions.emplace_back(x, y, z);
|
||||
auto result = ParseVertexCoordinates(stream);
|
||||
positions.emplace_back(result);
|
||||
} else if (prefix == "vt") {
|
||||
float u, v;
|
||||
stream >> u >> v;
|
||||
uvs.emplace_back(u, v);
|
||||
auto result = ParseVertexTextureCoordinates(stream);
|
||||
uvs.emplace_back(result);
|
||||
} else if (prefix == "f") {
|
||||
unsigned int vertexIndex[3], texCoordIndex[3];
|
||||
char slash;
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
stream >> vertexIndex[i] >> slash >> texCoordIndex[i];
|
||||
vertexIndex[i]--;
|
||||
texCoordIndex[i]--;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
Vertex vertex;
|
||||
TextureCoordinate textureCoordinate;
|
||||
vertex = positions[vertexIndex[i]];
|
||||
textureCoordinate = uvs[texCoordIndex[i]];
|
||||
|
||||
vertices.push_back(vertex);
|
||||
texCoords.push_back(textureCoordinate);
|
||||
indices.push_back(static_cast<unsigned int>(indices.size()));
|
||||
}
|
||||
auto result = ParseFaceIndices(stream);
|
||||
mapfaces(result, positions, uvs);
|
||||
}
|
||||
*/
|
||||
|
||||
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();
|
||||
|
||||
|
Reference in New Issue
Block a user