#729: import STL 3D models (binary and ASCII)
Problem: After Effects 26 imports STL models besides glTF and OBJ; we refused .stl files, and the Media Browser and import dialog did not list them as models. Fix: a pure-Rust STL reader in effectcraft-model (binary and ASCII, detected from the contents; several ASCII solids and polygon loops; VisCAM/SolidView and Materialise Magics facet colours as plain materials; Z-up turned to the model's Y-up; faceted normals from the winding). Truncated, empty or non-finite input is an error, never a crash. .stl is now a model extension for import, probing, the Media Browser, the import dialog and the system report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9a7d3e7699
commit
5661d5111c
@@ -58,7 +58,7 @@ pub const AUDIO_EXTENSIONS: &[&str] = filmcraft_media::AUDIO_EXTENSIONS;
|
||||
pub const VIDEO_EXTENSIONS: &[&str] = &["mp4", "m4v", "mov", "mkv", "webm"];
|
||||
|
||||
/// File extensions recognised as 3D models (Advanced 3D model layers).
|
||||
pub const MODEL_EXTENSIONS: &[&str] = &["gltf", "glb", "obj"];
|
||||
pub const MODEL_EXTENSIONS: &[&str] = &["gltf", "glb", "obj", "stl"];
|
||||
|
||||
/// Whether `path` has an extension we can import.
|
||||
pub fn is_importable(path: &std::path::Path) -> bool {
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn probe(path: impl AsRef<Path>) -> Result<Footage> {
|
||||
probe_bytes(&path.to_string_lossy(), bytes.into())
|
||||
}
|
||||
|
||||
/// Probe a 3D model (glTF 2.0 / OBJ): a [`FootageKind::Model`] item whose duration is its
|
||||
/// Probe a 3D model (glTF 2.0 / OBJ / STL): a [`FootageKind::Model`] item whose duration is its
|
||||
/// longest animation. `resolve` reads sibling resources.
|
||||
pub fn probe_model(path: &str, bytes: &[u8], resolve: &dyn Fn(&str) -> Option<Vec<u8>>) -> Result<Footage> {
|
||||
let m = effectcraft_model::load(path, bytes, resolve).map_err(|e| MediaError::Decode(format!("{path}: {e}")))?;
|
||||
@@ -31,6 +31,7 @@ pub fn probe_model(path: &str, bytes: &[u8], resolve: &dyn Fn(&str) -> Option<Ve
|
||||
let dur = s.animations.iter().map(|a| a.1).fold(0.0f64, f64::max);
|
||||
let codec = match effectcraft_model::format_of(path) {
|
||||
Some("obj") => "OBJ",
|
||||
Some("stl") => "STL",
|
||||
Some("glb") => "GLB",
|
||||
_ => "glTF",
|
||||
};
|
||||
|
||||
@@ -674,3 +674,13 @@ fn conformed_flac_audio_reads_back_like_the_decoder() {
|
||||
assert_eq!(pool.audio_samples(&f, at, 4800, 48_000), decoded);
|
||||
let _ = std::fs::remove_dir_all(&folder);
|
||||
}
|
||||
|
||||
/// File ▸ Import of an STL part: importable by extension and probed as a 3D model item.
|
||||
#[test]
|
||||
fn stl_imports_as_a_model() {
|
||||
assert!(effectcraft_media::is_importable(Path::new("part.stl")));
|
||||
let ascii = "solid part\nfacet normal 0 0 1\nouter loop\nvertex 0 0 0\nvertex 1 0 0\nvertex 0 1 0\nendloop\nendfacet\nendsolid part\n";
|
||||
let f = effectcraft_media::probe_bytes("part.stl", Arc::from(ascii.as_bytes())).expect("probe");
|
||||
assert_eq!(f.kind, FootageKind::Model);
|
||||
assert_eq!(f.codec, "STL (1 meshes, 1 triangles)");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user