33 : filename(filename), color(0), nTextures(0), nGroups(0), nPortals(0), nLights(0),
34 nDoodadNames(0), nDoodadDefs(0), nDoodadSets(0), RootWMOID(0),
flags(0), numLod(0)
47 printf(
"No such file.\n");
64 if (!strcmp(fourcc,
"MOHD"))
80 else if (!strcmp(fourcc,
"MODS"))
85 else if (!strcmp(fourcc,
"MODN"))
90 char* end = ptr +
size;
95 std::string path = ptr;
101 ptr += path.length() + 1;
107 else if (!strcmp(fourcc,
"MODI"))
114 for (
uint32 i = 0; i < fileDataIdCount; ++i)
124 else if (!strcmp(fourcc,
"MODD"))
129 else if (!strcmp(fourcc,
"MOGN"))
134 else if (!strcmp(fourcc,
"GFID"))
153 f.
read(&fileDataId, 4);
188 f.
seek((
int)nextpos);
199 unsigned int nVectors = 0;
200 fwrite(&nVectors,
sizeof(nVectors), 1, pOutfile);
201 fwrite(&
nGroups, 4, 1, pOutfile);
204 fwrite(&tcFlags,
sizeof(
ModelFlags), 1, pOutfile);
209 filename(filename), MPY2(nullptr), MOVX(nullptr), MOVT(nullptr), MOBA(nullptr), MobaEx(nullptr),
210 hlq(nullptr), LiquEx(nullptr), LiquBytes(nullptr), groupName(0), descGroupName(0), mogpFlags(0),
211 moprIdx(0), moprNItems(0), nBatchA(0), nBatchB(0), nBatchC(0), fogIdx(0),
212 groupLiquid(0), groupWMOID(0), moba_size(0), LiquEx_size(0),
213 nVertices(0), nTriangles(0), liquflags(0)
224 printf(
"No such file.\n");
228 char fourcc[5] = { };
234 if (!strcmp(fourcc,
"MOGP"))
238 if (!strcmp(fourcc,
"MOGP"))
255 if (rootWMO->
flags & 4)
265 else if (!strcmp(fourcc,
"MOPY"))
267 MPY2 = std::make_unique<uint16[]>(
size);
268 std::unique_ptr<uint8[]> MOPY = std::make_unique<uint8[]>(
size);
271 std::copy_n(MOPY.get(),
size,
MPY2.get());
273 else if (!strcmp(fourcc,
"MPY2"))
275 MPY2 = std::make_unique<uint16[]>(
size / 2);
279 else if (!strcmp(fourcc,
"MOVI"))
281 MOVX = std::make_unique<uint32[]>(
size / 2);
282 std::unique_ptr<uint16[]> MOVI = std::make_unique<uint16[]>(
size / 2);
284 std::copy_n(MOVI.get(),
size / 2,
MOVX.get());
286 else if (!strcmp(fourcc,
"MOVX"))
288 MOVX = std::make_unique<uint32[]>(
size / 4);
291 else if (!strcmp(fourcc,
"MOVT"))
297 else if (!strcmp(fourcc,
"MONR"))
300 else if (!strcmp(fourcc,
"MOTV"))
303 else if (!strcmp(fourcc,
"MOBA"))
309 else if (!strcmp(fourcc,
"MODR"))
314 else if (!strcmp(fourcc,
"MLIQ"))
346 f.
seek((
int)nextpos);
357 fwrite(
bbcorn1,
sizeof(
float), 3, output);
358 fwrite(
bbcorn2,
sizeof(
float), 3, output);
360 int nColTriangles = 0;
364 fwrite(GRP,1,4,output);
368 MobaEx =
new int[moba_batch*4];
373 int moba_size_grp = moba_batch*4+4;
374 fwrite(&moba_size_grp,4,1,output);
375 fwrite(&moba_batch,4,1,output);
376 fwrite(
MobaEx,4,k,output);
381 if(fwrite(
"INDX",4, 1, output) != 1)
383 printf(
"Error while writing file nbraches ID");
386 int wsize =
sizeof(
uint32) +
sizeof(
unsigned short) * nIdexes;
387 if(fwrite(&wsize,
sizeof(
int), 1, output) != 1)
389 printf(
"Error while writing file wsize");
392 if(fwrite(&nIdexes,
sizeof(
uint32), 1, output) != 1)
394 printf(
"Error while writing file nIndexes");
399 if (fwrite(
MOVX.get(),
sizeof(
uint32), nIdexes, output) != nIdexes)
401 printf(
"Error while writing file indexarray");
406 if(fwrite(
"VERT",4, 1, output) != 1)
408 printf(
"Error while writing file nbraches ID");
411 wsize =
sizeof(int) +
sizeof(
float) * 3 *
nVertices;
412 if(fwrite(&wsize,
sizeof(
int), 1, output) != 1)
414 printf(
"Error while writing file wsize");
417 if(fwrite(&
nVertices,
sizeof(
int), 1, output) != 1)
419 printf(
"Error while writing file nVertices");
426 printf(
"Error while writing file vectors");
436 fwrite(GRP,1,4,output);
439 MobaEx =
new int[moba_batch*4];
445 int moba_size_grp = moba_batch*4+4;
446 fwrite(&moba_size_grp,4,1,output);
447 fwrite(&moba_batch,4,1,output);
448 fwrite(
MobaEx,4,k,output);
453 std::unique_ptr<uint32[]> MovxEx = std::make_unique<uint32[]>(
nTriangles*3);
454 std::unique_ptr<int32[]> IndexRenum = std::make_unique<int32[]>(
nVertices);
455 std::fill_n(IndexRenum.get(),
nVertices, -1);
466 for (
int j=0; j<3; ++j)
468 IndexRenum[
MOVX[3*i + j]] = 1;
469 MovxEx[3*nColTriangles + j] =
MOVX[3*i + j];
478 if (IndexRenum[i] == 1)
480 IndexRenum[i] = nColVertices;
486 for (
int i=0; i<3*nColTriangles; ++i)
489 MovxEx[i] = IndexRenum[MovxEx[i]];
493 int INDX[] = {0x58444E49, nColTriangles*6+4, nColTriangles*3};
494 fwrite(INDX,4,3,output);
495 fwrite(MovxEx.get(),4,nColTriangles*3,output);
498 uint32 VERT[] = {0x54524556u, nColVertices*3*
static_cast<uint32>(
sizeof(float))+4, nColVertices};
499 int check = 3*nColVertices;
500 fwrite(VERT,4,3,output);
502 if(IndexRenum[i] >= 0)
503 check -= fwrite(
MOVT+3*i,
sizeof(
float), 3, output);
511 int LIQU_totalSize =
sizeof(
uint32);
518 int LIQU_h[] = { 0x5551494C, LIQU_totalSize };
519 fwrite(LIQU_h, 4, 2, output);
532 fwrite(&
LiquEx[i].height,
sizeof(
float), 1, output);
538 return nColTriangles;
543 if (liquidTypeId < 21 && liquidTypeId)
545 switch (((
static_cast<uint8>(liquidTypeId) - 1) & 3))
547 case 0:
return ((
mogpFlags & 0x80000) != 0) + 13;
586 if ((mapObjDef.
Flags & 0x1) != 0)
592 FILE* input = fopen(tempname.c_str(),
"r+b");
596 printf(
"WMOInstance::WMOInstance: couldn't open %s\n", tempname.c_str());
600 fseek(input, 8, SEEK_SET);
602 int count = fread(&nVertices,
sizeof(
int), 1, input);
605 if (count != 1 || nVertices == 0)
615 position +=
Vec3D(533.33333f * 32, 533.33333f * 32, 0.0f);
616 bounds +=
Vec3D(533.33333f * 32, 533.33333f * 32, 0.0f);
620 if (mapObjDef.
Flags & 0x4)
621 scale = mapObjDef.
Scale / 1024.0f;
625 if (mapID != originalMapId)
629 fwrite(&mapID,
sizeof(
uint32), 1, pDirfile);
631 fwrite(&nameSet,
sizeof(
uint8), 1, pDirfile);
632 fwrite(&uniqueId,
sizeof(
uint32), 1, pDirfile);
633 fwrite(&position,
sizeof(
Vec3D), 1, pDirfile);
635 fwrite(&scale,
sizeof(
float), 1, pDirfile);
636 fwrite(&bounds,
sizeof(
AaBox3D), 1, pDirfile);
637 uint32 nlen = strlen(WmoInstName);
638 fwrite(&nlen,
sizeof(
uint32), 1, pDirfile);
639 fwrite(WmoInstName,
sizeof(
char), nlen, pDirfile);
643 dirfileCache->emplace_back();
645 cacheModelData.
Flags =
flags & ~MOD_PARENT_SPAWN;
646 cacheModelData.
Data.resize(
656 uint8* cacheData = cacheModelData.
Data.data();
657#define CACHE_WRITE(value, size, count, dest) memcpy(dest, value, size * count); dest += size * count;
666 CACHE_WRITE(WmoInstName,
sizeof(
char), nlen, cacheData);
char const * GetPlainName(char const *FileName)
void NormalizeFileName(char *name, size_t len)
size_t read(void *dest, size_t bytes)
WMOGroup(std::string const &filename)
std::unique_ptr< uint16[]> MPY2
std::vector< uint16 > DoodadReferences
bool open(WMORoot *rootWMO)
uint32 GetLiquidTypeId(uint32 liquidTypeId)
int ConvertToVMAPGroupWmo(FILE *output, bool preciseVectorData)
bool ShouldSkip(WMORoot const *root) const
std::unique_ptr< uint32[]> MOVX
std::vector< char > GroupNames
std::vector< uint32 > groupFileDataIDs
std::unordered_set< uint32 > ValidDoodadNames
bool ConvertToVMAPRootWmo(FILE *output)
WMORoot(std::string const &filename)
void Extract(ADT::MODF const &mapObjDef, char const *WmoInstName, bool isGlobalWmo, uint32 mapID, uint32 originalMapId, FILE *pDirfile, std::vector< ADTOutputCache > *dirfileCache)
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default TC string format function.
constexpr std::size_t size()
const char RAW_VMAP_MAGIC[]
std::vector< uint8 > Data
std::vector< WMO::MODS > Sets
std::vector< WMO::MODD > Spawns
std::unique_ptr< uint32[]> FileDataIds
std::unique_ptr< char[]> Paths
uint32 GenerateUniqueObjectId(uint32 clientId, uint16 clientDoodadId, bool isWmo)
char const * szWorkDirWmo
#define CACHE_WRITE(value, size, count, dest)
std::shared_ptr< CASC::Storage > CascStorage
static Vec3D fixCoords(Vec3D const &v)