diff --git a/.vscode/settings.json b/.vscode/settings.json index 2e14da4..61116ba 100755 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -94,7 +94,9 @@ "expected": "cpp", "spanstream": "cpp", "stacktrace": "cpp", - "*.ipp": "cpp" + "*.ipp": "cpp", + "format": "cpp", + "stdfloat": "cpp" }, "workbench.colorCustomizations": { diff --git a/src/ogfx/OX3DLoader.cpp b/src/ogfx/OX3DLoader.cpp index 60a90f6..5c74974 100755 --- a/src/ogfx/OX3DLoader.cpp +++ b/src/ogfx/OX3DLoader.cpp @@ -12,26 +12,27 @@ namespace ogfx { using namespace ostd; - Mesh OX3DLoader::loadFromFile(const String& filePath, const ostd::String& texturesSubPath) + std::vector OX3DLoader::loadFromFile(const String& filePath, const ostd::String& texturesSubPath) { s_error = true; - Mesh mesh; + std::vector meshes; loadRawData(filePath); - if (s_rawData.size() == 0) return mesh; //TODO: Error + if (s_rawData.size() == 0) return { }; //TODO: Error serial::SerialIO reader(s_rawData, serial::SerialIO::tEndianness::BigEndian); int32_t meshCount = 0; StreamIndex addr = 0; //Start Reading reader.r_DWord(addr, meshCount); addr += tTypeSize::DWORD; - if (meshCount < 1) return mesh; //TODO: Error + if (meshCount < 1) return { }; //TODO: Error meshCount = 1; //TODO: Remove this. This is a manual override to force reading only the first mesh for (int32_t currentMeshIndex = meshCount - 1; currentMeshIndex >= 0; currentMeshIndex--) { + Mesh mesh; int32_t vertCount = 0; reader.r_DWord(addr, vertCount); addr += tTypeSize::DWORD; - if (vertCount < 3) return mesh; //TODO: Error + if (vertCount < 3) return { }; //TODO: Error for (uint32_t v = 0; v < vertCount; v++) { tVertex vertex; @@ -59,7 +60,7 @@ namespace ogfx int32_t indicesCount = 0; reader.r_DWord(addr, indicesCount); addr += tTypeSize::DWORD; - if (indicesCount < 3) return mesh; //TODO: Error + if (indicesCount < 3) return { }; //TODO: Error for (uint32_t i = 0; i < indicesCount; i++) { int32_t index = 0; @@ -79,7 +80,7 @@ namespace ogfx int32_t tex_path_len = 0; reader.r_DWord(addr, tex_path_len); addr += tTypeSize::DWORD; - if (tex_path_len < 1) return mesh; //TODO: Error + if (tex_path_len < 1) return { }; //TODO: Error StringEditor texPath_se; if (texturesSubPath != "") texPath_se.add(texturesSubPath).add("/"); @@ -94,7 +95,7 @@ namespace ogfx int32_t tex_size = 0; reader.r_DWord(addr, tex_size); addr += tTypeSize::DWORD; - if (tex_size < 4) return mesh; //TODO: Error + if (tex_size < 4) return { }; //TODO: Error for (uint32_t i = 0; i < tex_size; i++) { int8_t b = 0; @@ -106,9 +107,19 @@ namespace ogfx //mesh.textures.push_back(ResourceManager::loadTexture(&tex_data[0], tex_size, 0, 0)); mesh.textures.push_back(ResourceManager::loadTexture(texPath_se.str())); } + meshes.push_back(mesh); } s_error = false; //mesh.initialize(); + return meshes; + } + + Mesh OX3DLoader::loadSingleMeshFromFile(const ostd::String& filePath, const ostd::String& texturesPath) + { + Mesh mesh; + auto meshVec = loadFromFile(filePath, texturesPath); + if (meshVec.size() > 0) + mesh = meshVec[0]; return mesh; } diff --git a/src/ogfx/OX3DLoader.hpp b/src/ogfx/OX3DLoader.hpp index c85bf02..e2d26e6 100755 --- a/src/ogfx/OX3DLoader.hpp +++ b/src/ogfx/OX3DLoader.hpp @@ -9,7 +9,8 @@ namespace ogfx class OX3DLoader { public: - static Mesh loadFromFile(const ostd::String& filePath, const ostd::String& texturesSubPath = ""); //TODO: Handle more than only the first mesh + static std::vector loadFromFile(const ostd::String& filePath, const ostd::String& texturesSubPath = ""); //TODO: Handle more than only the first mesh + static Mesh loadSingleMeshFromFile(const ostd::String& filePath, const ostd::String& texturesPath = ""); static inline bool errorOccurred(void) { return s_error; } private: diff --git a/src/test/TestApp3D.cpp b/src/test/TestApp3D.cpp index 9a6cb36..c860930 100644 --- a/src/test/TestApp3D.cpp +++ b/src/test/TestApp3D.cpp @@ -12,7 +12,7 @@ TestApp3D::TestApp3D(void) window.centerMouse().hideMouseCursor(); camera.create(window); - tempMesh = OX3DLoader::loadFromFile("models/monkey2.ox3d", "textures"); + tempMesh = OX3DLoader::loadSingleMeshFromFile("models/monkey2.ox3d", "textures"); screenPlane = Mesh::newPlaneMesh(); floor = Mesh::newCubeMesh(); lightEmitter = Mesh::newCubeMesh(); diff --git a/src/test/main.cpp b/src/test/main.cpp index 30bacdd..22e1c7f 100755 --- a/src/test/main.cpp +++ b/src/test/main.cpp @@ -1,19 +1,18 @@ // #include "TestApp2D.hpp" #include "TestApp3D.hpp" +// #include "TetrisApp.hpp" int main(int argc, char** argv) { // ogfx::DebugTools::enableDebugWindow(); // ogfx::DebugTools::m_drawBasicFrameInfo = true; - // TestApp3D_2 app; + // TetrisApp app; // app.create(32*40, 720, "OmniaFramework TEST"); // while (app.isRunning()) // app.nextFrame(); // app.destroy(); - //TODO: I changed the endianness of ostd::serial::SerialIO and now the app crashes - // probably due to SerialIO beeing used in OX3DLoader TestApp3D app; app.gameLoop(); diff --git a/tools/build.nr b/tools/build.nr index 9b21444..ee67895 100755 --- a/tools/build.nr +++ b/tools/build.nr @@ -1 +1 @@ -1703 \ No newline at end of file +1711 \ No newline at end of file