Resolve FBX external texture dependencies
This commit is contained in:
1 parent
7e99243a78
commit
3e30c61c71
22 files changed
+1670
-265
No files matched your search
@@ -410,15 +410,19 @@ fn validate_asset_registry(
|
||||
&format!("registry_{}", record.kind_tag.to_lowercase()),
|
||||
&record.path,
|
||||
);
|
||||
for dependency in &record.dependencies {
|
||||
add_reference(
|
||||
project_root,
|
||||
report,
|
||||
&record.path,
|
||||
None,
|
||||
"import_dependency",
|
||||
dependency,
|
||||
);
|
||||
let generated_static_manifest_owns_dependencies = record.kind_tag == "Model"
|
||||
&& record.import_settings.static_mesh_manifest_path.is_some();
|
||||
if !generated_static_manifest_owns_dependencies {
|
||||
for dependency in &record.dependencies {
|
||||
add_reference(
|
||||
project_root,
|
||||
report,
|
||||
&record.path,
|
||||
None,
|
||||
"import_dependency",
|
||||
dependency,
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(manifest) = record.import_settings.static_mesh_manifest_path.as_deref() {
|
||||
add_reference(
|
||||
@@ -791,6 +795,8 @@ struct StaticMeshManifestView {
|
||||
asset_id: String,
|
||||
source: StaticMeshSourceView,
|
||||
#[serde(default)]
|
||||
import: StaticMeshImportView,
|
||||
#[serde(default)]
|
||||
warnings: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -798,11 +804,26 @@ struct StaticMeshManifestView {
|
||||
struct StaticMeshSourceView {
|
||||
path: String,
|
||||
#[serde(default)]
|
||||
format: String,
|
||||
#[serde(default)]
|
||||
fingerprint: AssetSourceFingerprint,
|
||||
#[serde(default)]
|
||||
dependencies: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize)]
|
||||
struct StaticMeshImportView {
|
||||
#[serde(default)]
|
||||
material_policy: StaticMeshMaterialPolicyView,
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize, PartialEq, Eq)]
|
||||
enum StaticMeshMaterialPolicyView {
|
||||
#[default]
|
||||
SourceMaterials,
|
||||
AuthoringOverride,
|
||||
}
|
||||
|
||||
const STATIC_MESH_MANIFEST_SCHEMA_VERSION: u32 = 4;
|
||||
|
||||
fn validate_static_mesh_manifests(project_root: &Path, report: &mut ProjectValidationReport) {
|
||||
@@ -855,16 +876,15 @@ fn validate_static_mesh_manifests(project_root: &Path, report: &mut ProjectValid
|
||||
"static_mesh.manifest_stale",
|
||||
"static mesh source",
|
||||
);
|
||||
for dependency in manifest.source.dependencies {
|
||||
add_reference(
|
||||
project_root,
|
||||
report,
|
||||
&source,
|
||||
None,
|
||||
"import_dependency",
|
||||
&dependency,
|
||||
);
|
||||
}
|
||||
let optional_source_textures = manifest.source.format.eq_ignore_ascii_case("fbx")
|
||||
&& manifest.import.material_policy == StaticMeshMaterialPolicyView::AuthoringOverride;
|
||||
add_import_dependencies(
|
||||
project_root,
|
||||
report,
|
||||
&source,
|
||||
&manifest.source.dependencies,
|
||||
optional_source_textures,
|
||||
);
|
||||
for warning in manifest.warnings {
|
||||
report.findings.push(ProjectValidationFinding {
|
||||
severity: ValidationSeverity::Warning,
|
||||
@@ -881,6 +901,79 @@ fn validate_static_mesh_manifests(project_root: &Path, report: &mut ProjectValid
|
||||
}
|
||||
}
|
||||
|
||||
fn add_import_dependencies(
|
||||
project_root: &Path,
|
||||
report: &mut ProjectValidationReport,
|
||||
owner_path: &str,
|
||||
dependencies: &[String],
|
||||
optional_source_textures: bool,
|
||||
) {
|
||||
let mut missing = Vec::new();
|
||||
for dependency in dependencies {
|
||||
match resolve_reference(project_root, dependency) {
|
||||
Some(path) if path.is_file() => add_reference(
|
||||
project_root,
|
||||
report,
|
||||
owner_path,
|
||||
None,
|
||||
"import_dependency",
|
||||
dependency,
|
||||
),
|
||||
Some(_) => {
|
||||
report.dependencies.push(ProjectDependency {
|
||||
owner_path: owner_path.to_string(),
|
||||
owner_actor_id: None,
|
||||
kind: "import_dependency".into(),
|
||||
reference: dependency.clone(),
|
||||
});
|
||||
missing.push(dependency.clone());
|
||||
}
|
||||
None => add_reference(
|
||||
project_root,
|
||||
report,
|
||||
owner_path,
|
||||
None,
|
||||
"import_dependency",
|
||||
dependency,
|
||||
),
|
||||
}
|
||||
}
|
||||
if missing.is_empty() {
|
||||
return;
|
||||
}
|
||||
missing.sort();
|
||||
missing.dedup();
|
||||
report.findings.push(ProjectValidationFinding {
|
||||
severity: if optional_source_textures {
|
||||
ValidationSeverity::Info
|
||||
} else {
|
||||
ValidationSeverity::Error
|
||||
},
|
||||
code: "import.external_texture_missing".into(),
|
||||
source_path: owner_path.to_string(),
|
||||
owner_actor_id: None,
|
||||
reference: Some(missing.join(", ")),
|
||||
message: if optional_source_textures {
|
||||
format!(
|
||||
"{} FBX source texture(s) are unavailable and intentionally ignored by Authoring Override",
|
||||
missing.len()
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"{} required imported texture dependency file(s) do not exist",
|
||||
missing.len()
|
||||
)
|
||||
},
|
||||
repair: if optional_source_textures {
|
||||
"No action is required while Authoring Override remains active; restore the texture bundle before selecting Source Materials."
|
||||
.into()
|
||||
} else {
|
||||
"Restore the referenced texture bundle and reimport, or select Authoring Override for a deliberately untextured asset."
|
||||
.into()
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
fn validate_animation_manifests(
|
||||
project_root: &Path,
|
||||
report: &mut ProjectValidationReport,
|
||||
@@ -3192,6 +3285,118 @@ mod tests {
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
fn write_fbx_dependency_fixture(
|
||||
root: &Path,
|
||||
material_policy: &str,
|
||||
dependencies: &[&str],
|
||||
) -> PathBuf {
|
||||
let source_path = "assets/models/chair.fbx";
|
||||
std::fs::create_dir_all(root.join("assets/models")).unwrap();
|
||||
std::fs::write(root.join(source_path), b"model").unwrap();
|
||||
std::fs::write(
|
||||
root.join("assets/levels/main.scn.ron"),
|
||||
"(schema_version:4,resources:{},entities:{})",
|
||||
)
|
||||
.unwrap();
|
||||
let artifact = root.join("assets/meshes/generated/chair.static_mesh.ron");
|
||||
std::fs::create_dir_all(artifact.parent().unwrap()).unwrap();
|
||||
let dependencies = dependencies
|
||||
.iter()
|
||||
.map(|path| format!("{path:?}"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(",");
|
||||
std::fs::write(
|
||||
&artifact,
|
||||
format!(
|
||||
"(schema_version:{STATIC_MESH_MANIFEST_SCHEMA_VERSION},asset_id:\"chair\",source:(path:\"{source_path}\",format:\"fbx\",fingerprint:(byte_len:5,content_hash:\"{}\"),dependencies:[{dependencies}]),import:(material_policy:{material_policy}),warnings:[])\n",
|
||||
blake3::hash(b"model").to_hex()
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
artifact
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_materials_consolidate_missing_fbx_textures_as_one_blocker() {
|
||||
let root = fixture_root();
|
||||
write_fbx_dependency_fixture(
|
||||
&root,
|
||||
"SourceMaterials",
|
||||
&[
|
||||
"assets/models/textures/chair_diff.jpg",
|
||||
"assets/models/textures/chair_normal.exr",
|
||||
"assets/models/textures/chair_rough.exr",
|
||||
],
|
||||
);
|
||||
|
||||
let report = validate_project(&root);
|
||||
let findings = report
|
||||
.findings
|
||||
.iter()
|
||||
.filter(|finding| finding.code == "import.external_texture_missing")
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(findings.len(), 1, "{:?}", report.findings);
|
||||
assert_eq!(findings[0].severity, ValidationSeverity::Error);
|
||||
assert!(findings[0].message.starts_with("3 required"));
|
||||
assert_eq!(
|
||||
report
|
||||
.dependencies
|
||||
.iter()
|
||||
.filter(|dependency| dependency.kind == "import_dependency")
|
||||
.count(),
|
||||
3
|
||||
);
|
||||
assert!(!report.is_release_ready());
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn authoring_override_reports_missing_fbx_textures_without_blocking_or_writing() {
|
||||
let root = fixture_root();
|
||||
let artifact = write_fbx_dependency_fixture(
|
||||
&root,
|
||||
"AuthoringOverride",
|
||||
&[
|
||||
"assets/models/textures/chair_diff.jpg",
|
||||
"assets/models/textures/chair_normal.exr",
|
||||
"assets/models/textures/chair_rough.exr",
|
||||
],
|
||||
);
|
||||
let before = std::fs::read(&artifact).unwrap();
|
||||
|
||||
let report = validate_project(&root);
|
||||
|
||||
let finding = report
|
||||
.findings
|
||||
.iter()
|
||||
.find(|finding| finding.code == "import.external_texture_missing")
|
||||
.expect("Authoring Override should retain one actionable dependency state");
|
||||
assert_eq!(finding.severity, ValidationSeverity::Info);
|
||||
assert!(finding.message.contains("Authoring Override"));
|
||||
assert!(report.is_release_ready(), "{:?}", report.findings);
|
||||
assert_eq!(std::fs::read(&artifact).unwrap(), before);
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn authoring_override_does_not_downgrade_unsafe_fbx_texture_paths() {
|
||||
let root = fixture_root();
|
||||
write_fbx_dependency_fixture(
|
||||
&root,
|
||||
"AuthoringOverride",
|
||||
&["assets/models/../outside/chair.jpg"],
|
||||
);
|
||||
|
||||
let report = validate_project(&root);
|
||||
|
||||
assert!(report.findings.iter().any(|finding| {
|
||||
finding.code == "asset.unsafe_path" && finding.severity == ValidationSeverity::Error
|
||||
}));
|
||||
assert!(!report.is_release_ready());
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn same_size_static_mesh_source_change_invalidates_content_hash() {
|
||||
let root = fixture_root();
|
||||
|
||||
Reference in new issue
Block a user