R3F26 (#130), SDK: <R3F width height>, the box's size, and docs/r3f.feature R3F26 done

<R3F> takes the box's width and height in frame pixels: R3F's own size (useThree's size and viewport), its camera's aspect and an orthographic camera's frame are the box's; by default the frame's, as before. raea draws the scene in the box it sits in either way (the engine's fix in the commit before). An orthographic plane R3F frames at zoom 40 is 80 px in a 400 x 300 box with them, as three draws it, and 40 px without. A width or height that isn't a size above 0 is refused, naming it. docs/r3f.feature R3F26's status: the cause, the fix and #130's five cases measured.
This commit is contained in:
shinyobjectz committed 2026-11-15 13:50:51 -08:00
1 parent 3e391e2afa
commit 190ced1d1f
2 files changed
+20 -2

No files matched your search

+10
View File
@@ -585,6 +585,16 @@ Feature: React Three Fiber both ways: an R3F scene drawn by raea, a raea composi
When raea draws it
Then its camera's aspect and projection are the box's, centred on the box, as R3F's <Canvas> is in a browser
And #130's five cases each draw the plane at its expected size and place
Status (11-15): done. The cause was the engine's, not <R3F>'s: a camera in a page element (docs/sdk.feature S3a)
is drawn as the element's box's own view (a SubCameraView: the box's size as the full view, offset by its
place), but engine/render target.rs gave every camera on the Engine's target a w x h Viewport on the frames
before the page had laid the box out, and skipped a camera with a Viewport after that, so the box's view never
came and the page's was cropped to the box (raea's own camera in a box too). The Viewport it gives is now taken
off when a box comes (unit tests in target.rs). #130's cases: 600 x 600 at fov 90, 80 px centred in the box
(was 120 px centred on the page); fov 32, 278 px (three: 279); 1080 x 1920, 80 px (was nothing); 2160 x 3840
with the box at (800, 1600), 80 px in the box. <R3F width height> (the box's size)
makes R3F's own size, its camera's aspect and an orthographic camera's frame the box's: an orthographic plane
R3F frames at zoom 40 is 80 px in a 400 x 300 box with them, 40 px without (R3F sizes it from the frame)
Scenario: R3F27. R3F's pointer events and controls in a live play
Given an <R3F> in a game played live: meshes with onClick, onPointerOver, onPointerMove; drei's <OrbitControls>
+10 -2
View File
@@ -23,11 +23,19 @@ export interface R3FProps extends Config {
children?: ReactNode;
/** a name of its own when one composition has more than one R3F scene that come and go */
name?: string;
/** the box's width and height in frame pixels, when the <R3F> sits in a box smaller than the frame: R3F's size
* (useThree's size and viewport), its camera's aspect and an orthographic camera's frame are the box's. raea draws
* the scene in the box it sits in either way (#130); by default R3F's size is the frame's */
width?: number;
height?: number;
}
function Inner({ fiber, children, name, ...config }: R3FProps & { fiber: Parameters<typeof useBridge>[0] }) {
function Inner({ fiber, children, name, width: boxW, height: boxH, ...config }: R3FProps & { fiber: Parameters<typeof useBridge>[0] }) {
const frame = useCurrentFrame();
const { fps, width, height } = useVideoConfig();
const video = useVideoConfig();
const { fps } = video;
for (const [k, v] of [["width", boxW], ["height", boxH]] as const) if (v !== undefined && !(v > 0 && Number.isFinite(v))) throw new RangeError(`<R3F>: ${k} is the box's size in frame pixels, above 0, got ${v}`);
const [width, height] = [boxW ?? video.width, boxH ?? video.height];
const clock = useContext(ClockContext);
const local = useContext(LocalTimeContext);
const bridge = useBridge(fiber);