mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 21:03:47 -10:00
Shane, 11-10: "include natively a blender api package in raea/blender using samchon/blendia as good starting place and get us to a solid scripting parity to the official blender python api. we will own this ourselves", and "make sure to add GodotJS which should add a more complete integration and bindings for godot integration". raea/blender (sdk/blender, started from samchon/blendia, MIT, and rewritten): bpy, bmesh, mathutils, bpy_extras and gpu typed from Blender 5.2.1's own RNA and docstrings (tools/gen.sh: 1809 structs, 2498 operators, 41 modules outside RNA; 102 of about 12 900 members any), run against a real Blender. Paths are lazy as Python's attribute access is (writes and calls sent in order, reads awaited, py.pin for a stable handle), errors are Python's (BlenderError), mathutils is computed in TypeScript with Blender's maths (1450 values within 1e-5 of Blender's), float arrays are the value Blender gives (Vector, Matrix, Euler, Quaternion, Color), a call that makes a thing by its type returns that class (tools/refine.py), node sockets are typed by name, and every argument can be given by keyword. `raea blender run SCRIPT.ts [FILE.blend] [ARGS...]` runs a script on raea's engine against a headless Blender (apps/tools blender_bridge.rs, runtime/calls blender.post); under Bun or Node it starts its own, or joins the person's Blender through raea's add-on (python/raea_blender). raea/godot (sdk/godot) on GodotJS (MIT): Godot 4.6.1's every class, singleton, enum and builtin typed from GodotJS's codegen, JavaScriptCore on the Mac and QuickJS-ng on Windows and Linux (no V8). `raea setup godot` downloads GodotJS's editor build pinned by size and sha256 (apps/tools godot.rs); `raea godot run SCRIPT.ts` bundles the script and runs its default export (a function given the SceneTree and ARGS, or a SceneTree subclass as the main loop) headless or with --window, --movie recording with Godot's Movie Maker (the window kept on top, the frame size from the project), a callback that throws stopping the run, RAEA_CWD with cwd() and resolve() for paths; `raea godot types` and `raea godot open` (godot_run.rs). The guides: raea guide bevy/blender gains "A step in TypeScript" and bevy/godot is new, each example type-checked with its SDK's tests (sdk/blender/test/guide.ts, sdk/godot/test/guide.ts) and run as shown; raea guide bevy routes to bevy/godot. Their raea-skills copies are 7497067 (branch blender-godot-ts, not pushed). sdk/tsconfig.base.json maps raea/blender and raea/godot; tools/release.sh ships @raea/blender's python/. Proven: sdk/blender's tsc and bun tests against Blender 5.2.1; sdk/godot's tsc and its 7 bun tests against the installed GodotJS; apps/tools godot_run's unit tests; post 07b's film (releases/0.1.1/src/engines), its left half built and keyed by raea/blender and its right half recorded by raea/godot.
104 lines
3.9 KiB
Python
104 lines
3.9 KiB
Python
"""What a collection's new() returns for each type it takes, and each node type's sockets by name: found by making one
|
|
of each in the scratch file dump.py runs in. RNA declares new() as returning the base (a Modifier), but Python gives the
|
|
subclass (modifiers.new(name, 'SUBSURF') is a SubsurfModifier), so the types can say what the script gets.
|
|
dump.py puts refine() into the dump as "refine"; tools/gen/refine.ts writes the types from it."""
|
|
import bpy
|
|
|
|
|
|
def enum_ids(struct, func, arg):
|
|
return [i.identifier for i in getattr(bpy.types, struct).bl_rna.functions[func].parameters[arg].enum_items]
|
|
|
|
|
|
def probe(make, ids):
|
|
out = {}
|
|
for t in ids:
|
|
try:
|
|
x = make(t)
|
|
except Exception:
|
|
continue
|
|
if x is not None:
|
|
out[t] = x.bl_rna.identifier
|
|
return out
|
|
|
|
|
|
def owner(data):
|
|
ob = bpy.data.objects.new("refine-probe", data)
|
|
bpy.context.scene.collection.objects.link(ob)
|
|
return ob
|
|
|
|
|
|
def node_classes():
|
|
"""Every node type Python knows by bl_idname (built-in and add-on)."""
|
|
seen = {}
|
|
for name in dir(bpy.types):
|
|
c = getattr(bpy.types, name, None)
|
|
if isinstance(c, type) and issubclass(c, bpy.types.Node) and c is not bpy.types.Node:
|
|
idname = getattr(c, "bl_idname", None) or name
|
|
seen.setdefault(idname, c)
|
|
return sorted(seen)
|
|
|
|
|
|
def sockets(coll):
|
|
out, names = [], set()
|
|
for s in coll:
|
|
if s.name in names:
|
|
continue # Python's coll[name] is the first of that name
|
|
names.add(s.name)
|
|
out.append([s.name, s.bl_rna.identifier])
|
|
return out
|
|
|
|
|
|
def nodes():
|
|
trees = []
|
|
for idname in ("ShaderNodeTree", "GeometryNodeTree", "CompositorNodeTree", "TextureNodeTree"):
|
|
try:
|
|
trees.append(bpy.data.node_groups.new("refine-" + idname, idname))
|
|
except Exception:
|
|
pass
|
|
out = {}
|
|
for idname in node_classes():
|
|
for tree in trees:
|
|
try:
|
|
n = tree.nodes.new(idname)
|
|
except Exception:
|
|
continue
|
|
out[idname] = {"struct": n.bl_rna.identifier, "in": sockets(n.inputs), "out": sockets(n.outputs)}
|
|
break
|
|
return out
|
|
|
|
|
|
def refine():
|
|
mesh = owner(bpy.data.meshes.new("refine-probe"))
|
|
gp = None
|
|
for coll in ("grease_pencils", "grease_pencils_v3"):
|
|
if hasattr(bpy.data, coll):
|
|
try:
|
|
gp = owner(getattr(bpy.data, coll).new("refine-gp"))
|
|
break
|
|
except Exception:
|
|
pass
|
|
|
|
def modifier(t):
|
|
try:
|
|
return mesh.modifiers.new("m", t)
|
|
except Exception:
|
|
return gp.modifiers.new("m", t) if gp else None
|
|
|
|
def shader_fx(t):
|
|
return (gp or mesh).shader_effects.new("fx", t)
|
|
|
|
constraints = probe(lambda t: mesh.constraints.new(t), enum_ids("ObjectConstraints", "new", "type"))
|
|
calls = [
|
|
("ObjectModifiers", "new", "type", probe(modifier, enum_ids("ObjectModifiers", "new", "type"))),
|
|
("ObjectConstraints", "new", "type", constraints),
|
|
("PoseBoneConstraints", "new", "type", constraints),
|
|
("BlendDataLights", "new", "type", probe(lambda t: bpy.data.lights.new("l", t), enum_ids("BlendDataLights", "new", "type"))),
|
|
("BlendDataTextures", "new", "type", probe(lambda t: bpy.data.textures.new("t", t), enum_ids("BlendDataTextures", "new", "type"))),
|
|
("BlendDataNodeTrees", "new", "type", probe(lambda t: bpy.data.node_groups.new("n", t), enum_ids("BlendDataNodeTrees", "new", "type"))),
|
|
]
|
|
if hasattr(bpy.types, "ObjectShaderFx"):
|
|
calls.append(("ObjectShaderFx", "new", "type", probe(shader_fx, enum_ids("ObjectShaderFx", "new", "type"))))
|
|
found = nodes()
|
|
calls.append(("Nodes", "new", "type", {k: v["struct"] for k, v in found.items()}))
|
|
return {"calls": [{"struct": s, "func": f, "arg": a, "map": m} for (s, f, a, m) in calls if m], "nodes": found}
|