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.

BL37, BL39, GD9, GD12: eleven new duplicate groups folded or written plainly (tools/dupes.sh: L1 counted 300 exact and 64 near against main's 294 and 59). Godot's pins are six consts, not two closures building them; a material's numbers read one table of defaults; scene export counts instances in the loop that lists what doesn't cross; a track no longer returns early when every channel holds still (each channel is skipped then anyway); an edit pushes itself onto the list; a shot's flags are a map and --transparent a field. Tests: apps/engines (15), apps/interchange (9)

shinyobjectzdfb13e6ec96f
diff --git a/apps/engines/src/godot.rs b/apps/engines/src/godot.rs
index bf24b3c5..57fd2d85 100644
--- a/apps/engines/src/godot.rs
+++ b/apps/engines/src/godot.rs
@@ -27,6 +27,7 @@ fn raea_base() -> String {
}
/// One platform's download: who built it, the asset, its sha256 and size, and the program inside its one top folder.
+#[derive(Clone, Copy)]
struct Pin {
by: &'static str,
asset: &'static str,
@@ -44,6 +45,14 @@ impl Pin {
}
}
+// raea's Mac build is arm64 and notarized; GodotJS's a universal app, ad-hoc signed
+const MAC_RAEA: Pin = Pin { by: "raea", asset: "godot-4.6.1-raea-macos-arm64.zip", sha256: "17e66b8f99134a67db29ce82b88ace7f4c2e4ae651c80a3876ac6bd5e68a8a75", size: 69_132_728, program: "Godot.app/Contents/MacOS/Godot" };
+const MAC_GODOTJS: Pin = Pin { by: "GodotJS", asset: "macos-editor-app-4.6.1-jsc.zip", sha256: "8a3022cb07c9740b2acc4a0b6bba6be78fb2fe46ba172b13abd51e6829cdca95", size: 143_940_673, program: "Godot.app/Contents/MacOS/Godot" };
+const LINUX_RAEA: Pin = Pin { by: "raea", asset: "godot-4.6.1-raea-linux-x86_64.zip", sha256: "9c86b3e6af0f8cc8a7158685103ccbe15d10aaf246067ec47509909647726b54", size: 78_737_822, program: "godot.linuxbsd.editor.x86_64" };
+const LINUX_GODOTJS: Pin = Pin { by: "GodotJS", asset: "linux-editor-4.6.1-qjs-ng.zip", sha256: "daa91d6cff5862ed9e0b3776694fbe4ea0ebb474d244f46ffb3aa5af0318989d", size: 78_737_089, program: "godot.linuxbsd.editor.x86_64" };
+const WINDOWS_RAEA: Pin = Pin { by: "raea", asset: "godot-4.6.1-raea-windows-x86_64.zip", sha256: "cf360e7a350f04a1cdb8d1ac475ebfc81518b5b49831ab2ed693f5d8127265e5", size: 73_171_472, program: "godot.windows.editor.x86_64.exe" };
+const WINDOWS_GODOTJS: Pin = Pin { by: "GodotJS", asset: "windows-editor-4.6.1-qjs-ng.zip", sha256: "041b761a945b6a34d40f508dbd1accca462d943d2941c3a1a4568f84dd29c1d4", size: 83_915_786, program: "godot.windows.editor.x86_64.exe" };
+
fn pins() -> R<Vec<Pin>> {
pins_for(std::env::consts::OS, std::env::consts::ARCH)
}
@@ -52,21 +61,11 @@ fn pins() -> R<Vec<Pin>> {
/// builds are among its files still installs). Both hold the program at the same path. A platform GodotJS doesn't
/// build for is told how to bring its own build (GD2), never given a stock Godot.
fn pins_for(os: &str, arch: &str) -> R<Vec<Pin>> {
- let raea = |asset, sha256, size, program| Pin { by: "raea", asset, sha256, size, program };
- let theirs = |asset, sha256, size, program| Pin { by: "GodotJS", asset, sha256, size, program };
- // GodotJS's Mac build: a universal app, ad-hoc signed; raea's: arm64, notarized
- let mac = theirs("macos-editor-app-4.6.1-jsc.zip", "8a3022cb07c9740b2acc4a0b6bba6be78fb2fe46ba172b13abd51e6829cdca95", 143_940_673, "Godot.app/Contents/MacOS/Godot");
match (os, arch) {
- ("macos", "aarch64") => Ok(vec![raea("godot-4.6.1-raea-macos-arm64.zip", "17e66b8f99134a67db29ce82b88ace7f4c2e4ae651c80a3876ac6bd5e68a8a75", 69_132_728, "Godot.app/Contents/MacOS/Godot"), mac]),
- ("macos", _) => Ok(vec![mac]),
- ("linux", "x86_64") => Ok(vec![
- raea("godot-4.6.1-raea-linux-x86_64.zip", "9c86b3e6af0f8cc8a7158685103ccbe15d10aaf246067ec47509909647726b54", 78_737_822, "godot.linuxbsd.editor.x86_64"),
- theirs("linux-editor-4.6.1-qjs-ng.zip", "daa91d6cff5862ed9e0b3776694fbe4ea0ebb474d244f46ffb3aa5af0318989d", 78_737_089, "godot.linuxbsd.editor.x86_64"),
- ]),
- ("windows", "x86_64") => Ok(vec![
- raea("godot-4.6.1-raea-windows-x86_64.zip", "cf360e7a350f04a1cdb8d1ac475ebfc81518b5b49831ab2ed693f5d8127265e5", 73_171_472, "godot.windows.editor.x86_64.exe"),
- theirs("windows-editor-4.6.1-qjs-ng.zip", "041b761a945b6a34d40f508dbd1accca462d943d2941c3a1a4568f84dd29c1d4", 83_915_786, "godot.windows.editor.x86_64.exe"),
- ]),
+ ("macos", "aarch64") => Ok(vec![MAC_RAEA, MAC_GODOTJS]),
+ ("macos", _) => Ok(vec![MAC_GODOTJS]),
+ ("linux", "x86_64") => Ok(vec![LINUX_RAEA, LINUX_GODOTJS]),
+ ("windows", "x86_64") => Ok(vec![WINDOWS_RAEA, WINDOWS_GODOTJS]),
(os, arch) => Err(format!("GodotJS has no build for {os} {arch}: build it (github.com/godotjs/GodotJS) and `git config --global raea.godot PATH`")),
}
}
@@ -75,8 +74,8 @@ fn pins_for(os: &str, arch: &str) -> R<Vec<Pin>> {
/// downloads again.
fn own_is_pinned() -> bool {
let Some(text) = own_dir("godot").ok().and_then(|d| std::fs::read_to_string(d.join("raea.json")).ok()) else { return false };
- let had = serde_json::from_str::<serde_json::Value>(&text).ok().and_then(|v| v["sha256"].as_str().map(str::to_string));
- pins().is_ok_and(|ps| ps.iter().any(|p| had.as_deref() == Some(p.sha256)))
+ let Ok(had) = serde_json::from_str::<serde_json::Value>(&text) else { return false };
+ pins().is_ok_and(|ps| ps.iter().any(|p| had["sha256"] == p.sha256))
}
/// The Godot to use and where it came from: `git config --global raea.godot` (a GodotJS build of your own), else
diff --git a/apps/engines/src/shot.rs b/apps/engines/src/shot.rs
index 0d9c7f5e..da2e77a1 100644
--- a/apps/engines/src/shot.rs
+++ b/apps/engines/src/shot.rs
@@ -5,6 +5,7 @@
//! raea godot shot SCRIPT.ts|res://SCENE.tscn [--project DIR] -o DIR --frames N [--fps F] [--size WxH] [--scene res://X]
//! [--timeout S] [-- ARGS]
+use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use serde_json::json;
@@ -23,42 +24,36 @@ struct Shot {
frames: u32,
fps: f64,
size: (u32, u32),
- flags: Vec<(String, Option<String>)>,
+ transparent: bool,
+ /// the flags that take a value, by name
+ flags: BTreeMap<String, String>,
rest: Vec<String>,
}
-impl Shot {
- fn flag(&self, k: &str) -> Option<&str> {
- self.flags.iter().find(|(f, _)| f == k).and_then(|(_, v)| v.as_deref())
- }
- fn has(&self, k: &str) -> bool {
- self.flags.iter().any(|(f, _)| f == k)
- }
-}
-
/// args[2] the source, then the flags (each taking a value but --transparent), then -- and the script's own.
fn parse(args: &[String], usage: &str) -> R<Shot> {
let src = args.get(2).filter(|a| !a.starts_with('-')).ok_or(usage)?.clone();
- let mut flags = Vec::new();
- let mut rest = Vec::new();
+ let (mut flags, mut rest, mut transparent) = (BTreeMap::new(), Vec::new(), false);
let mut it = args[3..].iter();
while let Some(a) = it.next() {
match a.as_str() {
"--" => rest.extend(it.by_ref().cloned()),
- "--transparent" => flags.push((a.clone(), None)),
- f if f.starts_with('-') => flags.push((a.clone(), Some(it.next().ok_or_else(|| format!("{a} needs a value: {usage}"))?.clone()))),
+ "--transparent" => transparent = true,
+ f if f.starts_with('-') => _ = flags.insert(a.clone(), it.next().ok_or_else(|| format!("{a} needs a value: {usage}"))?.clone()),
_ => return Err(format!("{a}: not a flag of this verb: {usage}")),
}
}
- let get = |k: &str| flags.iter().find(|(f, _): &&(String, Option<String>)| f == k).and_then(|(_, v)| v.clone());
- let out = std::path::absolute(get("-o").ok_or(usage)?).map_err(|e| e.to_string())?;
- let frames = get("--frames").and_then(|n| n.parse().ok()).filter(|n| *n > 0).ok_or("--frames needs a number of frames over 0")?;
- let fps = get("--fps").map_or(Ok(30.0), |f| f.parse::<f64>().ok().filter(|f| *f > 0.0).ok_or("--fps needs frames a second"))?;
- let size = match get("--size") {
+ let out = std::path::absolute(flags.get("-o").ok_or(usage)?).map_err(|e| e.to_string())?;
+ let frames = flags.get("--frames").and_then(|n| n.parse().ok()).filter(|n| *n > 0).ok_or("--frames needs a number of frames over 0")?;
+ let fps: f64 = match flags.get("--fps") {
+ Some(f) => f.parse().ok().filter(|f: &f64| *f > 0.0).ok_or("--fps needs frames a second")?,
+ None => 30.0,
+ };
+ let size = match flags.get("--size") {
Some(s) => s.split_once('x').and_then(|(w, h)| Some((w.parse().ok()?, h.parse().ok()?))).ok_or("--size needs WxH")?,
None => (1920, 1080),
};
- Ok(Shot { src, out, frames, fps, size, flags, rest })
+ Ok(Shot { src, out, frames, fps, size, transparent, flags, rest })
}
/// The frames a run wrote in `dir` (Blender's 0001.png on, Godot's f00000000.png on), by their number: the first
@@ -102,16 +97,16 @@ pub fn blender(args: &[String]) -> R<String> {
let s = parse(args, BLENDER_USAGE)?;
let src = std::path::absolute(&s.src).map_err(|e| e.to_string())?;
let is_blend = s.src.ends_with(".blend");
- let file = if is_blend { Some(src.clone()) } else { s.flag("--file").map(PathBuf::from) };
+ let file = if is_blend { Some(src.clone()) } else { s.flags.get("--file").map(PathBuf::from) };
if let Some(f) = file.as_ref().filter(|f| !f.is_file()) {
return Err(format!("{}: no such .blend", f.display()));
}
fresh(&s.out)?;
- let mut opts = json!({ "out": s.out.to_string_lossy(), "frames": s.frames, "fps": s.fps, "width": s.size.0, "height": s.size.1, "transparent": s.has("--transparent") });
- if let Some(e) = s.flag("--engine") {
+ let mut opts = json!({ "out": s.out.to_string_lossy(), "frames": s.frames, "fps": s.fps, "width": s.size.0, "height": s.size.1, "transparent": s.transparent });
+ if let Some(e) = s.flags.get("--engine").map(String::as_str) {
opts["engine"] = json!(e);
}
- if let Some(n) = s.flag("--samples") {
+ if let Some(n) = s.flags.get("--samples").map(String::as_str) {
opts["samples"] = json!(n.parse::<u32>().map_err(|_| "--samples needs a whole number")?);
}
let shoot = "import { shoot } from \"@raea/blender/shoot\";\nconst call = (globalThis as any).__raea_call;\n";
@@ -122,7 +117,7 @@ pub fn blender(args: &[String]) -> R<String> {
format!("import * as M from {};\n{shoot}{}.then(() => shoot({opts})){}\n", blender_ts::spec(&ts), blender_ts::DEFAULT, blender_ts::CLOSE)
};
let mut rest = s.rest.clone();
- let secs = s.flag("--timeout").and_then(|t| t.parse().ok()).unwrap_or_else(|| blender_ts::timeout(&mut rest));
+ let secs = s.flags.get("--timeout").map(String::as_str).and_then(|t| t.parse().ok()).unwrap_or_else(|| blender_ts::timeout(&mut rest));
let code = blender_ts::session(&entry, file.as_deref(), &rest, secs)?;
if code != 0 {
return Err(format!("{} ended with exit {code}", s.src));
@@ -165,12 +160,12 @@ pub fn godot(args: &[String]) -> R<String> {
let none = raea_io_home::home().join("sdk/godot/src/host/none.ts");
let (script, scene) = match s.src.strip_prefix("res://") {
Some(_) => (none.to_string_lossy().into_owned(), Some(s.src.clone())),
- None => (s.src.clone(), s.flag("--scene").map(str::to_string)),
+ None => (s.src.clone(), s.flags.get("--scene").cloned()),
};
fresh(&s.out)?;
let mut run = vec!["godot".to_string(), "run".into(), script, "--movie".into(), s.out.join("f.png").to_string_lossy().into_owned()];
run.extend(["--fps".into(), s.fps.round().to_string(), "--frames".into(), s.frames.to_string()]);
- let _over = match s.flag("--project") {
+ let _over = match s.flags.get("--project").map(String::as_str) {
Some(p) => {
run.extend(["--project".into(), p.to_string()]);
Some(Override::set(Path::new(p), s.size)?)
@@ -183,7 +178,7 @@ pub fn godot(args: &[String]) -> R<String> {
if let Some(sc) = scene {
run.extend(["--scene".into(), sc]);
}
- if let Some(t) = s.flag("--timeout") {
+ if let Some(t) = s.flags.get("--timeout").map(String::as_str) {
run.extend(["--timeout".into(), t.to_string()]);
}
if !s.rest.is_empty() {
@@ -231,6 +226,6 @@ mod tests {
assert!(parse(&a("blender shot x.ts --frames 3"), BLENDER_USAGE).is_err());
assert!(parse(&a("blender shot x.ts -o d"), BLENDER_USAGE).unwrap_err().contains("--frames"));
let s = parse(&a("godot shot res://m.tscn -o d --frames 4 --size 640x360 --project p -- go"), GODOT_USAGE).unwrap();
- assert_eq!((s.frames, s.size, s.flag("--project"), s.rest.clone()), (4, (640, 360), Some("p"), vec!["go".to_string()]));
+ assert_eq!((s.frames, s.size, s.flags.get("--project").map(String::as_str), s.rest.clone()), (4, (640, 360), Some("p"), vec!["go".to_string()]));
}
}
diff --git a/apps/interchange/src/back.rs b/apps/interchange/src/back.rs
index 4b65bed1..dd718c05 100644
--- a/apps/interchange/src/back.rs
+++ b/apps/interchange/src/back.rs
@@ -35,8 +35,9 @@ fn turned(a: &[f64], b: &[f64]) -> f64 {
2.0 * d.acos().to_degrees()
}
-fn edit(part: &Value, what: &str, prop: &str, from: Value, to: Value, said: String) -> Value {
- json!({ "id": part["id"], "name": part["source"]["name"], "loc": part["source"]["loc"], "change": what, "prop": prop, "from": from, "to": to, "says": said })
+/// One edit onto the list: the part, what changed, the prop with its old and new values, and the line said for it.
+fn edit(out: &mut Vec<Value>, part: &Value, what: &str, prop: &str, from: Value, to: Value, said: String) {
+ out.push(json!({ "id": part["id"], "name": part["source"]["name"], "loc": part["source"]["loc"], "change": what, "prop": prop, "from": from, "to": to, "says": said }));
}
fn surface(p: &Value, sent: &Value, now: &Value, out: &mut Vec<Value>) {
@@ -46,17 +47,17 @@ fn surface(p: &Value, sent: &Value, now: &Value, out: &mut Vec<Value>) {
if let (Some(a), Some(b)) = (sent["color"].as_str(), now["color"].as_str())
&& !a.eq_ignore_ascii_case(b)
{
- out.push(edit(p, "recoloured", "color", json!(a), json!(b), format!("color {a} -> {b}")));
+ edit(out, p, "recoloured", "color", json!(a), json!(b), format!("color {a} -> {b}"));
}
for (k, prop) in [("roughness", "roughness"), ("metallic", "metalness"), ("intensity", "intensity")] {
if let (Some(a), Some(b)) = (sent[k].as_f64(), now[k].as_f64())
&& (a - b).abs() > 0.005 * a.abs().max(1.0)
{
- out.push(edit(p, if k == "intensity" { "relit" } else { "resurfaced" }, prop, json!(r4(a)), json!(r4(b)), format!("{prop} {} -> {}", r4(a), r4(b))));
+ edit(out, p, if k == "intensity" { "relit" } else { "resurfaced" }, prop, json!(r4(a)), json!(r4(b)), format!("{prop} {} -> {}", r4(a), r4(b)));
}
}
if now["emissive"].as_str().is_some() && sent["emissive"].as_str() != now["emissive"].as_str() {
- out.push(edit(p, "glows", "emissive", sent["emissive"].clone(), now["emissive"].clone(), format!("emissive {} -> {}", sent["emissive"].as_str().unwrap_or("none"), now["emissive"].as_str().unwrap_or("none"))));
+ edit(out, p, "glows", "emissive", sent["emissive"].clone(), now["emissive"].clone(), format!("emissive {} -> {}", sent["emissive"].as_str().unwrap_or("none"), now["emissive"].as_str().unwrap_or("none")));
}
}
@@ -64,15 +65,15 @@ fn placement(p: &Value, a: &[f64], b: &[f64], out: &mut Vec<Value>) {
let d = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
if d.iter().any(|x| x.abs() > 1e-3) {
let to = [r4(b[0]), r4(b[1]), r4(b[2])];
- out.push(edit(p, "moved", "position", json!([r4(a[0]), r4(a[1]), r4(a[2])]), json!(to), format!("moved by [{}, {}, {}] to {to:?} (world)", r4(d[0]), r4(d[1]), r4(d[2]))));
+ edit(out, p, "moved", "position", json!([r4(a[0]), r4(a[1]), r4(a[2])]), json!(to), format!("moved by [{}, {}, {}] to {to:?} (world)", r4(d[0]), r4(d[1]), r4(d[2])));
}
if turned(&a[3..7], &b[3..7]) > 0.05 {
let e = euler_xyz(&b[3..7]);
- out.push(edit(p, "turned", "rotation", json!(euler_xyz(&a[3..7])), json!(e), format!("turned {:.1} degrees: rotation {e:?} (radians, X Y Z; world), quaternion [{}, {}, {}, {}]", turned(&a[3..7], &b[3..7]), r4(b[3]), r4(b[4]), r4(b[5]), r4(b[6]))));
+ edit(out, p, "turned", "rotation", json!(euler_xyz(&a[3..7])), json!(e), format!("turned {:.1} degrees: rotation {e:?} (radians, X Y Z; world), quaternion [{}, {}, {}, {}]", turned(&a[3..7], &b[3..7]), r4(b[3]), r4(b[4]), r4(b[5]), r4(b[6])));
}
if (0..3).any(|k| (a[7 + k] - b[7 + k]).abs() > 1e-3 * a[7 + k].abs().max(1.0)) {
let to = [r4(b[7]), r4(b[8]), r4(b[9])];
- out.push(edit(p, "scaled", "scale", json!([r4(a[7]), r4(a[8]), r4(a[9])]), json!(to), format!("scale {to:?}")));
+ edit(out, p, "scaled", "scale", json!([r4(a[7]), r4(a[8]), r4(a[9])]), json!(to), format!("scale {to:?}"));
}
}
@@ -82,7 +83,7 @@ pub fn compare(sent: &Value, now: &Value) -> Vec<Value> {
let held: Vec<&Value> = now["parts"].as_array().into_iter().flatten().collect();
for p in sent["parts"].as_array().into_iter().flatten() {
let Some(n) = held.iter().find(|n| n["id"] == p["id"]) else {
- out.push(edit(p, "deleted", "", Value::Null, Value::Null, "deleted".into()));
+ edit(&mut out, p, "deleted", "", Value::Null, Value::Null, "deleted".into());
continue;
};
let first = p["at"].as_array().into_iter().flatten().find(|a| !a.is_null()).and_then(nums);
@@ -101,7 +102,7 @@ pub fn compare(sent: &Value, now: &Value) -> Vec<Value> {
if let (Some(a), Some(b)) = (c["fov"].as_f64(), n.get("fov").and_then(Value::as_f64))
&& (a - b).abs() > 0.05
{
- out.push(edit(&me, "lens", "fov", json!(r4(a)), json!(r4(b)), format!("fov {} -> {} (degrees, vertical)", r4(a), r4(b))));
+ edit(&mut out, &me, "lens", "fov", json!(r4(a)), json!(r4(b)), format!("fov {} -> {} (degrees, vertical)", r4(a), r4(b)));
}
}
for n in now["new"].as_array().into_iter().flatten() {
@@ -149,7 +150,11 @@ pub fn said(edits: &[Value], tsx: &Path) -> String {
return "nothing changed".into();
}
edits.iter().map(|e| {
- let who = e["name"].as_str().map(|n| format!("\"{n}\"")).unwrap_or_else(|| e["id"].as_str().unwrap_or("").to_string());
+ // the part by its name in the TSX, else by its id
+ let who = match (e["name"].as_str(), e["id"].as_str()) {
+ (Some(n), _) => format!("\"{n}\""),
+ (None, id) => id.unwrap_or("").to_string(),
+ };
let at = line_of(tsx, e).map(|l| format!(" ({l})")).unwrap_or_default();
format!("{who}{at}: {}", e["says"].as_str().unwrap_or(""))
}).collect::<Vec<_>>().join("\n")
diff --git a/apps/interchange/src/export.rs b/apps/interchange/src/export.rs
index ad11c311..c991ac63 100644
--- a/apps/interchange/src/export.rs
+++ b/apps/interchange/src/export.rs
@@ -223,12 +223,13 @@ pub fn scene(all: &[Vec<Item>], frames: &[i64], dir: &Path, out: &Path) -> R<Val
let ambient = all[0].iter().find(|i| i.kind == "ambient").map(|a| json!({ "color": hex(a.props.get("color")).unwrap_or("#ffffff".into()), "nits": light_power("ambient", &a.props) }));
// what doesn't cross, by kind, counted on the first frame
let mut left: BTreeMap<&str, usize> = BTreeMap::new();
- for i in all[0].iter().filter(|i| !matches!(i.kind, "mesh" | "model" | "directional" | "point" | "spot" | "rect" | "camera" | "ambient")) {
- *left.entry(i.kind).or_default() += 1;
- }
- let copies = all[0].iter().filter(|i| i.kind == "mesh" && i.at.is_some()).count();
- if copies > 0 {
- left.insert("instances", copies);
+ for i in &all[0] {
+ match i.kind {
+ // a mesh drawn at many places (<Instances>) crosses as its first copy only
+ "mesh" if i.at.is_some() => *left.entry("instances").or_default() += 1,
+ "mesh" | "model" | "directional" | "point" | "spot" | "rect" | "camera" | "ambient" => {}
+ k => *left.entry(k).or_default() += 1,
+ }
}
Ok(json!({ "raea": "scene/1", "frames": frames, "parts": parts, "camera": cam, "ambient": ambient, "left": left }))
}
diff --git a/apps/interchange/src/godot.rs b/apps/interchange/src/godot.rs
index b5f3dfcb..600deaf5 100644
--- a/apps/interchange/src/godot.rs
+++ b/apps/interchange/src/godot.rs
@@ -97,10 +97,11 @@ impl Tscn {
}
fn material(m: &Value) -> String {
- let f = |k: &str, d: f64| m[k].as_f64().unwrap_or(d);
- let mut s = format!("albedo_color = {}\nmetallic = {}\nroughness = {}\n", color(m["color"].as_str().unwrap_or("#cccccc"), f("opacity", 1.0)), num(f("metallic", 0.0)), num(f("roughness", 0.5)));
+ // each number the material gives, else raea's default for it
+ let f = |k: &str| m[k].as_f64().unwrap_or(match k { "opacity" | "emissive_strength" => 1.0, "roughness" => 0.5, _ => 0.0 });
+ let mut s = format!("albedo_color = {}\nmetallic = {}\nroughness = {}\n", color(m["color"].as_str().unwrap_or("#cccccc"), f("opacity")), num(f("metallic")), num(f("roughness")));
if let Some(e) = m["emissive"].as_str() {
- let _ = write!(s, "emission_enabled = true\nemission = {}\nemission_energy_multiplier = {}\n", color(e, 1.0), num(f("emissive_strength", 1.0)));
+ let _ = write!(s, "emission_enabled = true\nemission = {}\nemission_energy_multiplier = {}\n", color(e, 1.0), num(f("emissive_strength")));
}
if m["opacity"].as_f64().is_some_and(|o| o < 1.0) {
s.push_str("transparency = 1\n");
@@ -184,9 +185,6 @@ fn tracks(anim: &mut String, k: &mut usize, path: &str, at: &[Value], fps: f64,
let v: Vec<f64> = a.as_array()?.iter().filter_map(Value::as_f64).collect();
(v.len() >= 10).then(|| ((f - f0) as f64 / fps, v))
}).collect();
- if keyed.windows(2).all(|w| w[0].1 == w[1].1) {
- return;
- }
for (kind, range) in [("position_3d", 0..3), ("rotation_3d", 3..7), ("scale_3d", 7..10)] {
// a channel that holds still isn't a track: a part that only turns keys its rotation alone
if keyed.windows(2).all(|w| w[0].1[range.clone()] == w[1].1[range.clone()]) {