Tools/MeshExtractor:

* Fixed a bunch of errors
* Allow to extract m2 and mdx models, WMOs are still not being extracted.
This commit is contained in:
Subv committed 2012-10-03 21:09:05 -05:00
1 parent e32ddea96a
commit d2437407f4
12 files changed
+183 -29

No files matched your search

+22 -7
View File
@@ -2,9 +2,14 @@
#include "MPQManager.h"
#include "Utils.h"
Model::Model( std::string path )
Model::Model( std::string path ) : IsCollidable(false), IsBad(false)
{
Stream = MPQHandler->GetFile(Utils::FixModelPath(path));
if (!Stream)
{
IsBad = true;
return;
}
Header.Read(Stream);
if (Header.OffsetBoundingNormals > 0 && Header.OffsetBoundingVertices > 0 &&
Header.OffsetBoundingTriangles > 0 && Header.BoundingRadius > 0.0f)
@@ -16,26 +21,36 @@ Model::Model( std::string path )
}
}
Model::~Model()
{
if (Stream)
fclose(Stream);
}
void Model::ReadVertices( FILE* stream )
{
fseek(stream, Header.OffsetBoundingVertices, SEEK_SET);
Vertices.reserve(Header.CountBoundingVertices);
for (int i = 0; i < Header.CountBoundingVertices; ++i)
Vertices[i] = Vector3::Read(stream);
for (uint32 i = 0; i < Header.CountBoundingVertices; ++i)
{
Vertices.push_back(Vector3::Read(stream));
if (Constants::ToWoWCoords)
Vertices[i] = Utils::ToWoWCoords(Vertices[i]);
}
}
void Model::ReadBoundingTriangles( FILE* stream )
{
fseek(stream, Header.OffsetBoundingTriangles, SEEK_SET);
Triangles.reserve(Header.CountBoundingTriangles / 3);
for (int i = 0; i < Header.CountBoundingTriangles / 3; i++)
for (uint32 i = 0; i < Header.CountBoundingTriangles / 3; i++)
{
Triangle<uint16> tri;
tri.Type = Constants::TRIANGLE_TYPE_DOODAD;
fread(&tri.V0, sizeof(uint16), 1, stream);
fread(&tri.V1, sizeof(uint16), 1, stream);
fread(&tri.V2, sizeof(uint16), 1, stream);
Triangles[i] = tri;
Triangles.push_back(tri);
}
}
@@ -43,7 +58,7 @@ void Model::ReadBoundingNormals( FILE* stream )
{
fseek(stream, Header.OffsetBoundingNormals, SEEK_SET);
Normals.reserve(Header.CountBoundingNormals);
for (int i = 0; i < Header.CountBoundingNormals; i++)
Normals[i] = Vector3::Read(stream);
for (uint32 i = 0; i < Header.CountBoundingNormals; i++)
Normals.push_back(Vector3::Read(stream));
}