Tools/MeshExtractor: Fixed(??????) Doodads in the terrain.

Semi-fixed WMOs in the terrain, they are wrongly rotated.
P.D: HALP
P.P.D: Entered "I don't know what i'm doing" mode.
This commit is contained in:
Sebastian Valle committed 2013-09-29 16:52:20 -05:00
1 parent 79ad89a3a7
commit 279183737c
6 files changed
+57 -51

No files matched your search

@@ -123,7 +123,7 @@ void ContinentBuilder::Build(bool debug)
{
if ((*_th)->Free)
{
(*_th)->SetData(40/*itr->X*/, 29/*itr->Y*/, MapId, Continent);
(*_th)->SetData(29/*itr->X*/, 40/*itr->Y*/, MapId, Continent);
(*_th)->activate();
next = true;
break;
+9 -15
View File
@@ -94,21 +94,15 @@ void DoodadHandler::ReadDoodadPaths( Chunk* id, Chunk* data )
Vector3 TransformDoodadVertex(const DoodadDefinition& def, Vector3& vec)
{
float mapOffset = 17066.0f + (2 / 3.0f);
Vector3 MapPos = Vector3(mapOffset, 0, mapOffset);
G3D::Matrix4 rot = G3D::Matrix4::identity();
rot = rot.pitchDegrees(def.Rotation.y - 90);
rot = rot.yawDegrees(-def.Rotation.x);
rot = rot.rollDegrees(def.Rotation.z - 90);
Vector3 offset = def.Position - MapPos;
// Rotate our Doodad vertex
G3D::Matrix4 rot = G3D::Matrix3::fromEulerAnglesXZY(Utils::ToRadians(-def.Rotation.z), Utils::ToRadians(def.Rotation.x), Utils::ToRadians(-def.Rotation.y + 180));
Vector3 ret = Utils::VectorTransform(vec, rot);
// Because homoMul wants a G3D::Vector3
G3D::Vector3 g3dvec(vec.x, vec.y, vec.z);
G3D::Vector3 g3dOffset(offset.x, offset.y, offset.z);
G3D::Vector3 ret = (rot.homoMul(g3dvec, 1) * def.Scale()) + g3dOffset;
Vector3 ret2 = (Utils::VectorTransform(vec, rot) * def.Scale()) + def.Position - MapPos;
return ret2; //Vector3(ret.x, ret.y, ret.z);
// Convert the rotated Doodad vector to our current coordinate system
ret = Vector3(ret.x, ret.z, -ret.y);
// And finally translate it to our origin
return ret + Vector3(Constants::MaxXY - def.Position.z, Constants::MaxXY - def.Position.x, def.Position.y);
}
void DoodadHandler::InsertModelGeometry(const DoodadDefinition& def, Model* model)
@@ -117,7 +111,7 @@ void DoodadHandler::InsertModelGeometry(const DoodadDefinition& def, Model* mode
uint32 vertOffset = Vertices.size();
for (std::vector<Vector3>::iterator itr = model->Vertices.begin(); itr != model->Vertices.end(); ++itr)
Vertices.push_back(TransformDoodadVertex(def, *itr)/*Utils::VectorTransform(*itr, transformation)*/);
Vertices.push_back(TransformDoodadVertex(def, *itr));
for (std::vector<Triangle<uint16> >::iterator itr = model->Triangles.begin(); itr != model->Triangles.end(); ++itr)
Triangles.push_back(Triangle<uint32>(Constants::TRIANGLE_TYPE_DOODAD, itr->V0 + vertOffset, itr->V1 + vertOffset, itr->V2 + vertOffset));
+6 -1
View File
@@ -17,13 +17,18 @@ public:
virtual float Scale() const { return DecimalScale / 1024.0f; }
Vector3 FixCoords(Vector3& vec)
{
return Vector3(vec.z, vec.x, vec.y);
}
void Read(FILE* stream)
{
int count = 0;
count += fread(&MmidIndex, sizeof(uint32), 1, stream);
count += fread(&UniqueId, sizeof(uint32), 1, stream);
Position = Vector3::Read(stream);
Position = (Vector3::Read(stream));
Rotation = Vector3::Read(stream);
count += fread(&DecimalScale, sizeof(uint16), 1, stream);
count += fread(&Flags, sizeof(uint16), 1, stream);
+2 -2
View File
@@ -117,7 +117,7 @@ void Geometry::AddAdt( ADT* adt )
if (!adt->_DoodadHandler->Triangles.empty())
AddData(adt->_DoodadHandler->Vertices, adt->_DoodadHandler->Triangles);
/*if (!adt->_WorldModelHandler->Triangles.empty())
AddData(adt->_WorldModelHandler->Vertices, adt->_WorldModelHandler->Triangles);*/
if (!adt->_WorldModelHandler->Triangles.empty())
AddData(adt->_WorldModelHandler->Vertices, adt->_WorldModelHandler->Triangles);
}
+20 -18
View File
@@ -86,18 +86,6 @@ std::string Utils::FixModelPath(const std::string& path )
return Utils::GetPathBase(path) + ".M2";
}
G3D::Matrix4 Utils::RotationX(float angle)
{
float _cos = cos(angle);
float _sin = sin(angle);
G3D::Matrix4 ret = G3D::Matrix4::identity();
ret[1][1] = _cos;
ret[2][1] = _sin;
ret[1][2] = -_sin;
ret[2][2] = _cos;
return ret;
}
G3D::Matrix4 Utils::GetTransformation(const IDefinition& def)
{
G3D::Matrix4 translation;
@@ -107,7 +95,8 @@ G3D::Matrix4 Utils::GetTransformation(const IDefinition& def)
translation = G3D::Matrix4::translation(-(def.Position.z - Constants::MaxXY),
-(def.Position.x - Constants::MaxXY), def.Position.y);
G3D::Matrix4 rotation = RotationX(ToRadians(def.Rotation.z)) * RotationY(ToRadians(def.Rotation.x)) * RotationZ(ToRadians(def.Rotation.y + 180));
//G3D::Matrix4 rotation = RotationX(ToRadians(def.Rotation.z)) * RotationY(ToRadians(def.Rotation.x)) * RotationZ(ToRadians(def.Rotation.y + 180));
G3D::Matrix4 rotation = G3D::Matrix4::identity().rollDegrees(def.Rotation.z).pitchDegrees(def.Rotation.x).yawDegrees(def.Rotation.y + 180);
if (def.Scale() < 1.0f || def.Scale() > 1.0f)
return G3D::Matrix4::scale(def.Scale()) * rotation * translation;
return rotation * translation;
@@ -137,6 +126,18 @@ G3D::Matrix4 Utils::RotationZ( float angle )
return ret;
}
G3D::Matrix4 Utils::RotationX(float angle)
{
float _cos = cos(angle);
float _sin = sin(angle);
G3D::Matrix4 ret = G3D::Matrix4::identity();
ret[1][1] = _cos;
ret[2][1] = _sin;
ret[1][2] = -_sin;
ret[2][2] = _cos;
return ret;
}
float Utils::ToRadians( float degrees )
{
return Constants::PI * degrees / 180.0f;
@@ -144,11 +145,12 @@ float Utils::ToRadians( float degrees )
Vector3 Utils::VectorTransform(const Vector3& vec, const G3D::Matrix4& matrix )
{
Vector3 ret;
ret.x = vec.x * matrix[0][0] + vec.y * matrix[1][0] + vec.z * matrix[2][0] + matrix[3][0];
G3D::Vector3 ret(vec.x, vec.y, vec.z);
ret = matrix.homoMul(ret, 1);
/*ret.x = vec.x * matrix[0][0] + vec.y * matrix[1][0] + vec.z * matrix[2][0] + matrix[3][0];
ret.y = vec.x * matrix[0][1] + vec.y * matrix[1][1] + vec.z * matrix[2][1] + matrix[3][1];
ret.z = vec.x * matrix[0][2] + vec.y * matrix[1][2] + vec.z * matrix[2][2] + matrix[3][2];
return ret;
ret.z = vec.x * matrix[0][2] + vec.y * matrix[1][2] + vec.z * matrix[2][2] + matrix[3][2];*/
return Vector3(ret.x, ret.y, ret.z);
}
std::string Utils::GetPathBase(const std::string& path )
@@ -230,7 +232,7 @@ void Utils::SaveToDisk( FILE* stream, const std::string& path )
Vector3 Utils::ToWoWCoords(const Vector3& vec )
{
return Vector3(vec.x, -vec.z, vec.y);
return Vector3(-vec.z, vec.x, vec.y);
}
std::string Utils::GetExtension( std::string path )
+19 -14
View File
@@ -5,6 +5,7 @@
#include "Model.h"
#include "Define.h"
#include "G3D/Matrix4.h"
#include "G3D/Quat.h"
#include <cstdio>
WorldModelDefinition WorldModelDefinition::Read( FILE* file )
@@ -82,21 +83,25 @@ void WorldModelHandler::ProcessInternal( MapChunk* mcnk )
Vector3 TransformDoodadVertex(const IDefinition& def, Vector3& vec)
{
float mapOffset = 17066.0f + (2 / 3.0f);
Vector3 MapPos = Vector3(mapOffset, 0, mapOffset);
G3D::Matrix4 rot = G3D::Matrix4::identity();
rot = rot.pitchDegrees(def.Rotation.y - 90);
rot = rot.yawDegrees(-def.Rotation.x);
rot = rot.rollDegrees(def.Rotation.z - 90);
// Rotate our Doodad vertex
G3D::Matrix4 rot = G3D::Matrix3::fromEulerAnglesXZY(Utils::ToRadians(-def.Rotation.z), Utils::ToRadians(def.Rotation.x), Utils::ToRadians(-def.Rotation.y + 180));
Vector3 ret = Utils::VectorTransform(vec, rot);
Vector3 offset = def.Position - MapPos;
// Convert the rotated Doodad vector to our current coordinate system
ret = Vector3(ret.x, ret.z, -ret.y);
// Because homoMul wants a G3D::Vector3
G3D::Vector3 g3dvec(vec.x, vec.y, vec.z);
G3D::Vector3 g3dOffset(offset.x, offset.y, offset.z);
G3D::Vector3 ret = (rot.homoMul(g3dvec, 1) * def.Scale()) + g3dOffset;
Vector3 ret2 = (Utils::VectorTransform(vec, rot) + def.Position - MapPos) * def.Scale();
return ret2; //Vector3(ret.x, ret.y, ret.z);
// And finally translate it to our origin
return ret + Vector3(Constants::MaxXY - def.Position.z, Constants::MaxXY - def.Position.x, def.Position.y);
}
Vector3 TransformDoodadToWMO(Vector3& vec, const DoodadInstance& inst, const WorldModelRoot& rootDef)
{
Vector3 translation = Vector3(inst.Position.x, inst.Position.z, -inst.Position.y);
G3D::Quat quat = G3D::Quat(inst.QuatX, inst.QuatZ, -inst.QuatY, inst.QuatW);
G3D::Matrix3 rotM;
quat.toRotationMatrix(rotM);
return (Utils::VectorTransform(vec, G3D::Matrix4(rotM)) + translation) * (1.0f / inst.Scale);
}
void WorldModelHandler::InsertModelGeometry( std::vector<Vector3>& verts, std::vector<Triangle<uint32> >& tris, WorldModelDefinition& def, WorldModelRoot* root )
@@ -144,7 +149,7 @@ void WorldModelHandler::InsertModelGeometry( std::vector<Vector3>& verts, std::v
G3D::Matrix4 doodadTransformation = Utils::GetWmoDoodadTransformation(*instance, def);
int vertOffset = verts.size();
for (std::vector<Vector3>::iterator itr2 = model->Vertices.begin(); itr2 != model->Vertices.end(); ++itr2)
verts.push_back(TransformDoodadVertex(def, *itr2)/*Utils::VectorTransform(*itr2, doodadTransformation)*/);
verts.push_back(TransformDoodadToWMO(*itr2, *instance, *root)/*TransformDoodadVertex(instance, *itr2)*//*Utils::VectorTransform(*itr2, doodadTransformation)*/);
for (std::vector<Triangle<uint16> >::iterator itr2 = model->Triangles.begin(); itr2 != model->Triangles.end(); ++itr2)
tris.push_back(Triangle<uint32>(Constants::TRIANGLE_TYPE_WMO, itr2->V0 + vertOffset, itr2->V1 + vertOffset, itr2->V2 + vertOffset));
}