From cd6693d145bc0b9443eea76a793ed7835312d4c7 Mon Sep 17 00:00:00 2001 From: Gundalf <gundalf01@users.sourceforge.net> Date: Sat, 24 Jun 2006 17:39:42 +0000 Subject: [PATCH] Fixed meshes without uv coordinates. Fixed holes in generated collision geometry. --- NifExport/Exporter.h | 1 - NifExport/Mesh.cpp | 28 +++++++++----- NifExport/NifExport.cpp | 2 +- NifExport/Strips.cpp | 83 ++++++++++++++++++++++++----------------- 4 files changed, 67 insertions(+), 47 deletions(-) diff --git a/NifExport/Exporter.h b/NifExport/Exporter.h index 84064f0..1b974f6 100755 --- a/NifExport/Exporter.h +++ b/NifExport/Exporter.h @@ -114,7 +114,6 @@ private: void getTextureMatrix(Matrix3 &mat, Mtl *mtl); /* havok & collision */ - bool hasCollision(INode *node); int addVertex(vector<Vector3> &verts, vector<Vector3> &vnorms, const Point3 &pt, const Point3 &norm); void addFace(Triangles &tris, vector<Vector3> &verts, vector<Vector3> &vnorms, int face, const int vi[3], Mesh *mesh); diff --git a/NifExport/Mesh.cpp b/NifExport/Mesh.cpp index fb94df6..47177d2 100755 --- a/NifExport/Mesh.cpp +++ b/NifExport/Mesh.cpp @@ -96,8 +96,12 @@ bool Exporter::makeMesh(NiNodeRef &parent, Mtl *mtl, FaceGroup &grp) data->SetVertices(grp.verts); data->SetNormals(grp.vnorms); - data->SetUVSetCount(1); - data->SetUVSet(0, grp.uvs); + + if (grp.uvs.size() > 0) + { + data->SetUVSetCount(1); + data->SetUVSet(0, grp.uvs); + } if (grp.vcolors.size() > 0) data->SetVertexColors(grp.vcolors); @@ -116,13 +120,12 @@ bool Exporter::makeMesh(NiNodeRef &parent, Mtl *mtl, FaceGroup &grp) 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 ]] * 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; -*/ + Point3 uv; + if (mesh->tvFace) + uv = mesh->tVerts[ mesh->tvFace[ face ].t[ vi ]] * texm; + VertColor col; if (mVertexColors && mesh->vertCol) col = mesh->vertCol[ mesh->vcFace[ face ].t[ vi ] ]; @@ -130,9 +133,11 @@ int Exporter::addVertex(FaceGroup &grp, int face, int vi, Mesh *mesh, const Matr for (int i=0; i<grp.verts.size(); i++) { if (equal(grp.verts[i], pt, mWeldThresh) && - grp.uvs[i].u==uv.x && grp.uvs[i].v==uv.y && equal(grp.vnorms[i], norm, 0)) { + if (mesh->tvFace && (grp.uvs[i].u!=uv.x || grp.uvs[i].v!=uv.y)) + continue; + if (mVertexColors && mesh->vertCol && (grp.vcolors[i].r!=col.x || grp.vcolors[i].g!=col.y || @@ -144,9 +149,11 @@ int Exporter::addVertex(FaceGroup &grp, int face, int vi, Mesh *mesh, const Matr } grp.verts.push_back(Vector3(pt.x, pt.y, pt.z)); - grp.uvs.push_back(TexCoord(uv.x, uv.y)); grp.vnorms.push_back(Vector3(norm.x, norm.y, norm.z)); + if (mesh->tvFace) + grp.uvs.push_back(TexCoord(uv.x, uv.y)); + if (mVertexColors && mesh->vertCol) grp.vcolors.push_back(Color4(col.x, col.y, col.z, 1)); @@ -158,11 +165,12 @@ void Exporter::addFace(FaceGroup &grp, int face, const int vi[3], Mesh *mesh, co Triangle tri; for (int i=0; i<3; i++) { - DWORD t0 = mesh->tvFace[ face ].getTVert(0); +/* 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, diff --git a/NifExport/NifExport.cpp b/NifExport/NifExport.cpp index b47763b..b356d58 100755 --- a/NifExport/NifExport.cpp +++ b/NifExport/NifExport.cpp @@ -153,7 +153,7 @@ int NifExport::ExtCount() const TCHAR *NifExport::Ext(int n) { - return _T("fif"); + return _T("nif"); } const TCHAR *NifExport::LongDesc() diff --git a/NifExport/Strips.cpp b/NifExport/Strips.cpp index bf05266..2a64946 100755 --- a/NifExport/Strips.cpp +++ b/NifExport/Strips.cpp @@ -18,47 +18,59 @@ void Exporter::strippify(TriStrips &strips, vector<Vector3> &verts, vector<Vecto tri_stripper::primitives_vector groups; stripper.Strip(&groups); + // triangles left over + Triangles stris; 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]; + if (groups[i].m_Type == tri_stripper::PT_Triangle_Strip) + { + 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]; + } else + { + int size = stris.size(); + stris.resize(size + groups[i].m_Indices.size()/3); + for (int j=(size>0)?(size-1):0; j<stris.size(); j++) + { + stris[j][0] = groups[i].m_Indices[j*3+0]; + stris[j][1] = groups[i].m_Indices[j*3+1]; + stris[j][2] = groups[i].m_Indices[j*3+2]; + } + } } -} -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++) + if (stris.size()) { - 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); + // stitch em + TriStrip strip; + if (strips.size() > 0) + { + strip.push_back(strips.back()[strips.back().size()-1]); + strip.push_back(stris[0][0]); + } + for (i=0; i<stris.size(); i++) + { + if (i > 0) + { + strip.push_back(stris[i][0]); + strip.push_back(stris[i][0]); + } - 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]; + strip.push_back(stris[i][0]); + strip.push_back(stris[i][1]); + strip.push_back(stris[i][2]); + if (i < stris.size()-1) + strip.push_back(stris[i][2]); + } + strips.push_back(strip); } -*/ +} + +void Exporter::strippify(TriStrips &strips, FaceGroup &grp) +{ unsigned short *data = (unsigned short *)malloc(grp.faces.size() * 3 * 2); int i; @@ -119,7 +131,8 @@ void Exporter::strippify(TriStrips &strips, FaceGroup &grp) grp.verts[a] = tmp.verts[b]; grp.vnorms[a] = tmp.vnorms[b]; - grp.uvs[a] = tmp.uvs[b]; + if (grp.uvs.size() > 0) + grp.uvs[a] = tmp.uvs[b]; if (grp.vcolors.size() > 0) grp.vcolors[a] = tmp.vcolors[b]; } -- GitLab