diff --git a/NifExport/Exporter.h b/NifExport/Exporter.h index abc98cf7a8686cf1f197ab0f89390bd3497ed797..84064f01a11648d02f32930e261d2ddf2cda118a 100755 --- a/NifExport/Exporter.h +++ b/NifExport/Exporter.h @@ -3,6 +3,8 @@ using namespace Niflib; +class BitmapTex; + class Exporter { @@ -91,9 +93,9 @@ private: /* mesh export */ // adds a vertex to a face group if it doesn't exist yet. returns new or previous index into the // vertex array. - int addVertex(FaceGroup &grp, int face, int vi, Mesh *mesh); + int addVertex(FaceGroup &grp, int face, int vi, Mesh *mesh, const Matrix3 &texm); // adds a face to a face group - void addFace(FaceGroup &grp, int face, const int vi[3], Mesh *mesh); + void addFace(FaceGroup &grp, int face, const int vi[3], Mesh *mesh, const Matrix3 &texm); // returns true if at least one of the colors in the group has a value != (1, 1, 1, 1) bool hasVertexColors(FaceGroup &grp); // creates face groups from faces with same sub material id @@ -108,6 +110,8 @@ private: void makeTexture(NiAVObjectRef &parent, Mtl *mtl); // creates a NiMaterialProperty void makeMaterial(NiAVObjectRef &parent, Mtl *mtl); + BitmapTex *getTexture(Mtl *mtl); + void getTextureMatrix(Matrix3 &mat, Mtl *mtl); /* havok & collision */ bool hasCollision(INode *node); diff --git a/NifExport/Mesh.cpp b/NifExport/Mesh.cpp index faf6c3272ddf31628802ed808f59321bfdda20a2..fb94df6359e63a0c18b5ba5343d1bc8d8370130c 100755 --- a/NifExport/Mesh.cpp +++ b/NifExport/Mesh.cpp @@ -113,12 +113,16 @@ bool Exporter::makeMesh(NiNodeRef &parent, Mtl *mtl, FaceGroup &grp) return true; } -int Exporter::addVertex(FaceGroup &grp, int face, int vi, Mesh *mesh) +int Exporter::addVertex(FaceGroup &grp, int face, int vi, Mesh *mesh, const Matrix3 &texm) { Point3 pt = mesh->verts[ mesh->faces[ face ].v[ vi ] ]; - Point3 uv = mesh->tVerts[ mesh->tvFace[ face ].t[ vi ]]; + Point3 uv = mesh->tVerts[ mesh->tvFace[ face ].t[ vi ]] * texm; Point3 norm = getVertexNormal(mesh, face, mesh->getRVertPtr(mesh->faces[ face ].v[ vi ])); +/* uv.z = uv.x; + uv.x = uv.y; + uv.y = uv.z; +*/ VertColor col; if (mVertexColors && mesh->vertCol) col = mesh->vertCol[ mesh->vcFace[ face ].t[ vi ] ]; @@ -149,18 +153,24 @@ int Exporter::addVertex(FaceGroup &grp, int face, int vi, Mesh *mesh) return grp.verts.size()-1; } -void Exporter::addFace(FaceGroup &grp, int face, const int vi[3], Mesh *mesh) +void Exporter::addFace(FaceGroup &grp, int face, const int vi[3], Mesh *mesh, const Matrix3 &texm) { Triangle tri; for (int i=0; i<3; i++) { + DWORD t0 = mesh->tvFace[ face ].getTVert(0); + DWORD t1 = mesh->tvFace[ face ].getTVert(1); + DWORD t2 = mesh->tvFace[ face ].getTVert(2); + + int dir = mesh->tvFace[ face ].Direction(t0, t1); + /* Point3 tv = mesh->verts[ mesh->faces[ face ].v[ vi[i] ] ]; // * tm; tri[i] = addVertex(grp, tv, mesh->tVerts[ mesh->tvFace[ face ].t[ vi[i] ]], getVertexNormal(mesh, face, mesh->getRVertPtr(mesh->faces[ face ].v[ vi[i] ]))); */ - tri[i] = addVertex(grp, face, vi[i], mesh); + tri[i] = addVertex(grp, face, vi[i], mesh, texm); } grp.faces.push_back(tri); @@ -190,7 +200,11 @@ bool Exporter::splitMesh(INode *node, Mesh *mesh, FaceGroups &grps, TimeValue t) for (i=0; i<mesh->getNumFaces(); i++) { int mtlID = (numSubMtls!=0) ? (mesh->faces[i].getMatID() % numSubMtls) : 0; - addFace(grps[mtlID], i, vi, mesh); + + Matrix3 texm; + getTextureMatrix(texm, getMaterial(node, mtlID)); + + addFace(grps[mtlID], i, vi, mesh, texm); } return true; diff --git a/NifExport/MtlTex.cpp b/NifExport/MtlTex.cpp index 360f30181893e9d0e539e6882cb98600469cf8b1..65bb3627aab23547efc4c3b21e278c9bc36ac6af 100755 --- a/NifExport/MtlTex.cpp +++ b/NifExport/MtlTex.cpp @@ -1,16 +1,14 @@ #include "pch.h" #include "stdmat.h" -void Exporter::makeTexture(NiAVObjectRef &parent, Mtl *mtl) +BitmapTex *Exporter::getTexture(Mtl *mtl) { if (!mtl) - return; - - string mtlName = mtl->GetName(); + return NULL; int texMaps = mtl->NumSubTexmaps(); if (!texMaps) - return; + return NULL; BitmapTex *bmTex = NULL; for (int i=0; i<texMaps; i++) @@ -26,6 +24,22 @@ void Exporter::makeTexture(NiAVObjectRef &parent, Mtl *mtl) } } + return bmTex; +} + +void Exporter::getTextureMatrix(Matrix3 &mat, Mtl *mtl) +{ + BitmapTex *tex = getTexture(mtl); + if (tex) + tex->GetUVTransform(mat); + else + mat.IdentityMatrix(); +} + +void Exporter::makeTexture(NiAVObjectRef &parent, Mtl *mtl) +{ + BitmapTex *bmTex = getTexture(mtl); + if (!bmTex) return; diff --git a/NifExport/NifExport.cpp b/NifExport/NifExport.cpp index b356d5880b87bb162c4e71577073847700dcfec8..b47763bc852b0360d38bb02445f7e52d467431c9 100755 --- a/NifExport/NifExport.cpp +++ b/NifExport/NifExport.cpp @@ -153,7 +153,7 @@ int NifExport::ExtCount() const TCHAR *NifExport::Ext(int n) { - return _T("nif"); + return _T("fif"); } const TCHAR *NifExport::LongDesc() diff --git a/NifExport/Strips.cpp b/NifExport/Strips.cpp index 845b92a133249518518f7106e89802871eb0ef88..bf0526632517047f3bf0f07c167938d2c35ffba5 100755 --- a/NifExport/Strips.cpp +++ b/NifExport/Strips.cpp @@ -33,6 +33,32 @@ void Exporter::strippify(TriStrips &strips, vector<Vector3> &verts, vector<Vecto void Exporter::strippify(TriStrips &strips, FaceGroup &grp) { +/* vector<unsigned int> idcs(grp.faces.size()*3); + int i; + for (i=0; i<grp.faces.size(); i++) + { + idcs[i * 3 + 0] = grp.faces[i][0]; + idcs[i * 3 + 1] = grp.faces[i][1]; + idcs[i * 3 + 2] = grp.faces[i][2]; + } + + tri_stripper stripper(idcs); + + tri_stripper::primitives_vector groups; + stripper.Strip(&groups); + + for (i=0; i<groups.size(); i++) + { + if (groups[i].m_Type != tri_stripper::PT_Triangle_Strip) + continue; + + strips.push_back(TriStrip(groups[i].m_Indices.size())); + TriStrip &strip = strips.back(); + + for (int j=0; j<groups[i].m_Indices.size(); j++) + strip[j] = groups[i].m_Indices[j]; + } +*/ unsigned short *data = (unsigned short *)malloc(grp.faces.size() * 3 * 2); int i;