diff --git a/bsa/tests/.gitignore b/bsa/tests/.gitignore index 3d21a0f57..e2f2f332d 100644 --- a/bsa/tests/.gitignore +++ b/bsa/tests/.gitignore @@ -1,2 +1,3 @@ *_test bsatool +*.bsa diff --git a/nifogre/ogre_nif_loader.cpp b/nifogre/ogre_nif_loader.cpp index fecde4b24..c0dc193e2 100644 --- a/nifogre/ogre_nif_loader.cpp +++ b/nifogre/ogre_nif_loader.cpp @@ -34,11 +34,15 @@ // For warning messages #include +typedef unsigned char ubyte; + using namespace std; using namespace Ogre; using namespace Nif; using namespace Mangle::VFS; +#define TRANSLATE 1 + // This is the interface to the Ogre resource system. It allows us to // load NIFs from BSAs, in the file system and in any other place we // tell Ogre to look (eg. in zip or rar files.) It's also used to @@ -56,7 +60,7 @@ static void warn(const string &msg) cout << "WARNING (NIF:" << errName << "): " << msg << endl; } -static void createMaterial(const String &material, +static void createMaterial(const String &name, const Vector &ambient, const Vector &diffuse, const Vector &specular, @@ -65,7 +69,7 @@ static void createMaterial(const String &material, float alphaFlags, float alphaTest, const String &texName) { - MaterialPtr material = MaterialManager::getSingleton().create(material, "General"); + MaterialPtr material = MaterialManager::getSingleton().create(name, "General"); // This assigns the texture to this material. If the texture name is // a file name, and this file exists (in a resource directory), it @@ -122,19 +126,18 @@ static String getUniqueName(const String &input) // does not, change the string IN PLACE to say .dds instead and try // that. The texture may still not exist, but no information of value // is lost in that case. -static findRealTexture(String &texName) +static void findRealTexture(String &texName) { assert(vfs); - if(vfs.isFile(texName)) return; + if(vfs->isFile(texName)) return; int len = texName.size(); if(len < 4) return; - // In-place string changing hack - char *ptr = (char*)texName.c_str(); - strcpy(ptr-3, "dds"); - - cout << "Replaced with " << texName << endl; + // Change texture extension to .dds + texName[len-3] = 'd'; + texName[len-2] = 'd'; + texName[len-1] = 's'; } // Convert Nif::NiTriShape to Ogre::SubMesh, attached to the given @@ -237,9 +240,9 @@ static void matrixMul(const Matrix &A, Matrix &B) float b = B.v[1].array[i]; float c = B.v[2].array[i]; - B.v[0].array[i] = a*A[0].array[0] + b*A[0].array[1] + c*A[0].array[2]; - B.v[1].array[i] = a*A[1].array[0] + b*A[1].array[1] + c*A[1].array[2]; - B.v[2].array[i] = a*A[2].array[0] + b*A[2].array[1] + c*A[2].array[2]; + B.v[0].array[i] = a*A.v[0].array[0] + b*A.v[0].array[1] + c*A.v[0].array[2]; + B.v[1].array[i] = a*A.v[1].array[0] + b*A.v[1].array[1] + c*A.v[1].array[2]; + B.v[2].array[i] = a*A.v[2].array[0] + b*A.v[2].array[1] + c*A.v[2].array[2]; } } @@ -253,7 +256,7 @@ static void vectorMulAdd(const Matrix &A, const Vector &B, float *C, float scale // Perform matrix multiplication, scaling and addition for(int i=0;i<3;i++) - C[i] = B.array[i] + (a*A[i].array[0] + b*A[i].array[1] + c*A[i].array[2])*scale; + C[i] = B.array[i] + (a*A.v[i].array[0] + b*A.v[i].array[1] + c*A.v[i].array[2])*scale; } // Computes B = AxB (matrix*vector) @@ -266,7 +269,7 @@ static void vectorMul(const Matrix &A, float *C) // Perform matrix multiplication, scaling and addition for(int i=0;i<3;i++) - C[i] = a*A[i].array[0] + b*A[i].array[1] + c*A[i].array[2]; + C[i] = a*A.v[i].array[0] + b*A.v[i].array[1] + c*A.v[i].array[2]; } static void handleNiTriShape(Mesh *mesh, NiTriShape *shape, int flags) @@ -344,7 +347,7 @@ static void handleNiTriShape(Mesh *mesh, NiTriShape *shape, int flags) problem since all the nif data is stored in a local throwaway buffer. */ - texName = tname.toString(); + texName = "textures\\" + tname.toString(); findRealTexture(texName); } else warn("Found internal texture, ignoring."); @@ -382,8 +385,8 @@ static void handleNiTriShape(Mesh *mesh, NiTriShape *shape, int flags) Vector zero, one; for(int i=0; i<3;i++) { - zero[i] = 0.0; - one[i] = 1.0; + zero.array[i] = 0.0; + one.array[i] = 1.0; } createMaterial(material, one, one, zero, zero, 0.0, 1.0, @@ -392,7 +395,7 @@ static void handleNiTriShape(Mesh *mesh, NiTriShape *shape, int flags) } } - if(0) // TODO FIXME TEMP + if(TRANSLATE) // TODO FIXME TEMP { /* Do in-place transformation of all the vertices and normals. This is pretty messy stuff, but we need it to make the sub-meshes @@ -403,11 +406,11 @@ static void handleNiTriShape(Mesh *mesh, NiTriShape *shape, int flags) NiTriShapeData *data = shape->data.getPtr(); int numVerts = data->vertices.length / 3; - float *ptr = data->vertices.ptr; + float *ptr = (float*)data->vertices.ptr; // Rotate, scale and translate all the vertices const Matrix &rot = shape->trafo->rotation; - const Vector &pos = shape->trafo->position; + const Vector &pos = shape->trafo->pos; float scale = shape->trafo->scale; for(int i=0; inormals.length) { - ptr = data->normals.ptr; + ptr = (float*)data->normals.ptr; for(int i=0; iwriteContentsToFile("nif.png"); + if(shot < 2) shot++; + if(window->isClosed()) return false; return true; @@ -73,15 +82,33 @@ int main(int argc, char**args) addBSA("../../data/Morrowind.bsa"); // Insert the mesh - const char* mesh = "meshes\\a\\towershield_steel.nif"; NIFLoader::load(mesh); NIFLoader::load(mesh); - // Display it + //* SceneNode *node = mgr->getRootSceneNode()->createChildSceneNode("node"); Entity *ent = mgr->createEntity("Mesh1", mesh); node->attachObject(ent); - node->setPosition(0,0,100); + node->setPosition(0,4,50); + node->pitch(Degree(20)); + node->roll(Degree(10)); + node->yaw(Degree(-10)); + /* + node->setPosition(0,-70,170); + node->pitch(Degree(-90)); + /* + // Display it from two different angles + const int sep = 45; + SceneNode *node = mgr->getRootSceneNode()->createChildSceneNode("node"); + Entity *ent = mgr->createEntity("Mesh1", mesh); + node->attachObject(ent); + node->setPosition(sep,0,100); + node = node->createChildSceneNode("node2"); + ent = mgr->createEntity("Mesh2", mesh); + node->attachObject(ent); + node->setPosition(-2*sep,0,0); + node->yaw(Degree(180)); + //*/ // Render loop if(render) diff --git a/nifogre/tests/output/ogre_nif_test.out b/nifogre/tests/output/ogre_nif_test.out index 84e3ef87d..e69de29bb 100644 --- a/nifogre/tests/output/ogre_nif_test.out +++ b/nifogre/tests/output/ogre_nif_test.out @@ -1,3 +0,0 @@ -Loading meshes\a\towershield_steel.nif -Number of records: 10 -First record type: NiNode