Fixed OX3DLoader class to work with correct endianness of ostd::SerialIO

This commit is contained in:
OmniaX-dev 2023-10-28 23:54:05 +02:00
parent 533aed49f6
commit 4f7dfb6c80
6 changed files with 28 additions and 15 deletions

View file

@ -94,7 +94,9 @@
"expected": "cpp", "expected": "cpp",
"spanstream": "cpp", "spanstream": "cpp",
"stacktrace": "cpp", "stacktrace": "cpp",
"*.ipp": "cpp" "*.ipp": "cpp",
"format": "cpp",
"stdfloat": "cpp"
}, },
"workbench.colorCustomizations": { "workbench.colorCustomizations": {

View file

@ -12,26 +12,27 @@ namespace ogfx
{ {
using namespace ostd; using namespace ostd;
Mesh OX3DLoader::loadFromFile(const String& filePath, const ostd::String& texturesSubPath) std::vector<Mesh> OX3DLoader::loadFromFile(const String& filePath, const ostd::String& texturesSubPath)
{ {
s_error = true; s_error = true;
Mesh mesh; std::vector<Mesh> meshes;
loadRawData(filePath); 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); serial::SerialIO reader(s_rawData, serial::SerialIO::tEndianness::BigEndian);
int32_t meshCount = 0; int32_t meshCount = 0;
StreamIndex addr = 0; StreamIndex addr = 0;
//Start Reading //Start Reading
reader.r_DWord(addr, meshCount); reader.r_DWord(addr, meshCount);
addr += tTypeSize::DWORD; 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 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--) for (int32_t currentMeshIndex = meshCount - 1; currentMeshIndex >= 0; currentMeshIndex--)
{ {
Mesh mesh;
int32_t vertCount = 0; int32_t vertCount = 0;
reader.r_DWord(addr, vertCount); reader.r_DWord(addr, vertCount);
addr += tTypeSize::DWORD; addr += tTypeSize::DWORD;
if (vertCount < 3) return mesh; //TODO: Error if (vertCount < 3) return { }; //TODO: Error
for (uint32_t v = 0; v < vertCount; v++) for (uint32_t v = 0; v < vertCount; v++)
{ {
tVertex vertex; tVertex vertex;
@ -59,7 +60,7 @@ namespace ogfx
int32_t indicesCount = 0; int32_t indicesCount = 0;
reader.r_DWord(addr, indicesCount); reader.r_DWord(addr, indicesCount);
addr += tTypeSize::DWORD; addr += tTypeSize::DWORD;
if (indicesCount < 3) return mesh; //TODO: Error if (indicesCount < 3) return { }; //TODO: Error
for (uint32_t i = 0; i < indicesCount; i++) for (uint32_t i = 0; i < indicesCount; i++)
{ {
int32_t index = 0; int32_t index = 0;
@ -79,7 +80,7 @@ namespace ogfx
int32_t tex_path_len = 0; int32_t tex_path_len = 0;
reader.r_DWord(addr, tex_path_len); reader.r_DWord(addr, tex_path_len);
addr += tTypeSize::DWORD; addr += tTypeSize::DWORD;
if (tex_path_len < 1) return mesh; //TODO: Error if (tex_path_len < 1) return { }; //TODO: Error
StringEditor texPath_se; StringEditor texPath_se;
if (texturesSubPath != "") if (texturesSubPath != "")
texPath_se.add(texturesSubPath).add("/"); texPath_se.add(texturesSubPath).add("/");
@ -94,7 +95,7 @@ namespace ogfx
int32_t tex_size = 0; int32_t tex_size = 0;
reader.r_DWord(addr, tex_size); reader.r_DWord(addr, tex_size);
addr += tTypeSize::DWORD; 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++) for (uint32_t i = 0; i < tex_size; i++)
{ {
int8_t b = 0; 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(&tex_data[0], tex_size, 0, 0));
mesh.textures.push_back(ResourceManager::loadTexture(texPath_se.str())); mesh.textures.push_back(ResourceManager::loadTexture(texPath_se.str()));
} }
meshes.push_back(mesh);
} }
s_error = false; s_error = false;
//mesh.initialize(); //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; return mesh;
} }

View file

@ -9,7 +9,8 @@ namespace ogfx
class OX3DLoader class OX3DLoader
{ {
public: public:
static Mesh loadFromFile(const ostd::String& filePath, const ostd::String& texturesSubPath = ""); //TODO: Handle more than only the first mesh static std::vector<Mesh> 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; } static inline bool errorOccurred(void) { return s_error; }
private: private:

View file

@ -12,7 +12,7 @@ TestApp3D::TestApp3D(void)
window.centerMouse().hideMouseCursor(); window.centerMouse().hideMouseCursor();
camera.create(window); camera.create(window);
tempMesh = OX3DLoader::loadFromFile("models/monkey2.ox3d", "textures"); tempMesh = OX3DLoader::loadSingleMeshFromFile("models/monkey2.ox3d", "textures");
screenPlane = Mesh::newPlaneMesh(); screenPlane = Mesh::newPlaneMesh();
floor = Mesh::newCubeMesh(); floor = Mesh::newCubeMesh();
lightEmitter = Mesh::newCubeMesh(); lightEmitter = Mesh::newCubeMesh();

View file

@ -1,19 +1,18 @@
// #include "TestApp2D.hpp" // #include "TestApp2D.hpp"
#include "TestApp3D.hpp" #include "TestApp3D.hpp"
// #include "TetrisApp.hpp"
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
// ogfx::DebugTools::enableDebugWindow(); // ogfx::DebugTools::enableDebugWindow();
// ogfx::DebugTools::m_drawBasicFrameInfo = true; // ogfx::DebugTools::m_drawBasicFrameInfo = true;
// TestApp3D_2 app; // TetrisApp app;
// app.create(32*40, 720, "OmniaFramework TEST"); // app.create(32*40, 720, "OmniaFramework TEST");
// while (app.isRunning()) // while (app.isRunning())
// app.nextFrame(); // app.nextFrame();
// app.destroy(); // 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; TestApp3D app;
app.gameLoop(); app.gameLoop();

View file

@ -1 +1 @@
1703 1711