Skip to content

Commit

Permalink
ed ror find mesh on old SR dirs, add only if exist
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed Feb 17, 2024
1 parent 4aae100 commit 3eba511
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 81 deletions.
32 changes: 19 additions & 13 deletions src/editor/ExportRoR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void CGui::btnCreateOdef(WP)
}


// ctor
// 🌟 ctor
ExportRoR::ExportRoR(App* app1)
{
app = app1;
Expand All @@ -71,9 +71,14 @@ ExportRoR::ExportRoR(App* app1)

data = scn->data;
pre = data->pre;

copyTerTex =1;
copyVeget =1;
copyGrass =1;
copyObjs =1;
}

// utils
// ⛓️ utils
//------------------------------------------------------------

// util convert SR pos to RoR pos
Expand All @@ -98,8 +103,8 @@ bool ExportRoR::CopyFile(const std::string& from, const std::string& to)
fs::remove(to.c_str());
fs::copy_file(from.c_str(), to.c_str());
#endif
String s = "Copied file: " + from + "\n to: " + to /*+ "\n "*/;
gui->Exp(CGui::TXT, s);
String s = "Copied: " + from + "\n to: " + to /*+ "\n "*/;
gui->Exp(CGui::DBG, s);
}
catch (exception ex)
{
Expand All @@ -111,7 +116,7 @@ bool ExportRoR::CopyFile(const std::string& from, const std::string& to)
}


