Backed out changeset: ad4f100c0a9d
--HG-- branch : trunk
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
//#include "common.h"
|
||||
#include "model.h"
|
||||
//#include "world.h"
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
|
||||
//int globalTime = 0;
|
||||
|
||||
Model::Model(std::string &filename) : filename(filename)
|
||||
{
|
||||
}
|
||||
@@ -20,31 +24,121 @@ bool Model::open()
|
||||
}
|
||||
|
||||
memcpy(&header, f.getBuffer(), sizeof(ModelHeader));
|
||||
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++)
|
||||
if(header.nBoundingTriangles > 0) {
|
||||
|
||||
#if 0
|
||||
animated = isAnimated(f);
|
||||
if(animated)
|
||||
{
|
||||
vertices[i] = fixCoordSystem(vertices[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]];
|
||||
}
|
||||
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());
|
||||
f.close();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -57,8 +151,7 @@ bool Model::ConvertToVMAPModel(char * outfilename)
|
||||
return false;
|
||||
}
|
||||
fwrite("VMAP002",8,1,output);
|
||||
uint32 nVertices = 0;
|
||||
nVertices = header.nBoundingVertices;
|
||||
int nVertices = header.nVertices;
|
||||
fwrite(&nVertices, sizeof(int), 1, output);
|
||||
uint32 nofgroups = 1;
|
||||
fwrite(&nofgroups,sizeof(uint32), 1, output);
|
||||
@@ -69,16 +162,15 @@ bool Model::ConvertToVMAPModel(char * outfilename)
|
||||
wsize = sizeof(branches) + sizeof(uint32) * branches;
|
||||
fwrite(&wsize, sizeof(int), 1, output);
|
||||
fwrite(&branches,sizeof(branches), 1, output);
|
||||
uint32 nIndexes = 0;
|
||||
nIndexes = header.nBoundingTriangles;
|
||||
fwrite(&nIndexes,sizeof(uint32), 1, output);
|
||||
uint32 nIdexes = (uint32) nIndices;
|
||||
fwrite(&nIndices,sizeof(uint32), 1, output);
|
||||
fwrite("INDX",4, 1, output);
|
||||
wsize = sizeof(uint32) + sizeof(unsigned short) * nIndexes;
|
||||
wsize = sizeof(uint32) + sizeof(unsigned short) * nIdexes;
|
||||
fwrite(&wsize, sizeof(int), 1, output);
|
||||
fwrite(&nIndexes, sizeof(uint32), 1, output);
|
||||
if(nIndexes >0)
|
||||
fwrite(&nIdexes, sizeof(uint32), 1, output);
|
||||
if(nIdexes >0)
|
||||
{
|
||||
fwrite(indices, sizeof(unsigned short), nIndexes, output);
|
||||
fwrite(indices, sizeof(unsigned short), nIdexes, output);
|
||||
}
|
||||
fwrite("VERT",4, 1, output);
|
||||
wsize = sizeof(int) + sizeof(float) * 3 * nVertices;
|
||||
@@ -86,7 +178,7 @@ bool Model::ConvertToVMAPModel(char * outfilename)
|
||||
fwrite(&nVertices, sizeof(int), 1, output);
|
||||
if(nVertices >0)
|
||||
{
|
||||
for(uint32 vpos=0; vpos <nVertices; ++vpos)
|
||||
for(int vpos=0; vpos <nVertices; ++vpos)
|
||||
{
|
||||
float sy = vertices[vpos].y;
|
||||
vertices[vpos].y = vertices[vpos].z;
|
||||
@@ -97,6 +189,7 @@ bool Model::ConvertToVMAPModel(char * outfilename)
|
||||
|
||||
delete[] vertices;
|
||||
delete[] indices;
|
||||
delete[] normals;
|
||||
|
||||
fclose(output);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "vec3d.h"
|
||||
#include "mpq.h"
|
||||
#include "modelheaders.h"
|
||||
//#include "quaternion.h"
|
||||
#include <vector>
|
||||
|
||||
class Model;
|
||||
@@ -17,14 +18,18 @@ Vec3D fixCoordSystem(Vec3D v);
|
||||
class Model
|
||||
{
|
||||
public:
|
||||
|
||||
ModelHeader header;
|
||||
ModelAnimation *anims;
|
||||
int *globalSequences;
|
||||
|
||||
public:
|
||||
bool animGeometry,animTextures,animBones;
|
||||
bool animated;
|
||||
|
||||
uint32 offsBB_vertices, offsBB_indices;
|
||||
Vec3D *BB_vertices, *vertices;
|
||||
uint16 *BB_indices, *indices;
|
||||
bool isAnimated(MPQFile &f);
|
||||
ModelVertex *origVertices;
|
||||
Vec3D *vertices, *normals;
|
||||
uint16 *indices;
|
||||
size_t nIndices;
|
||||
|
||||
bool open();
|
||||
@@ -33,6 +38,12 @@ public:
|
||||
public:
|
||||
|
||||
bool ok;
|
||||
bool ind;
|
||||
|
||||
float rad;
|
||||
float trans;
|
||||
bool animcalc;
|
||||
int anim, animtime;
|
||||
|
||||
Model(std::string &filename);
|
||||
~Model();
|
||||
@@ -48,9 +59,15 @@ public:
|
||||
Model *model;
|
||||
|
||||
int id;
|
||||
|
||||
Vec3D pos, rot;
|
||||
unsigned int d1, scale;
|
||||
float w,sc;
|
||||
|
||||
float frot,w,sc;
|
||||
|
||||
int light;
|
||||
Vec3D ldir;
|
||||
Vec3D lcol;
|
||||
|
||||
ModelInstance() {}
|
||||
ModelInstance(MPQFile &f,const char* ModelInstName,const char*MapName, FILE *pDirfile);
|
||||
|
||||
@@ -15,67 +15,289 @@ struct ModelHeader {
|
||||
uint8 version[4];
|
||||
uint32 nameLength;
|
||||
uint32 nameOfs;
|
||||
uint32 type;
|
||||
uint32 type;
|
||||
|
||||
uint32 nGlobalSequences;
|
||||
uint32 ofsGlobalSequences;
|
||||
uint32 nAnimations;
|
||||
uint32 ofsAnimations;
|
||||
uint32 nAnimationLookup;
|
||||
uint32 ofsAnimationLookup;
|
||||
uint32 nBones;
|
||||
uint32 ofsBones;
|
||||
uint32 nKeyBoneLookup;
|
||||
uint32 ofsKeyBoneLookup;
|
||||
uint32 nC;
|
||||
uint32 ofsC;
|
||||
uint32 nD;
|
||||
uint32 ofsD;
|
||||
uint32 nBones;
|
||||
uint32 ofsBones;
|
||||
uint32 nF;
|
||||
uint32 ofsF;
|
||||
|
||||
uint32 nVertices;
|
||||
uint32 ofsVertices;
|
||||
uint32 nViews;
|
||||
uint32 ofsViews;
|
||||
|
||||
uint32 nColors;
|
||||
uint32 ofsColors;
|
||||
|
||||
uint32 nTextures;
|
||||
uint32 ofsTextures;
|
||||
uint32 nTransparency;
|
||||
|
||||
uint32 nTransparency; // H
|
||||
uint32 ofsTransparency;
|
||||
uint32 nTextureanimations;
|
||||
uint32 ofsTextureanimations;
|
||||
uint32 nTexReplace;
|
||||
uint32 ofsTexReplace;
|
||||
uint32 nRenderFlags;
|
||||
uint32 ofsRenderFlags;
|
||||
uint32 nBoneLookupTable;
|
||||
uint32 ofsBoneLookupTable;
|
||||
uint32 nTexLookup;
|
||||
uint32 ofsTexLookup;
|
||||
uint32 nTexUnits;
|
||||
uint32 ofsTexUnits;
|
||||
uint32 nTransLookup;
|
||||
uint32 ofsTransLookup;
|
||||
uint32 nTexAnimLookup;
|
||||
uint32 ofsTexAnimLookup;
|
||||
float floats[14];
|
||||
uint32 nBoundingTriangles;
|
||||
uint32 ofsBoundingTriangles;
|
||||
uint32 nBoundingVertices;
|
||||
uint32 ofsBoundingVertices;
|
||||
uint32 nBoundingNormals;
|
||||
uint32 ofsBoundingNormals;
|
||||
uint32 nAttachments;
|
||||
uint32 ofsAttachments;
|
||||
uint32 nAttachLookup;
|
||||
uint32 ofsAttachLookup;
|
||||
uint32 nAttachments_2;
|
||||
uint32 ofsAttachments_2;
|
||||
uint32 nLights;
|
||||
uint32 ofsLights;
|
||||
uint32 nCameras;
|
||||
uint32 ofsCameras;
|
||||
uint32 nCameraLookup;
|
||||
uint32 ofsCameraLookup;
|
||||
uint32 nRibbonEmitters;
|
||||
uint32 ofsRibbonEmitters;
|
||||
uint32 nParticleEmitters;
|
||||
uint32 ofsParticleEmitters;
|
||||
uint32 nI; // always unused ?
|
||||
uint32 ofsI;
|
||||
uint32 nTexAnims; // J
|
||||
uint32 ofsTexAnims;
|
||||
uint32 nK;
|
||||
uint32 ofsK;
|
||||
|
||||
uint32 nTexFlags;
|
||||
uint32 ofsTexFlags;
|
||||
uint32 nY;
|
||||
uint32 ofsY;
|
||||
|
||||
uint32 nTexLookup;
|
||||
uint32 ofsTexLookup;
|
||||
|
||||
uint32 nTexUnitLookup; // L
|
||||
uint32 ofsTexUnitLookup;
|
||||
uint32 nTransparencyLookup; // M
|
||||
uint32 ofsTransparencyLookup;
|
||||
uint32 nTexAnimLookup;
|
||||
uint32 ofsTexAnimLookup;
|
||||
|
||||
float floats[14];
|
||||
|
||||
uint32 nBoundingTriangles;
|
||||
uint32 ofsBoundingTriangles;
|
||||
uint32 nBoundingVertices;
|
||||
uint32 ofsBoundingVertices;
|
||||
uint32 nBoundingNormals;
|
||||
uint32 ofsBoundingNormals;
|
||||
|
||||
uint32 nO;
|
||||
uint32 ofsO;
|
||||
uint32 nP;
|
||||
uint32 ofsP;
|
||||
uint32 nQ;
|
||||
uint32 ofsQ;
|
||||
uint32 nLights; // R
|
||||
uint32 ofsLights;
|
||||
uint32 nCameras; // S
|
||||
uint32 ofsCameras;
|
||||
uint32 nT;
|
||||
uint32 ofsT;
|
||||
uint32 nRibbonEmitters; // U
|
||||
uint32 ofsRibbonEmitters;
|
||||
uint32 nParticleEmitters; // V
|
||||
uint32 ofsParticleEmitters;
|
||||
|
||||
};
|
||||
|
||||
// block B - animations
|
||||
struct ModelAnimation {
|
||||
uint32 animID;
|
||||
uint32 timeStart;
|
||||
uint32 timeEnd;
|
||||
|
||||
float moveSpeed;
|
||||
|
||||
uint32 loopType;
|
||||
uint32 flags;
|
||||
uint32 d1;
|
||||
uint32 d2;
|
||||
uint32 playSpeed; // note: this can't be play speed because it's 0 for some models
|
||||
|
||||
Vec3D boxA, boxB;
|
||||
float rad;
|
||||
|
||||
int16 s[2];
|
||||
};
|
||||
|
||||
|
||||
// sub-block in block E - animation data
|
||||
struct AnimationBlock {
|
||||
int16 type; // interpolation type (0=none, 1=linear, 2=hermite)
|
||||
int16 seq; // global sequence id or -1
|
||||
uint32 nRanges;
|
||||
uint32 ofsRanges;
|
||||
uint32 nTimes;
|
||||
uint32 ofsTimes;
|
||||
uint32 nKeys;
|
||||
uint32 ofsKeys;
|
||||
};
|
||||
|
||||
// block E - bones
|
||||
struct ModelBoneDef {
|
||||
int32 animid;
|
||||
int32 flags;
|
||||
int16 parent; // parent bone index
|
||||
int16 geoid;
|
||||
// new int added to the bone definitions. Added in WoW 2.0
|
||||
int32 unknown;
|
||||
AnimationBlock translation;
|
||||
AnimationBlock rotation;
|
||||
AnimationBlock scaling;
|
||||
Vec3D pivot;
|
||||
};
|
||||
|
||||
struct ModelTexAnimDef {
|
||||
AnimationBlock trans, rot, scale;
|
||||
};
|
||||
|
||||
struct ModelVertex {
|
||||
Vec3D pos;
|
||||
uint8 weights[4];
|
||||
uint8 bones[4];
|
||||
Vec3D normal;
|
||||
Vec2D texcoords;
|
||||
int unk1, unk2; // always 0,0 so this is probably unused
|
||||
};
|
||||
|
||||
struct ModelView {
|
||||
uint32 nIndex, ofsIndex; // Vertices in this model (index into vertices[])
|
||||
uint32 nTris, ofsTris; // indices
|
||||
uint32 nProps, ofsProps; // additional vtx properties
|
||||
uint32 nSub, ofsSub; // materials/renderops/submeshes
|
||||
uint32 nTex, ofsTex; // material properties/textures
|
||||
int32 lod; // LOD bias?
|
||||
};
|
||||
|
||||
|
||||
/// One material + render operation
|
||||
struct ModelGeoset {
|
||||
uint16 d1; // mesh part id?
|
||||
uint16 d2; // ?
|
||||
uint16 vstart; // first vertex
|
||||
uint16 vcount; // num vertices
|
||||
uint16 istart; // first index
|
||||
uint16 icount; // num indices
|
||||
uint16 d3; // number of bone indices
|
||||
uint16 d4; // offset into bone index list
|
||||
uint16 d5; // ?
|
||||
uint16 d6; // root bone?
|
||||
Vec3D v;
|
||||
float unknown[4]; // Added in WoW 2.0?
|
||||
};
|
||||
|
||||
/// A texture unit (sub of material)
|
||||
struct ModelTexUnit{
|
||||
// probably the texture units
|
||||
// size always >=number of materials it seems
|
||||
uint16 flags; // Flags
|
||||
uint16 order; // ?
|
||||
uint16 op; // Material this texture is part of (index into mat)
|
||||
uint16 op2; // Always same as above?
|
||||
int16 colorIndex; // color or -1
|
||||
uint16 flagsIndex; // more flags...
|
||||
uint16 texunit; // Texture unit (0 or 1)
|
||||
uint16 d4; // ? (seems to be always 1)
|
||||
uint16 textureid; // Texture id (index into global texture list)
|
||||
uint16 texunit2; // copy of texture unit value?
|
||||
uint16 transid; // transparency id (index into transparency list)
|
||||
uint16 texanimid; // texture animation id
|
||||
};
|
||||
|
||||
// block X - render flags
|
||||
struct ModelRenderFlags {
|
||||
uint16 flags;
|
||||
uint16 blend;
|
||||
};
|
||||
|
||||
// block G - color defs
|
||||
struct ModelColorDef {
|
||||
AnimationBlock color;
|
||||
AnimationBlock opacity;
|
||||
};
|
||||
|
||||
// block H - transp defs
|
||||
struct ModelTransDef {
|
||||
AnimationBlock trans;
|
||||
};
|
||||
|
||||
struct ModelTextureDef {
|
||||
uint32 type;
|
||||
uint32 flags;
|
||||
uint32 nameLen;
|
||||
uint32 nameOfs;
|
||||
};
|
||||
|
||||
struct ModelLightDef {
|
||||
int16 type;
|
||||
int16 bone;
|
||||
Vec3D pos;
|
||||
AnimationBlock ambColor;
|
||||
AnimationBlock ambIntensity;
|
||||
AnimationBlock color;
|
||||
AnimationBlock intensity;
|
||||
AnimationBlock attStart;
|
||||
AnimationBlock attEnd;
|
||||
AnimationBlock unk1;
|
||||
};
|
||||
|
||||
struct ModelCameraDef {
|
||||
int32 id;
|
||||
float fov, farclip, nearclip;
|
||||
AnimationBlock transPos;
|
||||
Vec3D pos;
|
||||
AnimationBlock transTarget;
|
||||
Vec3D target;
|
||||
AnimationBlock rot;
|
||||
};
|
||||
|
||||
|
||||
struct ModelParticleParams {
|
||||
float mid;
|
||||
uint32 colors[3];
|
||||
float sizes[3];
|
||||
int16 d[10];
|
||||
float unk[3];
|
||||
float scales[3];
|
||||
float slowdown;
|
||||
float rotation;
|
||||
float f2[16];
|
||||
};
|
||||
|
||||
struct ModelParticleEmitterDef {
|
||||
int32 id;
|
||||
int32 flags;
|
||||
Vec3D pos;
|
||||
int16 bone;
|
||||
int16 texture;
|
||||
int32 nZero1;
|
||||
int32 ofsZero1;
|
||||
int32 nZero2;
|
||||
int32 ofsZero2;
|
||||
int16 blend;
|
||||
int16 type;
|
||||
int16 s1;
|
||||
int16 s2;
|
||||
int16 cols;
|
||||
int16 rows;
|
||||
AnimationBlock params[10];
|
||||
ModelParticleParams p;
|
||||
AnimationBlock unk;
|
||||
};
|
||||
|
||||
|
||||
struct ModelRibbonEmitterDef {
|
||||
int32 id;
|
||||
int32 bone;
|
||||
Vec3D pos;
|
||||
int32 nTextures;
|
||||
int32 ofsTextures;
|
||||
int32 nUnknown;
|
||||
int32 ofsUnknown;
|
||||
AnimationBlock color;
|
||||
AnimationBlock opacity;
|
||||
AnimationBlock above;
|
||||
AnimationBlock below;
|
||||
float res, length, unk;
|
||||
int16 s1, s2;
|
||||
AnimationBlock unk1;
|
||||
AnimationBlock unk2;
|
||||
};
|
||||
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
|
||||
@@ -421,10 +421,6 @@ bool fillArchiveNameVector(std::vector<std::string>& pArchiveNames) {
|
||||
|
||||
// open expansion and common files
|
||||
printf("Opening data files from data directory.\n");
|
||||
sprintf(path, "%slichking.mpq", input_path);
|
||||
pArchiveNames.push_back(path);
|
||||
sprintf(path, "%scommon-2.mpq", input_path);
|
||||
pArchiveNames.push_back(path);
|
||||
sprintf(path, "%sexpansion.mpq", input_path);
|
||||
pArchiveNames.push_back(path);
|
||||
sprintf(path, "%scommon.mpq", input_path);
|
||||
@@ -436,8 +432,6 @@ bool fillArchiveNameVector(std::vector<std::string>& pArchiveNames) {
|
||||
for (std::vector<std::string>::iterator i = locales.begin(); i != locales.end(); i++)
|
||||
{
|
||||
printf("Locale: %s\n", i->c_str());
|
||||
sprintf(path, "%s%s\\lichking-locale-%s.mpq", input_path, i->c_str(), i->c_str());
|
||||
pArchiveNames.push_back(path);
|
||||
sprintf(path, "%s%s\\expansion-locale-%s.mpq", input_path, i->c_str(), i->c_str());
|
||||
pArchiveNames.push_back(path);
|
||||
sprintf(path, "%s%s\\locale-%s.mpq", input_path, i->c_str(), i->c_str());
|
||||
|
||||
Reference in New Issue
Block a user