mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 21:03:47 -10:00
Fold two new copies into shared readers: keyed_vec (a camera's up, a 2D part's quat) and the sprite Tiled flags
This commit is contained in:
1 parent
5f5e7190db
commit
ced8fe55a2
4 files changed
+16
-14
No files matched your search
@@ -64,12 +64,7 @@ fn one(all: &[Vec<Item>], p: &mut Program, row: &mut BTreeMap<String, V>, k: usi
|
||||
column(p, row, id, "ortho", &its.iter().map(|c| n(&c.props, "ortho", 0.0)).collect::<Vec<_>>());
|
||||
}
|
||||
// which way is up (`up`; +Y by default): a camera that rolls, as a solved one does (raea-render's up_x/y/z, Matchmove)
|
||||
if its.iter().any(|c| c.props.get("up").is_some()) {
|
||||
let up: Vec<[f64; 3]> = its.iter().map(|c| vec3(&c.props, "up", [0.0, 1.0, 0.0])).collect();
|
||||
for (k, name) in ["up_x", "up_y", "up_z"].iter().enumerate() {
|
||||
column(p, row, id, name, &up.iter().map(|v| v[k]).collect::<Vec<_>>());
|
||||
}
|
||||
}
|
||||
keyed_vec(p, row, id, &its, "up", &["up_x", "up_y", "up_z"], &[0.0, 1.0, 0.0]);
|
||||
// a window on a larger view (`view`: its full size and this frame's offset, in frame pixels): a crop of
|
||||
// footage keeps its lens's centre (raea-render's camera view_*, Matchmove's 9:16 from 16:9)
|
||||
if its.iter().any(|c| c.props.get("view").is_some_and(Value::is_object)) {
|
||||
|
||||
@@ -29,3 +29,15 @@ pub fn tint(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, its: &[Ite
|
||||
exact(p, row, id, name, &colors.iter().map(|v| v[c]).collect::<Vec<_>>());
|
||||
}
|
||||
}
|
||||
|
||||
/// A vector prop keyed as one column per component (a camera's `up` as up_x/y/z, a 2D part's `quat` as q_x..q_w),
|
||||
/// written only when some frame sets it; a frame without it (or with the wrong length) takes `d`
|
||||
pub fn keyed_vec(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, its: &[Item], key: &str, names: &[&str], d: &[f64]) {
|
||||
if !its.iter().any(|i| i.props.contains_key(key)) {
|
||||
return;
|
||||
}
|
||||
for (k, name) in names.iter().enumerate() {
|
||||
let at = |i: &Item| i.props.get(key).and_then(Value::as_array).filter(|a| a.len() == names.len()).and_then(|a| a[k].as_f64());
|
||||
column(p, row, id, name, &its.iter().map(|i| at(i).unwrap_or(d[k])).collect::<Vec<_>>());
|
||||
}
|
||||
}
|
||||
@@ -28,12 +28,7 @@ fn place2d(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, its: &[Item
|
||||
column(p, row, id, col, &its.iter().map(|i| scale(i, k)).collect::<Vec<_>>());
|
||||
}
|
||||
// `quat`: Bevy's rotation as given, in place of `rot` (q_x q_y q_z q_w, as a 3D part's)
|
||||
if its.iter().any(|i| i.props.get("quat").is_some()) {
|
||||
let q = |i: &Item, k: usize| i.props.get("quat").and_then(|q| q.get(k)).and_then(Value::as_f64).unwrap_or(if k == 3 { 1.0 } else { 0.0 });
|
||||
for (k, col) in ["q_x", "q_y", "q_z", "q_w"].iter().enumerate() {
|
||||
column(p, row, id, col, &its.iter().map(|i| q(i, k)).collect::<Vec<_>>());
|
||||
}
|
||||
}
|
||||
keyed_vec(p, row, id, its, "quat", &["q_x", "q_y", "q_z", "q_w"], &[0.0, 0.0, 0.0, 1.0]);
|
||||
tint(p, row, id, its, color);
|
||||
}
|
||||
|
||||
|
||||
@@ -251,8 +251,8 @@ fn image_mode(json: &str) -> SpriteImageMode {
|
||||
return SpriteImageMode::Sliced(TextureSlicer { border, center_scale_mode: slice(s.get("center_scale_mode")), sides_scale_mode: slice(s.get("sides_scale_mode")), max_corner_scale: f(s, "max_corner_scale", 1.0) });
|
||||
}
|
||||
if let Some(t) = v.get("Tiled") {
|
||||
let b = |k: &str| t.get(k).and_then(|x| x.as_bool()).unwrap_or(false);
|
||||
return SpriteImageMode::Tiled { tile_x: b("tile_x"), tile_y: b("tile_y"), stretch_value: f(t, "stretch_value", 1.0) };
|
||||
let on = |k: &str| t.get(k) == Some(&serde_json::Value::Bool(true));
|
||||
return SpriteImageMode::Tiled { tile_x: on("tile_x"), tile_y: on("tile_y"), stretch_value: f(t, "stretch_value", 1.0) };
|
||||
}
|
||||
default()
|
||||
}
|
||||
Reference in new issue
Block a user