forked from StrafesNET/map-tool
map converter
This commit is contained in:
parent
fdc5cccc6d
commit
7cc018e61e
50
src/main.rs
50
src/main.rs
@ -13,7 +13,7 @@ struct Cli {
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
ConvertToSNF(PathBufList),
|
||||
ConvertToSNF(ConvertToSNFSubcommand),
|
||||
DownloadTextures(DownloadTexturesSubcommand),
|
||||
ExtractTextures(ExtractTexturesSubcommand),
|
||||
ConvertTextures(ConvertTexturesSubcommand),
|
||||
@ -23,6 +23,13 @@ enum Commands {
|
||||
WriteAttributes(WriteAttributesSubcommand),
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct ConvertToSNFSubcommand {
|
||||
#[arg(long,required=true)]
|
||||
input_files:Vec<PathBuf>,
|
||||
#[arg(long)]
|
||||
output_folder:PathBuf,
|
||||
}
|
||||
#[derive(Args)]
|
||||
struct DownloadTexturesSubcommand {
|
||||
#[arg(long,required=true)]
|
||||
@ -60,7 +67,7 @@ struct WriteAttributesSubcommand {
|
||||
fn main() -> AResult<()> {
|
||||
let cli = Cli::parse();
|
||||
match cli.command {
|
||||
Commands::ConvertToSNF(pathlist)=>convert_to_snf(pathlist.paths),
|
||||
Commands::ConvertToSNF(subcommand)=>convert_to_snf(subcommand.input_files,subcommand.output_folder),
|
||||
Commands::DownloadTextures(subcommand)=>download_textures(subcommand.roblox_files),
|
||||
Commands::ExtractTextures(subcommand)=>extract_textures(vec![subcommand.bsp_file],subcommand.vpk_dir_files),
|
||||
Commands::VPKContents(subcommand)=>vpk_contents(subcommand.input_file),
|
||||
@ -634,9 +641,44 @@ fn bsp_contents(path:PathBuf)->AResult<()>{
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn convert_to_snf(pathlist:Vec<std::path::PathBuf>)->AResult<()>{
|
||||
fn convert_to_snf(pathlist:Vec<std::path::PathBuf>,output_folder:PathBuf)->AResult<()>{
|
||||
for path in pathlist{
|
||||
let something=strafesnet_rbx_loader::read_file(path);
|
||||
let dom=strafesnet_rbx_loader::read(std::fs::File::open(path.as_path())?)?;
|
||||
let mut loader=strafesnet_deferred_loader::roblox_legacy();
|
||||
|
||||
let (texture_loader,mesh_loader)=loader.get_inner_mut();
|
||||
|
||||
let map_step1=strafesnet_rbx_loader::convert(
|
||||
&dom,
|
||||
|name|texture_loader.acquire_render_config_id(name),
|
||||
|name|mesh_loader.acquire_mesh_id(name),
|
||||
);
|
||||
|
||||
let meshpart_meshes=mesh_loader.load_meshes()?;
|
||||
|
||||
let map_step2=map_step1.add_meshpart_meshes_and_calculate_attributes(
|
||||
meshpart_meshes.into_iter().map(|(mesh_id,loader_model)|
|
||||
(mesh_id,strafesnet_rbx_loader::data::RobloxMeshBytes::new(loader_model.get()))
|
||||
)
|
||||
);
|
||||
|
||||
let (textures,render_configs)=loader.into_render_configs()?.consume();
|
||||
|
||||
let map=map_step2.add_render_configs_and_textures(
|
||||
render_configs.into_iter(),
|
||||
textures.into_iter().map(|(texture_id,texture)|
|
||||
(texture_id,match texture{
|
||||
strafesnet_deferred_loader::texture::Texture::ImageDDS(data)=>data,
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
let mut dest=output_folder.clone();
|
||||
dest.push(path.file_stem().unwrap());
|
||||
dest.set_extension("snfm");
|
||||
let file=std::fs::File::create(dest)?;
|
||||
|
||||
strafesnet_snf::map::write_map(file,map)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user