Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

A staticFile path is found in the media folders wherever a source is resolved, a three.js shader's texture too

shinyobjectz4217941ad5f7
diff --git a/Cargo.lock b/Cargo.lock
index f9223c14..ce479c33 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -15229,6 +15229,7 @@ version = "0.1.0"
dependencies = [
"bevy",
"raea-core-program",
+ "raea-core-scene",
"raea-io-media",
"serde_json",
]
diff --git a/systems/frame/Cargo.toml b/systems/frame/Cargo.toml
index 744ea3e4..8f57b55a 100644
--- a/systems/frame/Cargo.toml
+++ b/systems/frame/Cargo.toml
@@ -13,5 +13,7 @@ native = ["dep:raea-io-media"]
[dependencies]
bevy = { version = "=0.20.0", default-features = false, features = ["std", "default_app", "3d_bevy_render", "bevy_ui"] }
raea-core-program = { path = "../../core/program" }
+# a staticFile path (/media/x) as a file: the media folders it can be in (raea-core-scene media_path)
+raea-core-scene = { path = "../../core/scene" }
serde_json = "1"
raea-io-media = { path = "../../io/media", default-features = false, optional = true }
diff --git a/systems/frame/src/lib.rs b/systems/frame/src/lib.rs
index 3cdf29c8..4795f592 100644
--- a/systems/frame/src/lib.rs
+++ b/systems/frame/src/lib.rs
@@ -272,9 +272,13 @@ pub fn image_file(world: &mut World, what: &str, p: &str) -> Result<Handle<Image
}
/// A clip's or audio row's source: `media:<sha256>` names a row of the media table (content-addressed footage, music
-/// and voice; the row holds the file's path and size), anything else is a path. The size is checked on every
+/// and voice; the row holds the file's path and size), a staticFile path (/media/x) is found in the media folders as
+/// every other source of it is (raea-core-scene media_path), anything else is a path. The size is checked on every
/// resolve (cheap); the hash was checked when the row was made (`raea media`).
pub fn resolve_src(rows: &[Tup], src: &str, dir: &Path) -> Result<PathBuf, String> {
+ if src.starts_with("/media/") {
+ return Ok(raea_core_scene::media_path(dir, src));
+ }
let Some(hash) = src.strip_prefix("media:") else { return Ok(find(dir, src)) };
let m = rows.iter().find(|t| t.kind == "media" && t.id == hash).ok_or(format!("{src}: no such row in media"))?;
// the portable decoders read the row's edit mezzanine when it has one (the platform's read the original)
diff --git a/systems/frame/tests/resolve_src.rs b/systems/frame/tests/resolve_src.rs
new file mode 100644
index 00000000..d95e81a6
--- /dev/null
+++ b/systems/frame/tests/resolve_src.rs
@@ -0,0 +1,14 @@
+//! A row's source as a file: a staticFile path (/media/x) is found in the media folders, as a material's map and every
+//! other media src is, not read as a file at the root (a three.js shader's texture once was: "/media/fonts/x.png").
+
+use raea_sys_frame::resolve_src;
+
+#[test]
+fn a_static_file_is_found_in_media() {
+ let dir = std::env::temp_dir().join(format!("raea-resolve-src-{}", std::process::id()));
+ std::fs::create_dir_all(dir.join("media/fonts")).unwrap();
+ std::fs::write(dir.join("media/fonts/x.png"), "").unwrap();
+ assert_eq!(resolve_src(&[], "/media/fonts/x.png", &dir).unwrap(), dir.join("media/fonts/x.png"));
+ // a relative path is still the edit's own
+ assert_eq!(resolve_src(&[], "media/fonts/x.png", &dir).unwrap(), dir.join("media/fonts/x.png"));
+}