Skip to content
Snippets Groups Projects
Commit cd6693d1 authored by Gundalf's avatar Gundalf
Browse files

Fixed meshes without uv coordinates. Fixed holes in generated collision geometry.

parent 67e1aa38
No related branches found
No related tags found
No related merge requests found
...@@ -114,7 +114,6 @@ private: ...@@ -114,7 +114,6 @@ private:
void getTextureMatrix(Matrix3 &mat, Mtl *mtl); void getTextureMatrix(Matrix3 &mat, Mtl *mtl);
/* havok & collision */ /* havok & collision */
bool hasCollision(INode *node);
int addVertex(vector<Vector3> &verts, vector<Vector3> &vnorms, const Point3 &pt, const Point3 &norm); int addVertex(vector<Vector3> &verts, vector<Vector3> &vnorms, const Point3 &pt, const Point3 &norm);
void addFace(Triangles &tris, vector<Vector3> &verts, vector<Vector3> &vnorms, void addFace(Triangles &tris, vector<Vector3> &verts, vector<Vector3> &vnorms,
int face, const int vi[3], Mesh *mesh); int face, const int vi[3], Mesh *mesh);
......
...@@ -96,8 +96,12 @@ bool Exporter::makeMesh(NiNodeRef &parent, Mtl *mtl, FaceGroup &grp) ...@@ -96,8 +96,12 @@ bool Exporter::makeMesh(NiNodeRef &parent, Mtl *mtl, FaceGroup &grp)
data->SetVertices(grp.verts); data->SetVertices(grp.verts);
data->SetNormals(grp.vnorms); 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) if (grp.vcolors.size() > 0)
data->SetVertexColors(grp.vcolors); data->SetVertexColors(grp.vcolors);
...@@ -116,13 +120,12 @@ bool Exporter::makeMesh(NiNodeRef &parent, Mtl *mtl, FaceGroup &grp) ...@@ -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) int Exporter::addVertex(FaceGroup &grp, int face, int vi, Mesh *mesh, const Matrix3 &texm)
{ {
Point3 pt = mesh->verts[ mesh->faces[ face ].v[ vi ] ]; 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 ])); Point3 norm = getVertexNormal(mesh, face, mesh->getRVertPtr(mesh->faces[ face ].v[ vi ]));
/* uv.z = uv.x; Point3 uv;
uv.x = uv.y; if (mesh->tvFace)
uv.y = uv.z; uv = mesh->tVerts[ mesh->tvFace[ face ].t[ vi ]] * texm;
*/
VertColor col; VertColor col;
if (mVertexColors && mesh->vertCol) if (mVertexColors && mesh->vertCol)
col = mesh->vertCol[ mesh->vcFace[ face ].t[ vi ] ]; 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 ...@@ -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++) for (int i=0; i<grp.verts.size(); i++)
{ {
if (equal(grp.verts[i], pt, mWeldThresh) && 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)) 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 && if (mVertexColors && mesh->vertCol &&
(grp.vcolors[i].r!=col.x || (grp.vcolors[i].r!=col.x ||
grp.vcolors[i].g!=col.y || grp.vcolors[i].g!=col.y ||
...@@ -144,9 +149,11 @@ int Exporter::addVertex(FaceGroup &grp, int face, int vi, Mesh *mesh, const Matr ...@@ -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.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)); 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) if (mVertexColors && mesh->vertCol)
grp.vcolors.push_back(Color4(col.x, col.y, col.z, 1)); 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 ...@@ -158,11 +165,12 @@ void Exporter::addFace(FaceGroup &grp, int face, const int vi[3], Mesh *mesh, co
Triangle tri; Triangle tri;
for (int i=0; i<3; i++) 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 t1 = mesh->tvFace[ face ].getTVert(1);
DWORD t2 = mesh->tvFace[ face ].getTVert(2); DWORD t2 = mesh->tvFace[ face ].getTVert(2);
int dir = mesh->tvFace[ face ].Direction(t0, t1); int dir = mesh->tvFace[ face ].Direction(t0, t1);
*/
/* Point3 tv = mesh->verts[ mesh->faces[ face ].v[ vi[i] ] ]; // * tm; /* Point3 tv = mesh->verts[ mesh->faces[ face ].v[ vi[i] ] ]; // * tm;
tri[i] = addVertex(grp, tri[i] = addVertex(grp,
......
...@@ -153,7 +153,7 @@ int NifExport::ExtCount() ...@@ -153,7 +153,7 @@ int NifExport::ExtCount()
const TCHAR *NifExport::Ext(int n) const TCHAR *NifExport::Ext(int n)
{ {
return _T("fif"); return _T("nif");
} }
const TCHAR *NifExport::LongDesc() const TCHAR *NifExport::LongDesc()
......
...@@ -18,47 +18,59 @@ void Exporter::strippify(TriStrips &strips, vector<Vector3> &verts, vector<Vecto ...@@ -18,47 +18,59 @@ void Exporter::strippify(TriStrips &strips, vector<Vector3> &verts, vector<Vecto
tri_stripper::primitives_vector groups; tri_stripper::primitives_vector groups;
stripper.Strip(&groups); stripper.Strip(&groups);
// triangles left over
Triangles stris;
for (i=0; i<groups.size(); i++) for (i=0; i<groups.size(); i++)
{ {
if (groups[i].m_Type != tri_stripper::PT_Triangle_Strip) if (groups[i].m_Type == tri_stripper::PT_Triangle_Strip)
continue; {
strips.push_back(TriStrip(groups[i].m_Indices.size()));
strips.push_back(TriStrip(groups[i].m_Indices.size())); TriStrip &strip = strips.back();
TriStrip &strip = strips.back();
for (int j=0; j<groups[i].m_Indices.size(); j++)
for (int j=0; j<groups[i].m_Indices.size(); j++) strip[j] = groups[i].m_Indices[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) if (stris.size())
{
/* 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]; // stitch em
idcs[i * 3 + 1] = grp.faces[i][1]; TriStrip strip;
idcs[i * 3 + 2] = grp.faces[i][2]; if (strips.size() > 0)
} {
strip.push_back(strips.back()[strips.back().size()-1]);
tri_stripper stripper(idcs); strip.push_back(stris[0][0]);
}
tri_stripper::primitives_vector groups; for (i=0; i<stris.size(); i++)
stripper.Strip(&groups); {
if (i > 0)
{
strip.push_back(stris[i][0]);
strip.push_back(stris[i][0]);
}
for (i=0; i<groups.size(); i++) strip.push_back(stris[i][0]);
{ strip.push_back(stris[i][1]);
if (groups[i].m_Type != tri_stripper::PT_Triangle_Strip) strip.push_back(stris[i][2]);
continue; if (i < stris.size()-1)
strip.push_back(stris[i][2]);
strips.push_back(TriStrip(groups[i].m_Indices.size())); }
TriStrip &strip = strips.back(); strips.push_back(strip);
for (int j=0; j<groups[i].m_Indices.size(); j++)
strip[j] = groups[i].m_Indices[j];
} }
*/ }
void Exporter::strippify(TriStrips &strips, FaceGroup &grp)
{
unsigned short *data = (unsigned short *)malloc(grp.faces.size() * 3 * 2); unsigned short *data = (unsigned short *)malloc(grp.faces.size() * 3 * 2);
int i; int i;
...@@ -119,7 +131,8 @@ void Exporter::strippify(TriStrips &strips, FaceGroup &grp) ...@@ -119,7 +131,8 @@ void Exporter::strippify(TriStrips &strips, FaceGroup &grp)
grp.verts[a] = tmp.verts[b]; grp.verts[a] = tmp.verts[b];
grp.vnorms[a] = tmp.vnorms[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) if (grp.vcolors.size() > 0)
grp.vcolors[a] = tmp.vcolors[b]; grp.vcolors[a] = tmp.vcolors[b];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment