mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 15:15:31 +00:00
Finished and tested materials and transformations. Made nice pictures.
This commit is contained in:
parent
70f9e63cd1
commit
a21628d9c5
5 changed files with 58 additions and 28 deletions
1
bsa/tests/.gitignore
vendored
1
bsa/tests/.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
*_test
|
||||
bsatool
|
||||
*.bsa
|
||||
|
|
|
@ -34,11 +34,15 @@
|
|||
// For warning messages
|
||||
#include <iostream>
|
||||
|
||||
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; i<numVerts; i++)
|
||||
{
|
||||
|
@ -418,7 +421,7 @@ static void handleNiTriShape(Mesh *mesh, NiTriShape *shape, int flags)
|
|||
// Remember to rotate all the vertex normals as well
|
||||
if(data->normals.length)
|
||||
{
|
||||
ptr = data->normals.ptr;
|
||||
ptr = (float*)data->normals.ptr;
|
||||
for(int i=0; i<numVerts; i++)
|
||||
{
|
||||
vectorMul(rot, ptr);
|
||||
|
@ -464,7 +467,7 @@ static void handleNode(Mesh* mesh, Nif::Node *node, int flags, const Transformat
|
|||
|
||||
// Apply the parent transformation to this node. We overwrite the
|
||||
// existing data with the final transformation.
|
||||
if(0) // TODO FIXME TEMP
|
||||
if(TRANSLATE) // TODO FIXME TEMP
|
||||
if(trafo)
|
||||
{
|
||||
// Get a non-const reference to the node's data, since we're
|
||||
|
|
2
nifogre/tests/.gitignore
vendored
2
nifogre/tests/.gitignore
vendored
|
@ -1,2 +1,4 @@
|
|||
*.png
|
||||
meshlist.txt
|
||||
ogre.cfg
|
||||
*_test
|
||||
|
|
|
@ -8,11 +8,20 @@ using namespace Ogre;
|
|||
|
||||
RenderWindow *window;
|
||||
|
||||
//const char* mesh = "meshes\\a\\towershield_steel.nif";
|
||||
//const char* mesh = "meshes\\r\\bonelord.nif";
|
||||
const char* mesh = "meshes\\m\\text_scroll_open_01.nif";
|
||||
|
||||
int shot = 0;
|
||||
|
||||
// Lets you quit by closing the window
|
||||
struct QuitListener : FrameListener
|
||||
{
|
||||
bool frameStarted(const FrameEvent& evt)
|
||||
{
|
||||
if(shot == 1) window->writeContentsToFile("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)
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
Loading meshes\a\towershield_steel.nif
|
||||
Number of records: 10
|
||||
First record type: NiNode
|
Loading…
Reference in a new issue