New flag: get_materials_from_prefabs
This commit is contained in:
parent
c46de6ebae
commit
c3b959f632
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "lwa_unity_unpack"
|
||||
version = "0.3.0"
|
||||
version = "0.4.0"
|
||||
edition = "2021"
|
||||
repository = "https://github.com/Leinnan/lwa_unity_unpack"
|
||||
homepage = "https://github.com/Leinnan/lwa_unity_unpack"
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@ pub struct Args {
|
|||
#[arg(short, long)]
|
||||
pub fbx_to_gltf: Option<PathBuf>,
|
||||
|
||||
/// checks if material base texture in prefabs differ from the one specified in fbx model
|
||||
/// that is converted to GLTF and overrides it with the one from prefab and copy texture to models folder
|
||||
#[arg(long, default_value = "false", default_missing_value = "true")]
|
||||
pub get_materials_from_prefabs: bool,
|
||||
|
||||
/// optional- extensions that will be ignored during unpacking
|
||||
#[arg(long, action = clap::ArgAction::Append)]
|
||||
pub ignore_extensions: Option<Vec<String>>,
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ impl Unpacker {
|
|||
}
|
||||
|
||||
pub fn update_gltf_materials(&self) {
|
||||
if self.args.fbx_to_gltf.is_none() {
|
||||
if self.args.fbx_to_gltf.is_none() || !self.args.get_materials_from_prefabs {
|
||||
return;
|
||||
}
|
||||
let fbx_models: Vec<Asset> = self
|
||||
|
|
@ -122,7 +122,7 @@ impl Unpacker {
|
|||
};
|
||||
// here we should read gltf file and replace material texture with Uri based on texture_asset
|
||||
let model_path = Path::new(&model.path).with_extension("glb");
|
||||
Self::modify_material(&model_path, Path::new(&texture_asset.path));
|
||||
Self::update_material(&model_path, Path::new(&texture_asset.path));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ impl Unpacker {
|
|||
*n = (*n + 3) & !3;
|
||||
}
|
||||
|
||||
fn modify_material(gltf_path: &Path, texture_asset: &Path) {
|
||||
fn update_material(gltf_path: &Path, texture_asset: &Path) {
|
||||
let file = fs::File::open(gltf_path).unwrap();
|
||||
let reader = io::BufReader::new(file);
|
||||
let mut gltf = gltf::Gltf::from_reader(reader).unwrap();
|
||||
|
|
@ -211,16 +211,7 @@ impl Unpacker {
|
|||
fn process_fbx_file(&self, source_asset: &Path, result_path: &Path) {
|
||||
let tool = self.args.fbx_to_gltf.clone().unwrap();
|
||||
let out_path = result_path.with_extension("");
|
||||
println!(
|
||||
"{:?}",
|
||||
&[
|
||||
"--input",
|
||||
source_asset.to_str().unwrap(),
|
||||
"--output",
|
||||
out_path.to_str().unwrap()
|
||||
]
|
||||
);
|
||||
let output = Command::new(tool)
|
||||
let _output = Command::new(tool)
|
||||
.args([
|
||||
"--input",
|
||||
source_asset.to_str().unwrap(),
|
||||
|
|
@ -230,8 +221,10 @@ impl Unpacker {
|
|||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
let output_result = String::from_utf8_lossy(&output.stdout);
|
||||
println!("output: {}", output_result);
|
||||
println!(
|
||||
"Fbx converted to GLTF: {}",
|
||||
out_path.with_extension("glb").to_str().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
fn extract_archive(archive_path: &Path, extract_to: &Path) -> io::Result<()> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue