mirror of
https://github.com/mangosfour/server.git
synced 2025-12-31 13:37:07 +00:00
Fixed vmaps extraction. Patch provided by andstan. Untested. Please test and report bugs to http://mangos.lighthouseapp.com
This commit is contained in:
parent
d1b5944000
commit
4908ecd7c8
3 changed files with 77 additions and 409 deletions
|
|
@ -1,11 +1,7 @@
|
|||
//#include "common.h"
|
||||
#include "model.h"
|
||||
//#include "world.h"
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
|
||||
//int globalTime = 0;
|
||||
|
||||
Model::Model(std::string &filename) : filename(filename)
|
||||
{
|
||||
}
|
||||
|
|
@ -24,43 +20,24 @@ bool Model::open()
|
|||
}
|
||||
|
||||
memcpy(&header, f.getBuffer(), sizeof(ModelHeader));
|
||||
if(header.nBoundingTriangles > 0) {
|
||||
|
||||
#if 0
|
||||
animated = isAnimated(f);
|
||||
if(animated)
|
||||
if(header.nBoundingTriangles > 0)
|
||||
{
|
||||
f.seek(0);
|
||||
f.seekRelative(header.ofsBoundingVertices);
|
||||
vertices = new Vec3D[header.nBoundingVertices];
|
||||
f.read(vertices,header.nBoundingVertices*12);
|
||||
for (uint32 i=0; i<header.nBoundingVertices; i++)
|
||||
{
|
||||
f.close();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
trans = 1.0f;
|
||||
origVertices = (ModelVertex*)(f.getBuffer() + header.ofsVertices);
|
||||
|
||||
vertices = new Vec3D[header.nVertices];
|
||||
normals = new Vec3D[header.nVertices];
|
||||
|
||||
for (size_t i=0; i<header.nVertices; i++)
|
||||
{
|
||||
origVertices[i].pos = fixCoordSystem(origVertices[i].pos);
|
||||
origVertices[i].normal = fixCoordSystem(origVertices[i].normal);
|
||||
vertices[i] = origVertices[i].pos;
|
||||
normals[i] = origVertices[i].normal.normalize();
|
||||
}
|
||||
|
||||
ModelView *view = (ModelView*)(f.getBuffer() + header.ofsViews);
|
||||
|
||||
uint16 *indexLookup = (uint16*)(f.getBuffer() + view->ofsIndex);
|
||||
uint16 *triangles = (uint16*)(f.getBuffer() + view->ofsTris);
|
||||
|
||||
nIndices = view->nTris;
|
||||
indices = new uint16[nIndices];
|
||||
for (size_t i = 0; i<nIndices; i++)
|
||||
{
|
||||
indices[i] = indexLookup[triangles[i]];
|
||||
vertices[i] = fixCoordSystem(vertices[i]);
|
||||
}
|
||||
f.seek(0);
|
||||
f.seekRelative(header.ofsBoundingTriangles);
|
||||
indices = new uint16[header.nBoundingTriangles];
|
||||
f.read(indices,header.nBoundingTriangles*2);
|
||||
f.close();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("not included %s\n", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
|
@ -68,77 +45,6 @@ bool Model::open()
|
|||
|
||||
}
|
||||
|
||||
bool Model::isAnimated(MPQFile &f)
|
||||
{
|
||||
// see if we have any animated bones
|
||||
ModelBoneDef *bo = (ModelBoneDef*)(f.getBuffer() + header.ofsBones);
|
||||
|
||||
animGeometry = false;
|
||||
animBones = false;
|
||||
ind = false;
|
||||
|
||||
ModelVertex *verts = (ModelVertex*)(f.getBuffer() + header.ofsVertices);
|
||||
for (size_t i=0; i<header.nVertices && !animGeometry; i++) {
|
||||
for (size_t b=0; b<4; b++) {
|
||||
if (verts[i].weights[b]>0) {
|
||||
ModelBoneDef &bb = bo[verts[i].bones[b]];
|
||||
if (bb.translation.type || bb.rotation.type || bb.scaling.type || (bb.flags&8)) {
|
||||
if (bb.flags&8) {
|
||||
// if we have billboarding, the model will need per-instance animation
|
||||
ind = true;
|
||||
}
|
||||
animGeometry = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (animGeometry) animBones = true;
|
||||
else {
|
||||
for (size_t i=0; i<header.nBones; i++) {
|
||||
ModelBoneDef &bb = bo[i];
|
||||
if (bb.translation.type || bb.rotation.type || bb.scaling.type) {
|
||||
animBones = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
animTextures = header.nTexAnims > 0;
|
||||
|
||||
bool animMisc = header.nCameras>0 || // why waste time, pretty much all models with cameras need animation
|
||||
header.nLights>0 || // same here
|
||||
header.nParticleEmitters>0 ||
|
||||
header.nRibbonEmitters>0;
|
||||
|
||||
if (animMisc) animBones = true;
|
||||
|
||||
// animated colors
|
||||
if (header.nColors) {
|
||||
ModelColorDef *cols = (ModelColorDef*)(f.getBuffer() + header.ofsColors);
|
||||
for (size_t i=0; i<header.nColors; i++) {
|
||||
if (cols[i].color.type!=0 || cols[i].opacity.type!=0) {
|
||||
animMisc = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// animated opacity
|
||||
if (header.nTransparency && !animMisc) {
|
||||
ModelTransDef *trs = (ModelTransDef*)(f.getBuffer() + header.ofsTransparency);
|
||||
for (size_t i=0; i<header.nTransparency; i++) {
|
||||
if (trs[i].trans.type!=0) {
|
||||
animMisc = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// guess not...
|
||||
return animGeometry || animTextures || animMisc;
|
||||
}
|
||||
|
||||
bool Model::ConvertToVMAPModel(char * outfilename)
|
||||
{
|
||||
|
|
@ -151,7 +57,8 @@ bool Model::ConvertToVMAPModel(char * outfilename)
|
|||
return false;
|
||||
}
|
||||
fwrite("VMAP002",8,1,output);
|
||||
int nVertices = header.nVertices;
|
||||
uint32 nVertices = 0;
|
||||
nVertices = header.nBoundingVertices;
|
||||
fwrite(&nVertices, sizeof(int), 1, output);
|
||||
uint32 nofgroups = 1;
|
||||
fwrite(&nofgroups,sizeof(uint32), 1, output);
|
||||
|
|
@ -162,15 +69,16 @@ bool Model::ConvertToVMAPModel(char * outfilename)
|
|||
wsize = sizeof(branches) + sizeof(uint32) * branches;
|
||||
fwrite(&wsize, sizeof(int), 1, output);
|
||||
fwrite(&branches,sizeof(branches), 1, output);
|
||||
uint32 nIdexes = (uint32) nIndices;
|
||||
fwrite(&nIndices,sizeof(uint32), 1, output);
|
||||
uint32 nIndexes = 0;
|
||||
nIndexes = header.nBoundingTriangles;
|
||||
fwrite(&nIndexes,sizeof(uint32), 1, output);
|
||||
fwrite("INDX",4, 1, output);
|
||||
wsize = sizeof(uint32) + sizeof(unsigned short) * nIdexes;
|
||||
wsize = sizeof(uint32) + sizeof(unsigned short) * nIndexes;
|
||||
fwrite(&wsize, sizeof(int), 1, output);
|
||||
fwrite(&nIdexes, sizeof(uint32), 1, output);
|
||||
if(nIdexes >0)
|
||||
fwrite(&nIndexes, sizeof(uint32), 1, output);
|
||||
if(nIndexes >0)
|
||||
{
|
||||
fwrite(indices, sizeof(unsigned short), nIdexes, output);
|
||||
fwrite(indices, sizeof(unsigned short), nIndexes, output);
|
||||
}
|
||||
fwrite("VERT",4, 1, output);
|
||||
wsize = sizeof(int) + sizeof(float) * 3 * nVertices;
|
||||
|
|
@ -178,7 +86,7 @@ bool Model::ConvertToVMAPModel(char * outfilename)
|
|||
fwrite(&nVertices, sizeof(int), 1, output);
|
||||
if(nVertices >0)
|
||||
{
|
||||
for(int vpos=0; vpos <nVertices; ++vpos)
|
||||
for(uint32 vpos=0; vpos <nVertices; ++vpos)
|
||||
{
|
||||
float sy = vertices[vpos].y;
|
||||
vertices[vpos].y = vertices[vpos].z;
|
||||
|
|
@ -189,7 +97,6 @@ bool Model::ConvertToVMAPModel(char * outfilename)
|
|||
|
||||
delete[] vertices;
|
||||
delete[] indices;
|
||||
delete[] normals;
|
||||
|
||||
fclose(output);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue