Skip to content

Commit

Permalink
ed ror 3rd tool ConvertTerrainTex
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed Feb 17, 2024
1 parent 290a891 commit b540caf
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 96 deletions.
31 changes: 21 additions & 10 deletions data/gui/Editor_Track.layout
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@
<Property key="WordWrap" value="true"/>
<Property key="VisibleHScroll" value="false"/>
<Property key="VisibleVScroll" value="true"/>
<Property key="MaxTextLength" value="24000"/>
<Property key="MaxTextLength" value="64000"/>
<Property key="TextColour" value="1.0 0.8 0.8"/>
<Property key="Colour" value="0.6 0.7 0.8"/>
<Property key="FontName" value="font.small"/>
Expand All @@ -719,19 +719,30 @@
<Property key="TextColour" value="0.5 0.7 1.0"/>
</Widget>

<Widget type="Button" skin="Button" position="312 480 180 24" name="ConvertMat4RoR">
<Property key="Caption" value="Convert materials"/>
<Property key="TextColour" value="0.9 0.7 0.9"/>
</Widget>
<!-- tools other -->
<Widget type="Button" skin="Button" position="512 480 180 24" name="ConvertTerrain4RoR">
<Property key="Caption" value="Convert terrain textures"/>
<Property key="TextColour" value="0.9 0.7 0.9"/>
<Property key="Caption" value="terrain textures"/>
<Property key="TextColour" value="0.8 1.0 0.6"/>
<Property key="Colour" value="0.8 1.0 0.6"/>
<UserString key="tip" value="Combine Stunt Rally terrain textures _d, _s, _n to _ds and _nh"/>
</Widget>
<Widget type="Button" skin="Button" position="312 450 180 24" name="ConvertMat4RoR">
<Property key="Caption" value=".materials"/>
<Property key="TextColour" value="0.6 0.9 0.9"/>
<Property key="Colour" value="0.6 0.9 0.9"/>
<UserString key="tip" value="Convert old Stunt Rally .mat to .material in RoR path, subdir materials"/>
</Widget>
<Widget type="Button" skin="Button" position="512 450 180 24" name="CreateOdef4RoR">
<Property key="Caption" value=".odef for .mesh"/>
<Property key="TextColour" value="0.9 0.8 0.6"/>
<Property key="Colour" value="0.9 0.8 0.6"/>
<UserString key="tip" value="Create .odef for all .mesh files in main RoR path subdirs"/>
</Widget>
</Widget>

<!-- Settings -->
<Widget type="TabItem" skin="" position="2 24 794 562">
<Property key="Caption" value="#C0F0F0#{Settings}"/>
<Property key="Caption" value="#C0D0E0#{Settings}"/>
<Property key="Colour" value="1 0.9 0.4"/>

<Widget type="TextBox" skin="TextBox" position="32 32 484 24">
Expand All @@ -754,9 +765,9 @@
<Property key="TextColour" value="0.9 0.95 1.0"/>
</Widget>

<Widget type="Button" skin="CheckBox" position="32 150 200 24" name="ExportOnLoad">
<Widget type="Button" skin="CheckBox" position="32 170 200 24" name="ExportOnLoad">
<Property key="Caption" value="#{ExportOnLoad}"/>
<Property key="TextColour" value="0.6 0.7 0.8"/>
<Property key="TextColour" value="0.6 0.8 0.9"/>
</Widget>

</Widget>
Expand Down
2 changes: 1 addition & 1 deletion src/editor/CGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ class CGui : public BGui

// RoR export
void btnExport(WP);
void btnConvertMat(WP), btnConvertTerrain(WP);
void btnConvertMat(WP), btnConvertTerrain(WP), btnCreateOdef(WP);

Ck ckExportOnLoad;
Ed edExportLog =0, edRoRPath =0; void editRoRPath(Ed);
Expand Down
14 changes: 9 additions & 5 deletions src/editor/ExportRoR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ void CGui::btnConvertMat(WP)
{
app->ror->ConvertMat();
}
void CGui::btnCreateOdef(WP)
{
app->ror->CreateOdef();
}


