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:
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);
......
......@@ -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,
......
......@@ -153,7 +153,7 @@ int NifExport::ExtCount()
const TCHAR *NifExport::Ext(int n)
{
return _T("fif");
return _T("nif");
}
const TCHAR *NifExport::LongDesc()
......
......@@ -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];
}
......
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