Fixed OX3DLoader class to work with correct endianness of ostd::SerialIO
This commit is contained in:
parent
533aed49f6
commit
4f7dfb6c80
6 changed files with 28 additions and 15 deletions
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
|
|
@ -94,7 +94,9 @@
|
|||
"expected": "cpp",
|
||||
"spanstream": "cpp",
|
||||
"stacktrace": "cpp",
|
||||
"*.ipp": "cpp"
|
||||
"*.ipp": "cpp",
|
||||
"format": "cpp",
|
||||
"stdfloat": "cpp"
|
||||
},
|
||||
|
||||
"workbench.colorCustomizations": {
|
||||
|
|
|
|||
|
|
@ -12,26 +12,27 @@ namespace ogfx
|
|||
{
|
||||
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;
|
||||
Mesh mesh;
|
||||
std::vector<Mesh> 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<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; }
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
1703
|
||||
1711
|
||||
Loading…
Reference in a new issue