//#include "common.h" #include "model.h" //#include "world.h" #include #include //int globalTime = 0; Model::Model(std::string &filename) : filename(filename) { } bool Model::open() { MPQFile f(filename.c_str()); ok = !f.isEof(); if (!ok) { f.close(); printf("Error loading model %s\n", filename.c_str()); return false; } memcpy(&header, f.getBuffer(), sizeof(ModelHeader)); if(header.nBoundingTriangles > 0) { #if 0 animated = isAnimated(f); if(animated) { 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; iofsIndex); uint16 *triangles = (uint16*)(f.getBuffer() + view->ofsTris); nIndices = view->nTris; indices = new uint16[nIndices]; for (size_t i = 0; i0) { 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 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; i0) { fwrite(indices, sizeof(unsigned short), nIdexes, output); } fwrite("VERT",4, 1, output); wsize = sizeof(int) + sizeof(float) * 3 * nVertices; fwrite(&wsize, sizeof(int), 1, output); fwrite(&nVertices, sizeof(int), 1, output); if(nVertices >0) { for(int vpos=0; vpos