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.

1.3 KB
Raw Blame
// `raea playable`'s lint, the part that renders (docs/playables.feature PA4): run by `raea run` on an entry that imports
// the game first, so its compositions are registered. Each composition is rendered at 12 frames through its length,
// and every 3D kind it draws is held to what the playable host draws (kinds.ts). Returns its shapes and the kinds.
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { Clock, getCompositions } from "raea";
import { PLAYABLE_KINDS } from "../host/kinds";

export default function walk() {
  const kinds: Record<string, number> = {};
  const comps = getCompositions().map((c) => {
    const step = Math.max(1, Math.floor(c.durationInFrames / 12));
    for (let f = 0; f < c.durationInFrames; f += step) {
      const html = renderToStaticMarkup(
        createElement(Clock, { frame: f, fps: c.fps, width: c.width, height: c.height, durationInFrames: c.durationInFrames }, createElement(c.component, c.defaultProps)),
      );
      for (const m of html.matchAll(/data-3d="([A-Za-z0-9]+)"/g)) kinds[m[1]] = (kinds[m[1]] ?? 0) + 1;
    }
    return { id: c.id, width: c.width, height: c.height, fps: c.fps, frames: c.durationInFrames };
  });
  return { comps, kinds: Object.keys(kinds), refused: Object.keys(kinds).filter((k) => !PLAYABLE_KINDS.has(k)) };
}