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.5 KB
Raw Blame
// bpy.ops as TypeScript: one file per operator module (bpy.ops.mesh, bpy.ops.object, ...), each operator typed by
// its properties, which it takes as keyword arguments.
import type { Op } from "./dump";
import { enumDoc, jsdoc, key, type Names } from "./names";
import { input, propTy } from "./rna";

function opArgs(op: Op, n: Names): string {
  if (!op.args.length) return "{}";
  const owner = `${op.mod}_${op.name}`;
  const lines = op.args.map((a) => {
    const bits = [a.desc ?? a.name ?? ""];
    if (a.default !== undefined) bits.push(`Default: ${Array.isArray(a.default) ? `[${a.default.join(", ")}]` : a.default}.`);
    const doc = bits.filter(Boolean).join(" ") + enumDoc(a.type === "enum" ? a.items : undefined);
    return `${jsdoc(doc, "    ")}    ${key(a.id)}?: ${input(propTy(a, n, owner, "in"))};`;
  });
  return `{\n${lines.join("\n")}\n  }`;
}

/** The file for one operator module: an interface whose members are its operators. */
export function emitOpModule(mod: string, ops: Op[], n: Names): string {
  const body = ops.map((op) => `${jsdoc(`${op.desc}\n\nbpy.ops.${mod}.${op.name}`)}  ${key(op.name)}: H.Operator<${opArgs(op, n)}>;`);
  return `// Generated by tools/gen.sh from Blender's own API (tools/dump.py). Don't edit: regenerate.\n` +
    `import type * as H from "../../types";\nimport type * as M from "../../mathutils";\nimport type * as R from "../rna";\nimport type * as E from "../enums";\n\n` +
    `${jsdoc(`bpy.ops.${mod}`, "")}export interface Ops {\n${body.join("\n")}\n}\n`;
}