// ctor
Expand Down Expand Up @@ -213,12 +217,12 @@ void ExportRoR::ExportTrack() // whole, full
// guid ----
// hash from tacrk name
size_t hsh = std::hash<std::string>()(name);
hsh = max(0xFFFFFFFFFFFFu, hsh); // max 12 chars
char hex[32];
sprintf(hex, "%012zX", hsh);
gui->Exp(CGui::TXT, "Name hash: " + string(hex));
hsh &= 0xFFFFFFFFFFFFu; // max 12 chars
char hex[32]; sprintf(hex, "%012zX", hsh);
string shex = hex; //if (shex.length() > 12) shex = shex.substr(0,12);
gui->Exp(CGui::TXT, "Track id: " + toStr(trkId) + " Name hash: " + shex);

trn << "GUID = 11223344-5566-7788-" << fToStr(trkId,0,4,'0') <<"-"<< hex <<"\n";
trn << "GUID = 11223344-5566-7788-" << fToStr(trkId,0,4,'0') <<"-"<< shex <<"\n";
trn << "\n";

// if has groundmodel, define landuse file
Expand Down
7 changes: 4 additions & 3 deletions src/editor/ExportRoR.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class ExportRoR
void ExportRoad(); // *-road.tobj and *.as
void ExportVeget(); // *-veget.tobj and density maps *-veget?.png

