Add sky dome conversion
This commit is contained in:
parent
1c07e44a00
commit
491c65a181
2 changed files with 65 additions and 0 deletions
|
@ -168,6 +168,23 @@ namespace DgfTxmConvert
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.Command("convert-bg", config =>
|
||||||
|
{
|
||||||
|
config.FullName = "Converts sky dome";
|
||||||
|
config.Description = "Converts sky dome.";
|
||||||
|
|
||||||
|
var bgPathArg = config.Argument("bgPath", "Path of the sky dome pack to extract").IsRequired();
|
||||||
|
bgPathArg.Accepts().ExistingFile();
|
||||||
|
var outBaseArg = config.Argument("outBase", "Directory to write converted files");
|
||||||
|
outBaseArg.Accepts().LegalFilePath();
|
||||||
|
config.HelpOption();
|
||||||
|
|
||||||
|
config.OnExecute(() =>
|
||||||
|
{
|
||||||
|
ExtractBg(bgPathArg.Value, outBaseArg.Value);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
app.VersionOptionFromAssemblyAttributes(System.Reflection.Assembly.GetExecutingAssembly());
|
app.VersionOptionFromAssemblyAttributes(System.Reflection.Assembly.GetExecutingAssembly());
|
||||||
app.HelpOption();
|
app.HelpOption();
|
||||||
|
|
||||||
|
@ -605,5 +622,51 @@ namespace DgfTxmConvert
|
||||||
converter.ExportTextures(sw, basePath + ".");
|
converter.ExportTextures(sw, basePath + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ExtractBg(string bgPath, string basePath = null)
|
||||||
|
{
|
||||||
|
if (basePath == null)
|
||||||
|
basePath = Path.ChangeExtension(bgPath, null);
|
||||||
|
else
|
||||||
|
basePath = Path.Combine(basePath, Path.GetFileNameWithoutExtension(bgPath));
|
||||||
|
|
||||||
|
DatReader dat = new DatReader(Utils.CheckDecompress(File.OpenRead(bgPath)));
|
||||||
|
using ObjConverter converter = new ObjConverter(dat);
|
||||||
|
string mtlPath = basePath + ".mtl";
|
||||||
|
string mtlName = Path.GetFileName(mtlPath);
|
||||||
|
for (int i = 0; i < 3; ++i)
|
||||||
|
{
|
||||||
|
using MemoryStream ms = new MemoryStream(dat.GetData(i));
|
||||||
|
DatReader innerDat = new DatReader(ms);
|
||||||
|
for (int j = 0; j < innerDat.EntriesCount; ++j)
|
||||||
|
{
|
||||||
|
using BinaryReader br = new BinaryReader(new MemoryStream(innerDat.GetData(j)));
|
||||||
|
Tdb tdb = new Tdb();
|
||||||
|
tdb.Read(br);
|
||||||
|
|
||||||
|
// Remap textures (only known for Windows version, PS2 todo when files obtained)
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
tdb.Textures[0].DatIndex = 4;
|
||||||
|
tdb.Textures[1].DatIndex = 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tdb.Textures[0].DatIndex = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
using StreamWriter sw = File.CreateText($"{basePath}.{i}_{j}.obj");
|
||||||
|
sw.WriteLine($"mtllib {mtlName}");
|
||||||
|
sw.WriteLine();
|
||||||
|
|
||||||
|
converter.ConvertObj(tdb, sw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using (StreamWriter sw = File.CreateText(mtlPath))
|
||||||
|
{
|
||||||
|
converter.ExportTextures(sw, basePath + ".", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ option.
|
||||||
- `convert-trm`: Converts train model file contents to Wavefront OBJ models.
|
- `convert-trm`: Converts train model file contents to Wavefront OBJ models.
|
||||||
- `convert-pdb`: Converts other model files to Wavefront OBJ models. Note the
|
- `convert-pdb`: Converts other model files to Wavefront OBJ models. Note the
|
||||||
corresponding texture DAT needs to be supplied as well.
|
corresponding texture DAT needs to be supplied as well.
|
||||||
|
- `convert-bg`: Converts sky dome to Wavefront OBJ models. Note only the first
|
||||||
|
far texture is extracted.
|
||||||
|
|
||||||
Other
|
Other
|
||||||
-----
|
-----
|
||||||
|
|
Loading…
Add table
Reference in a new issue