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

UV fix

parent f2578f1f
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
using namespace Niflib; using namespace Niflib;
class BitmapTex;
class Exporter class Exporter
{ {
...@@ -91,9 +93,9 @@ private: ...@@ -91,9 +93,9 @@ private:
/* mesh export */ /* mesh export */
// adds a vertex to a face group if it doesn't exist yet. returns new or previous index into the // adds a vertex to a face group if it doesn't exist yet. returns new or previous index into the
// vertex array. // 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 // 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) // returns true if at least one of the colors in the group has a value != (1, 1, 1, 1)
bool hasVertexColors(FaceGroup &grp); bool hasVertexColors(FaceGroup &grp);
// creates face groups from faces with same sub material id // creates face groups from faces with same sub material id
...@@ -108,6 +110,8 @@ private: ...@@ -108,6 +110,8 @@ private:
void makeTexture(NiAVObjectRef &parent, Mtl *mtl); void makeTexture(NiAVObjectRef &parent, Mtl *mtl);
// creates a NiMaterialProperty // creates a NiMaterialProperty
void makeMaterial(NiAVObjectRef &parent, Mtl *mtl); void makeMaterial(NiAVObjectRef &parent, Mtl *mtl);
BitmapTex *getTexture(Mtl *mtl);
void getTextureMatrix(Matrix3 &mat, Mtl *mtl);
/* havok & collision */ /* havok & collision */
bool hasCollision(INode *node); bool hasCollision(INode *node);
......
...@@ -113,12 +113,16 @@ bool Exporter::makeMesh(NiNodeRef &parent, Mtl *mtl, FaceGroup &grp) ...@@ -113,12 +113,16 @@ bool Exporter::makeMesh(NiNodeRef &parent, Mtl *mtl, FaceGroup &grp)
return true; 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 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 ])); 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; 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 ] ];
...@@ -149,18 +153,24 @@ int Exporter::addVertex(FaceGroup &grp, int face, int vi, Mesh *mesh) ...@@ -149,18 +153,24 @@ int Exporter::addVertex(FaceGroup &grp, int face, int vi, Mesh *mesh)
return grp.verts.size()-1; 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; Triangle tri;
for (int i=0; i<3; i++) 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; /* Point3 tv = mesh->verts[ mesh->faces[ face ].v[ vi[i] ] ]; // * tm;
tri[i] = addVertex(grp, tri[i] = addVertex(grp,
tv, tv,
mesh->tVerts[ mesh->tvFace[ face ].t[ vi[i] ]], mesh->tVerts[ mesh->tvFace[ face ].t[ vi[i] ]],
getVertexNormal(mesh, face, mesh->getRVertPtr(mesh->faces[ face ].v[ 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); grp.faces.push_back(tri);
...@@ -190,7 +200,11 @@ bool Exporter::splitMesh(INode *node, Mesh *mesh, FaceGroups &grps, TimeValue t) ...@@ -190,7 +200,11 @@ bool Exporter::splitMesh(INode *node, Mesh *mesh, FaceGroups &grps, TimeValue t)
for (i=0; i<mesh->getNumFaces(); i++) for (i=0; i<mesh->getNumFaces(); i++)
{ {
int mtlID = (numSubMtls!=0) ? (mesh->faces[i].getMatID() % numSubMtls) : 0; 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; return true;
......
#include "pch.h" #include "pch.h"
#include "stdmat.h" #include "stdmat.h"
void Exporter::makeTexture(NiAVObjectRef &parent, Mtl *mtl) BitmapTex *Exporter::getTexture(Mtl *mtl)
{ {
if (!mtl) if (!mtl)
return; return NULL;
string mtlName = mtl->GetName();
int texMaps = mtl->NumSubTexmaps(); int texMaps = mtl->NumSubTexmaps();
if (!texMaps) if (!texMaps)
return; return NULL;
BitmapTex *bmTex = NULL; BitmapTex *bmTex = NULL;
for (int i=0; i<texMaps; i++) for (int i=0; i<texMaps; i++)
...@@ -26,6 +24,22 @@ void Exporter::makeTexture(NiAVObjectRef &parent, Mtl *mtl) ...@@ -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) if (!bmTex)
return; return;
......
...@@ -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("nif"); return _T("fif");
} }
const TCHAR *NifExport::LongDesc() const TCHAR *NifExport::LongDesc()
......
...@@ -33,6 +33,32 @@ void Exporter::strippify(TriStrips &strips, vector<Vector3> &verts, vector<Vecto ...@@ -33,6 +33,32 @@ void Exporter::strippify(TriStrips &strips, vector<Vector3> &verts, vector<Vecto
void Exporter::strippify(TriStrips &strips, FaceGroup &grp) 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); unsigned short *data = (unsigned short *)malloc(grp.faces.size() * 3 * 2);
int i; int i;
......
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