From 236bbcbd52252fa95a44ee8124de0cb63a68fd36 Mon Sep 17 00:00:00 2001
From: Ragulsundaram <41433645+Ragulsundaram@users.noreply.github.com>
Date: Thu, 12 Nov 2026 23:56:32 +0530
Subject: [PATCH] R3F: an opacity outside [0, 1] is clamped, as three draws it,
instead of throwing
An easing that overshoots (bezier(0.34, 1.4, 0.64, 1)) gives a material opacity of 1.03; three clamps it when it
draws, but the bridge handed it straight to raea's MeshBasicMaterial, whose check threw RangeError. The bridge now
clamps opacity before converting.
---
sdk/r3f/src/input/material.ts | 6 ++++--
sdk/r3f/test/input.test.tsx | 9 +++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/sdk/r3f/src/input/material.ts b/sdk/r3f/src/input/material.ts
index 0714a45a..d6b6f43f 100644
--- a/sdk/r3f/src/input/material.ts
+++ b/sdk/r3f/src/input/material.ts
@@ -22,13 +22,15 @@ export interface Part {
}
const hex = (c: THREE.Color) => "#" + c.getHexString();
+/** three draws an opacity outside [0, 1] clamped (an easing that overshoots gives 1.03); raea's materials refuse it */
+const unit = (v: number) => Math.min(1, Math.max(0, v));
const side = (s: THREE.Side) => (s === THREE.BackSide ? "back" : s === THREE.DoubleSide ? "double" : undefined);
/** the props every surface shares: colour, opacity and blending, side, fog */
function drawn(m: THREE.Material & { color?: THREE.Color; map?: THREE.Texture | null }, p: Props) {
if (m.color) p.color = hex(m.color);
if (m.opacity < 1 || m.transparent) {
- p.opacity = m.opacity;
+ p.opacity = unit(m.opacity);
p.transparent = true;
}
if (m.blending === THREE.AdditiveBlending) p.alphaMode = "add";
@@ -177,7 +179,7 @@ export function materialOf(m: THREE.Material, vertexColors: boolean, at?: NodeAt
return { type: "MeshBasicMaterial", props: { color: "#808080" } };
case "ShadowMaterial": {
const s = m as THREE.ShadowMaterial;
- return { type: "MeshBasicMaterial", props: { color: hex(s.color), opacity: s.opacity, transparent: true }, catchShadow: true } as Part;
+ return { type: "MeshBasicMaterial", props: { color: hex(s.color), opacity: unit(s.opacity), transparent: true }, catchShadow: true } as Part;
}
default: {
// a TSL node material (three/webgpu): one with no node of its own is its classic material; one with a graph is
diff --git a/sdk/r3f/test/input.test.tsx b/sdk/r3f/test/input.test.tsx
index 097dbbff..09a51c42 100644
--- a/sdk/r3f/test/input.test.tsx
+++ b/sdk/r3f/test/input.test.tsx
@@ -179,6 +179,15 @@ describe("the scene graph", () => {
expect(meshes.map((m) => (m.children![0].props.indices as number[]).length)).toEqual([6, 6, 6, 6, 6, 6]);
end(r.key);
});
+ test("an opacity past 1 or below 0 (an overshooting easing) is clamped, as three draws it", () => {
+ const r = partsOf(() => <>
+
+
+ >);
+ const ops = flat(r.parts).filter((p) => p.type === "Mesh").map((m) => m.children!.find((c) => "opacity" in c.props)!.props.opacity);
+ expect(ops).toEqual([1, 0]);
+ end(r.key);
+ });
});
describe("textures", () => {