diff --git a/README.md b/README.md index 3881ca2..d599773 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ See `checks/` for a detailed list of checks and reasonings. In summary: - **Is Binary**: Verifies the file is saved in the FBX Binary format. (Blender can't open ASCII files) - **Bounding Box**: Verifies any given mesh is not massive or tiny. This can cause "Generate Lightmap UVs" in Unity to fail. - **No Scale Compensation**: Maya animations use Scale Compensation by default. Unity (or any other tool) doesn't support this attribute. + - **No Namespaces**: Requires all model names to be exported without namespaces. ## Usage ``` diff --git a/fbx-sanitizer/src/checks/mod.rs b/fbx-sanitizer/src/checks/mod.rs index 8a5fcfb..7966b3a 100644 --- a/fbx-sanitizer/src/checks/mod.rs +++ b/fbx-sanitizer/src/checks/mod.rs @@ -7,3 +7,4 @@ pub mod no_quads; pub mod root_has_identity_transform; pub mod units_are_in_meters; pub mod no_scale_compensation; +pub mod no_namespaces; diff --git a/fbx-sanitizer/src/checks/no_namespaces.rs b/fbx-sanitizer/src/checks/no_namespaces.rs new file mode 100644 index 0000000..a954155 --- /dev/null +++ b/fbx-sanitizer/src/checks/no_namespaces.rs @@ -0,0 +1,35 @@ +use fbxcel_dom::v7400::object::TypedObjectHandle; +use fbxcel_dom::v7400::Document; +use lazy_static::lazy_static; +use regex::Regex; + +lazy_static! { + static ref RE_NAMESPACE: Regex = Regex::new(r"^(.*):.*$").unwrap(); +} + +/// Depending on your setup, Maya may or may not export namespaces within the names of objects in a +/// model. This can result in mismatches if only certain meshes have namespaces. For example, exporting +/// a rig with namespaces, but an animation pointing at that rig *without* namespaces. +/// +/// This check ensures that no namespaces are exported with a mesh. This is a sensible default as +/// namespaces are unnecessary in Unity, and just add noise. +pub fn verify(doc: &Document) -> anyhow::Result> { + let mut errors = vec![]; + + for obj in doc.objects() { + if let TypedObjectHandle::Model(model) = obj.get_typed() { + let name = model.name(); + match name { + None => {} + Some(name) => { + if RE_NAMESPACE.is_match(name) { + errors.push(format!("Objects should not be exported with namespaces: [{name}]")) + } + } + } + + } + } + + Ok(errors) +} diff --git a/fbx-sanitizer/src/main.rs b/fbx-sanitizer/src/main.rs index 121868d..9346fec 100644 --- a/fbx-sanitizer/src/main.rs +++ b/fbx-sanitizer/src/main.rs @@ -19,6 +19,7 @@ use checks::units_are_in_meters; use checks::bounding_box_size; use checks::no_scale_compensation; use itertools::Itertools; +use crate::checks::no_namespaces; fn main() { // Custom logging formatting: "[ERROR] Error text." @@ -166,6 +167,10 @@ pub fn check_fbx_file(path: &Path, args: &clap::ArgMatches) -> Result