Skip to content

Commit

Permalink
split_smd: print some more errors just in case
Browse files Browse the repository at this point in the history
  • Loading branch information
khanghugo committed Nov 7, 2024
1 parent cc21c33 commit ef0dccb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/gui/programs/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Default for Misc {
impl Misc {
fn split_model(&mut self, ui: &mut eframe::egui::Ui) {
ui.label("Split model").on_hover_text(
"Splits a complete .qc linked with some smds to produce more smds with less triangles",
"Splits a complete .qc linked with ONE smd to produce more smds with less triangles",
);
egui::Grid::new("split_model")
.num_columns(2)
Expand Down
34 changes: 31 additions & 3 deletions src/modules/split_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ pub fn split_smd(smd_path: &str) -> eyre::Result<()> {
let smd_path = PathBuf::from(smd_path);
let smd_file_name = smd_path.file_stem().unwrap().to_str().unwrap();

if !smd_path.exists() {
return err!("{} does not exist", smd_path.display());
}

if smd_path.extension().is_none() || smd_path.extension().unwrap() != "smd" {
return err!("{} is not a .smd file", smd_path.display());
}

let smd = Smd::from_file(&smd_path)?;

let smds = maybe_split_smd(&smd);
Expand All @@ -36,8 +44,17 @@ pub fn split_smd(smd_path: &str) -> eyre::Result<()> {
/// That SMD file must be under the $body command
///
/// THe QC file must contain $modelname, $cd, and $cdtexture
pub fn split_model(qc_path: &str) -> eyre::Result<()> {
let qc_path = PathBuf::from(qc_path);
pub fn split_model(qc_path_str: &str) -> eyre::Result<()> {
let qc_path = PathBuf::from(qc_path_str);

if !qc_path.exists() {
return err!("{} does not exist", qc_path_str);
}

if qc_path.extension().is_none() || qc_path.extension().unwrap() != "qc" {
return err!("{} is not a .qc file", qc_path.display());
}

let qc_file_name = qc_path.file_stem().unwrap().to_str().unwrap();

let qc = Qc::from_file(&qc_path)?;
Expand Down Expand Up @@ -78,6 +95,7 @@ pub fn split_model(qc_path: &str) -> eyre::Result<()> {
return err!("Does not contain $cdtexture");
}

// this mean this only supports 1 smd mesh for now
let body = qc.commands().iter().find_map(|command| {
if let qc::QcCommand::Body(x) = command {
Some(x)
Expand All @@ -94,7 +112,17 @@ pub fn split_model(qc_path: &str) -> eyre::Result<()> {
let body = body.unwrap();
let modelname = modelname.unwrap();

let smd = Smd::from_file(cd.join(body.mesh.clone()).with_extension("smd"))?;
let smd_path = cd.join(body.mesh.clone()).with_extension("smd");

if !smd_path.exists() {
return err!(
"Linked smd file `{}` with path `{}` does not exist",
body.mesh,
smd_path.display()
);
}

let smd = Smd::from_file(smd_path)?;
let smd_file_name = body.mesh.clone();

// this just conveniently fixes lots of things soooooooooooooooooo
Expand Down

0 comments on commit ef0dccb

Please sign in to comment.