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.

FC0a: UiTargetCamera (its roots drawn by their own Camera2d: a layer stacked by the camera's order; the window's main texture cleared by the first camera only, as bevy_render's ViewTarget does); ui/ui_target_camera ported

shinyobjectz8c96f67da881
diff --git a/bench/bevy-parity/examples.list b/bench/bevy-parity/examples.list
index 3dba70b6..1e656882 100644
--- a/bench/bevy-parity/examples.list
+++ b/bench/bevy-parity/examples.list
@@ -73,3 +73,4 @@ ui/styling/gradients
ui/text/generic_font_families
ui/layout/ghost_nodes
ui/relative_cursor_position
+ui/ui_target_camera
diff --git a/bench/bevy-parity/runs.tsv b/bench/bevy-parity/runs.tsv
index 006fa729..2f808695 100644
--- a/bench/bevy-parity/runs.tsv
+++ b/bench/bevy-parity/runs.tsv
@@ -72,3 +72,4 @@ ui/styling/gradients - 10
ui/text/generic_font_families - 10
ui/layout/ghost_nodes - 10
ui/relative_cursor_position - 10
+ui/ui_target_camera - 10
diff --git a/docs/bevy-parity.md b/docs/bevy-parity.md
index 038b68dd..51d039c1 100644
--- a/docs/bevy-parity.md
+++ b/docs/bevy-parity.md
@@ -4,7 +4,7 @@ Bevy v0.20.0's examples against their raea TSX ports (docs/control.feature FC0a)
don't edit. An example passes when every probed frame passes pixels (SSIM 0.98 and no 32 px tile off by more than 24 of 255) and cost (batch keys and
frame time at most 1.25x the example's). Wall time is one machine's, measured in the same run.
-Examples: **438**, ported **73**, passing **69**, excluded **16** (docs/bevy-parity/excluded.tsv), left **353**.
+Examples: **438**, ported **74**, passing **70**, excluded **16** (docs/bevy-parity/excluded.tsv), left **352**.
raea's frame ms is its update's plus the time React takes to step a frame for its 3D (step), which the example
doesn't pay.
@@ -129,6 +129,7 @@ doesn't pay.
| ui/text/generic_font_families | 10 | 0.990063 | 19 | 0 / 0 | 457 / 492 | 5 / 7 | 1 / 1 | 41.156 / 2.365 = 2.083 + 0.282 | yes | |
| ui/layout/ghost_nodes | 10 | 0.998544 | 9 | 0 / 0 | 455 / 492 | 5 / 7 | 1 / 1 | 35.333 / 1.312 = 1.13 + 0.182 | yes | |
| ui/relative_cursor_position | 10 | 0.999907 | 2 | 0 / 0 | 443 / 492 | 5 / 7 | 1 / 1 | 52.279 / 3.978 = 3.723 + 0.255 | yes | |
+| ui/ui_target_camera | 10 | 0.998769 | 7 | 0 / 0 | 452 / 492 | 5 / 7 | 1 / 1 | 39.413 / 1.71 = 1.71 + 0 | yes | |
## Excluded
diff --git a/docs/bevy-parity/results.jsonl b/docs/bevy-parity/results.jsonl
index 989894f3..f90ec197 100644
--- a/docs/bevy-parity/results.jsonl
+++ b/docs/bevy-parity/results.jsonl
@@ -116,3 +116,4 @@
{"example":"ui/text/generic_font_families","frame":10,"ssim":0.990063,"tile":19,"bevy":{"batch_keys":0,"entities":457,"extents":[],"frame":10,"frame_ms":41.156,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":2.083,"step_ms":0.282,"cost_ms":2.365},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/layout/ghost_nodes","frame":10,"ssim":0.998544,"tile":9,"bevy":{"batch_keys":0,"entities":455,"extents":[],"frame":10,"frame_ms":35.333,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.13,"step_ms":0.182,"cost_ms":1.312},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/relative_cursor_position","frame":10,"ssim":0.999907,"tile":2,"bevy":{"batch_keys":0,"entities":443,"extents":[],"frame":10,"frame_ms":52.279,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":3.723,"step_ms":0.255,"cost_ms":3.978},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
+{"example":"ui/ui_target_camera","frame":10,"ssim":0.998769,"tile":7,"bevy":{"batch_keys":0,"entities":452,"extents":[],"frame":10,"frame_ms":39.413,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.71,"step_ms":null,"cost_ms":1.71},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
diff --git a/sdk/raea/bench/bevy-parity/ui/ui_target_camera.tsx b/sdk/raea/bench/bevy-parity/ui/ui_target_camera.tsx
new file mode 100644
index 00000000..49ad6028
--- /dev/null
+++ b/sdk/raea/bench/bevy-parity/ui/ui_target_camera.tsx
@@ -0,0 +1,33 @@
+// Bevy v0.20.0 examples/ui/ui_target_camera.rs in raea's TSX: three Camera2ds (orders 0, 1, 2) cleared red, green and
+// blue, each drawing one 100 x 100 black box with a 10 px yellow border and its order in 50 px of its own colour
+// (UiTargetCamera), the boxes 67 px apart diagonally about the centre; the text over them has no target, so the default
+// camera (the highest order) draws it. The cameras share the window's main texture, which only the first clears: red,
+// the layered <Canvas3D>.
+// Its clicks see no pointer here. In Bevy's default 1280 x 720 window.
+import { AbsoluteFill, Composition, registerRoot } from "raea";
+import { Canvas3D } from "raea/3d";
+import { Node, Text, UiRect, UiTargetCamera, px } from "raea/ui";
+import { Srgba } from "raea/color";
+
+const BOX = 100;
+const CAMERAS = [new Srgba(1, 0, 0), new Srgba(0, 0.5019608, 0), new Srgba(0, 0, 1)];
+
+function Shot() {
+ return (
+ <AbsoluteFill>
+ <Canvas3D layered clearColor="rgb(255, 0, 0)" />
+ {CAMERAS.map((color, i) => (
+ <UiTargetCamera key={i} order={i}>
+ <Node align_self="Center" justify_self="Center" justify_content="Center" align_items="Center" left={px(0.67 * BOX * (i - 1))} top={px(0.67 * BOX * (i - 1))} width={px(BOX)} height={px(BOX)} border={UiRect.all(px(0.1 * BOX))} background_color={new Srgba(0, 0, 0)} border_color={new Srgba(1, 1, 0)}>
+ <Text font_size={50} color={color}>{`${i}`}</Text>
+ </Node>
+ {i === CAMERAS.length - 1 && (
+ <Text align_self="Center" justify_self="Center" justify_content="Center" bottom={px(2 * BOX)}>{"Each box is rendered by a different camera\n* left-click: increase the camera's order\n* right-click: decrease the camera's order"}</Text>
+ )}
+ </UiTargetCamera>
+ ))}
+ </AbsoluteFill>
+ );
+}
+
+registerRoot(() => <Composition id="main" component={Shot} durationInFrames={11} fps={60} width={1280} height={720} />);
diff --git a/sdk/raea/conformance/ui.test.tsx b/sdk/raea/conformance/ui.test.tsx
index 61681415..8ce53a8d 100644
--- a/sdk/raea/conformance/ui.test.tsx
+++ b/sdk/raea/conformance/ui.test.tsx
@@ -1,7 +1,7 @@
// docs/control.feature FC0a: bevy_ui's Node, Text and TextSpan on the page, with Bevy's defaults, values and blend
// (ui/styling/transparency_ui, ui/layout/fixed_node).
import { describe, expect, test } from "bun:test";
-import { AngularColorStop, GhostNode, Viewport, UiRect as GradRect, FontSource, GridPlacement, GridTrack, RepeatedGridTrack, ColorStop, ConicGradient, LinearGradient, RadialGradient, UiPosition, BorderRadius, CornerRadius, FontVariationTag, ImageNode, InlineImage, ImagePlugin, Node, TextureAtlasLayout, Overflow, OverflowClipMargin, Text, TextShadow, Text2d, UiScale, TextSpan, UiRect, auto, percent, px, vw } from "raea/ui";
+import { AngularColorStop, GhostNode, Viewport, UiTargetCamera, UiRect as GradRect, FontSource, GridPlacement, GridTrack, RepeatedGridTrack, ColorStop, ConicGradient, LinearGradient, RadialGradient, UiPosition, BorderRadius, CornerRadius, FontVariationTag, ImageNode, InlineImage, ImagePlugin, Node, TextureAtlasLayout, Overflow, OverflowClipMargin, Text, TextShadow, Text2d, UiScale, TextSpan, UiRect, auto, percent, px, vw } from "raea/ui";
import { LinearRgba, Srgba } from "raea/color";
import { Canvas3D } from "raea/3d";
import { renderFrame } from "../src/test";
@@ -259,6 +259,12 @@ describe("A sliced ImageNode, a sampled picture and UiScale", () => {
expect(out).toContain("position:absolute;left:200px;top:100px;width:600px;height:500px;overflow:hidden");
expect(() => html(<Viewport physical_position={[0, 0]} physical_size={[0, 5]} />)).toThrow(/physical_size/);
});
+ test("UiTargetCamera is a layer over the window stacked by its camera's order, its roots roots", () => {
+ const out = html(<UiTargetCamera order={3}><Node width={px(9)} /></UiTargetCamera>);
+ expect(out).toContain("z-index:3;isolation:isolate");
+ expect(out).toContain('data-raea-blend="linear"');
+ expect(() => html(<UiTargetCamera order={1.5} />)).toThrow(/whole number/);
+ });
test("BorderColor takes a colour per side", () => {
const out = html(<Node border={UiRect.all(px(2))} border_color={{ top: new Srgba(1, 0, 0), right: new Srgba(0, 0, 1), bottom: new Srgba(1, 1, 0), left: new Srgba(0, 1, 0) }} />);
expect(out).toContain("border-color:rgba(255, 0, 0, 1) rgba(0, 0, 255, 1) rgba(255, 255, 0, 1) rgba(0, 255, 0, 1)");
diff --git a/sdk/raea/src/ui.ts b/sdk/raea/src/ui.ts
index f5682b95..90145fd1 100644
--- a/sdk/raea/src/ui.ts
+++ b/sdk/raea/src/ui.ts
@@ -6,6 +6,6 @@ export * from "@raea/video/region";
// InputRegion (input-region.tsx) joins when it is committed
export * from "@raea/video/panel";
// bevy_ui's Node and Text, and bevy_text's TextSpan, with their values (Val, UiRect, BorderRadius, Overflow)
-export { Node, GhostNode, Text, TextSpan, TextShadow, Text2d, UiScale, Viewport, ImageNode, InlineImage, type TextureSlicer, type SliceScaleMode, ImagePlugin, FontVariationTag, TextureAtlasLayout, type ImageNodeProps, px, percent, vw, vh, vmin, vmax, auto, UiRect, BorderRadius, CornerRadius, Overflow, OverflowClipMargin, type NodeProps, type TextProps, type TextStyleProps, type TextRunProps, type Text2dProps, type Val } from "@raea/render/bevy3d";
+export { Node, GhostNode, Text, TextSpan, TextShadow, Text2d, UiScale, Viewport, UiTargetCamera, ImageNode, InlineImage, type TextureSlicer, type SliceScaleMode, ImagePlugin, FontVariationTag, TextureAtlasLayout, type ImageNodeProps, px, percent, vw, vh, vmin, vmax, auto, UiRect, BorderRadius, CornerRadius, Overflow, OverflowClipMargin, type NodeProps, type TextProps, type TextStyleProps, type TextRunProps, type Text2dProps, type Val } from "@raea/render/bevy3d";
export { LinearGradient, RadialGradient, ConicGradient, ColorStop, AngularColorStop, UiPosition, type Gradient, type RadialGradientShape, type InterpolationColorSpace } from "@raea/render/bevy3d";
export { GridTrack, RepeatedGridTrack, GridPlacement, type GridTrackRepetition, type GridAutoFlow, type MinTrackSizingFunction, type MaxTrackSizingFunction, FontSource, type GenericFontFamily } from "@raea/render/bevy3d";
diff --git a/sdk/render/src/bevy3d.tsx b/sdk/render/src/bevy3d.tsx
index 0776376a..c368f98a 100644
--- a/sdk/render/src/bevy3d.tsx
+++ b/sdk/render/src/bevy3d.tsx
@@ -28,7 +28,7 @@ export { Hdr } from "./bevy3d/core";
// Lightmap (bevy_pbr::lightmap): a bake on a <Model>'s glTF meshes by name (docs/control.feature FC0a)
export { Lightmap, type LightmapProps } from "./bevy3d/lightmap";
// bevy_ui's Node, Text and TextSpan, and their values, drawn by the page
-export { Node, GhostNode, Text, TextSpan, TextShadow, Text2d, UiScale, Viewport, FontVariationTag, type NodeProps, type TextProps, type TextStyleProps, type TextRunProps, type Text2dProps } from "./bevy3d/ui";
+export { Node, GhostNode, Text, TextSpan, TextShadow, Text2d, UiScale, Viewport, UiTargetCamera, FontVariationTag, type NodeProps, type TextProps, type TextStyleProps, type TextRunProps, type Text2dProps } from "./bevy3d/ui";
export { ImageNode, InlineImage, ImagePlugin, TextureAtlasLayout, type TextureSlicer, type SliceScaleMode, type ImageNodeProps } from "./bevy3d/ui-image";
export { px, percent, vw, vh, vmin, vmax, auto, UiRect, BorderRadius, CornerRadius, Overflow, OverflowClipMargin, type Val } from "./bevy3d/ui-val";
export { LinearGradient, RadialGradient, ConicGradient, ColorStop, AngularColorStop, UiPosition, type Gradient, type RadialGradientShape, type InterpolationColorSpace } from "./bevy3d/ui-gradient";
diff --git a/sdk/render/src/bevy3d/ui.tsx b/sdk/render/src/bevy3d/ui.tsx
index 2563800d..0d5b2430 100644
--- a/sdk/render/src/bevy3d/ui.tsx
+++ b/sdk/render/src/bevy3d/ui.tsx
@@ -410,3 +410,13 @@ export function Viewport({ physical_position, physical_size, children }: { physi
const [[left, top], [width, height]] = [physical_position, physical_size];
return <div style={{ position: "absolute", left, top, width, height, overflow: "hidden" }}>{children}</div>;
}
+
+/** The roots inside drawn by their own Camera2d (bevy_ui's UiTargetCamera): a layer over the whole window, stacked by
+ * the camera's `order` as Bevy draws its cameras, lowest first. Cameras on one window share its main texture, which
+ * only the first of them clears (bevy_render's ViewTarget, its first call), so the window's clear is the layered
+ * <Canvas3D clearColor>'s and a later camera's own clear colour shows nowhere. Roots outside any are the default
+ * camera's (the highest order). @bevy bevy_ui::UiTargetCamera */
+export function UiTargetCamera({ order = 0, children }: { order?: number; children?: ReactNode }) {
+ if (!Number.isInteger(order)) throw new RangeError(`UiTargetCamera: order is a whole number, got ${order}`);
+ return <div style={{ position: "absolute", left: 0, top: 0, width: "100%", height: "100%", zIndex: order, isolation: "isolate" }}>{children}</div>;
+}
diff --git a/sdk/skills/raea/reference/sdk.md b/sdk/skills/raea/reference/sdk.md
index b8a51081..960b6074 100644
--- a/sdk/skills/raea/reference/sdk.md
+++ b/sdk/skills/raea/reference/sdk.md
@@ -99,7 +99,7 @@ with a capital, hooks with `use`. A component's props are in its file.
## `raea/ui` (sdk/raea/src/ui.ts)
-`AbsoluteFill`, `AngularColorStop`, `BorderRadius`, `ColorStop`, `ConicGradient`, `CornerRadius`, `FontSource`, `FontVariationTag`, `GhostNode`, `GridPlacement`, `GridTrack`, `ImageNode`, `ImagePlugin`, `InlineImage`, `LinearGradient`, `Node`, `Overflow`, `OverflowClipMargin`, `RadialGradient`, `RepeatedGridTrack`, `Text`, `Text2d`, `TextShadow`, `TextSpan`, `TextureAtlasLayout`, `UiPosition`, `UiRect`, `UiScale`, `Viewport`, `auto`, `percent`, `px`, `vh`, `vmax`, `vmin`, `vw`
+`AbsoluteFill`, `AngularColorStop`, `BorderRadius`, `ColorStop`, `ConicGradient`, `CornerRadius`, `FontSource`, `FontVariationTag`, `GhostNode`, `GridPlacement`, `GridTrack`, `ImageNode`, `ImagePlugin`, `InlineImage`, `LinearGradient`, `Node`, `Overflow`, `OverflowClipMargin`, `RadialGradient`, `RepeatedGridTrack`, `Text`, `Text2d`, `TextShadow`, `TextSpan`, `TextureAtlasLayout`, `UiPosition`, `UiRect`, `UiScale`, `UiTargetCamera`, `Viewport`, `auto`, `percent`, `px`, `vh`, `vmax`, `vmin`, `vw`
## `raea/video` (sdk/raea/src/video.ts)