Skip to content

Commit

Permalink
ror exp util strPos, CopyFile
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed Feb 16, 2024
1 parent dd62267 commit 7c265f5
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 85 deletions.
28 changes: 27 additions & 1 deletion src/editor/ExportRoR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <string>
#include <map>
#include <filesystem>
#include <sstream>
namespace fs = std::filesystem;
using namespace Ogre;
using namespace std;
Expand All @@ -45,6 +46,7 @@ void CGui::btnExport(WP)
app->ror->ExportTrack();
}

// ctor
ExportRoR::ExportRoR(App* app1)
{
app = app1;
Expand All @@ -59,6 +61,30 @@ ExportRoR::ExportRoR(App* app1)
pre = data->pre;
}

// util convert SR pos to RoR pos
Ogre::String ExportRoR::strPos(Ogre::Vector3 pos)
{
stringstream ss;
ss << half - pos.z << ", " << pos.y - hmin << ", " << pos.x + half << ", ";
return ss.str();
}

// util copy file
bool ExportRoR::CopyFile(std::string from, std::string to)
{
try
{
if (!fs::exists(to.c_str()))
fs::copy_file(from.c_str(), to.c_str());
return true;
}
catch (exception ex)
{
String s = "Error copying file: " + from + "\n to: " + to + "\n " + ex.what();
gui->Exp(CGui::WARN, s);
}
}


// Export current track for Rigs Of Rods
//------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -156,7 +182,7 @@ void ExportRoR::ExportTrack() // whole, full
// 0, y, 0 = -470, y, 460
// 959, 340 y, 950 = 487, y, -472
Vector3 st = Axes::toOgre(sc->startPos[0]);
trn << "StartPosition = " << fToStr(half - st.z)+", "+fToStr(st.y - hmin)+", "+fToStr(st.x + half)+"\n";
trn << "StartPosition = " << strPos(st) + "\n";
trn << "\n";

trn << "CaelumConfigFile = " + name + ".os\n";
Expand Down
4 changes: 3 additions & 1 deletion src/editor/ExportRoR.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ class ExportRoR
float hmin = 0.f, half = 0.f; // min height, half world size
int water = 0; float Ywater = 0.f; // bool, level

Ogre::String toPos(Ogre::Vector3 pos); // util convert SR pos to RoR pos
Ogre::String strPos(Ogre::Vector3 pos); // util convert SR pos to RoR pos
bool CopyFile(std::string from, std::string to); // both args are path with filenames

public:
ExportRoR(App* app1);
void Default();

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

Expand Down
20 changes: 5 additions & 15 deletions src/editor/ExportRoR_Objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
#include "CScene.h"
#include "CData.h"
#include "TracksXml.h"
#include "PresetsXml.h"
#include "Axes.h"
#include "Road.h"
#include "TracksXml.h"

#include <Terra.h>
#include <OgreString.h>
#include <OgreImage2.h>
#include <OgreVector3.h>
Expand Down Expand Up @@ -98,19 +94,13 @@ void ExportRoR::ExportObjects()
}
if (exists)
{
try
{ // copy
to = path + mesh;
if (!fs::exists(to.c_str()))
fs::copy_file(from.c_str(), to.c_str());
// copy
to = path + mesh;
CopyFile(from, to);
if (CopyFile(from, to))
++iObjMesh;
}
catch (const fs::filesystem_error & ex)
{
String s = "Error: Copying mesh " + from + " to " + to + " failed ! \n" + ex.what();
gui->Exp(CGui::WARN, s);
else
continue;
}

// get mtr? read .mat, copy textures, write .material ...
}
Expand Down
9 changes: 7 additions & 2 deletions src/editor/ExportRoR_Road.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ using namespace std;
//------------------------------------------------------------------------------------------------------------------------
void ExportRoR::ExportRoad()
{
Ogre::Timer ti;

std::vector<string> chks;
const bool roadtxt = !scn->roads.empty();
const bool road = roadtxt && scn->roads[0]->getNumPoints() > 2;
Expand Down Expand Up @@ -106,7 +108,8 @@ void ExportRoR::ExportRoad()

// write ------
// pos
trd << half - vP.z << ", " << vP.y - hmin << ", " << vP.x + half << ", ";
// trd << half - vP.z << ", " << vP.y - hmin << ", " << vP.x + half << ", ";
trd << strPos(vP) << " ";
// rot
trd << "0, " << yaw << ", 0, "; // todo p.aRoll
trd << width << ", ";
Expand Down Expand Up @@ -155,7 +158,7 @@ void ExportRoR::ExportRoad()
Vector3 dir = vP1 - vP; // along length
float yaw = TerUtil::GetAngle(dir.x, dir.z) *180.f/PI_d - 45.f - 15.f; // par ? 45
// pos
string s = fToStr(half - vP.z) + ", " + fToStr(vP.y - hmin) + ", " + fToStr(vP.x + half) + ", ";
string s = strPos(vP) + " ";
// rot
s += "0.0, " + fToStr(yaw) + ", 0.0";
chks.push_back(s);
Expand Down Expand Up @@ -235,4 +238,6 @@ void ExportRoR::ExportRoad()
as << "\n";

as.close();

gui->Exp(CGui::INFO, "Road Time: " + fToStr(ti.getMilliseconds()/1000.f,1,3) + " s");
}
24 changes: 3 additions & 21 deletions src/editor/ExportRoR_Terrain.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
#include "pch.h"
#include "ExportRoR.h"

