20 template<
typename To,
typename From>
22 return std::unique_ptr<To>(
static_cast<To*
>(p.release()));
31 const uint32_t ChunkFileHeader::CurrentVersion = 1080;
32 const std::map<std::string, uint32_t> ChunkFileHeader::VersionTable = {
34 std::make_pair(
"[MeshSerializer_v1.8]", CurrentVersion),
36 std::make_pair(
"[MeshSerializer_v1.41]", 1041),
38 std::make_pair(
"[MeshSerializer_v1.40]", 1040)
48 id =
static_cast<ChunkID>(stream->
Read<uint16_t>());
59 std::unique_ptr<Chunk> chunk;
62 case CID_Header: chunk = std::make_unique<Ogre::Mesh::ChunkFileHeader>();
break;
63 case CID_Mesh: chunk = std::make_unique<Ogre::Mesh::ChunkMesh>();
break;
66 chunk = std::make_unique<Ogre::Mesh::ChunkMeshBoneAssignments>();
break;
68 case CID_Mesh_Bounds: chunk = std::make_unique<Ogre::Mesh::ChunkMeshBounds>();
break;
69 case CID_Submesh: chunk = std::make_unique<Ogre::Mesh::ChunkSubmesh>();
break;
70 case CID_Submesh_Op: chunk = std::make_unique<Ogre::Mesh::ChunkSubmeshOp>();
break;
71 case CID_Geometry: chunk = std::make_unique<Ogre::Mesh::ChunkGeometry>();
break;
77 LogF(
"StdMeshLoader: I don't know what to do with a chunk of type 0x%xu",
id);
81 chunk = std::make_unique<Ogre::Mesh::ChunkUnknown>();
break;
85 chunk->ReadImpl(stream);
94 VersionTable_t::const_iterator it = VersionTable.find(stream->
Read<std::string>());
95 if (it == VersionTable.end())
96 throw InvalidVersion();
107 std::unique_ptr<Chunk> chunk =
Chunk::Read(stream);
108 switch (chunk->GetType())
112 throw MultipleSingletonChunks(
"There's only one CID_Geometry chunk allowed within a CID_Mesh chunk");
113 geometry = static_unique_cast<ChunkGeometry>(move(chunk));
116 submeshes.push_back(static_unique_cast<ChunkSubmesh>(move(chunk)));
120 throw MultipleSingletonChunks(
"There's only one CID_Mesh_Skeleton_Link chunk allowed within a CID_Mesh chunk");
135 LogF(
"StdMeshLoader: I don't know what to do with a chunk of type 0x%xu inside a CID_Mesh chunk", chunk->GetType());
142 if (stream->
AtEof())
break;
156 size_t index_count = stream->
Read<uint32_t>();
157 bool indexes_are_32bit = stream->
Read<
bool>();
159 while (index_count--)
162 if (indexes_are_32bit)
163 index = stream->
Read<uint32_t>();
165 index = stream->
Read<uint16_t>();
173 std::unique_ptr<Chunk> chunk =
Chunk::Read(stream);
175 switch (chunk->GetType())
180 throw SharedVertexGeometryForbidden();
182 throw MultipleSingletonChunks(
"There's only one CID_Geometry chunk allowed within a CID_Submesh chunk");
183 geometry = static_unique_cast<ChunkGeometry>(move(chunk));
196 LogF(
"StdMeshLoader: I don't know what to do with a chunk of type 0x%xu inside a CID_Submesh chunk", chunk->GetType());
199 if (stream->
AtEof())
break;
205 uint32_t op = stream->
Read<uint16_t>();
207 throw InvalidSubmeshOp();
213 size_t bone_count =
GetSize() / (
sizeof(uint32_t)+
sizeof(uint16_t)+
sizeof(float));
215 while (bone_count-- > 0)
218 assignment.
bone = stream->
Read<uint16_t>();
243 std::unique_ptr<Chunk> chunk =
Chunk::Read(stream);
245 switch (chunk->GetType())
249 throw MultipleSingletonChunks(
"There's only one CID_Geometry_Vertex_Decl chunk allowed within a CID_Geometry chunk");
253 vertexBuffers.push_back(static_unique_cast<ChunkGeometryVertexBuffer>(move(chunk)));
256 LogF(
"StdMeshLoader: I don't know what to do with a chunk of type 0x%xu inside a CID_Geometry chunk", chunk->GetType());
259 if (stream->
AtEof())
break;
267 std::unique_ptr<Chunk> chunk =
Chunk::Read(stream);
269 declaration.push_back(static_unique_cast<ChunkGeometryVertexDeclElement>(chunk));
270 if (stream->
AtEof())
break;
277 int32_t t = stream->
Read<uint16_t>();
279 throw InvalidVertexType();
281 t = stream->
Read<uint16_t>();
283 throw InvalidVertexSemantic();
296 std::unique_ptr<Chunk> chunk =
Chunk::Read(stream);
299 throw MultipleSingletonChunks(
"There's only one CID_Geometry_Vertex_Data chunk allowed within a CID_Geometry_Vertex_Buffer chunk");
300 data = static_unique_cast<ChunkGeometryVertexData>(move(chunk));
301 if (stream->
AtEof())
break;
314 const uint32_t ChunkFileHeader::CurrentVersion = 1080;
315 const std::map<std::string, uint32_t> ChunkFileHeader::VersionTable = {
317 std::make_pair(
"[Serializer_v1.80]", CurrentVersion),
319 std::make_pair(
"[Serializer_v1.10]", 1010)
328 id =
static_cast<ChunkID>(stream->
Read<uint16_t>());
339 std::unique_ptr<Chunk> chunk;
342 case CID_Header: chunk = std::make_unique<Ogre::Skeleton::ChunkFileHeader>();
break;
343 case CID_BlendMode: chunk = std::make_unique<Ogre::Skeleton::ChunkBlendMode>();
break;
344 case CID_Bone: chunk = std::make_unique<Ogre::Skeleton::ChunkBone>();
break;
345 case CID_Bone_Parent: chunk = std::make_unique<Ogre::Skeleton::ChunkBoneParent>();
break;
346 case CID_Animation: chunk = std::make_unique<Ogre::Skeleton::ChunkAnimation>();
break;
348 case CID_Animation_Track: chunk = std::make_unique<Ogre::Skeleton::ChunkAnimationTrack>();
break;
350 case CID_Animation_Link: chunk = std::make_unique<Ogre::Skeleton::ChunkAnimationLink>();
break;
352 LogF(
"StdMeshLoader: I don't know what to do with a chunk of type 0x%xu",
id);
353 chunk = std::make_unique<Ogre::Skeleton::ChunkUnknown>();
break;
357 chunk->ReadImpl(stream);
366 VersionTable_t::const_iterator it = VersionTable.find(stream->
Read<std::string>());
367 if (it == VersionTable.end())
368 throw InvalidVersion();
413 std::unique_ptr<Chunk> chunk =
Chunk::Read(stream);
416 LogF(
"StdMeshLoader: CID_Animation_BaseInfo not implemented. Skeleton might not be imported properly.");
421 std::unique_ptr<Chunk> chunk =
Chunk::Read(stream);
423 tracks.push_back(static_unique_cast<ChunkAnimationTrack>(move(chunk)));
438 std::unique_ptr<Chunk> chunk =
Chunk::Read(stream);
440 keyframes.push_back(static_unique_cast<ChunkAnimationTrackKF>(move(chunk)));
441 if (stream->
AtEof())
break;
456 if (
GetSize() >
sizeof(float) * 8)
bool LogF(const char *strMessage,...)
std::unique_ptr< To > static_unique_cast(From &&p)
static Type Peek(const DataStream *stream)
static const size_t ChunkHeaderLength
size_t GetRemainingBytes() const
void Seek(ptrdiff_t offset)
unique_ptr_vector< ChunkGeometryVertexDeclElement > vertexDeclaration
void ReadImpl(DataStream *stream) override
unique_ptr_vector< ChunkGeometryVertexBuffer > vertexBuffers
void ReadImpl(DataStream *stream) override
std::unique_ptr< ChunkGeometryVertexData > data
void ReadImpl(DataStream *stream) override
enum Ogre::Mesh::ChunkGeometryVertexDeclElement::Semantic semantic
void ReadImpl(DataStream *stream) override
enum Ogre::Mesh::ChunkGeometryVertexDeclElement::Type type
void ReadImpl(DataStream *stream) override
unique_ptr_vector< ChunkGeometryVertexDeclElement > declaration
static std::unique_ptr< Chunk > Read(DataStream *stream)
std::vector< BoneAssignment > assignments
void ReadImpl(DataStream *stream) override
void ReadImpl(DataStream *stream) override
void ReadImpl(DataStream *stream) override
std::unique_ptr< ChunkGeometry > geometry
std::vector< BoneAssignment > boneAssignments
unique_ptr_vector< ChunkSubmesh > submeshes
void ReadImpl(DataStream *stream) override
std::vector< size_t > faceVertices
std::unique_ptr< ChunkGeometry > geometry
enum Ogre::Mesh::ChunkSubmesh::SubmeshOperation SO_TriList
std::vector< BoneAssignment > boneAssignments
void ReadImpl(DataStream *stream) override
ChunkSubmesh::SubmeshOperation operation
void ReadImpl(DataStream *stream) override
void ReadImpl(DataStream *stream) override
void ReadImpl(DataStream *stream) override
float base_key_frame_time
std::string base_animation_name
void ReadImpl(DataStream *stream) override
unique_ptr_vector< ChunkAnimationTrack > tracks
void ReadImpl(DataStream *stream) override
void ReadImpl(DataStream *stream) override
unique_ptr_vector< ChunkAnimationTrackKF > keyframes
StdMeshQuaternion rotation
void ReadImpl(DataStream *stream) override
StdMeshVector translation
void ReadImpl(DataStream *stream) override
void ReadImpl(DataStream *stream) override
StdMeshQuaternion orientation
void ReadImpl(DataStream *stream) override
static std::unique_ptr< Chunk > Read(DataStream *stream)
void ReadImpl(DataStream *stream) override
@ CID_Mesh_Bone_Assignment
@ CID_Submesh_Bone_Assignment
@ CID_Geometry_Vertex_Decl
@ CID_Geometry_Vertex_Decl_Element
@ CID_Geometry_Vertex_Buffer
@ CID_Geometry_Vertex_Data
static StdMeshVector UnitScale()