diff --git a/code/OgreBinarySerializer.cpp b/code/OgreBinarySerializer.cpp index 7ade0baa7..96977e175 100644 --- a/code/OgreBinarySerializer.cpp +++ b/code/OgreBinarySerializer.cpp @@ -43,6 +43,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ASSIMP_BUILD_NO_OGRE_IMPORTER +// Define as 1 to get verbose logging. +#define OGRE_BINARY_SERIALIZER_DEBUG 0 + namespace Assimp { namespace Ogre @@ -146,8 +149,12 @@ uint16_t OgreBinarySerializer::ReadHeader(bool readLen) uint16_t id = Read(); if (readLen) m_currentLen = Read(); - //if (id != HEADER_CHUNK_ID) - // DefaultLogger::get()->debug(Formatter::format() << MeshHeaderToString(static_cast(id))); + +#if (OGRE_BINARY_SERIALIZER_DEBUG == 1) + if (id != HEADER_CHUNK_ID) + DefaultLogger::get()->debug(Formatter::format() << MeshHeaderToString(static_cast(id))); +#endif + return id; } @@ -156,9 +163,13 @@ void OgreBinarySerializer::RollbackHeader() m_reader->IncPtr(-MSTREAM_OVERHEAD_SIZE); } -void OgreBinarySerializer::SkipBytes(size_t num) +void OgreBinarySerializer::SkipBytes(size_t numBytes) { - m_reader->IncPtr(num); +#if (OGRE_BINARY_SERIALIZER_DEBUG == 1) + DefaultLogger::get()->debug(Formatter::format() << "Skipping " << numBytes << " bytes"); +#endif + + m_reader->IncPtr(numBytes); } Mesh *OgreBinarySerializer::ImportMesh(MemoryStreamReader *stream) @@ -166,9 +177,10 @@ Mesh *OgreBinarySerializer::ImportMesh(MemoryStreamReader *stream) OgreBinarySerializer serializer(stream); uint16_t id = serializer.ReadHeader(false); - if (id != HEADER_CHUNK_ID) - throw DeadlyExportError("Invalid Mesh file header"); - + if (id != HEADER_CHUNK_ID) { + throw DeadlyExportError("Invalid Ogre Mesh file header."); + } + /// @todo Check what we can actually support. std::string version = serializer.ReadLine(); if (version != VERSION_1_8) @@ -222,35 +234,55 @@ void OgreBinarySerializer::ReadMesh(Mesh *mesh) break; } case M_SUBMESH: + { ReadSubMesh(mesh); break; + } case M_MESH_SKELETON_LINK: + { ReadMeshSkeletonLink(mesh); break; + } case M_MESH_BONE_ASSIGNMENT: + { ReadBoneAssignment(mesh); break; + } case M_MESH_LOD: + { ReadMeshLodInfo(mesh); break; + } case M_MESH_BOUNDS: + { ReadMeshBounds(mesh); break; + } case M_SUBMESH_NAME_TABLE: + { ReadSubMeshNames(mesh); break; + } case M_EDGE_LISTS: + { ReadEdgeList(mesh); break; + } case M_POSES: + { ReadPoses(mesh); break; + } case M_ANIMATIONS: + { ReadAnimations(mesh); break; + } case M_TABLE_EXTREMES: + { ReadMeshExtremes(mesh); break; + } } if (!AtEnd()) @@ -273,16 +305,18 @@ void OgreBinarySerializer::ReadMeshLodInfo(Mesh *mesh) for (size_t i=1; iIncPtr(sizeof(float)); // user value if (manual) { id = ReadHeader(); - if (id != M_MESH_LOD_MANUAL) + if (id != M_MESH_LOD_MANUAL) { throw DeadlyImportError("Manual M_MESH_LOD_USAGE does not contain M_MESH_LOD_MANUAL"); + } ReadLine(); // manual mesh name (ref to another mesh) } @@ -291,8 +325,9 @@ void OgreBinarySerializer::ReadMeshLodInfo(Mesh *mesh) for(size_t si=0, silen=mesh->NumSubMeshes(); si(); bool is32bit = Read(); @@ -378,8 +413,9 @@ void OgreBinarySerializer::ReadSubMesh(Mesh *mesh) if (!submesh->usesSharedVertexData) { id = ReadHeader(); - if (id != M_GEOMETRY) + if (id != M_GEOMETRY) { throw DeadlyImportError("M_SUBMESH does not contain M_GEOMETRY, but shader geometry is set to false"); + } submesh->vertexData = new VertexData(); ReadGeometry(mesh, submesh->vertexData); @@ -445,14 +481,14 @@ void OgreBinarySerializer::ReadSubMeshNames(Mesh *mesh) id = ReadHeader(); while (!AtEnd() && id == M_SUBMESH_NAME_TABLE_ELEMENT) { - SubMesh2 *submesh = mesh->SubMesh(Read()); - if (submesh) - { - submesh->name = ReadLine(); - DefaultLogger::get()->debug(Formatter::format() << " - SubMesh " << submesh->index << " name '" << submesh->name << "'"); + uint16_t submeshIndex = Read(); + SubMesh2 *submesh = mesh->SubMesh(submeshIndex); + if (!submesh) { + throw DeadlyImportError(Formatter::format() << "Ogre Mesh does not include submesh " << submeshIndex << " referenced in M_SUBMESH_NAME_TABLE_ELEMENT. Invalid mesh file."); } - else - ReadLine(); + + submesh->name = ReadLine(); + DefaultLogger::get()->debug(Formatter::format() << " - SubMesh " << submesh->index << " name '" << submesh->name << "'"); if (!AtEnd()) id = ReadHeader(); @@ -752,7 +788,6 @@ void OgreBinarySerializer::ReadAnimationKeyFrames(Animation2 *anim, VertexAnimat } } - } // Ogre } // Assimp diff --git a/code/OgreBinarySerializer.h b/code/OgreBinarySerializer.h index 26e2951c7..1eede65f9 100644 --- a/code/OgreBinarySerializer.h +++ b/code/OgreBinarySerializer.h @@ -106,7 +106,7 @@ namespace Ogre std::string ReadString(size_t len); std::string ReadLine(); - void SkipBytes(size_t num); + void SkipBytes(size_t numBytes); uint32_t m_currentLen; MemoryStreamReader *m_reader; diff --git a/code/OgreStructs.cpp b/code/OgreStructs.cpp index 9390021d9..1ba269ef4 100644 --- a/code/OgreStructs.cpp +++ b/code/OgreStructs.cpp @@ -328,6 +328,7 @@ Mesh::~Mesh() void Mesh::Reset() { OGRE_SAFE_DELETE(sharedVertexData) + for(size_t i=0, len=subMeshes.size(); i