From 3e9f6822aab0a6a93242c78a4a63ac429e41638a Mon Sep 17 00:00:00 2001 From: ousnius Date: Sun, 24 Jan 2016 16:57:54 +0100 Subject: [PATCH] Revert slider OBJ export --- ObjFile.cpp | 179 ++-------------------------------------------- ObjFile.h | 5 -- OutfitProject.cpp | 18 +---- OutfitStudio.cpp | 14 ---- 4 files changed, 7 insertions(+), 209 deletions(-) diff --git a/ObjFile.cpp b/ObjFile.cpp index d5484843..ab1d53fd 100644 --- a/ObjFile.cpp +++ b/ObjFile.cpp @@ -30,21 +30,6 @@ int ObjFile::AddGroup(const string& name, const vector& verts, const ve return 0; } - -int ObjFile::AddGroup(const string& name, const vector& verts, const vector& faces, const vector& uvs) { - if (name.empty() || verts.empty()) - return 1; - - ObjData* newData = new ObjData(); - newData->name = name; - newData->verts = verts; - newData->faces = faces; - newData->uvs = uvs; - - data[name] = newData; - return 0; -} - int ObjFile::LoadForNif(const string &fileName) { fstream base(fileName.c_str(), ios_base::in | ios_base::binary); if (base.fail()) @@ -188,147 +173,6 @@ int ObjFile::LoadForNif(fstream &base) { return 0; } -int ObjFile::LoadVertOrderMap(const string &fileName, map& outMap, vector& origFaces, vector& origUVs) { - fstream base(fileName.c_str(), ios_base::in | ios_base::binary); - if (base.fail()) - return 1; - - LoadVertOrderMap(base, outMap, origFaces, origUVs); - base.close(); - return 0; -} - -int ObjFile::LoadVertOrderMap(fstream &base, map& outMap, vector& origFaces, vector& origUVs) { - ObjData* di = new ObjData(); - - Vector3 v; - Vector2 uv; - Vector2 uv2; - Triangle t; - - string dump; - string curgrp; - string facept1; - string facept2; - string facept3; - string facept4; - int f[4]; - int ft[4]; - int nPoints = 0; - int v_idx[4]; - - vector verts; - vector uvs; - size_t pos; - map> vertMap; - map>::iterator savedVert; - - bool gotface = false; - - while (!base.eof()) { - if (!gotface) - base >> dump; - else - gotface = false; - - if (dump.compare("v") == 0) { - base >> v.x >> v.y >> v.z; - verts.push_back(v); - } - else if (dump.compare("g") == 0 || dump.compare("o") == 0) { - base >> curgrp; - - if (di->name != "") { - data[di->name] = di; - di = new ObjData; - } - - di->name = curgrp; - objGroups.push_back(curgrp); - } - else if (dump.compare("vt") == 0) { - base >> uv.u >> uv.v; - uv.v = 1.0f - uv.v; - uvs.push_back(uv); - origUVs.push_back(uv); - } - else if (dump.compare("f") == 0) { - base >> facept1 >> facept2 >> facept3; - pos = facept1.find('/'); - f[0] = atoi(facept1.c_str()) - 1; - ft[0] = atoi(facept1.substr(pos + 1).c_str()) - 1; - pos = facept2.find('/'); - f[1] = atoi(facept2.c_str()) - 1; - ft[1] = atoi(facept2.substr(pos + 1).c_str()) - 1; - pos = facept3.find('/'); - f[2] = atoi(facept3.c_str()) - 1; - ft[2] = atoi(facept3.substr(pos + 1).c_str()) - 1; - base >> facept4; - - if (facept4 == "f" || facept4 == "g" || facept4 == "s" || facept4 == "#") { - gotface = true; - dump = facept4; - nPoints = 3; - } - else if (facept4.length() > 0) { - pos = facept4.find('/'); - f[3] = atoi(facept4.c_str()) - 1; - ft[3] = atoi(facept4.substr(pos + 1).c_str()) - 1; - nPoints = 4; - } - - if (f[0] == -1 || f[1] == -1 || f[2] == -1) - continue; - - origFaces.emplace_back(nPoints, f, ft); - - for (int i = 0; i < nPoints; i++) { - v_idx[i] = di->verts.size(); - if ((savedVert = vertMap.find(f[i])) != vertMap.end()) { - for (int j = 0; j < savedVert->second.size(); j++) { - if (savedVert->second[j].uv == ft[i]) - v_idx[i] = savedVert->second[j].v; - else if (uvs.size() > 0) { - uv = uvs[ft[i]]; - uv2 = uvs[savedVert->second[j].uv]; - if (fabs(uv.u - uv2.u) > uvDupThreshold) { - v_idx[i] = v_idx[i]; - continue; - } - else if (fabs(uv.v - uv2.v) > uvDupThreshold) { - v_idx[i] = v_idx[i]; - continue; - } - v_idx[i] = savedVert->second[j].v; - } - } - } - - if (v_idx[i] == di->verts.size()) { - vertMap[f[i]].push_back(VertUV(v_idx[i], ft[i])); - outMap[f[i]] = di->verts.size(); - di->verts.push_back(verts[f[i]]); - if (uvs.size() > 0) { - di->uvs.push_back(uvs[ft[i]]); - } - } - } - t.p1 = v_idx[0]; - t.p2 = v_idx[1]; - t.p3 = v_idx[2]; - di->tris.push_back(t); - if (nPoints == 4) { - t.p1 = v_idx[0]; - t.p2 = v_idx[2]; - t.p3 = v_idx[3]; - di->tris.push_back(t); - } - } - } - - delete di; - return 0; -} int ObjFile::Save(const string &fileName) { ofstream file(fileName.c_str(), ios_base::binary); @@ -353,24 +197,11 @@ int ObjFile::Save(const string &fileName) { file << "vt " << d.second->uvs[i].u << " " << (1.0f - d.second->uvs[i].v) << endl; file << endl; - if (d.second->faces.size() > 0) { - for (int i = 0; i < d.second->faces.size(); i++) { - file << "f " << d.second->faces[i].p1 + 1 << "/" << d.second->faces[i].uv1 + 1 << " " - << d.second->faces[i].p2 + 1 << "/" << d.second->faces[i].uv2 + 1 << " " - << d.second->faces[i].p3 + 1 << "/" << d.second->faces[i].uv3 + 1; - if (d.second->faces[i].nPoints == 4) { - file << " " << d.second->faces[i].p4 + 1 << "/" << d.second->faces[i].uv4 + 1; - } - file << endl; - } - } - else { - for (int i = 0; i < d.second->tris.size(); i++) { - file << "f " << d.second->tris[i].p1 + 1 << "/" << d.second->tris[i].p1 + 1 << " " - << d.second->tris[i].p2 + 1 << "/" << d.second->tris[i].p2 + 1 << " " - << d.second->tris[i].p3 + 1 << "/" << d.second->tris[i].p3 + 1 - << endl; - } + for (int i = 0; i < d.second->tris.size(); i++) { + file << "f " << d.second->tris[i].p1 + 1 << "/" << d.second->tris[i].p1 + 1 << " " + << d.second->tris[i].p2 + 1 << "/" << d.second->tris[i].p2 + 1 << " " + << d.second->tris[i].p3 + 1 << "/" << d.second->tris[i].p3 + 1 + << endl; } file << endl; } diff --git a/ObjFile.h b/ObjFile.h index 1d0062c2..7b00db0c 100644 --- a/ObjFile.h +++ b/ObjFile.h @@ -25,7 +25,6 @@ struct ObjData { vector verts; vector tris; vector uvs; - vector faces; // only for quad support during special output operations. }; class ObjFile { @@ -41,7 +40,6 @@ class ObjFile { ~ObjFile(); int AddGroup(const string& name, const vector& verts, const vector& tris, const vector& uvs); - int AddGroup(const string& name, const vector& verts, const vector& faces, const vector& uvs); void SetScale(const Vector3& inScale) { scale = inScale; } void SetOffset(const Vector3& inOffset) { offset = inOffset; } @@ -49,9 +47,6 @@ class ObjFile { int LoadForNif(const string& fileName); int LoadForNif(fstream& base); - int LoadVertOrderMap(const string& fileName, map& outMap, vector& origFaces, vector& origUVs); - int LoadVertOrderMap(fstream& base, map& outMap, vector& origFaces, vector& origUVs); - int Save(const string& fileName); bool CopyDataForGroup(const string& name, vector* v, vector* t, vector* uv); diff --git a/OutfitProject.cpp b/OutfitProject.cpp index eac88ec9..c723ec5b 100644 --- a/OutfitProject.cpp +++ b/OutfitProject.cpp @@ -730,6 +730,7 @@ int OutfitProject::SaveSliderOBJ(const string& sliderName, const string& shapeNa vector tris; const vector* verts = workNif.GetRawVertsForShape(shapeName); workNif.GetTrisForShape(shapeName, &tris); + const vector* uvs = workNif.GetUvsForShape(shapeName); vector outVerts = *verts; @@ -740,24 +741,9 @@ int OutfitProject::SaveSliderOBJ(const string& sliderName, const string& shapeNa else morpher.ApplyResultToVerts(sliderName, target, &outVerts); - - string mapfn = wxFileSelector("Choose vertex map source .obj", wxEmptyString, wxEmptyString, ".obj", "*.obj", wxFD_OPEN | wxFD_FILE_MUST_EXIST, owner); - if (mapfn.empty()) - return 1; - - map orderMap; - vector origFaces; - vector origUvs; - ObjFile orderFile; - orderFile.LoadVertOrderMap(mapfn, orderMap, origFaces, origUvs); - - vector swizzleverts(orderMap.size()); - for (int i = 0; i < orderMap.size(); i++) - swizzleverts[i] = outVerts[orderMap[i]]; - ObjFile obj; obj.SetScale(Vector3(0.1f, 0.1f, 0.1f)); - obj.AddGroup(shapeName, swizzleverts, origFaces, origUvs); + obj.AddGroup(shapeName, outVerts, tris, *uvs); if (obj.Save(fileName)) return 1; diff --git a/OutfitStudio.cpp b/OutfitStudio.cpp index 57cf0701..14acea29 100644 --- a/OutfitStudio.cpp +++ b/OutfitStudio.cpp @@ -2559,7 +2559,6 @@ void OutfitStudio::OnSliderExportOBJ(wxCommandEvent& WXUNUSED(event)) { } } else { - /* string fn = wxFileSelector("Export .obj slider data", wxEmptyString, wxEmptyString, ".obj", "*.obj", wxFD_SAVE | wxFD_OVERWRITE_PROMPT, this); if (fn.empty()) return; @@ -2569,19 +2568,6 @@ void OutfitStudio::OnSliderExportOBJ(wxCommandEvent& WXUNUSED(event)) { wxLogError("Failed to export OBJ file '%s'!", fn); wxMessageBox("Failed to export OBJ file!", "Error", wxICON_ERROR); } - */ - // TEMPORARY bulk slider export - string dir = wxDirSelector("Export .obj slider data to directory", wxEmptyString, wxDD_DIR_MUST_EXIST, wxDefaultPosition, this); - vector sliderNames; - project->GetSliderList(sliderNames); - - for (auto s : sliderNames) { - statusBar->SetStatusText("Exporting " + s); - string fn = dir; - fn += "\\" + s + ".obj"; - project->SaveSliderOBJ(s, activeItem->shapeName, fn); - - } statusBar->SetStatusText("Ready!"); }