diff --git a/apps/cli/mesh_tool/src/apps/anim.rs b/apps/cli/mesh_tool/src/apps/anim.rs new file mode 100644 index 0000000..3310f58 --- /dev/null +++ b/apps/cli/mesh_tool/src/apps/anim.rs @@ -0,0 +1,34 @@ +use crate::apps::SubApp; +use clap::Parser; + +use std::error::Error; + +use grim::{Platform, SystemInfo}; +use grim::model::*; +use grim::io::*; + +#[derive(Parser, Debug)] +pub struct AnimApp { + #[arg(help = "Path to input animation file (.gltf)", required = true)] + pub anim_path: String, + #[arg(help = "Path to output directory", required = true)] + pub output_path: String, +} + +// TODO: Get from args +const SYSTEM_INFO: SystemInfo = SystemInfo { + version: 25, + platform: Platform::X360, + endian: IOEndian::Little, +}; + +impl SubApp for AnimApp { + fn process(&mut self) -> Result<(), Box> { + let importer = GltfImporter2::new(&self.anim_path)?; + let assets = importer.process(); + + assets.dump_to_directory(&self.output_path, &SYSTEM_INFO)?; + + Ok(()) + } +} diff --git a/apps/cli/mesh_tool/src/apps/mod.rs b/apps/cli/mesh_tool/src/apps/mod.rs index 6fcbfa0..da21769 100644 --- a/apps/cli/mesh_tool/src/apps/mod.rs +++ b/apps/cli/mesh_tool/src/apps/mod.rs @@ -3,8 +3,10 @@ use std::error::Error; use grim::SystemInfo; +mod anim; mod milo2gltf; mod model2group; +use self::anim::*; use self::model2group::*; use self::milo2gltf::*; @@ -25,6 +27,8 @@ struct Options { #[derive(Subcommand, Debug)] enum SubCommand { + #[command(name = "anim", about = "Import character anims from gltf")] + Anim(AnimApp), #[command(name = "milo2gltf", about = "Convert milo to gltf")] Milo2Gltf(Milo2GltfApp), #[command(name = "model2group", about = "Convert model to milo group")] @@ -45,6 +49,7 @@ impl MeshTool { pub fn run(&mut self) -> Result<(), Box> { match &mut self.options.commands { + SubCommand::Anim(app) => app.process(), SubCommand::Milo2Gltf(app) => app.process(), SubCommand::Model2Group(app) => app.process() } diff --git a/core/grim/src/model/import.rs b/core/grim/src/model/import.rs index 6390dee..bba80a8 100644 --- a/core/grim/src/model/import.rs +++ b/core/grim/src/model/import.rs @@ -9,6 +9,7 @@ use gltf::mesh::util::*; use gltf::json::extensions::scene::*; use gltf::json::extensions::mesh::*; use gltf::scene::Node; +use crate::SystemInfo; use std::collections::{HashMap, HashSet}; use std::path::{Path, PathBuf}; @@ -30,6 +31,23 @@ pub struct MiloAssets { char_clip_samples: Vec, } +impl MiloAssets { + pub fn dump_to_directory(&self, out_dir: T, info: &SystemInfo) -> Result<(), Box> where T: AsRef { + // Create output dir + super::create_dir_if_not_exists(&out_dir)?; + + for char_clip in self.char_clip_samples.iter() { + let char_clip_dir = out_dir.as_ref().join("CharClipSamples"); + super::create_dir_if_not_exists(&char_clip_dir)?; + + let char_clip_path = char_clip_dir.join(&char_clip.name); + save_to_file(char_clip, &char_clip_path, info)?; + } + + Ok(()) + } +} + impl GltfImporter2 { pub fn new(source_path: T) -> Result where T: AsRef { let (document, buffers, images) = gltf::import(&source_path)?;