OgreImporter: Format code and move commented verbose debug logging behind internal OGRE_BINARY_SERIALIZER_DEBUG. Thow deadly importer error on clear invlid mesh file errors.
parent
4b16b182be
commit
75598f69b7
|
@ -43,6 +43,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#ifndef ASSIMP_BUILD_NO_OGRE_IMPORTER
|
#ifndef ASSIMP_BUILD_NO_OGRE_IMPORTER
|
||||||
|
|
||||||
|
// Define as 1 to get verbose logging.
|
||||||
|
#define OGRE_BINARY_SERIALIZER_DEBUG 0
|
||||||
|
|
||||||
namespace Assimp
|
namespace Assimp
|
||||||
{
|
{
|
||||||
namespace Ogre
|
namespace Ogre
|
||||||
|
@ -146,8 +149,12 @@ uint16_t OgreBinarySerializer::ReadHeader(bool readLen)
|
||||||
uint16_t id = Read<uint16_t>();
|
uint16_t id = Read<uint16_t>();
|
||||||
if (readLen)
|
if (readLen)
|
||||||
m_currentLen = Read<uint32_t>();
|
m_currentLen = Read<uint32_t>();
|
||||||
//if (id != HEADER_CHUNK_ID)
|
|
||||||
// DefaultLogger::get()->debug(Formatter::format() << MeshHeaderToString(static_cast<MeshChunkId>(id)));
|
#if (OGRE_BINARY_SERIALIZER_DEBUG == 1)
|
||||||
|
if (id != HEADER_CHUNK_ID)
|
||||||
|
DefaultLogger::get()->debug(Formatter::format() << MeshHeaderToString(static_cast<MeshChunkId>(id)));
|
||||||
|
#endif
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,9 +163,13 @@ void OgreBinarySerializer::RollbackHeader()
|
||||||
m_reader->IncPtr(-MSTREAM_OVERHEAD_SIZE);
|
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)
|
Mesh *OgreBinarySerializer::ImportMesh(MemoryStreamReader *stream)
|
||||||
|
@ -166,9 +177,10 @@ Mesh *OgreBinarySerializer::ImportMesh(MemoryStreamReader *stream)
|
||||||
OgreBinarySerializer serializer(stream);
|
OgreBinarySerializer serializer(stream);
|
||||||
|
|
||||||
uint16_t id = serializer.ReadHeader(false);
|
uint16_t id = serializer.ReadHeader(false);
|
||||||
if (id != HEADER_CHUNK_ID)
|
if (id != HEADER_CHUNK_ID) {
|
||||||
throw DeadlyExportError("Invalid Mesh file header");
|
throw DeadlyExportError("Invalid Ogre Mesh file header.");
|
||||||
|
}
|
||||||
|
|
||||||
/// @todo Check what we can actually support.
|
/// @todo Check what we can actually support.
|
||||||
std::string version = serializer.ReadLine();
|
std::string version = serializer.ReadLine();
|
||||||
if (version != VERSION_1_8)
|
if (version != VERSION_1_8)
|
||||||
|
@ -222,35 +234,55 @@ void OgreBinarySerializer::ReadMesh(Mesh *mesh)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case M_SUBMESH:
|
case M_SUBMESH:
|
||||||
|
{
|
||||||
ReadSubMesh(mesh);
|
ReadSubMesh(mesh);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case M_MESH_SKELETON_LINK:
|
case M_MESH_SKELETON_LINK:
|
||||||
|
{
|
||||||
ReadMeshSkeletonLink(mesh);
|
ReadMeshSkeletonLink(mesh);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case M_MESH_BONE_ASSIGNMENT:
|
case M_MESH_BONE_ASSIGNMENT:
|
||||||
|
{
|
||||||
ReadBoneAssignment(mesh);
|
ReadBoneAssignment(mesh);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case M_MESH_LOD:
|
case M_MESH_LOD:
|
||||||
|
{
|
||||||
ReadMeshLodInfo(mesh);
|
ReadMeshLodInfo(mesh);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case M_MESH_BOUNDS:
|
case M_MESH_BOUNDS:
|
||||||
|
{
|
||||||
ReadMeshBounds(mesh);
|
ReadMeshBounds(mesh);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case M_SUBMESH_NAME_TABLE:
|
case M_SUBMESH_NAME_TABLE:
|
||||||
|
{
|
||||||
ReadSubMeshNames(mesh);
|
ReadSubMeshNames(mesh);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case M_EDGE_LISTS:
|
case M_EDGE_LISTS:
|
||||||
|
{
|
||||||
ReadEdgeList(mesh);
|
ReadEdgeList(mesh);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case M_POSES:
|
case M_POSES:
|
||||||
|
{
|
||||||
ReadPoses(mesh);
|
ReadPoses(mesh);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case M_ANIMATIONS:
|
case M_ANIMATIONS:
|
||||||
|
{
|
||||||
ReadAnimations(mesh);
|
ReadAnimations(mesh);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case M_TABLE_EXTREMES:
|
case M_TABLE_EXTREMES:
|
||||||
|
{
|
||||||
ReadMeshExtremes(mesh);
|
ReadMeshExtremes(mesh);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AtEnd())
|
if (!AtEnd())
|
||||||
|
@ -273,16 +305,18 @@ void OgreBinarySerializer::ReadMeshLodInfo(Mesh *mesh)
|
||||||
for (size_t i=1; i<numLods; ++i)
|
for (size_t i=1; i<numLods; ++i)
|
||||||
{
|
{
|
||||||
uint16_t id = ReadHeader();
|
uint16_t id = ReadHeader();
|
||||||
if (id != M_MESH_LOD_USAGE)
|
if (id != M_MESH_LOD_USAGE) {
|
||||||
throw DeadlyImportError("M_MESH_LOD does not contain a M_MESH_LOD_USAGE for each LOD level");
|
throw DeadlyImportError("M_MESH_LOD does not contain a M_MESH_LOD_USAGE for each LOD level");
|
||||||
|
}
|
||||||
|
|
||||||
m_reader->IncPtr(sizeof(float)); // user value
|
m_reader->IncPtr(sizeof(float)); // user value
|
||||||
|
|
||||||
if (manual)
|
if (manual)
|
||||||
{
|
{
|
||||||
id = ReadHeader();
|
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");
|
throw DeadlyImportError("Manual M_MESH_LOD_USAGE does not contain M_MESH_LOD_MANUAL");
|
||||||
|
}
|
||||||
|
|
||||||
ReadLine(); // manual mesh name (ref to another mesh)
|
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<silen; ++si)
|
for(size_t si=0, silen=mesh->NumSubMeshes(); si<silen; ++si)
|
||||||
{
|
{
|
||||||
id = ReadHeader();
|
id = ReadHeader();
|
||||||
if (id != M_MESH_LOD_GENERATED)
|
if (id != M_MESH_LOD_GENERATED) {
|
||||||
throw DeadlyImportError("Generated M_MESH_LOD_USAGE does not contain M_MESH_LOD_GENERATED");
|
throw DeadlyImportError("Generated M_MESH_LOD_USAGE does not contain M_MESH_LOD_GENERATED");
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t indexCount = Read<uint32_t>();
|
uint32_t indexCount = Read<uint32_t>();
|
||||||
bool is32bit = Read<bool>();
|
bool is32bit = Read<bool>();
|
||||||
|
@ -378,8 +413,9 @@ void OgreBinarySerializer::ReadSubMesh(Mesh *mesh)
|
||||||
if (!submesh->usesSharedVertexData)
|
if (!submesh->usesSharedVertexData)
|
||||||
{
|
{
|
||||||
id = ReadHeader();
|
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");
|
throw DeadlyImportError("M_SUBMESH does not contain M_GEOMETRY, but shader geometry is set to false");
|
||||||
|
}
|
||||||
|
|
||||||
submesh->vertexData = new VertexData();
|
submesh->vertexData = new VertexData();
|
||||||
ReadGeometry(mesh, submesh->vertexData);
|
ReadGeometry(mesh, submesh->vertexData);
|
||||||
|
@ -445,14 +481,14 @@ void OgreBinarySerializer::ReadSubMeshNames(Mesh *mesh)
|
||||||
id = ReadHeader();
|
id = ReadHeader();
|
||||||
while (!AtEnd() && id == M_SUBMESH_NAME_TABLE_ELEMENT)
|
while (!AtEnd() && id == M_SUBMESH_NAME_TABLE_ELEMENT)
|
||||||
{
|
{
|
||||||
SubMesh2 *submesh = mesh->SubMesh(Read<uint16_t>());
|
uint16_t submeshIndex = Read<uint16_t>();
|
||||||
if (submesh)
|
SubMesh2 *submesh = mesh->SubMesh(submeshIndex);
|
||||||
{
|
if (!submesh) {
|
||||||
submesh->name = ReadLine();
|
throw DeadlyImportError(Formatter::format() << "Ogre Mesh does not include submesh " << submeshIndex << " referenced in M_SUBMESH_NAME_TABLE_ELEMENT. Invalid mesh file.");
|
||||||
DefaultLogger::get()->debug(Formatter::format() << " - SubMesh " << submesh->index << " name '" << submesh->name << "'");
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
ReadLine();
|
submesh->name = ReadLine();
|
||||||
|
DefaultLogger::get()->debug(Formatter::format() << " - SubMesh " << submesh->index << " name '" << submesh->name << "'");
|
||||||
|
|
||||||
if (!AtEnd())
|
if (!AtEnd())
|
||||||
id = ReadHeader();
|
id = ReadHeader();
|
||||||
|
@ -752,7 +788,6 @@ void OgreBinarySerializer::ReadAnimationKeyFrames(Animation2 *anim, VertexAnimat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // Ogre
|
} // Ogre
|
||||||
} // Assimp
|
} // Assimp
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ namespace Ogre
|
||||||
std::string ReadString(size_t len);
|
std::string ReadString(size_t len);
|
||||||
std::string ReadLine();
|
std::string ReadLine();
|
||||||
|
|
||||||
void SkipBytes(size_t num);
|
void SkipBytes(size_t numBytes);
|
||||||
|
|
||||||
uint32_t m_currentLen;
|
uint32_t m_currentLen;
|
||||||
MemoryStreamReader *m_reader;
|
MemoryStreamReader *m_reader;
|
||||||
|
|
|
@ -328,6 +328,7 @@ Mesh::~Mesh()
|
||||||
void Mesh::Reset()
|
void Mesh::Reset()
|
||||||
{
|
{
|
||||||
OGRE_SAFE_DELETE(sharedVertexData)
|
OGRE_SAFE_DELETE(sharedVertexData)
|
||||||
|
|
||||||
for(size_t i=0, len=subMeshes.size(); i<len; ++i) {
|
for(size_t i=0, len=subMeshes.size(); i<len; ++i) {
|
||||||
OGRE_SAFE_DELETE(subMeshes[i])
|
OGRE_SAFE_DELETE(subMeshes[i])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue