1 #define __STORMLIB_SELF__
9 WMORoot::WMORoot(std::string
&filename
) : filename(filename
)
15 MPQFile
f(filename
.c_str());
18 printf("No such file.\n");
35 size_t nextpos
= f
.getPos() + size
;
37 if (!strcmp(fourcc
,"MOHD"))//header
39 f
.read(&nTextures
, 4);
45 f
.read(&nDoodadSets
, 4);
53 else if (!strcmp(fourcc,"MOTX"))
56 else if (!strcmp(fourcc,"MOMT"))
59 else if (!strcmp(fourcc,"MOGN"))
62 else if (!strcmp(fourcc,"MOGI"))
65 else if (!strcmp(fourcc,"MOLT"))
68 else if (!strcmp(fourcc,"MODN"))
71 else if (!strcmp(fourcc,"MODS"))
74 else if (!strcmp(fourcc,"MODD"))
77 else if (!strcmp(fourcc,"MOSB"))
80 else if (!strcmp(fourcc,"MOPV"))
83 else if (!strcmp(fourcc,"MOPT"))
86 else if (!strcmp(fourcc,"MOPR"))
89 else if (!strcmp(fourcc,"MFOG"))
99 bool WMORoot::ConvertToVMAPRootWmo(FILE *pOutfile
)
101 //printf("Convert RootWmo...\n");
103 fwrite("VMAP002",1,8,pOutfile
);
104 unsigned int nVectors
= 0;
105 fwrite(&nVectors
,sizeof(nVectors
),1,pOutfile
); // will be filled later
106 fwrite(&nGroups
,4,1,pOutfile
);
114 WMOGroup::WMOGroup(std::string
&filename
) : filename(filename
)
118 bool WMOGroup::open()
120 MPQFile
f(filename
.c_str());
123 printf("No such file.\n");
135 if (!strcmp(fourcc
,"MOGP"))//Fix sizeoff = Data size.
140 size_t nextpos
= f
.getPos() + size
;
144 if (!strcmp(fourcc
,"MOGP"))//header
160 else if (!strcmp(fourcc
,"MOPY"))
162 MOPY
= new char[size
];
164 nTriangles
= (int)size
/ 2;
167 else if (!strcmp(fourcc
,"MOVI"))
169 MOVI
= new uint16
[size
/2];
172 else if (!strcmp(fourcc
,"MOVT"))
174 MOVT
= new float[size
/4];
176 nVertices
= (int)size
/ 12;
178 else if (!strcmp(fourcc
,"MONR"))
181 else if (!strcmp(fourcc
,"MOTV"))
184 else if (!strcmp(fourcc
,"MOBA"))
186 MOBA
= new uint16
[size
/2];
190 else if (!strcmp(fourcc
,"MLIQ"))
196 hlq_xverts
= hlq
.xverts
;
197 hlq_yverts
= hlq
.yverts
;
198 int noVer
= hlq
.xverts
* hlq
.yverts
;
199 float tilesize
= CHUNKSIZE
/ 8.0f
;
200 LiquEx_size
= sizeof(float) * 3 * noVer
;
201 LiquEx
= new float[sizeof(float) * 3 * noVer
];
204 for (int j
=0; j
<hlq
.yverts
; ++j
)
206 for (int i
=0; i
<hlq
.xverts
; ++i
)
208 LiquEx
[p
++] = hlq
.pos_x
+ tilesize
* i
;
209 LiquEx
[p
++] = hlq
.pos_z
;
210 LiquEx
[p
++] = ydir
* (hlq
.pos_y
+ tilesize
* j
);
214 f
.seek((int)nextpos
);
220 int WMOGroup::ConvertToVMAPGroupWmo(FILE *output
, bool pPreciseVectorData
)
222 if(pPreciseVectorData
)
224 fwrite(&liquflags
,sizeof(uint32
),1,output
);
226 fwrite(GRP
,1,4,output
);
229 int moba_batch
= moba_size
/12;
230 MobaEx
= new int[moba_batch
*4];
231 for(int i
=8; i
<moba_size
; i
+=12)
233 MobaEx
[k
++] = MOBA
[i
];
236 int moba_size_grp
= moba_batch
*4+4;
237 fwrite(&moba_size_grp
,4,1,output
);
238 fwrite(&moba_batch
,4,1,output
);
239 fwrite(MobaEx
,4,k
,output
);
242 uint32 nIdexes
= nTriangles
* 3;
244 if(fwrite("INDX",4, 1, output
) != 1)
246 printf("Error while writing file nbraches ID");
249 int wsize
= sizeof(uint32
) + sizeof(unsigned short) * nIdexes
;
250 if(fwrite(&wsize
, sizeof(int), 1, output
) != 1)
252 printf("Error while writing file wsize");
255 if(fwrite(&nIdexes
, sizeof(uint32
), 1, output
) != 1)
257 printf("Error while writing file nIndexes");
262 if(fwrite(MOVI
, sizeof(unsigned short), nIdexes
, output
) != nIdexes
)
264 printf("Error while writing file indexarray");
269 if(fwrite("VERT",4, 1, output
) != 1)
271 printf("Error while writing file nbraches ID");
274 wsize
= sizeof(int) + sizeof(float) * 3 * nVertices
;
275 if(fwrite(&wsize
, sizeof(int), 1, output
) != 1)
277 printf("Error while writing file wsize");
280 if(fwrite(&nVertices
, sizeof(int), 1, output
) != 1)
282 printf("Error while writing file nVertices");
287 if(fwrite(MOVT
, sizeof(float)*3, nVertices
, output
) != nVertices
)
289 printf("Error while writing file vectors");
296 int LIQU_h
[] = {0x5551494C,LiquEx_size
+8,hlq_xverts
,hlq_yverts
};// "LIQU"
297 fwrite(LIQU_h
,4,4,output
);
298 fwrite(LiquEx
,4,LiquEx_size
/4,output
);
306 //printf("Convert GroupWmo...\n");
307 //-------GRP -------------------------------------
308 fwrite(&liquflags
,sizeof(uint32
),1,output
);
310 fwrite(GRP
,1,4,output
);
312 int moba_batch
= moba_size
/12;
313 MobaEx
= new int[moba_batch
*4];
314 for(int i
=8; i
<moba_size
; i
+=12)
316 MobaEx
[k
++] = MOBA
[i
];
319 int moba_size_grp
= moba_batch
*4+4;
320 fwrite(&moba_size_grp
,4,1,output
);
321 fwrite(&moba_batch
,4,1,output
);
322 fwrite(MobaEx
,4,k
,output
);
325 //-------INDX------------------------------------
326 //-------MOPY--------
329 MopyEx
= new char[mopy_size
];
330 IndexExTr
= new int[mopy_size
];
331 for (int i
=0; i
<mopy_size
; i
+=2)
333 // Skip no collision triangles
334 if ((int)MOPY
[i
]&WMO_MATERIAL_NO_COLLISION
)
336 // Use only this triangles
337 if ((int)MOPY
[i
]&(WMO_MATERIAL_HINT
|WMO_MATERIAL_COLLIDE_HIT
))
340 MopyEx
[(n
+1)] = MOPY
[(i
+1)];
351 //---------MOVI-----------
352 MoviEx
= new uint16
[IndexExTr_size
*3];
354 for (int i
=0; i
<IndexExTr_size
; ++i
)
358 for (int x
=0; x
<3; ++x
)
367 MoviExSort
= new uint16
[IndexExTr_size
*3];
368 for(int y
=0; y
<IndexExTr_size
*3; ++y
)
370 MoviExSort
[y
]=MoviEx
[y
];
374 for (int pass
= 1; pass
< IndexExTr_size
*3; ++pass
)
376 for (int i
=0; i
< IndexExTr_size
*3-1; ++i
)
378 if (MoviExSort
[i
] > MoviExSort
[i
+1])
380 hold
= MoviExSort
[i
];
381 MoviExSort
[i
] = MoviExSort
[i
+1];
382 MoviExSort
[i
+1] = hold
;
386 if (MoviExSort
[i
] == MoviExSort
[i
+1])
387 MoviExSort
[i
+1] = 65535;
392 for (int i
=0; i
< IndexExTr_size
*3; ++i
)
394 if (MoviExSort
[i
]!=65535)
396 MoviExSort
[s
] = MoviExSort
[i
];
400 MovtExSort
= new uint16
[s
];
401 for (int i
=0; i
< s
; ++i
)
403 MovtExSort
[i
] = MoviExSort
[i
];
406 for (int i
=0; i
< IndexExTr_size
*3; ++i
)
408 uint16 b
= MoviEx
[i
];
409 for (uint16 x
= 0; x
< s
; ++x
)
411 if(MoviExSort
[x
] == b
)
418 int INDX
[] = {0x58444E49,IndexExTr_size
*6+4,IndexExTr_size
*3};
419 fwrite(INDX
,4,3,output
);
420 fwrite(MoviEx
,2,IndexExTr_size
*3,output
);
423 delete [] MoviExSort
;
426 //----------VERT---------
427 //-----MOVT----------
429 MovtEx
= new float[s
*3];
430 for (uint16 i
=0; i
<s
; ++i
)
432 int c
=0;//!!!!data in MovtExSort[i] more uint16 in great group wmo files!!!!
434 for (int y
=0; y
<3; ++y
)
441 int VERT
[] = {0x54524556,d
*4+4,d
*4/12};// "VERT"
442 fwrite(VERT
,4,3,output
);
443 fwrite(MovtEx
,4,d
,output
);
444 //------LIQU------------------------
447 int LIQU_h
[] = {0x5551494C,LiquEx_size
+8,hlq_xverts
,hlq_yverts
};// "LIQU"
448 fwrite(LIQU_h
,4,4,output
);
449 fwrite(LiquEx
,4,LiquEx_size
/4,output
);
455 delete [] MovtExSort
;
457 //---------------------------------------------
458 return IndexExTr_size
;
462 WMOGroup::~WMOGroup()
466 WMOInstance::WMOInstance(MPQFile
&f
,const char* WmoInstName
,const char*MapName
, FILE *pDirfile
)
473 pos
= Vec3D(ff
[0],ff
[1],ff
[2]);
475 rot
= Vec3D(ff
[0],ff
[1],ff
[2]);
477 pos2
= Vec3D(ff
[0],ff
[1],ff
[2]);
479 pos3
= Vec3D(ff
[0],ff
[1],ff
[2]);
483 doodadset
= (d2
& 0xFFFF0000) >> 16;
485 int realx1
= (int) ((float) pos2
.x
/ 533.333333f
);
486 int realy1
= (int) ((float) pos2
.z
/ 533.333333f
);
487 int realx2
= (int) ((float) pos3
.x
/ 533.333333f
);
488 int realy2
= (int) ((float) pos3
.z
/ 533.333333f
);
492 realx1
+=20; realx2
+=20;
496 realy1
+=20; realy2
+=20;
497 } // hack to prevent neg. values
499 //-----------add_in _dir_file----------------
502 // const char dirname[] = "buildings\\dir";
504 sprintf(tempname
, "buildings\\%s", WmoInstName
);
506 input
= fopen(tempname
, "r+b");
511 fseek(input
, 8, SEEK_SET
); // get the correct no of vertices
513 fread(&nVertices
, sizeof (int), 1, input
);
520 dirfile = fopen(dirname, "ab");
523 printf("Can't open dirfile!'%s'\n");
536 fprintf(pDirfile
,"%s/%s %f,%f,%f_%f,%f,%f 1.0 %d %d %d,%d %d\n",
539 (float) x
, (float) pos
.y
, (float) z
,
540 (float) rot
.x
, (float) rot
.y
, (float) rot
.z
,