// other
void ConvertTerrainTex();
void ConvertMat();
// 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
};
153 changes: 79 additions & 74 deletions src/editor/ExportRoR_Terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,91 +109,96 @@ void ExportRoR::ExportTerrain() // whole, full
{
const TerLayer& l = td.layersAll[td.layers[i]];

// diffuse _d, normal _n, specular _s
String pathTer = PATHS::Data() + "/terrain/";
String d_d, d_s, d_r, n_n, n_s;
d_d = l.texFile; // ends with _d
d_s = StringUtil::replaceAll(l.texFile,"_d.","_s."); // _s
n_n = l.texNorm; // _n
n_s = StringUtil::replaceAll(l.texNorm,"_n.","_s."); // _s

string ext = 1 ? "png" : "dds"; // todo as dds fails..
layTexDS[i] = StringUtil::replaceAll(l.texFile,"_d.jpg","_ds."+ext);
layTexNH[i] = StringUtil::replaceAll(l.texNorm,"_n.jpg","_nh."+ext);

gui->Exp(CGui::TXT, "layer " + toStr(i+1) + " diff, norm: " + d_d + " " + n_n);

String diff = d_d, norm = n_n;
string from, to;
{ // copy _d _n
from = pathTer + diff; to = path + diff;
CopyFile(from, to);

from = pathTer + norm; to = path + norm;
CopyFile(from, to);
}
//#if 0 // NO, once for all ? is black-
if (1)
{
// diffuse _d, normal _n, specular _s
String pathTer = PATHS::Data() + "/terrain/";
String d_d, d_s, d_r, n_n, n_s;
d_d = l.texFile; // ends with _d
d_s = StringUtil::replaceAll(l.texFile,"_d.","_s."); // _s
n_n = l.texNorm; // _n
n_s = StringUtil::replaceAll(l.texNorm,"_n.","_s."); // _s

gui->Exp(CGui::TXT, "layer " + toStr(i+1) + " diff, norm: " + d_d + " " + n_n);

String diff = d_d, norm = n_n;
string from, to;
if (0) // jpg not needed
{ // copy _d _n
from = pathTer + diff; to = path + diff;
CopyFile(from, to);

from = pathTer + norm; to = path + norm;
CopyFile(from, to);
}

// find _s for specular
String spec = d_s;
if (!PATHS::FileExists(pathTer + spec))
{ spec = n_s;
// find _s for specular
String spec = d_s;
if (!PATHS::FileExists(pathTer + spec))
{ spec = d_d;
gui->Exp(CGui::TXT, "layer " + toStr(i+1) + " spec: " + spec + " " + fToStr(l.tiling));
} }

// combine RGB+A diff + spec
//------------------------------------------------------------
Image2 imD, imS, imDS;
imD.load(diff, "General"); imS.load(spec, "General");
const int xx = imD.getWidth(), yy = imD.getHeight();

auto pfA = PFG_RGBA8_UNORM;
imDS.createEmptyImage(xx, yy, 1, TextureTypes::Type2D, pfA);
try
{
TextureBox tbD = imD.getData(0), tbS = imS.getData(0), tbDS = imDS.getData(0);
auto pfD = imD.getPixelFormat(), pfS = imD.getPixelFormat();
for (int y = 0; y < yy; ++y)
for (int x = 0; x < xx; ++x)
{ spec = n_s;
if (!PATHS::FileExists(pathTer + spec))
{ spec = d_d;
gui->Exp(CGui::TXT, "layer " + toStr(i+1) + " spec: " + spec + " " + fToStr(l.tiling));
} }

// combine RGB+A diff + spec
//------------------------------------------------------------
Image2 imD, imS, imDS;
imD.load(diff, "General"); imS.load(spec, "General");
const int xx = imD.getWidth(), yy = imD.getHeight();

auto pfA = PFG_RGBA8_UNORM;
imDS.createEmptyImage(xx, yy, 1, TextureTypes::Type2D, pfA);
try
{
ColourValue rgb = tbD.getColourAt(x, y, 0, pfD);
ColourValue a = tbS.getColourAt(x, y, 0, pfS) * 0.5f; // par spec mul ..
ColourValue ds(rgb.r, rgb.g, rgb.b, a.r);
tbDS.setColourAt(ds, x, y, 0, pfA);
TextureBox tbD = imD.getData(0), tbS = imS.getData(0), tbDS = imDS.getData(0);
auto pfD = imD.getPixelFormat(), pfS = imD.getPixelFormat();
for (int y = 0; y < yy; ++y)
for (int x = 0; x < xx; ++x)
{
ColourValue rgb = tbD.getColourAt(x, y, 0, pfD);
ColourValue a = tbS.getColourAt(x, y, 0, pfS) * 0.5f; // par spec mul ..
ColourValue ds(rgb.r, rgb.g, rgb.b, a.r);
tbDS.setColourAt(ds, x, y, 0, pfA);
}
imDS.save(path + layTexDS[i], 0, 0);
}
catch (exception ex)
{
gui->Exp(CGui::WARN, string("Exception in combine DS: ") + ex.what());
}
imDS.save(path + layTexDS[i], 0, 0);
}
catch (exception ex)
{
gui->Exp(CGui::WARN, string("Exception in combine DS: ") + ex.what());
}

// combine Norm+H
//------------------------------------------------------------
Image2 imN, imH, imNH;
imD.load(norm, "General"); //imS.load(spec, "General");
const int xn = imN.getWidth(), yn = imD.getHeight();

imNH.createEmptyImage(xx, yy, 1, TextureTypes::Type2D, pfA);
try
{
TextureBox tbN = imN.getData(0), tbNH = imNH.getData(0);
auto pfN = imN.getPixelFormat();
for (int y = 0; y < yn; ++y)
for (int x = 0; x < xn; ++x)
// combine Norm+H
//------------------------------------------------------------
Image2 imN, imH, imNH;
imD.load(norm, "General"); //imS.load(spec, "General");
const int xn = imN.getWidth(), yn = imD.getHeight();

imNH.createEmptyImage(xx, yy, 1, TextureTypes::Type2D, pfA);
try
{
ColourValue c = tbN.getColourAt(x, y, 0, pfN);
// const float a = 0.f;
const float a = max(0.f, 1.f - c.r - c.g); // par side ?..
ColourValue nh(c.r, c.g, c.b, a);
tbNH.setColourAt(nh, x, y, 0, pfA);
TextureBox tbN = imN.getData(0), tbNH = imNH.getData(0);
auto pfN = imN.getPixelFormat();
for (int y = 0; y < yn; ++y)
for (int x = 0; x < xn; ++x)
{
ColourValue c = tbN.getColourAt(x, y, 0, pfN);
// const float a = 0.f;
const float a = max(0.f, 1.f - c.r - c.g); // par side ?..
ColourValue nh(c.r, c.g, c.b, a);
tbNH.setColourAt(nh, x, y, 0, pfA);
}
imNH.save(path + layTexNH[i], 0, 0);
}
catch (exception ex)
{
gui->Exp(CGui::WARN, string("Exception in combine NH: ") + ex.what());
}
imNH.save(path + layTexNH[i], 0, 0);
}
catch (exception ex)
{
gui->Exp(CGui::WARN, string("Exception in combine NH: ") + ex.what());
}
}

Expand Down
Loading

0 comments on commit b540caf

Please sign in to comment.