model/blend: Blender 1.6x-2.0x files (big-endian, 32-bit, TFace / MCol, IPO curves, additive dsize), easing curves, owner-scoped address lookup; containers/Blend tests; docs section; bench line
This commit is contained in:
1 parent
2e82b7d0af
commit
3c8d5e99d7
14 files changed
+766
-110
No files matched your search
@@ -0,0 +1,73 @@
|
||||
# Docs inputs for the .blend section of docs/guide/scene.md (tools/fixtures.py; tools/docs_check.py explains the
|
||||
# inputs): a small rig saved zstd-compressed by the nixpkgs Blender (a two-bone armature, a skinned cylinder with a
|
||||
# shape key, a bone action and a Principled material).
|
||||
# tests/gen/docs_blend.luau { files = { ["rig.blend"] = bytes }, vars = { riggedBlendBytes = "rig.blend" } }
|
||||
import importlib.util, os, shutil, subprocess, tempfile
|
||||
|
||||
INPUTS = ["tools/docs_check.py"]
|
||||
|
||||
SCRIPT = r'''
|
||||
import bpy, sys, math
|
||||
out = sys.argv[sys.argv.index("--") + 1]
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
arm = bpy.data.armatures.new("RigData")
|
||||
rig = bpy.data.objects.new("Rig", arm)
|
||||
bpy.context.scene.collection.objects.link(rig)
|
||||
bpy.context.view_layer.objects.active = rig
|
||||
bpy.ops.object.mode_set(mode="EDIT")
|
||||
a = arm.edit_bones.new("lower")
|
||||
a.head, a.tail = (0, 0, 0), (0, 0, 1)
|
||||
b = arm.edit_bones.new("upper")
|
||||
b.head, b.tail, b.parent, b.use_connect = (0, 0, 1), (0, 0, 2), a, True
|
||||
bpy.ops.object.mode_set(mode="OBJECT")
|
||||
ring = [(math.cos(k * math.pi / 3) * 0.3, math.sin(k * math.pi / 3) * 0.3) for k in range(6)]
|
||||
verts = [(x, y, z) for z in (0, 1, 2) for x, y in ring]
|
||||
faces = [(r * 6 + k, r * 6 + (k + 1) % 6, (r + 1) * 6 + (k + 1) % 6, (r + 1) * 6 + k) for r in range(2) for k in range(6)]
|
||||
me = bpy.data.meshes.new("Tube")
|
||||
me.from_pydata(verts, [], faces)
|
||||
mat = bpy.data.materials.new("Skin")
|
||||
mat.use_nodes = True
|
||||
bsdf = mat.node_tree.nodes["Principled BSDF"]
|
||||
bsdf.inputs["Base Color"].default_value = (0.9, 0.6, 0.5, 1)
|
||||
bsdf.inputs["Roughness"].default_value = 0.7
|
||||
me.materials.append(mat)
|
||||
tube = bpy.data.objects.new("Tube", me)
|
||||
bpy.context.scene.collection.objects.link(tube)
|
||||
tube.parent = rig
|
||||
tube.modifiers.new("Armature", "ARMATURE").object = rig
|
||||
lo, up = tube.vertex_groups.new(name="lower"), tube.vertex_groups.new(name="upper")
|
||||
for i in range(18):
|
||||
lo.add([i], 1.0 - (i // 6) * 0.5, "REPLACE")
|
||||
up.add([i], (i // 6) * 0.5, "REPLACE")
|
||||
tube.shape_key_add(name="Basis")
|
||||
bulge = tube.shape_key_add(name="Bulge")
|
||||
for p in bulge.data:
|
||||
p.co = (p.co[0] * 1.4, p.co[1] * 1.4, p.co[2])
|
||||
pb = rig.pose.bones["upper"]
|
||||
for f, angle in ((1, 0.0), (12, 0.8), (24, 0.0)):
|
||||
pb.rotation_quaternion = (math.cos(angle / 2), math.sin(angle / 2), 0, 0)
|
||||
pb.keyframe_insert("rotation_quaternion", frame=f)
|
||||
bpy.context.scene.frame_set(1)
|
||||
bpy.ops.wm.save_as_mainfile(filepath=out, compress=True)
|
||||
'''
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
spec = importlib.util.spec_from_file_location("docs_check", os.path.join(ctx.root, "tools", "docs_check.py"))
|
||||
check = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(check)
|
||||
tmp = tempfile.mkdtemp(prefix="formats-docs-blend-")
|
||||
try:
|
||||
script = os.path.join(tmp, "make.py")
|
||||
with open(script, "w") as f:
|
||||
f.write(SCRIPT)
|
||||
out = os.path.join(tmp, "rig.blend")
|
||||
exe = shutil.which("blender")
|
||||
cmd = [exe] if exe else ["nix", "shell", "nixpkgs#blender", "-c", "blender"]
|
||||
env = dict(os.environ)
|
||||
env.pop("LD_LIBRARY_PATH", None)
|
||||
subprocess.run(cmd + ["-b", "--factory-startup", "--python", script, "--", out], capture_output=True, check=True, timeout=900, env=env)
|
||||
files = {"rig.blend": open(out, "rb").read()}
|
||||
finally:
|
||||
shutil.rmtree(tmp, ignore_errors=True)
|
||||
check.emit_inputs(ctx, files, {"riggedBlendBytes": "rig.blend"})
|
||||
Reference in new issue
Block a user