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.

LinearRgba.from takes an Srgba and names the fix when given anything else

shinyobjectz3f9508039471
diff --git a/sdk/raea/conformance/bevy3d.test.tsx b/sdk/raea/conformance/bevy3d.test.tsx
index 0db117a1..179afe35 100644
--- a/sdk/raea/conformance/bevy3d.test.tsx
+++ b/sdk/raea/conformance/bevy3d.test.tsx
@@ -204,6 +204,8 @@ describe("Mesh3d, Camera3d and StandardMaterial", () => {
html(<MeshStandardMaterial color="#ffffff" roughness={0.5} metalness={0} emissive="#ff4070" {...nits(1)} animate={{ emissive_nits: track({ 0: 0, 30: 2.5 }, "out-cubic") } as never} />),
);
const F = LinearRgba.from(Srgba.hex("#00ff00"));
+ // a hex string, not an Srgba, once made NaN channels and a glow that drew nothing: it names the form that works
+ expect(() => LinearRgba.from("#ff3fa4" as never)).toThrow(/LinearRgba.from\(Srgba.hex\("#ff3fa4"\)\)/);
expect(() => html(<StandardMaterial animate={{ emissive: track({ 0: E, 30: F }) }} />)).toThrow(/one colour/);
expect(() => html(<StandardMaterial animate={{ metallic: track({ 0: "#fff", 30: "#000" }) as never }} />)).toThrow(/numbers/);
expect(() => html(<StandardMaterial animate={{ roughness: track({ 0: 0, 30: 1 }) } as never} />)).toThrow(/not roughness/);
diff --git a/sdk/render/src/bevy3d/colors.ts b/sdk/render/src/bevy3d/colors.ts
index d4221573..56af461c 100644
--- a/sdk/render/src/bevy3d/colors.ts
+++ b/sdk/render/src/bevy3d/colors.ts
@@ -77,7 +77,9 @@ export class LinearRgba {
}
/** Bevy's LinearRgba::from(Srgba) */
static from(c: Srgba): LinearRgba {
- const l = new LinearRgba(srgbToLinear(c.red), srgbToLinear(c.green), srgbToLinear(c.blue), c.alpha);
+ // a hex string here read as NaN channels and drew nothing, silently: name the form that works
+ if (!(c instanceof Srgba)) throw new TypeError(`LinearRgba.from takes an Srgba, as Bevy's does: LinearRgba.from(Srgba.hex(${JSON.stringify(c)})), got ${typeof c === "string" ? "a string" : JSON.stringify(c)}`);
+ const l =new LinearRgba(srgbToLinear(c.red), srgbToLinear(c.green), srgbToLinear(c.blue), c.alpha);
l[MADE_FROM] = c[MADE_FROM];
return l;
}