#include "enums.h"
#include "Def_Str.h"
#include "BaseApp.h"
#include "settings.h"
#include "paths.h"

#include "CApp.h"
#include "CGui.h"
#include "CScene.h"
#include "CData.h"
#include "TracksXml.h"
#include "PresetsXml.h"
#include "Axes.h"
#include "Road.h"
#include "TracksXml.h"

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

#include <exception>
#include <string>
Expand All @@ -39,7 +29,6 @@ void ExportRoR::ExportTerrain() // whole, full
{
Ogre::Timer ti;


// ⛰️ Heightmap convert to .raw
//------------------------------------------------------------------------------------------------------------------------
const auto& td = sc->tds[0]; // 1st ter only
Expand Down Expand Up @@ -136,20 +125,12 @@ void ExportRoR::ExportTerrain() // whole, full

String diff = d_d, norm = n_n;
string from, to;
try
{ // copy _d _n
from = pathTer + diff; to = path + diff;
if (!fs::exists(to.c_str()))
fs::copy_file(from.c_str(), to.c_str());
CopyFile(from, to);

from = pathTer + norm; to = path + norm;
if (!fs::exists(to.c_str()))
fs::copy_file(from.c_str(), to.c_str());
}
catch (const fs::filesystem_error & ex)
{
String s = "Error: Copying file " + from + " to " + to + " failed ! \n" + ex.what();
gui->Exp(CGui::WARN, s);
CopyFile(from, to);
}

// find _s for specular
Expand Down Expand Up @@ -411,4 +392,5 @@ void ExportRoR::ExportTerrain() // whole, full

otc.close();

gui->Exp(CGui::INFO, "Terrain Time: " + fToStr(ti.getMilliseconds()/1000.f,1,3) + " s");
}
44 changes: 12 additions & 32 deletions src/editor/ExportRoR_Veget.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
#include "pch.h"
#include "ExportRoR.h"

#include "enums.h"
#include "Def_Str.h"
#include "BaseApp.h"
#include "settings.h"
#include "paths.h"

#include "CApp.h"
#include "CGui.h"
#include "CScene.h"
#include "CData.h"
#include "TracksXml.h"
#include "PresetsXml.h"
#include "Axes.h"
#include "Road.h"
#include "TracksXml.h"

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

#include <exception>
#include <string>
Expand Down Expand Up @@ -128,18 +121,10 @@ void ExportRoR::ExportVeget()
//------------------------------------------------------------
String pathGrs = PATHS::Data() + "/grass/";
String grassPng = gr->material + ".png"; // same as mtr name
string from, to;
try
{ // copy _d _n
from = pathGrs + grassPng; to = path + grassPng;
if (!fs::exists(to.c_str()))
fs::copy_file(from.c_str(), to.c_str());
}
catch (const fs::filesystem_error & ex)
{
String s = "Error: Copying file " + from + " to " + to + " failed ! \n" + ex.what();
gui->Exp(CGui::WARN, s);
}

// copy _d _n
string from = pathGrs + grassPng, to = path + grassPng;
CopyFile(from, to);

// create .material for it
mat << "material " << gr->material << "\n";
Expand Down Expand Up @@ -281,21 +266,16 @@ void ExportRoR::ExportVeget()
// copy mesh from old SR ..or slow convert v2 to v1-
if (exists)
{
#if 1 // no, once for all tracks

if (once.find(mesh) == once.end())
{ once[mesh] = 1;
try
{ // copy
to = path + mesh;
if (!fs::exists(to.c_str()))
fs::copy_file(from.c_str(), to.c_str());

to = path + mesh;
if (CopyFile(from, to))
++iVegetMesh;
}
catch (const fs::filesystem_error & ex)
{
String s = "Error: Copying mesh " + from + " to " + to + " failed ! \n" + ex.what();
gui->Exp(CGui::WARN, s);
continue;
}
else
continue;
}

// get mesh mtr
Expand Down Expand Up @@ -323,7 +303,7 @@ void ExportRoR::ExportVeget()
}
// todo read .mat,
// copy textures, write .material ...

#endif

// write ------
if (l==0)
Expand Down
15 changes: 2 additions & 13 deletions src/editor/ExportRoR_WaterSky.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
#include "pch.h"
#include "ExportRoR.h"

#include "enums.h"
#include "Def_Str.h"
#include "BaseApp.h"
#include "settings.h"
#include "paths.h"
// #include "settings.h"

#include "CApp.h"
#include "CGui.h"
#include "CScene.h"
#include "CData.h"
#include "TracksXml.h"
#include "PresetsXml.h"
#include "TracksXml.h"

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

#include <string>
using namespace Ogre;
using namespace std;
Expand Down Expand Up @@ -112,7 +101,7 @@ void ExportRoR::ExportWaterSky()
os << "\n";

// clouds factor from presets.xml
auto* sky = scn->data->pre->GetSky(sc->skyMtr);
auto* sky = pre->GetSky(sc->skyMtr);
float cld = sky ? sky->clouds : 0.2f;
if (cld > 0.f)
{
Expand Down

0 comments on commit 7c265f5

Please sign in to comment.