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.

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

shinyobjectz190ced1d1f9a
diff --git a/docs/r3f.feature b/docs/r3f.feature
index b3cd3df0..e6f52847 100644
--- a/docs/r3f.feature
+++ b/docs/r3f.feature
@@ -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>
diff --git a/sdk/r3f/src/input/R3F.tsx b/sdk/r3f/src/input/R3F.tsx
index 166994b9..4e7a79ba 100644
--- a/sdk/r3f/src/input/R3F.tsx
+++ b/sdk/r3f/src/input/R3F.tsx
@@ -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);