Tools: merged Master tools updates
This commit is contained in:
1 parent
9ade5b77ff
commit
fbcb423f60
27 files changed
+723
-571
No files matched your search
@@ -18,13 +18,10 @@
|
||||
|
||||
#include "vmapexport.h"
|
||||
#include "adtfile.h"
|
||||
|
||||
#include "StringFormat.h"
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
|
||||
#ifdef WIN32
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
#include "Errors.h"
|
||||
|
||||
char const* GetPlainName(char const* FileName)
|
||||
{
|
||||
@@ -63,11 +60,12 @@ void FixNameCase(char* name, size_t len)
|
||||
|
||||
void FixNameSpaces(char* name, size_t len)
|
||||
{
|
||||
for (size_t i=0; i<len-3; i++)
|
||||
{
|
||||
if (len < 3)
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i < len - 3; i++)
|
||||
if (name[i] == ' ')
|
||||
name[i] = '_';
|
||||
}
|
||||
}
|
||||
|
||||
char* GetExtension(char* FileName)
|
||||
@@ -79,7 +77,7 @@ char* GetExtension(char* FileName)
|
||||
|
||||
extern HANDLE WorldMpq;
|
||||
|
||||
ADTFile::ADTFile(char* filename, bool cache) : ADT(WorldMpq, filename, false)
|
||||
ADTFile::ADTFile(char* filename, bool cache) : _file(WorldMpq, filename, false)
|
||||
{
|
||||
Adtfilename.append(filename);
|
||||
cacheable = cache;
|
||||
@@ -91,7 +89,7 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY, uint32 originalMa
|
||||
if (dirfileCache)
|
||||
return initFromCache(map_num, tileX, tileY, originalMapId);
|
||||
|
||||
if (ADT.isEof ())
|
||||
if (_file.isEof ())
|
||||
return false;
|
||||
|
||||
uint32 size;
|
||||
@@ -122,15 +120,15 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY, uint32 originalMa
|
||||
if (cacheable)
|
||||
dirfileCache = new std::vector<ADTOutputCache>();
|
||||
|
||||
while (!ADT.isEof())
|
||||
while (!_file.isEof())
|
||||
{
|
||||
char fourcc[5];
|
||||
ADT.read(&fourcc,4);
|
||||
ADT.read(&size, 4);
|
||||
_file.read(&fourcc,4);
|
||||
_file.read(&size, 4);
|
||||
flipcc(fourcc);
|
||||
fourcc[4] = 0;
|
||||
|
||||
size_t nextpos = ADT.getPos() + size;
|
||||
size_t nextpos = _file.getPos() + size;
|
||||
|
||||
if (!strcmp(fourcc,"MCIN"))
|
||||
{
|
||||
@@ -143,7 +141,7 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY, uint32 originalMa
|
||||
if (size)
|
||||
{
|
||||
char* buf = new char[size];
|
||||
ADT.read(buf, size);
|
||||
_file.read(buf, size);
|
||||
char* p = buf;
|
||||
int t = 0;
|
||||
ModelInstanceNames = new std::string[size];
|
||||
@@ -169,7 +167,7 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY, uint32 originalMa
|
||||
if (size)
|
||||
{
|
||||
char* buf = new char[size];
|
||||
ADT.read(buf, size);
|
||||
_file.read(buf, size);
|
||||
char* p = buf;
|
||||
int q = 0;
|
||||
WmoInstanceNames = new std::string[size];
|
||||
@@ -187,17 +185,27 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY, uint32 originalMa
|
||||
}
|
||||
}
|
||||
//======================
|
||||
else if (!strcmp(fourcc,"MDDF"))
|
||||
else if (!strcmp(fourcc, "MDDF"))
|
||||
{
|
||||
if (size)
|
||||
{
|
||||
nMDX = (int)size / 36;
|
||||
for (int i=0; i<nMDX; ++i)
|
||||
uint32 doodadCount = size / sizeof(ADT::MDDF);
|
||||
for (uint32 i = 0; i < doodadCount; ++i)
|
||||
{
|
||||
uint32 id;
|
||||
ADT.read(&id, 4);
|
||||
ModelInstance inst(ADT, ModelInstanceNames[id].c_str(), map_num, tileX, tileY, originalMapId, dirfile, dirfileCache);
|
||||
ADT::MDDF doodadDef;
|
||||
_file.read(&doodadDef, sizeof(ADT::MDDF));
|
||||
if (!(doodadDef.Flags & 0x40))
|
||||
{
|
||||
Doodad::Extract(doodadDef, ModelInstanceNames[doodadDef.Id].c_str(), map_num, tileX, tileY, originalMapId, dirfile, dirfileCache);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string fileName = Trinity::StringFormat("FILE%08X.xxx", doodadDef.Id);
|
||||
ExtractSingleModel(fileName);
|
||||
Doodad::Extract(doodadDef, fileName.c_str(), map_num, tileX, tileY, originalMapId, dirfile, dirfileCache);
|
||||
}
|
||||
}
|
||||
|
||||
delete[] ModelInstanceNames;
|
||||
ModelInstanceNames = nullptr;
|
||||
}
|
||||
@@ -206,12 +214,23 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY, uint32 originalMa
|
||||
{
|
||||
if (size)
|
||||
{
|
||||
nWMO = (int)size / 64;
|
||||
for (int i=0; i<nWMO; ++i)
|
||||
uint32 mapObjectCount = size / sizeof(ADT::MODF);
|
||||
for (uint32 i = 0; i < mapObjectCount; ++i)
|
||||
{
|
||||
uint32 id;
|
||||
ADT.read(&id, 4);
|
||||
WMOInstance inst(ADT, WmoInstanceNames[id].c_str(), map_num, tileX, tileY, originalMapId, dirfile, dirfileCache);
|
||||
ADT::MODF mapObjDef;
|
||||
_file.read(&mapObjDef, sizeof(ADT::MODF));
|
||||
if (!(mapObjDef.Flags & 0x8))
|
||||
{
|
||||
MapObject::Extract(mapObjDef, WmoInstanceNames[mapObjDef.Id].c_str(), map_num, tileX, tileY, originalMapId, dirfile, dirfileCache);
|
||||
Doodad::ExtractSet(WmoDoodads[WmoInstanceNames[mapObjDef.Id]], mapObjDef, map_num, tileX, tileY, originalMapId, dirfile, dirfileCache);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string fileName = Trinity::StringFormat("FILE%08X.xxx", mapObjDef.Id);
|
||||
ExtractSingleWmo(fileName);
|
||||
MapObject::Extract(mapObjDef, fileName.c_str(), map_num, tileX, tileY, originalMapId, dirfile, dirfileCache);
|
||||
Doodad::ExtractSet(WmoDoodads[fileName], mapObjDef, map_num, tileX, tileY, originalMapId, dirfile, dirfileCache);
|
||||
}
|
||||
}
|
||||
|
||||
delete[] WmoInstanceNames;
|
||||
@@ -220,10 +239,10 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY, uint32 originalMa
|
||||
}
|
||||
|
||||
//======================
|
||||
ADT.seek(nextpos);
|
||||
_file.seek(nextpos);
|
||||
}
|
||||
|
||||
ADT.close();
|
||||
_file.close();
|
||||
fclose(dirfile);
|
||||
return true;
|
||||
}
|
||||
@@ -259,6 +278,6 @@ bool ADTFile::initFromCache(uint32 map_num, uint32 tileX, uint32 tileY, uint32 o
|
||||
|
||||
ADTFile::~ADTFile()
|
||||
{
|
||||
ADT.close();
|
||||
_file.close();
|
||||
delete dirfileCache;
|
||||
}
|
||||
@@ -23,88 +23,33 @@
|
||||
#include "wmo.h"
|
||||
#include "model.h"
|
||||
|
||||
#define TILESIZE (533.33333f)
|
||||
#define CHUNKSIZE ((TILESIZE) / 16.0f)
|
||||
#define UNITSIZE (CHUNKSIZE / 8.0f)
|
||||
|
||||
class Liquid;
|
||||
|
||||
typedef struct
|
||||
#pragma pack(push, 1)
|
||||
namespace ADT
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
}svec;
|
||||
struct MDDF
|
||||
{
|
||||
uint32 Id;
|
||||
uint32 UniqueId;
|
||||
Vec3D Position;
|
||||
Vec3D Rotation;
|
||||
uint16 Scale;
|
||||
uint16 Flags;
|
||||
};
|
||||
|
||||
struct vec
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
};
|
||||
|
||||
struct triangle
|
||||
{
|
||||
vec v[3];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float v9[16*8+1][16*8+1];
|
||||
float v8[16*8][16*8];
|
||||
}Cell;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double v9[9][9];
|
||||
double v8[8][8];
|
||||
uint16 area_id;
|
||||
//Liquid *lq;
|
||||
float waterlevel[9][9];
|
||||
uint8 flag;
|
||||
}chunk;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
chunk ch[16][16];
|
||||
}mcell;
|
||||
|
||||
struct MapChunkHeader
|
||||
{
|
||||
uint32 flags;
|
||||
uint32 ix;
|
||||
uint32 iy;
|
||||
uint32 nLayers;
|
||||
uint32 nDoodadRefs;
|
||||
uint32 ofsHeight;
|
||||
uint32 ofsNormal;
|
||||
uint32 ofsLayer;
|
||||
uint32 ofsRefs;
|
||||
uint32 ofsAlpha;
|
||||
uint32 sizeAlpha;
|
||||
uint32 ofsShadow;
|
||||
uint32 sizeShadow;
|
||||
uint32 areaid;
|
||||
uint32 nMapObjRefs;
|
||||
uint32 holes;
|
||||
uint16 s1;
|
||||
uint16 s2;
|
||||
uint32 d1;
|
||||
uint32 d2;
|
||||
uint32 d3;
|
||||
uint32 predTex;
|
||||
uint32 nEffectDoodad;
|
||||
uint32 ofsSndEmitters;
|
||||
uint32 nSndEmitters;
|
||||
uint32 ofsLiquid;
|
||||
uint32 sizeLiquid;
|
||||
float zpos;
|
||||
float xpos;
|
||||
float ypos;
|
||||
uint32 textureId;
|
||||
uint32 props;
|
||||
uint32 effectId;
|
||||
};
|
||||
struct MODF
|
||||
{
|
||||
uint32 Id;
|
||||
uint32 UniqueId;
|
||||
Vec3D Position;
|
||||
Vec3D Rotation;
|
||||
AaBox3D Bounds;
|
||||
uint16 Flags;
|
||||
uint16 DoodadSet; // // can be larger than number of doodad sets in WMO
|
||||
uint16 NameSet;
|
||||
uint16 Scale;
|
||||
};
|
||||
}
|
||||
#pragma pack(pop)
|
||||
|
||||
struct ADTOutputCache
|
||||
{
|
||||
@@ -115,15 +60,13 @@ struct ADTOutputCache
|
||||
class ADTFile
|
||||
{
|
||||
private:
|
||||
MPQFile ADT;
|
||||
MPQFile _file;
|
||||
std::string Adtfilename;
|
||||
bool cacheable;
|
||||
std::vector<ADTOutputCache>* dirfileCache;
|
||||
public:
|
||||
ADTFile(char* filename, bool cache);
|
||||
~ADTFile();
|
||||
int nWMO;
|
||||
int nMDX;
|
||||
std::string* WmoInstanceNames;
|
||||
std::string* ModelInstanceNames;
|
||||
bool init(uint32 map_num, uint32 tileX, uint32 tileY, uint32 originalMapId);
|
||||
|
||||
@@ -20,13 +20,17 @@
|
||||
#include "dbcfile.h"
|
||||
#include "adtfile.h"
|
||||
#include "vmapexport.h"
|
||||
|
||||
#include "VMapDefinitions.h"
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
|
||||
bool ExtractSingleModel(std::string& fname)
|
||||
{
|
||||
if (fname.substr(fname.length() - 4, 4) == ".mdx")
|
||||
if (fname.length() < 4)
|
||||
return false;
|
||||
|
||||
std::string extension = fname.substr(fname.length() - 4, 4);
|
||||
if (extension == ".mdx" || extension == ".MDX" || extension == ".mdl" || extension == ".MDL")
|
||||
{
|
||||
fname.erase(fname.length() - 2, 2);
|
||||
fname.append("2");
|
||||
@@ -76,6 +80,8 @@ void ExtractGameobjectModels()
|
||||
return;
|
||||
}
|
||||
|
||||
fwrite(VMAP::RAW_VMAP_MAGIC, 1, 8, model_list);
|
||||
|
||||
for (DBCFile::Iterator it = dbc.begin(); it != dbc.end(); ++it)
|
||||
{
|
||||
path = it->getString(1);
|
||||
@@ -91,12 +97,14 @@ void ExtractGameobjectModels()
|
||||
if (!ch_ext)
|
||||
continue;
|
||||
|
||||
strToLower(ch_ext);
|
||||
|
||||
bool result = false;
|
||||
if (!strcmp(ch_ext, ".wmo"))
|
||||
uint8 isWmo = 0;
|
||||
if (!strcmp(ch_ext, ".WMO") && !strcmp(ch_ext, ".wmo"))
|
||||
{
|
||||
isWmo = 1;
|
||||
result = ExtractSingleWmo(path);
|
||||
else if (!strcmp(ch_ext, ".mdl")) // TODO: extract .mdl files, if needed
|
||||
}
|
||||
else if (!strcmp(ch_ext, ".MDL") && !strcmp(ch_ext, ".mdl")) // TODO: extract .mdl files, if needed
|
||||
continue;
|
||||
else //if (!strcmp(ch_ext, ".mdx") || !strcmp(ch_ext, ".m2"))
|
||||
result = ExtractSingleModel(path);
|
||||
@@ -106,6 +114,7 @@ void ExtractGameobjectModels()
|
||||
uint32 displayId = it->getUInt(0);
|
||||
uint32 path_length = strlen(name);
|
||||
fwrite(&displayId, sizeof(uint32), 1, model_list);
|
||||
fwrite(&isWmo, sizeof(uint8), 1, model_list);
|
||||
fwrite(&path_length, sizeof(uint32), 1, model_list);
|
||||
fwrite(name, sizeof(char), path_length, model_list);
|
||||
}
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
*/
|
||||
|
||||
#include "vmapexport.h"
|
||||
#include "Errors.h"
|
||||
#include "model.h"
|
||||
#include "wmo.h"
|
||||
#include "adtfile.h"
|
||||
#include "mpqfile.h"
|
||||
#include <cassert>
|
||||
#include "VMapDefinitions.h"
|
||||
#include <G3D/Quat.h>
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
|
||||
extern HANDLE WorldMpq;
|
||||
|
||||
@@ -79,7 +82,7 @@ bool Model::ConvertToVMAPModel(const char * outfilename)
|
||||
printf("Can't create the output file '%s'\n",outfilename);
|
||||
return false;
|
||||
}
|
||||
fwrite(szRawVMAPMagic, 8, 1, output);
|
||||
fwrite(VMAP::RAW_VMAP_MAGIC, 8, 1, output);
|
||||
uint32 nVertices = header.nBoundingVertices;
|
||||
fwrite(&nVertices, sizeof(int), 1, output);
|
||||
uint32 nofgroups = 1;
|
||||
@@ -135,39 +138,23 @@ bool Model::ConvertToVMAPModel(const char * outfilename)
|
||||
}
|
||||
|
||||
|
||||
Vec3D fixCoordSystem(Vec3D v)
|
||||
Vec3D fixCoordSystem(Vec3D const& v)
|
||||
{
|
||||
return Vec3D(v.x, v.z, -v.y);
|
||||
}
|
||||
|
||||
Vec3D fixCoordSystem2(Vec3D v)
|
||||
void Doodad::Extract(ADT::MDDF const& doodadDef, char const* ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId,
|
||||
FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache)
|
||||
{
|
||||
return Vec3D(v.x, v.z, v.y);
|
||||
}
|
||||
|
||||
ModelInstance::ModelInstance(MPQFile& f, char const* ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId, FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache)
|
||||
: id(0), scale(0), flags(0)
|
||||
{
|
||||
float ff[3];
|
||||
f.read(&id, 4);
|
||||
f.read(ff, 12);
|
||||
pos = fixCoords(Vec3D(ff[0], ff[1], ff[2]));
|
||||
f.read(ff, 12);
|
||||
rot = Vec3D(ff[0], ff[1], ff[2]);
|
||||
f.read(&scale, 2);
|
||||
f.read(&flags, 2);
|
||||
// scale factor - divide by 1024. blizzard devs must be on crack, why not just use a float?
|
||||
sc = scale / 1024.0f;
|
||||
float sc = doodadDef.Scale / 1024.0f;
|
||||
|
||||
char tempname[512];
|
||||
sprintf(tempname, "%s/%s", szWorkDirWmo, ModelInstName);
|
||||
FILE* input = fopen(tempname, "r+b");
|
||||
|
||||
if (!input)
|
||||
{
|
||||
//printf("ModelInstance::ModelInstance couldn't open %s\n", tempname);
|
||||
return;
|
||||
}
|
||||
|
||||
fseek(input, 8, SEEK_SET); // get the correct no of vertices
|
||||
int nVertices;
|
||||
@@ -177,22 +164,25 @@ ModelInstance::ModelInstance(MPQFile& f, char const* ModelInstName, uint32 mapID
|
||||
if (count != 1 || nVertices == 0)
|
||||
return;
|
||||
|
||||
uint16 adtId = 0;// not used for models
|
||||
Vec3D position = fixCoords(doodadDef.Position);
|
||||
|
||||
uint16 nameSet = 0;// not used for models
|
||||
uint32 uniqueId = GenerateUniqueObjectId(doodadDef.UniqueId, 0);
|
||||
uint32 flags = MOD_M2;
|
||||
if (tileX == 65 && tileY == 65)
|
||||
flags |= MOD_WORLDSPAWN;
|
||||
if (mapID != originalMapId)
|
||||
flags |= MOD_PARENT_SPAWN;
|
||||
|
||||
//write mapID, tileX, tileY, Flags, ID, Pos, Rot, Scale, name
|
||||
//write mapID, tileX, tileY, Flags, NameSet, UniqueId, Pos, Rot, Scale, name
|
||||
fwrite(&mapID, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&tileX, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&tileY, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&flags, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&adtId, sizeof(uint16), 1, pDirfile);
|
||||
fwrite(&id, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&pos, sizeof(float), 3, pDirfile);
|
||||
fwrite(&rot, sizeof(float), 3, pDirfile);
|
||||
fwrite(&nameSet, sizeof(uint16), 1, pDirfile);
|
||||
fwrite(&uniqueId, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&position, sizeof(Vec3D), 1, pDirfile);
|
||||
fwrite(&doodadDef.Rotation, sizeof(Vec3D), 1, pDirfile);
|
||||
fwrite(&sc, sizeof(float), 1, pDirfile);
|
||||
uint32 nlen=strlen(ModelInstName);
|
||||
fwrite(&nlen, sizeof(uint32), 1, pDirfile);
|
||||
@@ -204,41 +194,134 @@ ModelInstance::ModelInstance(MPQFile& f, char const* ModelInstName, uint32 mapID
|
||||
ADTOutputCache& cacheModelData = dirfileCache->back();
|
||||
cacheModelData.Flags = flags & ~MOD_PARENT_SPAWN;
|
||||
cacheModelData.Data.resize(
|
||||
sizeof(uint16) + // adtId
|
||||
sizeof(uint32) + // id
|
||||
sizeof(float) * 3 + // pos
|
||||
sizeof(float) * 3 + // rot
|
||||
sizeof(uint16) + // nameSet
|
||||
sizeof(uint32) + // uniqueId
|
||||
sizeof(Vec3D) + // position
|
||||
sizeof(Vec3D) + // doodadDef.Rotation
|
||||
sizeof(float) + // sc
|
||||
sizeof(uint32) + // nlen
|
||||
nlen); // ModelInstName
|
||||
|
||||
uint8* cacheData = cacheModelData.Data.data();
|
||||
#define CACHE_WRITE(value, size, count, dest) memcpy(dest, value, size * count); dest += size * count;
|
||||
#define CACHE_WRITE(value, size, cnt, dest) memcpy(dest, value, size * cnt); dest += size * cnt;
|
||||
|
||||
CACHE_WRITE(&adtId, sizeof(uint16), 1, cacheData);
|
||||
CACHE_WRITE(&id, sizeof(uint32), 1, cacheData);
|
||||
CACHE_WRITE(&pos, sizeof(float), 3, cacheData);
|
||||
CACHE_WRITE(&rot, sizeof(float), 3, cacheData);
|
||||
CACHE_WRITE(&nameSet, sizeof(uint16), 1, cacheData);
|
||||
CACHE_WRITE(&uniqueId, sizeof(uint32), 1, cacheData);
|
||||
CACHE_WRITE(&position, sizeof(Vec3D), 1, cacheData);
|
||||
CACHE_WRITE(&doodadDef.Rotation, sizeof(Vec3D), 1, cacheData);
|
||||
CACHE_WRITE(&sc, sizeof(float), 1, cacheData);
|
||||
CACHE_WRITE(&nlen, sizeof(uint32), 1, cacheData);
|
||||
CACHE_WRITE(ModelInstName, sizeof(char), nlen, cacheData);
|
||||
}
|
||||
}
|
||||
|
||||
void Doodad::ExtractSet(WMODoodadData const& doodadData, ADT::MODF const& wmo, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId,
|
||||
FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache)
|
||||
{
|
||||
if (wmo.DoodadSet >= doodadData.Sets.size())
|
||||
return;
|
||||
|
||||
G3D::Vector3 wmoPosition(wmo.Position.z, wmo.Position.x, wmo.Position.y);
|
||||
G3D::Matrix3 wmoRotation = G3D::Matrix3::fromEulerAnglesZYX(G3D::toRadians(wmo.Rotation.y), G3D::toRadians(wmo.Rotation.x), G3D::toRadians(wmo.Rotation.z));
|
||||
|
||||
uint16 doodadId = 0;
|
||||
WMO::MODS const& doodadSetData = doodadData.Sets[wmo.DoodadSet];
|
||||
for (uint16 doodadIndex : doodadData.References)
|
||||
{
|
||||
if (doodadIndex < doodadSetData.StartIndex ||
|
||||
doodadIndex >= doodadSetData.StartIndex + doodadSetData.Count)
|
||||
continue;
|
||||
|
||||
WMO::MODD const& doodad = doodadData.Spawns[doodadIndex];
|
||||
|
||||
char ModelInstName[1024];
|
||||
sprintf(ModelInstName, "%s", GetPlainName(&doodadData.Paths[doodad.NameIndex]));
|
||||
uint32 nlen = strlen(ModelInstName);
|
||||
FixNameCase(ModelInstName, nlen);
|
||||
FixNameSpaces(ModelInstName, nlen);
|
||||
if (nlen > 3)
|
||||
{
|
||||
char const* extension = &ModelInstName[nlen - 4];
|
||||
if (!strcmp(extension, ".mdx") || !strcmp(extension, ".mdl"))
|
||||
{
|
||||
ModelInstName[nlen - 2] = '2';
|
||||
ModelInstName[nlen - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
char tempname[512];
|
||||
sprintf(tempname, "%s/%s", szWorkDirWmo, ModelInstName);
|
||||
FILE* input = fopen(tempname, "r+b");
|
||||
if (!input)
|
||||
continue;
|
||||
|
||||
fseek(input, 8, SEEK_SET); // get the correct no of vertices
|
||||
int nVertices;
|
||||
int count = fread(&nVertices, sizeof(int), 1, input);
|
||||
fclose(input);
|
||||
|
||||
if (count != 1 || nVertices == 0)
|
||||
continue;
|
||||
|
||||
ASSERT(doodadId < std::numeric_limits<uint16>::max());
|
||||
++doodadId;
|
||||
|
||||
G3D::Vector3 position = wmoPosition + (wmoRotation * G3D::Vector3(doodad.Position.x, doodad.Position.y, doodad.Position.z));
|
||||
|
||||
Vec3D rotation;
|
||||
(G3D::Quat(doodad.Rotation.X, doodad.Rotation.Y, doodad.Rotation.Z, doodad.Rotation.W)
|
||||
.toRotationMatrix() * wmoRotation)
|
||||
.toEulerAnglesXYZ(rotation.z, rotation.x, rotation.y);
|
||||
|
||||
rotation.z = G3D::toDegrees(rotation.z);
|
||||
rotation.x = G3D::toDegrees(rotation.x);
|
||||
rotation.y = G3D::toDegrees(rotation.y);
|
||||
|
||||
uint16 nameSet = 0; // not used for models
|
||||
uint32 uniqueId = GenerateUniqueObjectId(wmo.UniqueId, doodadId);
|
||||
uint32 tcflags = MOD_M2;
|
||||
if (tileX == 65 && tileY == 65)
|
||||
tcflags |= MOD_WORLDSPAWN;
|
||||
if (mapID != originalMapId)
|
||||
tcflags |= MOD_PARENT_SPAWN;
|
||||
|
||||
//write mapID, tileX, tileY, Flags, NameSet, UniqueId, Pos, Rot, Scale, name
|
||||
fwrite(&mapID, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&tileX, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&tileY, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&tcflags, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&nameSet, sizeof(uint16), 1, pDirfile);
|
||||
fwrite(&uniqueId, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&position, sizeof(Vec3D), 1, pDirfile);
|
||||
fwrite(&rotation, sizeof(Vec3D), 1, pDirfile);
|
||||
fwrite(&doodad.Scale, sizeof(float), 1, pDirfile);
|
||||
fwrite(&nlen, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(ModelInstName, sizeof(char), nlen, pDirfile);
|
||||
|
||||
if (dirfileCache)
|
||||
{
|
||||
dirfileCache->emplace_back();
|
||||
ADTOutputCache& cacheModelData = dirfileCache->back();
|
||||
cacheModelData.Flags = tcflags & ~MOD_PARENT_SPAWN;
|
||||
cacheModelData.Data.resize(
|
||||
sizeof(uint16) + // nameSet
|
||||
sizeof(uint32) + // uniqueId
|
||||
sizeof(Vec3D) + // position
|
||||
sizeof(Vec3D) + // rotation
|
||||
sizeof(float) + // doodad.Scale
|
||||
sizeof(uint32) + // nlen
|
||||
nlen); // ModelInstName
|
||||
|
||||
uint8* cacheData = cacheModelData.Data.data();
|
||||
CACHE_WRITE(&nameSet, sizeof(uint16), 1, cacheData);
|
||||
CACHE_WRITE(&uniqueId, sizeof(uint32), 1, cacheData);
|
||||
CACHE_WRITE(&position, sizeof(Vec3D), 1, cacheData);
|
||||
CACHE_WRITE(&rotation, sizeof(Vec3D), 1, cacheData);
|
||||
CACHE_WRITE(&doodad.Scale, sizeof(float), 1, cacheData);
|
||||
CACHE_WRITE(&nlen, sizeof(uint32), 1, cacheData);
|
||||
CACHE_WRITE(ModelInstName, sizeof(char), nlen, cacheData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#undef CACHE_WRITE
|
||||
}
|
||||
|
||||
/* int realx1 = (int) ((float) pos.x / 533.333333f);
|
||||
int realy1 = (int) ((float) pos.z / 533.333333f);
|
||||
int realx2 = (int) ((float) pos.x / 533.333333f);
|
||||
int realy2 = (int) ((float) pos.z / 533.333333f);
|
||||
|
||||
fprintf(pDirfile,"%s/%s %f,%f,%f_%f,%f,%f %f %d %d %d,%d %d\n",
|
||||
MapName,
|
||||
ModelInstName,
|
||||
(float) pos.x, (float) pos.y, (float) pos.z,
|
||||
(float) rot.x, (float) rot.y, (float) rot.z,
|
||||
sc,
|
||||
nVertices,
|
||||
realx1, realy1,
|
||||
realx2, realy2
|
||||
); */
|
||||
}
|
||||
@@ -25,8 +25,10 @@
|
||||
|
||||
class MPQFile;
|
||||
struct ADTOutputCache;
|
||||
struct WMODoodadData;
|
||||
namespace ADT { struct MDDF; struct MODF; }
|
||||
|
||||
Vec3D fixCoordSystem(Vec3D v);
|
||||
Vec3D fixCoordSystem(Vec3D const& v);
|
||||
|
||||
class Model
|
||||
{
|
||||
@@ -51,17 +53,13 @@ public:
|
||||
~Model() { _unload(); }
|
||||
};
|
||||
|
||||
class ModelInstance
|
||||
namespace Doodad
|
||||
{
|
||||
public:
|
||||
uint32 id;
|
||||
Vec3D pos, rot;
|
||||
uint16 scale, flags;
|
||||
float sc;
|
||||
void Extract(ADT::MDDF const& doodadDef, char const* ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId,
|
||||
FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache);
|
||||
|
||||
ModelInstance() : id(0), scale(0), flags(0), sc(0.0f) {}
|
||||
ModelInstance(MPQFile& f, char const* ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId, FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache);
|
||||
|
||||
};
|
||||
void ExtractSet(WMODoodadData const& doodadData, ADT::MODF const& wmo, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId,
|
||||
FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -137,6 +137,12 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class AaBox3D
|
||||
{
|
||||
public:
|
||||
Vec3D min;
|
||||
Vec3D max;
|
||||
};
|
||||
|
||||
class Vec2D
|
||||
{
|
||||
@@ -245,4 +251,9 @@ inline void rotate(float x0, float y0, float *x, float *y, float angle)
|
||||
*y = xa*sinf(angle) + ya*cosf(angle) + y0;
|
||||
}
|
||||
|
||||
struct Quaternion
|
||||
{
|
||||
float X, Y, Z, W;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -127,12 +127,11 @@ std::unordered_map<uint32, LiquidTypeEntry> LiquidTypes;
|
||||
char output_path[128]=".";
|
||||
char input_path[1024]=".";
|
||||
bool preciseVectorData = false;
|
||||
std::unordered_map<std::string, WMODoodadData> WmoDoodads;
|
||||
|
||||
// Constants
|
||||
|
||||
//static const char * szWorkDirMaps = ".\\Maps";
|
||||
char const* szWorkDirWmo = "./Buildings";
|
||||
char const* szRawVMAPMagic = "VMAP045";
|
||||
|
||||
bool LoadLocaleMPQFile(int locale)
|
||||
{
|
||||
@@ -247,7 +246,12 @@ void LoadCommonMPQFiles(uint32 build)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
std::map<std::pair<uint32, uint16>, uint32> uniqueObjectIds;
|
||||
|
||||
uint32 GenerateUniqueObjectId(uint32 clientId, uint16 clientDoodadId)
|
||||
{
|
||||
return uniqueObjectIds.emplace(std::make_pair(clientId, clientDoodadId), uniqueObjectIds.size() + 1).first->second;
|
||||
}
|
||||
// Local testing functions
|
||||
|
||||
bool FileExists(char const* file)
|
||||
@@ -260,15 +264,6 @@ bool FileExists(char const* file)
|
||||
return false;
|
||||
}
|
||||
|
||||
void strToLower(char* str)
|
||||
{
|
||||
while(*str)
|
||||
{
|
||||
*str=tolower(*str);
|
||||
++str;
|
||||
}
|
||||
}
|
||||
|
||||
// copied from contrib/extractor/System.cpp
|
||||
void ReadLiquidMaterialTable()
|
||||
{
|
||||
@@ -360,11 +355,13 @@ bool ExtractWmo()
|
||||
bool ExtractSingleWmo(std::string& fname)
|
||||
{
|
||||
// Copy files from archive
|
||||
std::string originalName = fname;
|
||||
|
||||
char szLocalFile[1024];
|
||||
const char * plain_name = GetPlainName(fname.c_str());
|
||||
char* plain_name = GetPlainName(&fname[0]);
|
||||
FixNameCase(plain_name, strlen(plain_name));
|
||||
FixNameSpaces(plain_name, strlen(plain_name));
|
||||
sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name);
|
||||
FixNameCase(szLocalFile,strlen(szLocalFile));
|
||||
|
||||
if (FileExists(szLocalFile))
|
||||
return true;
|
||||
@@ -388,8 +385,8 @@ bool ExtractSingleWmo(std::string& fname)
|
||||
return true;
|
||||
|
||||
bool file_ok = true;
|
||||
std::cout << "Extracting " << fname << std::endl;
|
||||
WMORoot froot(fname);
|
||||
std::cout << "Extracting " << originalName << std::endl;
|
||||
WMORoot froot(originalName);
|
||||
if (!froot.open())
|
||||
{
|
||||
printf("Couldn't open RootWmo!!!\n");
|
||||
@@ -402,6 +399,8 @@ bool ExtractSingleWmo(std::string& fname)
|
||||
return false;
|
||||
}
|
||||
froot.ConvertToVMAPRootWmo(output);
|
||||
WMODoodadData& doodads = WmoDoodads[plain_name];
|
||||
std::swap(doodads, froot.DoodadData);
|
||||
int Wmo_nVertices = 0;
|
||||
//printf("root has %d groups\n", froot->nGroups);
|
||||
if (froot.nGroups !=0)
|
||||
@@ -417,14 +416,25 @@ bool ExtractSingleWmo(std::string& fname)
|
||||
|
||||
std::string s = groupFileName;
|
||||
WMOGroup fgroup(s);
|
||||
if (!fgroup.open())
|
||||
if (!fgroup.open(&froot))
|
||||
{
|
||||
printf("Could not open all Group file for: %s\n", plain_name);
|
||||
file_ok = false;
|
||||
break;
|
||||
}
|
||||
|
||||
Wmo_nVertices += fgroup.ConvertToVMAPGroupWmo(output, &froot, preciseVectorData);
|
||||
Wmo_nVertices += fgroup.ConvertToVMAPGroupWmo(output, preciseVectorData);
|
||||
for (uint16 groupReference : fgroup.DoodadReferences)
|
||||
{
|
||||
if (groupReference >= doodads.Spawns.size())
|
||||
continue;
|
||||
|
||||
uint32 doodadNameIndex = doodads.Spawns[groupReference].NameIndex;
|
||||
if (froot.ValidDoodadNames.find(doodadNameIndex) == froot.ValidDoodadNames.end())
|
||||
continue;
|
||||
|
||||
doodads.References.insert(groupReference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,11 @@
|
||||
#ifndef VMAPEXPORT_H
|
||||
#define VMAPEXPORT_H
|
||||
|
||||
#include "Define.h"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
struct WMODoodadData;
|
||||
|
||||
enum ModelFlags
|
||||
{
|
||||
@@ -30,10 +34,10 @@ enum ModelFlags
|
||||
};
|
||||
|
||||
extern const char * szWorkDirWmo;
|
||||
extern const char * szRawVMAPMagic; // vmap magic string for extracted raw vmap data
|
||||
extern std::unordered_map<std::string, WMODoodadData> WmoDoodads;
|
||||
uint32 GenerateUniqueObjectId(uint32 clientId, uint16 clientDoodadId);
|
||||
|
||||
bool FileExists(const char * file);
|
||||
void strToLower(char* str);
|
||||
|
||||
bool ExtractSingleWmo(std::string& fname);
|
||||
bool ExtractSingleModel(std::string& fname);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "vmapexport.h"
|
||||
#include "wdtfile.h"
|
||||
#include "adtfile.h"
|
||||
|
||||
#include "StringFormat.h"
|
||||
#include <cstdio>
|
||||
|
||||
char * wdtGetPlainName(char * FileName)
|
||||
@@ -104,13 +104,23 @@ bool WDTFile::init(uint32 mapId)
|
||||
// global wmo instance data
|
||||
if (size)
|
||||
{
|
||||
int32 gnWMO = (int)size / 64;
|
||||
|
||||
for (int i = 0; i < gnWMO; ++i)
|
||||
uint32 mapObjectCount = size / sizeof(ADT::MODF);
|
||||
for (uint32 i = 0; i < mapObjectCount; ++i)
|
||||
{
|
||||
int id;
|
||||
_file.read(&id, 4);
|
||||
WMOInstance inst(_file, _wmoNames[id].c_str(), mapId, 65, 65, mapId, dirfile, nullptr);
|
||||
ADT::MODF mapObjDef;
|
||||
_file.read(&mapObjDef, sizeof(ADT::MODF));
|
||||
if (!(mapObjDef.Flags & 0x8))
|
||||
{
|
||||
MapObject::Extract(mapObjDef, _wmoNames[mapObjDef.Id].c_str(), mapId, 65, 65, mapId, dirfile, nullptr);
|
||||
Doodad::ExtractSet(WmoDoodads[_wmoNames[mapObjDef.Id]], mapObjDef, mapId, 65, 65, mapId, dirfile, nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string fileName = Trinity::StringFormat("FILE%08X.xxx", mapObjDef.Id);
|
||||
ExtractSingleWmo(fileName);
|
||||
MapObject::Extract(mapObjDef, fileName.c_str(), mapId, 65, 65, mapId, dirfile, nullptr);
|
||||
Doodad::ExtractSet(WmoDoodads[fileName], mapObjDef, mapId, 65, 65, mapId, dirfile, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+141
-148
@@ -17,20 +17,19 @@
|
||||
*/
|
||||
|
||||
#include "vmapexport.h"
|
||||
#include "wmo.h"
|
||||
#include "adtfile.h"
|
||||
#include "mpqfile.h"
|
||||
#include "vec3d.h"
|
||||
|
||||
#include "VMapDefinitions.h"
|
||||
#include "wmo.h"
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#undef min
|
||||
#undef max
|
||||
#include "mpqfile.h"
|
||||
|
||||
extern uint16 *LiqType;
|
||||
|
||||
WMORoot::WMORoot(std::string &filename)
|
||||
WMORoot::WMORoot(std::string const& filename)
|
||||
: filename(filename), col(0), nTextures(0), nGroups(0), nP(0), nLights(0),
|
||||
nModels(0), nDoodads(0), nDoodadSets(0), RootWMOID(0), liquidType(0)
|
||||
{
|
||||
@@ -78,6 +77,37 @@ bool WMORoot::open()
|
||||
f.read(&liquidType, 4);
|
||||
break;
|
||||
}
|
||||
else if (!strcmp(fourcc, "MODS"))
|
||||
{
|
||||
DoodadData.Sets.resize(size / sizeof(WMO::MODS));
|
||||
f.read(DoodadData.Sets.data(), size);
|
||||
}
|
||||
else if (!strcmp(fourcc, "MODN"))
|
||||
{
|
||||
char* ptr = f.getPointer();
|
||||
char* end = ptr + size;
|
||||
DoodadData.Paths = std::make_unique<char[]>(size);
|
||||
memcpy(DoodadData.Paths.get(), ptr, size);
|
||||
while (ptr < end)
|
||||
{
|
||||
std::string path = ptr;
|
||||
|
||||
char* s = GetPlainName(ptr);
|
||||
FixNameCase(s, strlen(s));
|
||||
FixNameSpaces(s, strlen(s));
|
||||
|
||||
uint32 doodadNameIndex = ptr - f.getPointer();
|
||||
ptr += path.length() + 1;
|
||||
|
||||
if (ExtractSingleModel(path))
|
||||
ValidDoodadNames.insert(doodadNameIndex);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(fourcc, "MODD"))
|
||||
{
|
||||
DoodadData.Spawns.resize(size / sizeof(WMO::MODD));
|
||||
f.read(DoodadData.Spawns.data(), size);
|
||||
}
|
||||
/*
|
||||
else if (!strcmp(fourcc,"MOTX"))
|
||||
{
|
||||
@@ -94,15 +124,6 @@ bool WMORoot::open()
|
||||
else if (!strcmp(fourcc,"MOLT"))
|
||||
{
|
||||
}
|
||||
else if (!strcmp(fourcc,"MODN"))
|
||||
{
|
||||
}
|
||||
else if (!strcmp(fourcc,"MODS"))
|
||||
{
|
||||
}
|
||||
else if (!strcmp(fourcc,"MODD"))
|
||||
{
|
||||
}
|
||||
else if (!strcmp(fourcc,"MOSB"))
|
||||
{
|
||||
}
|
||||
@@ -129,7 +150,7 @@ bool WMORoot::ConvertToVMAPRootWmo(FILE* pOutfile)
|
||||
{
|
||||
//printf("Convert RootWmo...\n");
|
||||
|
||||
fwrite(szRawVMAPMagic, 1, 8, pOutfile);
|
||||
fwrite(VMAP::RAW_VMAP_MAGIC, 1, 8, pOutfile);
|
||||
unsigned int nVectors = 0;
|
||||
fwrite(&nVectors,sizeof(nVectors), 1, pOutfile); // will be filled later
|
||||
fwrite(&nGroups, 4, 1, pOutfile);
|
||||
@@ -141,14 +162,14 @@ WMOGroup::WMOGroup(const std::string &filename) :
|
||||
filename(filename), MOPY(0), MOVI(0), MoviEx(0), MOVT(0), MOBA(0), MobaEx(0),
|
||||
hlq(0), LiquEx(0), LiquBytes(0), groupName(0), descGroupName(0), mogpFlags(0),
|
||||
moprIdx(0), moprNItems(0), nBatchA(0), nBatchB(0), nBatchC(0), fogIdx(0),
|
||||
liquidType(0), groupWMOID(0), mopy_size(0), moba_size(0), LiquEx_size(0),
|
||||
groupLiquid(0), groupWMOID(0), mopy_size(0), moba_size(0), LiquEx_size(0),
|
||||
nVertices(0), nTriangles(0), liquflags(0)
|
||||
{
|
||||
memset(bbcorn1, 0, sizeof(bbcorn1));
|
||||
memset(bbcorn2, 0, sizeof(bbcorn2));
|
||||
}
|
||||
|
||||
bool WMOGroup::open()
|
||||
bool WMOGroup::open(WMORoot* rootWMO)
|
||||
{
|
||||
MPQFile f(WorldMpq, filename.c_str());
|
||||
if (f.isEof ())
|
||||
@@ -170,7 +191,7 @@ bool WMOGroup::open()
|
||||
fourcc[4] = 0;
|
||||
size_t nextpos = f.getPos() + size;
|
||||
|
||||
if (!strcmp(fourcc,"MOGP"))//header
|
||||
if (!strcmp(fourcc,"MOGP")) //header
|
||||
{
|
||||
f.read(&groupName, 4);
|
||||
f.read(&descGroupName, 4);
|
||||
@@ -183,8 +204,19 @@ bool WMOGroup::open()
|
||||
f.read(&nBatchB, 2);
|
||||
f.read(&nBatchC, 4);
|
||||
f.read(&fogIdx, 4);
|
||||
f.read(&liquidType, 4);
|
||||
f.read(&groupWMOID,4);
|
||||
f.read(&groupLiquid, 4);
|
||||
f.read(&groupWMOID, 4);
|
||||
|
||||
// according to WoW.Dev Wiki:
|
||||
if (rootWMO->liquidType & 4)
|
||||
groupLiquid = GetLiquidTypeId(groupLiquid);
|
||||
else if (groupLiquid == 15)
|
||||
groupLiquid = 0;
|
||||
else
|
||||
groupLiquid = GetLiquidTypeId(groupLiquid + 1);
|
||||
|
||||
if (groupLiquid)
|
||||
liquflags |= 2;
|
||||
|
||||
}
|
||||
else if (!strcmp(fourcc,"MOPY"))
|
||||
@@ -217,11 +249,16 @@ bool WMOGroup::open()
|
||||
moba_size = size/2;
|
||||
f.read(MOBA, size);
|
||||
}
|
||||
else if (!strcmp(fourcc, "MODR"))
|
||||
{
|
||||
DoodadReferences.resize(size / sizeof(uint16));
|
||||
f.read(DoodadReferences.data(), size);
|
||||
}
|
||||
else if (!strcmp(fourcc,"MLIQ"))
|
||||
{
|
||||
liquflags |= 1;
|
||||
hlq = new WMOLiquidHeader();
|
||||
f.read(hlq, 0x1E);
|
||||
f.read(hlq, sizeof(WMOLiquidHeader));
|
||||
LiquEx_size = sizeof(WMOLiquidVert) * hlq->xverts * hlq->yverts;
|
||||
LiquEx = new WMOLiquidVert[hlq->xverts * hlq->yverts];
|
||||
f.read(LiquEx, LiquEx_size);
|
||||
@@ -229,6 +266,19 @@ bool WMOGroup::open()
|
||||
LiquBytes = new char[nLiquBytes];
|
||||
f.read(LiquBytes, nLiquBytes);
|
||||
|
||||
// Determine legacy liquid type
|
||||
if (!groupLiquid)
|
||||
{
|
||||
for (int i = 0; i < hlq->xtiles * hlq->ytiles; ++i)
|
||||
{
|
||||
if ((LiquBytes[i] & 0xF) != 15)
|
||||
{
|
||||
groupLiquid = GetLiquidTypeId((LiquBytes[i] & 0xF) + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* std::ofstream llog("Buildings/liquid.log", ios_base::out | ios_base::app);
|
||||
llog << filename;
|
||||
llog << "\nbbox: " << bbcorn1[0] << ", " << bbcorn1[1] << ", " << bbcorn1[2] << " | " << bbcorn2[0] << ", " << bbcorn2[1] << ", " << bbcorn2[2];
|
||||
@@ -242,7 +292,7 @@ bool WMOGroup::open()
|
||||
return true;
|
||||
}
|
||||
|
||||
int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, WMORoot *rootWMO, bool preciseVectorData)
|
||||
int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, bool preciseVectorData)
|
||||
{
|
||||
fwrite(&mogpFlags,sizeof(uint32),1,output);
|
||||
fwrite(&groupWMOID,sizeof(uint32),1,output);
|
||||
@@ -401,78 +451,54 @@ int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, WMORoot *rootWMO, bool precise
|
||||
}
|
||||
|
||||
//------LIQU------------------------
|
||||
if (LiquEx_size != 0)
|
||||
if (liquflags & 3)
|
||||
{
|
||||
int LIQU_h[] = {0x5551494C, static_cast<int>(sizeof(WMOLiquidHeader) + LiquEx_size) + hlq->xtiles*hlq->ytiles};// "LIQU"
|
||||
int LIQU_totalSize = sizeof(uint32);
|
||||
if (liquflags & 1)
|
||||
{
|
||||
LIQU_totalSize += sizeof(WMOLiquidHeader);
|
||||
LIQU_totalSize += LiquEx_size / sizeof(WMOLiquidVert) * sizeof(float);
|
||||
LIQU_totalSize += hlq->xtiles * hlq->ytiles;
|
||||
}
|
||||
int LIQU_h[] = { 0x5551494C, LIQU_totalSize };// "LIQU"
|
||||
fwrite(LIQU_h, 4, 2, output);
|
||||
|
||||
// according to WoW.Dev Wiki:
|
||||
uint32 liquidEntry;
|
||||
if (rootWMO->liquidType & 4)
|
||||
liquidEntry = liquidType;
|
||||
else if (liquidType == 15)
|
||||
liquidEntry = 0;
|
||||
else
|
||||
liquidEntry = liquidType + 1;
|
||||
|
||||
if (!liquidEntry)
|
||||
{
|
||||
int v1; // edx@1
|
||||
int v2; // eax@1
|
||||
|
||||
v1 = hlq->xtiles * hlq->ytiles;
|
||||
v2 = 0;
|
||||
if (v1 > 0)
|
||||
{
|
||||
while ((LiquBytes[v2] & 0xF) == 15)
|
||||
{
|
||||
++v2;
|
||||
if (v2 >= v1)
|
||||
break;
|
||||
}
|
||||
|
||||
if (v2 < v1 && (LiquBytes[v2] & 0xF) != 15)
|
||||
liquidEntry = (LiquBytes[v2] & 0xF) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (liquidEntry && liquidEntry < 21)
|
||||
{
|
||||
switch ((liquidEntry - 1) & 3)
|
||||
{
|
||||
case 0:
|
||||
liquidEntry = ((mogpFlags & 0x80000) != 0) + 13;
|
||||
break;
|
||||
case 1:
|
||||
liquidEntry = 14;
|
||||
break;
|
||||
case 2:
|
||||
liquidEntry = 19;
|
||||
break;
|
||||
case 3:
|
||||
liquidEntry = 20;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
hlq->type = liquidEntry;
|
||||
|
||||
/* std::ofstream llog("Buildings/liquid.log", ios_base::out | ios_base::app);
|
||||
llog << filename;
|
||||
llog << ":\nliquidEntry: " << liquidEntry << " type: " << hlq->type << " (root:" << rootWMO->liquidType << " group:" << liquidType << ")\n";
|
||||
llog << ":\nliquidEntry: " << liquidEntry << " type: " << hlq->type << " (root:" << rootWMO->flags << " group:" << flags << ")\n";
|
||||
llog.close(); */
|
||||
|
||||
fwrite(hlq, sizeof(WMOLiquidHeader), 1, output);
|
||||
// only need height values, the other values are unknown anyway
|
||||
for (uint32 i = 0; i<LiquEx_size/sizeof(WMOLiquidVert); ++i)
|
||||
fwrite(&LiquEx[i].height, sizeof(float), 1, output);
|
||||
// todo: compress to bit field
|
||||
fwrite(LiquBytes, 1, hlq->xtiles*hlq->ytiles, output);
|
||||
fwrite(&groupLiquid, sizeof(uint32), 1, output);
|
||||
if (liquflags & 1)
|
||||
{
|
||||
fwrite(hlq, sizeof(WMOLiquidHeader), 1, output);
|
||||
// only need height values, the other values are unknown anyway
|
||||
for (uint32 i = 0; i < LiquEx_size / sizeof(WMOLiquidVert); ++i)
|
||||
fwrite(&LiquEx[i].height, sizeof(float), 1, output);
|
||||
// todo: compress to bit field
|
||||
fwrite(LiquBytes, 1, hlq->xtiles * hlq->ytiles, output);
|
||||
}
|
||||
}
|
||||
|
||||
return nColTriangles;
|
||||
}
|
||||
|
||||
uint32 WMOGroup::GetLiquidTypeId(uint32 liquidTypeId)
|
||||
{
|
||||
if (liquidTypeId < 21 && liquidTypeId)
|
||||
{
|
||||
switch (((static_cast<uint8>(liquidTypeId) - 1) & 3))
|
||||
{
|
||||
case 0: return ((mogpFlags & 0x80000) != 0) + 13;
|
||||
case 1: return 14;
|
||||
case 2: return 19;
|
||||
case 3: return 20;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return liquidTypeId;
|
||||
}
|
||||
|
||||
WMOGroup::~WMOGroup()
|
||||
{
|
||||
delete [] MOPY;
|
||||
@@ -484,33 +510,11 @@ WMOGroup::~WMOGroup()
|
||||
delete [] LiquBytes;
|
||||
}
|
||||
|
||||
WMOInstance::WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId, FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache)
|
||||
: currx(0), curry(0), wmo(nullptr), doodadset(0), pos(), indx(0), id(0)
|
||||
void MapObject::Extract(ADT::MODF const& mapObjDef, char const* WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId, FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache)
|
||||
{
|
||||
float ff[3];
|
||||
f.read(&id, 4);
|
||||
f.read(ff,12);
|
||||
pos = Vec3D(ff[0],ff[1],ff[2]);
|
||||
f.read(ff,12);
|
||||
rot = Vec3D(ff[0],ff[1],ff[2]);
|
||||
f.read(ff,12);
|
||||
pos2 = Vec3D(ff[0],ff[1],ff[2]); // bounding box corners
|
||||
f.read(ff,12);
|
||||
pos3 = Vec3D(ff[0],ff[1],ff[2]); // bounding box corners
|
||||
|
||||
uint16 fflags;
|
||||
f.read(&fflags, 2);
|
||||
|
||||
uint16 doodadSet;
|
||||
f.read(&doodadSet, 2);
|
||||
|
||||
uint16 trash,adtId;
|
||||
f.read(&adtId,2);
|
||||
f.read(&trash,2);
|
||||
|
||||
// destructible wmo, do not dump. we can handle the vmap for these
|
||||
// in dynamic tree (gameobject vmaps)
|
||||
if ((fflags & 0x01) != 0)
|
||||
if ((mapObjDef.Flags & 0x1) != 0)
|
||||
return;
|
||||
|
||||
//-----------add_in _dir_file----------------
|
||||
@@ -534,37 +538,40 @@ WMOInstance::WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint
|
||||
if (count != 1 || nVertices == 0)
|
||||
return;
|
||||
|
||||
float x,z;
|
||||
x = pos.x;
|
||||
z = pos.z;
|
||||
if (x==0 && z == 0)
|
||||
Vec3D position = mapObjDef.Position;
|
||||
|
||||
float x, z;
|
||||
x = position.x;
|
||||
z = position.z;
|
||||
if (x == 0 && z == 0)
|
||||
{
|
||||
pos.x = 533.33333f*32;
|
||||
pos.z = 533.33333f*32;
|
||||
position.x = 533.33333f * 32;
|
||||
position.z = 533.33333f * 32;
|
||||
}
|
||||
pos = fixCoords(pos);
|
||||
pos2 = fixCoords(pos2);
|
||||
pos3 = fixCoords(pos3);
|
||||
position = fixCoords(position);
|
||||
AaBox3D bounds;
|
||||
bounds.min = fixCoords(mapObjDef.Bounds.min);
|
||||
bounds.max = fixCoords(mapObjDef.Bounds.max);
|
||||
|
||||
float scale = 1.0f;
|
||||
uint32 uniqueId = GenerateUniqueObjectId(mapObjDef.UniqueId, 0);
|
||||
uint32 flags = MOD_HAS_BOUND;
|
||||
if (tileX == 65 && tileY == 65)
|
||||
flags |= MOD_WORLDSPAWN;
|
||||
if (mapID != originalMapId)
|
||||
flags |= MOD_PARENT_SPAWN;
|
||||
|
||||
//write mapID, tileX, tileY, Flags, ID, Pos, Rot, Scale, Bound_lo, Bound_hi, name
|
||||
//write mapID, tileX, tileY, Flags, NameSet, UniqueId, Pos, Rot, Scale, Bound_lo, Bound_hi, name
|
||||
fwrite(&mapID, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&tileX, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&tileY, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&flags, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&adtId, sizeof(uint16), 1, pDirfile);
|
||||
fwrite(&id, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&pos, sizeof(float), 3, pDirfile);
|
||||
fwrite(&rot, sizeof(float), 3, pDirfile);
|
||||
fwrite(&mapObjDef.NameSet, sizeof(uint16), 1, pDirfile);
|
||||
fwrite(&uniqueId, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(&position, sizeof(Vec3D), 1, pDirfile);
|
||||
fwrite(&mapObjDef.Rotation, sizeof(Vec3D), 1, pDirfile);
|
||||
fwrite(&scale, sizeof(float), 1, pDirfile);
|
||||
fwrite(&pos2, sizeof(float), 3, pDirfile);
|
||||
fwrite(&pos3, sizeof(float), 3, pDirfile);
|
||||
fwrite(&bounds, sizeof(AaBox3D), 1, pDirfile);
|
||||
uint32 nlen = strlen(WmoInstName);
|
||||
fwrite(&nlen, sizeof(uint32), 1, pDirfile);
|
||||
fwrite(WmoInstName, sizeof(char), nlen, pDirfile);
|
||||
@@ -575,41 +582,27 @@ WMOInstance::WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint
|
||||
ADTOutputCache& cacheModelData = dirfileCache->back();
|
||||
cacheModelData.Flags = flags & ~MOD_PARENT_SPAWN;
|
||||
cacheModelData.Data.resize(
|
||||
sizeof(uint16) + // adtId
|
||||
sizeof(uint32) + // id
|
||||
sizeof(float) * 3 + // pos
|
||||
sizeof(float) * 3 + // rot
|
||||
sizeof(uint16) + // mapObjDef.NameSet
|
||||
sizeof(uint32) + // uniqueId
|
||||
sizeof(Vec3D) + // position
|
||||
sizeof(Vec3D) + // mapObjDef.Rotation
|
||||
sizeof(float) + // scale
|
||||
sizeof(float) * 3 + // pos2
|
||||
sizeof(float) * 3 + // pos3
|
||||
sizeof(AaBox3D) + // bounds
|
||||
sizeof(uint32) + // nlen
|
||||
nlen); // WmoInstName
|
||||
|
||||
uint8* cacheData = cacheModelData.Data.data();
|
||||
#define CACHE_WRITE(value, size, count, dest) memcpy(dest, value, size * count); dest += size * count;
|
||||
|
||||
CACHE_WRITE(&adtId, sizeof(uint16), 1, cacheData);
|
||||
CACHE_WRITE(&id, sizeof(uint32), 1, cacheData);
|
||||
CACHE_WRITE(&pos, sizeof(float), 3, cacheData);
|
||||
CACHE_WRITE(&rot, sizeof(float), 3, cacheData);
|
||||
CACHE_WRITE(&mapObjDef.NameSet, sizeof(uint16), 1, cacheData);
|
||||
CACHE_WRITE(&uniqueId, sizeof(uint32), 1, cacheData);
|
||||
CACHE_WRITE(&position, sizeof(Vec3D), 1, cacheData);
|
||||
CACHE_WRITE(&mapObjDef.Rotation, sizeof(Vec3D), 1, cacheData);
|
||||
CACHE_WRITE(&scale, sizeof(float), 1, cacheData);
|
||||
CACHE_WRITE(&pos2, sizeof(float), 3, cacheData);
|
||||
CACHE_WRITE(&pos3, sizeof(float), 3, cacheData);
|
||||
CACHE_WRITE(&bounds, sizeof(AaBox3D), 1, cacheData);
|
||||
CACHE_WRITE(&nlen, sizeof(uint32), 1, cacheData);
|
||||
CACHE_WRITE(WmoInstName, sizeof(char), nlen, cacheData);
|
||||
|
||||
#undef CACHE_WRITE
|
||||
}
|
||||
|
||||
/* fprintf(pDirfile,"%s/%s %f,%f,%f_%f,%f,%f 1.0 %d %d %d,%d %d\n",
|
||||
MapName,
|
||||
WmoInstName,
|
||||
(float) x, (float) pos.y, (float) z,
|
||||
(float) rot.x, (float) rot.y, (float) rot.z,
|
||||
nVertices,
|
||||
realx1, realy1,
|
||||
realx2, realy2
|
||||
); */
|
||||
|
||||
// fclose(dirfile);
|
||||
}
|
||||
@@ -18,11 +18,10 @@
|
||||
|
||||
#ifndef WMO_H
|
||||
#define WMO_H
|
||||
#define TILESIZE (533.33333f)
|
||||
#define CHUNKSIZE ((TILESIZE) / 16.0f)
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
#include <memory>
|
||||
#include "vec3d.h"
|
||||
#include "mpqfile.h"
|
||||
|
||||
@@ -43,10 +42,40 @@ class WMOInstance;
|
||||
class WMOManager;
|
||||
class MPQFile;
|
||||
struct ADTOutputCache;
|
||||
namespace ADT { struct MODF; }
|
||||
|
||||
namespace WMO
|
||||
{
|
||||
struct MODS
|
||||
{
|
||||
char Name[20];
|
||||
uint32 StartIndex; // index of first doodad instance in this set
|
||||
uint32 Count; // number of doodad instances in this set
|
||||
char _pad[4];
|
||||
};
|
||||
|
||||
struct MODD
|
||||
{
|
||||
uint32 NameIndex : 24;
|
||||
Vec3D Position;
|
||||
Quaternion Rotation;
|
||||
float Scale;
|
||||
uint32 Color;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/* for whatever reason a certain company just can't stick to one coordinate system... */
|
||||
static inline Vec3D fixCoords(const Vec3D &v){ return Vec3D(v.z, v.x, v.y); }
|
||||
|
||||
struct WMODoodadData
|
||||
{
|
||||
std::vector<WMO::MODS> Sets;
|
||||
std::unique_ptr<char[]> Paths;
|
||||
std::vector<WMO::MODD> Spawns;
|
||||
std::unordered_set<uint16> References;
|
||||
};
|
||||
|
||||
class WMORoot
|
||||
{
|
||||
private:
|
||||
@@ -57,23 +86,25 @@ public:
|
||||
float bbcorn1[3];
|
||||
float bbcorn2[3];
|
||||
|
||||
WMORoot(std::string& filename);
|
||||
WMODoodadData DoodadData;
|
||||
std::unordered_set<uint32> ValidDoodadNames;
|
||||
|
||||
WMORoot(std::string const& filename);
|
||||
|
||||
bool open();
|
||||
bool ConvertToVMAPRootWmo(FILE* output);
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct WMOLiquidHeader
|
||||
{
|
||||
int xverts, yverts, xtiles, ytiles;
|
||||
float pos_x;
|
||||
float pos_y;
|
||||
float pos_z;
|
||||
short type;
|
||||
short material;
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
struct WMOLiquidVert
|
||||
{
|
||||
uint16 unk1;
|
||||
@@ -107,7 +138,7 @@ public:
|
||||
uint16 moprNItems;
|
||||
uint16 nBatchA;
|
||||
uint16 nBatchB;
|
||||
uint32 nBatchC, fogIdx, liquidType, groupWMOID;
|
||||
uint32 nBatchC, fogIdx, groupLiquid, groupWMOID;
|
||||
|
||||
int mopy_size, moba_size;
|
||||
int LiquEx_size;
|
||||
@@ -115,29 +146,19 @@ public:
|
||||
int nTriangles; // number when loaded
|
||||
uint32 liquflags;
|
||||
|
||||
std::vector<uint16> DoodadReferences;
|
||||
|
||||
WMOGroup(std::string const& filename);
|
||||
~WMOGroup();
|
||||
|
||||
bool open();
|
||||
int ConvertToVMAPGroupWmo(FILE* output, WMORoot* rootWMO, bool preciseVectorData);
|
||||
bool open(WMORoot* rootWMO);
|
||||
int ConvertToVMAPGroupWmo(FILE* output, bool preciseVectorData);
|
||||
uint32 GetLiquidTypeId(uint32 liquidTypeId);
|
||||
};
|
||||
|
||||
class WMOInstance
|
||||
namespace MapObject
|
||||
{
|
||||
static std::set<int> ids;
|
||||
public:
|
||||
std::string MapName;
|
||||
int currx;
|
||||
int curry;
|
||||
WMOGroup* wmo;
|
||||
int doodadset;
|
||||
Vec3D pos;
|
||||
Vec3D pos2, pos3, rot;
|
||||
uint32 indx, id;
|
||||
|
||||
WMOInstance(MPQFile&f , char const* WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId, FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache);
|
||||
|
||||
static void reset();
|
||||
};
|
||||
void Extract(ADT::MODF const& mapObjDef, char const* WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, uint32 originalMapId, FILE* pDirfile, std::vector<ADTOutputCache>* dirfileCache);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user