From 45ab466c356f5d8c2c4c65041789d0d3a72e618b Mon Sep 17 00:00:00 2001 From: Gundalf <gundalf01@users.sourceforge.net> Date: Sat, 24 Jun 2006 15:37:42 +0000 Subject: [PATCH] UV fix --- NifExport/Exporter.h | 8 ++++++-- NifExport/Mesh.cpp | 24 +++++++++++++++++++----- NifExport/MtlTex.cpp | 24 +++++++++++++++++++----- NifExport/NifExport.cpp | 2 +- NifExport/Strips.cpp | 26 ++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 13 deletions(-) diff --git a/NifExport/Exporter.h b/NifExport/Exporter.h index abc98cf..84064f0 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 faf6c32..fb94df6 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 360f301..65bb362 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 b356d58..b47763b 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 845b92a..bf05266 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; -- GitLab