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.

SG10: Text3D in its own file (sdk/render/src/3d/text3d.tsx, re-exported from shapes.tsx, which was 515 lines); the stage checks' two new one-line copies folded (a part's opacity is a named fn, a Label's points parse through serde)

shinyobjectz0d853cff8e3a
diff --git a/sdk/render/src/3d/shapes.tsx b/sdk/render/src/3d/shapes.tsx
index 9287fae5..772b7287 100644
--- a/sdk/render/src/3d/shapes.tsx
+++ b/sdk/render/src/3d/shapes.tsx
@@ -7,6 +7,8 @@ import { Canvas3DProps, Vec3, checkArgs, checkPass, checkVec, node3d, serialisab
import { InCanvas3D } from "./model";
import type { MeshAttribute } from "./attribute";
import { firstKey, useSequenceFrames } from "./clock";
+import { Text3D, text3dShape, type Text3DProps } from "./text3d";
+export { Text3D, type Text3DProps };
const FILL = { position: "absolute", left: 0, top: 0, width: "100%", height: "100%" } as const;
@@ -345,39 +347,6 @@ export function BufferMesh(props: BufferMeshProps) {
return node3d("BufferMesh", {});
}
-export interface Text3DProps {
- /** the words, extruded */
- children?: string;
- /** the words, when they aren't its child (no quotes or backslashes) */
- text?: string;
- /** letter height in scene units (default 0.5) */
- size?: number;
- /** extrusion depth (default 0.2) */
- depth?: number;
- /** a family (Inter by default, or another of raea's bundled faces) */
- font?: string;
- /** 100..900 (800 by default) */
- weight?: number;
- /** false: scenery (a sign seen in passing), not held to the type checks raea render runs on 3D type: its size on screen,
- * its angle to the camera, the title-safe area, its reading time and parts in front of it (docs/stage-guards.feature
- * SG10). Words meant to be read are better as page type: a Label */
- read?: boolean;
-}
-
-/** Solid 3D letters (Manifold's text3d), as a Mesh's geometry: `<Mesh><Text3D size={0.6}>SALE</Text3D>...</Mesh>`. */
-export function Text3D(props: Text3DProps) {
- return node3d("Text3D", { ...props, shape: text3dShape(props) });
-}
-
-function text3dShape(p: Text3DProps): string {
- const text = p.text ?? (typeof p.children === "string" ? p.children : undefined);
- if (typeof text !== "string" || text === "") throw new TypeError("Text3D: give the words as its child or `text`");
- if (/["\\]/.test(text)) throw new TypeError(`Text3D: the words can't hold a quote or backslash, got ${JSON.stringify(text)}`);
- const size = p.size ?? 0.5, depth = p.depth ?? 0.2, weight = p.weight ?? 800, font = p.font ?? "Inter";
- for (const [k, v] of [["size", size], ["depth", depth]] as const) if (!(v > 0) || !Number.isFinite(v)) throw new RangeError(`Text3D: ${k} must be a positive number, got ${v}`);
- return `text3d("${text}", ${size}, ${depth}, "${font}", ${weight})`;
-}
-
export interface MeshProps extends PointerHandlers3d {
/** what the mesh is called across frames: give one when meshes come and go, so each keeps its own motion */
name?: string;
diff --git a/sdk/render/src/3d/text3d.tsx b/sdk/render/src/3d/text3d.tsx
new file mode 100644
index 00000000..37d4883c
--- /dev/null
+++ b/sdk/render/src/3d/text3d.tsx
@@ -0,0 +1,35 @@
+// Text3D: solid 3D letters as a Mesh's geometry (Manifold's text3d), split from shapes.tsx, which re-exports it.
+import { node3d } from "./all";
+
+export interface Text3DProps {
+ /** the words, extruded */
+ children?: string;
+ /** the words, when they aren't its child (no quotes or backslashes) */
+ text?: string;
+ /** letter height in scene units (default 0.5) */
+ size?: number;
+ /** extrusion depth (default 0.2) */
+ depth?: number;
+ /** a family (Inter by default, or another of raea's bundled faces) */
+ font?: string;
+ /** 100..900 (800 by default) */
+ weight?: number;
+ /** false: scenery (a sign seen in passing), not held to the type checks raea render runs on 3D type: its size on screen,
+ * its angle to the camera, the title-safe area, its reading time and parts in front of it (docs/stage-guards.feature
+ * SG10). Words meant to be read are better as page type: a Label */
+ read?: boolean;
+}
+
+/** Solid 3D letters (Manifold's text3d), as a Mesh's geometry: `<Mesh><Text3D size={0.6}>SALE</Text3D>...</Mesh>`. */
+export function Text3D(props: Text3DProps) {
+ return node3d("Text3D", { ...props, shape: text3dShape(props) });
+}
+
+export function text3dShape(p: Text3DProps): string {
+ const text = p.text ?? (typeof p.children === "string" ? p.children : undefined);
+ if (typeof text !== "string" || text === "") throw new TypeError("Text3D: give the words as its child or `text`");
+ if (/["\\]/.test(text)) throw new TypeError(`Text3D: the words can't hold a quote or backslash, got ${JSON.stringify(text)}`);
+ const size = p.size ?? 0.5, depth = p.depth ?? 0.2, weight = p.weight ?? 800, font = p.font ?? "Inter";
+ for (const [k, v] of [["size", size], ["depth", depth]] as const) if (!(v > 0) || !Number.isFinite(v)) throw new RangeError(`Text3D: ${k} must be a positive number, got ${v}`);
+ return `text3d("${text}", ${size}, ${depth}, "${font}", ${weight})`;
+}
diff --git a/systems/stage/src/cover.rs b/systems/stage/src/cover.rs
index dffbfa86..f74e6e28 100644
--- a/systems/stage/src/cover.rs
+++ b/systems/stage/src/cover.rs
@@ -68,10 +68,17 @@ pub(crate) fn behind(its: &[Item], parts: &[Part], me: usize, world: &Mat4, x: (
by.into_iter().max_by_key(|(j, n)| (*n, std::cmp::Reverse(*j))).map(|(j, _)| called(&its[j]))
}
-/// Whether a part lets the words through: its material's opacity under SEE_THROUGH.
+/// Whether a part lets the words through: its material's opacity (else its own) under SEE_THROUGH.
fn see_through(it: &Item) -> bool {
- let o = |p: &serde_json::Map<String, Value>| p.get("opacity").and_then(Value::as_f64);
- it.material.as_ref().and_then(|m| o(&m.props)).or_else(|| o(&it.props)).is_some_and(|o| o < SEE_THROUGH)
+ let material = match &it.material {
+ Some(m) => opacity(&m.props),
+ None => None,
+ };
+ material.or(opacity(&it.props)).is_some_and(|o| o < SEE_THROUGH)
+}
+
+fn opacity(props: &serde_json::Map<String, Value>) -> Option<f64> {
+ props.get("opacity")?.as_f64()
}
/// Where the segment o to q first enters the box [lo, hi], as a share of its length, if it does before q.
diff --git a/systems/stage/src/manifest.rs b/systems/stage/src/manifest.rs
index 328c08cc..2015bdde 100644
--- a/systems/stage/src/manifest.rs
+++ b/systems/stage/src/manifest.rs
@@ -31,7 +31,7 @@ pub fn pages(frames: &[Value], nums: &[i64], w: u32, h: u32) -> Vec<Page> {
}
let words = |t: &Value| {
let text = Some(t["text"].as_str()?.trim()).filter(|s| !s.is_empty())?.into();
- let points = t["points"].as_array().and_then(|p| p.iter().map(|v| v.as_f64().map(|v| v as f32)).collect::<Option<Vec<f32>>>()?.try_into().ok());
+ let points = serde_json::from_value::<[f32; 3]>(t["points"].clone()).ok();
Some(Words { text, bx: shown(t, "ink").or_else(|| shown(t, "box"))?, allow_overlap: t["allowOverlap"] == true, points })
};
nums.iter()