// setup path, name, create dir
// ⚙️ Setup path, name, create dir
//------------------------------------------------------------
void ExportRoR::SetupPath()
{
Expand Down Expand Up @@ -214,7 +219,7 @@ void ExportRoR::ExportTrack() // whole, full
trn << "CategoryID = 129\n";
trn << "Version = " << 1 << "\n"; // todo global manual +

// guid ----
// Guid ----
// hash from tacrk name
size_t hsh = std::hash<std::string>()(name);
hsh &= 0xFFFFFFFFFFFFu; // max 12 chars
Expand Down Expand Up @@ -253,15 +258,16 @@ void ExportRoR::ExportTrack() // whole, full
trn << "[Objects]\n";
if (hasRoad)
trn << name+"-road.tobj=\n";
// if (hasVeget)
// trn << name+"-veget.tobj=\n";
// if (hasObjects)
// trn << name+"-obj.tobj=\n";
if (hasVeget)
trn << name+"-veget.tobj=\n";
if (hasObjects)
trn << name+"-obj.tobj=\n";
trn << "\n";

trn << "[Scripts]\n";
trn << name + ".as=\n";
//trn << name+".terrn.as=\n";
if (hasRoad)
{ trn << "[Scripts]\n";
trn << name + ".as=\n"; //".terrn.as=\n";
}

trn.close();

Expand Down
7 changes: 5 additions & 2 deletions src/editor/ExportRoR.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ExportRoR
class CData* data =0;
class Presets* pre =0;

bool copyTerTex, copyVeget, copyGrass, copyObjs;

// var
std::string
path, // main RoR content or mods path
Expand All @@ -33,10 +35,11 @@ class ExportRoR
bool CopyFile(const std::string& from, const std::string& to); // both args are path with filenames

public:
// 🌟 ctor
ExportRoR(App* app1);
void Default();

// main
// 🏗️ main
void ExportTrack(); // whole / full, needs paths set in settings

// parts
Expand All @@ -48,7 +51,7 @@ class ExportRoR
void ExportRoad(); // *-road.tobj and *.as
void ExportVeget(); // *-veget.tobj and density maps *-veget?.png

// tools other
// 🛠️ tools other
void CreateOdef(); // make .odef for all .mesh files in main path subdirs
void ConvertTerrainTex(); // combines _d + _s to _ds and _nh as .png
void ConvertMat(); // reads old SR .mat and saves as .material
Expand Down
70 changes: 39 additions & 31 deletions src/editor/ExportRoR_Objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@
#include "Axes.h"

#include <OgreString.h>
#include <OgreImage2.h>
#include <OgreVector3.h>
#include <OgreException.h>

#include <exception>
#include <string>
#include <map>
#include <filesystem>
namespace fs = std::filesystem;
using namespace Ogre;
using namespace std;

Expand All @@ -41,25 +36,39 @@ void ExportRoR::ExportObjects()

int iodef = 0, iObjMesh = 0;
std::map<string, int> once;
hasObjects = sc->objects.empty();
hasObjects = !sc->objects.empty();

for (const auto& o : sc->objects)
if (!o.dyn) // skip dynamic
{
Vector3 p = Axes::toOgre(o.pos);
auto q = Axes::toOgreW(o.rot);

obj << fToStr(half - p.z)+", "+fToStr(p.y - hmin)+", "+fToStr(p.x + half)+", ";
// todo fix all rot ?
// obj << fToStr(q.getPitch().valueDegrees()+90.f,0,3)+", "+fToStr(q.getYaw().valueDegrees(),0,3)+", "+fToStr(q.getRoll().valueDegrees(),0,3)+", ";
obj << fToStr(90.f,0,3)+", "+fToStr(0.f,0,3)+", "+fToStr(q.getYaw().valueDegrees(),0,3)+", ";
// todo no scale ??
obj << o.name +"\n";

const string mesh = o.name + ".mesh";

//------------------------------------------------------------
// Find mesh in old SR dirs
//------------------------------------------------------------
bool exists = 0;
string from, to;

for (auto& d : dirs)
{
string file = pSet->pathExportOldSR + d +"/"+ mesh;
if (PATHS::FileExists(file))
{ exists = 1; from = file; }
// gui->Exp(CGui::INFO, String("obj: ")+file+ " ex: "+(exists?"y":"n"));
}
if (!exists) //! skip RoR would crash
{
gui->Exp(CGui::WARN, "object not found in old SR: "+mesh);
continue;
}

if (copyObjs)
{
// object save .odef
//------------------------------------------------------------
const string mesh = o.name + ".mesh";
string odefFile = path + o.name + ".odef";
// if (!fs::exists(odefFile))
if (once.find(o.name) == once.end())
Expand All @@ -72,30 +81,18 @@ void ExportRoR::ExportObjects()
odef << "1, 1, 1\n";
odef << "\n";
odef << "beginmesh\n";
odef << "mesh " + o.name + ".mesh\n";
odef << "mesh " + mesh + "\n";
odef << "stdfriction concrete\n";
odef << "endmesh\n";
odef << "\n";
odef << "end\n";

odef.close(); ++iodef;


//------------------------------------------------------------
// Find mesh in old SR dirs
//------------------------------------------------------------
bool exists = 0;
string from, to;
for (auto& d : dirs)
{
string file = pSet->pathExportOldSR + d +"/"+ mesh;
if (PATHS::FileExists(file))
{ exists = 1; from = file; }
// gui->Exp(CGui::INFO, String("obj: ")+file+ " ex: "+(exists?"y":"n"));
}

// copy
//----------------------------------
if (exists)
{
// copy
to = path + mesh;
CopyFile(from, to);
if (CopyFile(from, to))
Expand All @@ -106,9 +103,20 @@ void ExportRoR::ExportObjects()
// get mtr? read .mat, copy textures, write .material ...
}
}
} // copyObjs

// write ------
if (exists)
{
obj << fToStr(half - p.z)+", "+fToStr(p.y - hmin)+", "+fToStr(p.x + half)+", ";
// todo fix all rot ?
// obj << fToStr(q.getPitch().valueDegrees()+90.f,0,3)+", "+fToStr(q.getYaw().valueDegrees(),0,3)+", "+fToStr(q.getRoll().valueDegrees(),0,3)+", ";
obj << "90, 0, "+fToStr(q.getYaw().valueDegrees() + 180.f, 1,4)+", "; // fix?
// todo no scale ??
obj << o.name +"\n";
}
}
obj.close();

gui->Exp(CGui::TXT, "Objects: "+toStr(sc->objects.size())+" odef: "+toStr(iodef)+" meshes: "+toStr(iObjMesh) + "\n");
gui->Exp(CGui::NOTE, "Objects: "+toStr(sc->objects.size())+" odef: "+toStr(iodef)+" meshes: "+toStr(iObjMesh) + "\n");
}
Loading

0 comments on commit 3eba511

Please sign in to comment.