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.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
A material: row sets only the fields it gives on the part's own StandardMaterial, the rest as they were (part of #38). patch_material deserialized the given fields as a whole StandardMaterial, every field it wasn't given at its default, and applied all of them. So material-field's patch of emissive_exposure_weight also blacked out the cube's emissive and turned its black base white. On frame 0 the scene sync put the row's colours back. From frame 1 on, a render leaves an unchanged mesh alone (StillSynced), so the program route drew the cube grey (red 49) at a weight of 0.14, in stills too. Live play re-synced every frame, which hid it, and so the two routes differed on 29 of 30 frames. Each given field is now deserialized by its own type and applied to that field alone. An unknown field is refused by name.
shinyobjectzc0fd55f43d0d
diff --git a/runtime/plugins/src/reflect.rs b/runtime/plugins/src/reflect.rsindex b446ae13..1ef40831 100644--- a/runtime/plugins/src/reflect.rs+++ b/runtime/plugins/src/reflect.rs@@ -2,6 +2,7 @@//! registers (fields, shapes, roles), for the generated TypeScript.use super::*;+use bevy::reflect::structs::Struct;/// Before the first frame: every asset a handle field loaded by path, loaded with its dependencies (a material's/// textures), or the load's error.@@ -239,7 +240,16 @@ pub fn patch_material(world: &mut World, e: Entity, path: &str, json: &Value) ->}let registry = world.resource::<AppTypeRegistry>().clone();let reg = registry.read();- let v = value_of(world, ®, registration(®, path)?, path, json)?;+ // each field given, by its own type: the whole StandardMaterial deserialized from a partial one took every field+ // it wasn't given at its default, so a patch of emissive_exposure_weight blacked out the emissive (#38: a render's+ // frames after the first, which the scene sync leaves alone, drew the glowing cube grey)+ let Value::Object(given) = json else { return Err(format!("material:{path}: give its fields as an object")) };+ let TypeInfo::Struct(info) = registration(®, path)?.type_info() else { return Err(format!("material:{path}: not a struct")) };+ let mut fields = Vec::with_capacity(given.len());+ for (name, x) in given {+ let ty = info.field(name).ok_or_else(|| format!("material:{path}: no field {name}"))?.type_path();+ fields.push((name.as_str(), value_of(world, ®, registration(®, ty)?, &format!("{path}.{name}"), x)?));+ }let Some(h) = world.get::<MeshMaterial3d<StandardMaterial>>(e).map(|m| m.0.clone()) else {return Err(format!("material:{path}: the part has no StandardMaterial"));};@@ -254,5 +264,9 @@ pub fn patch_material(world: &mut World, e: Entity, path: &str, json: &Value) ->};let mut mats = world.resource_mut::<Assets<StandardMaterial>>();let Some(mut m) = mats.get_mut(&h) else { return Err(format!("material:{path}: its material isn't loaded")) };- PartialReflect::try_apply(&mut *m, v.as_partial_reflect()).map_err(|err| format!("material:{path}: {err}"))+ for (name, v) in fields {+ let f = Struct::field_mut(&mut *m, name).ok_or_else(|| format!("material:{path}: no field {name}"))?;+ f.try_apply(v.as_partial_reflect()).map_err(|err| format!("material:{path}.{name}: {err}"))?;+ }+ Ok(())}diff --git a/runtime/plugins/src/tests.rs b/runtime/plugins/src/tests.rsindex 51cb7eb5..093ff09f 100644--- a/runtime/plugins/src/tests.rs+++ b/runtime/plugins/src/tests.rs@@ -87,3 +87,25 @@ fn keyed_components_land_on_their_frame_forwards_backwards_and_jumping() {assert_eq!((x(w, a), x(w, b)), (Some(want_a), Some(want_b)), "frame {f}");}}++/// A `material:` row sets only the fields it gives on the part's own copy of its material (#38): it took the whole+/// StandardMaterial from them, every other field at its default, so a patch of emissive_exposure_weight blacked out the+/// emissive and whitened the base, and a render's frames after the first drew the glowing cube grey+#[test]+fn a_material_row_sets_only_its_fields() {+ let mut app = app();+ app.register_type::<StandardMaterial>();+ let w = app.world_mut();+ let mut mats = Assets::<StandardMaterial>::default();+ let (black, red) = (Color::BLACK, LinearRgba::rgb(1.0, 0.0, 0.0));+ let shared = mats.add(StandardMaterial { base_color: black, emissive: red, ..default() });+ w.insert_resource(mats);+ let e = w.spawn(MeshMaterial3d(shared.clone())).id();+ insert_reflect(w, e, "material:bevy_pbr::pbr_material::StandardMaterial", &json!({"emissive_exposure_weight": 0.5})).unwrap();+ let own = w.get::<MeshMaterial3d<StandardMaterial>>(e).unwrap().0.clone();+ assert_ne!(own, shared, "the part's own copy, not the shared material");+ let m = w.resource::<Assets<StandardMaterial>>().get(&own).unwrap();+ assert_eq!((m.emissive_exposure_weight, m.emissive, m.base_color), (0.5, red, black));+ let err = insert_reflect(w, e, "material:bevy_pbr::pbr_material::StandardMaterial", &json!({"no_such": 1.0})).unwrap_err();+ assert!(err.contains("no field no_such"), "{err}");+}diff --git a/sdk/raea/bench/bevy-ts/cases/material-field-20.tsx b/sdk/raea/bench/bevy-ts/cases/material-field-20.tsxindex 7a75cf34..cfc9f459 100644--- a/sdk/raea/bench/bevy-ts/cases/material-field-20.tsx+++ b/sdk/raea/bench/bevy-ts/cases/material-field-20.tsx@@ -1,7 +1,7 @@// gap: FC1c// A StandardMaterial field past the row columns' four, animated (docs/control.feature FC1c): a black cube glowing red// whose emissive_exposure_weight runs from 0 at frame 0 to 1 at frame 20, set by reflection on its own material each-// frame. At frame 20 it is grey, not red: the emissive under the camera's exposure leaves only the black base's specular.+// frame. At frame 20 it is dark, not red: the emissive under the camera's exposure leaves only the black base's specular.// frame: 20// probe: 32 32 r<80import { AbsoluteFill, Composition, registerRoot } from "raea";diff --git a/sdk/raea/bench/bevy-ts/cases/material-field-live.tsx b/sdk/raea/bench/bevy-ts/cases/material-field-live.tsxindex e854a16f..a9782cdf 100644--- a/sdk/raea/bench/bevy-ts/cases/material-field-live.tsx+++ b/sdk/raea/bench/bevy-ts/cases/material-field-live.tsx@@ -1,7 +1,7 @@// gap: FC1c// A StandardMaterial field past the row columns' four, animated (docs/control.feature FC1c): a black cube glowing red// whose emissive_exposure_weight runs from 0 at frame 0 to 1 at frame 20, set by reflection on its own material each-// frame. Played live (0.85 s, frame 25, past the track's end) it is grey, not red: the emissive under the camera's exposure leaves only the black base's specular.+// frame. Played live (0.85 s, frame 25, past the track's end) it is dark, not red: the emissive under the camera's exposure leaves only the black base's specular.// play: live-world.json 0.85// probe: 32 32 r<80import { AbsoluteFill, Composition, registerRoot } from "raea";