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
@@ -941,6 +941,15 @@ do
|
||||
bench("fbx ascii decode (" .. buffer.len(fbxa) // 1000 .. " KB)", 2, buffer.len(fbxa), function()
|
||||
Fbx.decode(Bytes.reader(fbxa))
|
||||
end)
|
||||
local BlendFmt = require("@rosetta/model/blend")
|
||||
for _, c in require("@tests/gen/blend_cur") do
|
||||
if c.name == "rig_52.blend" or c.name == "scene_52_z.blend" then
|
||||
local bb = buffer.fromstring(c.data)
|
||||
bench("blend decode " .. c.name .. " (" .. buffer.len(bb) // 1000 .. " KB)", 5, buffer.len(bb), function()
|
||||
BlendFmt.decode(Bytes.reader(bb))
|
||||
end)
|
||||
end
|
||||
end
|
||||
local ThreeMf = require("@rosetta/model/3mf")
|
||||
local tmf = assert(ThreeMf.encode(scene))
|
||||
bench("3mf decode (" .. buffer.len(tmf) // 1000 .. " KB zipped)", 2, buffer.len(tmf), function()
|
||||
|
||||
@@ -365,6 +365,18 @@ def rig_file():
|
||||
mover.keyframe_insert("location", frame=f)
|
||||
mover.keyframe_insert("rotation_euler", frame=f)
|
||||
mover.keyframe_insert("scale", frame=f)
|
||||
# easing interpolations (Penner) with explicit and automatic easing
|
||||
easer = link(bpy.data.objects.new("Easer", None))
|
||||
eases = (("SINE", "EASE_IN_OUT"), ("BOUNCE", "AUTO"), ("SINE", "EASE_OUT"), ("BACK", "EASE_IN"),
|
||||
("EXPO", "AUTO"), ("CIRC", "EASE_OUT"), ("QUART", "EASE_IN_OUT"), ("EXPO", "EASE_OUT"), ("EXPO", "EASE_IN_OUT"), ("CUBIC", "EASE_IN"))
|
||||
for k in range(len(eases) + 1):
|
||||
easer.location = (k % 2 * 2.0, k * 0.5, 0)
|
||||
easer.keyframe_insert("location", frame=1 + k * 2.5)
|
||||
for fc in (easer.animation_data.action.fcurves if hasattr(easer.animation_data.action, "fcurves") else
|
||||
[c for l in easer.animation_data.action.layers for s in l.strips for b in s.channelbags for c in b.fcurves]):
|
||||
for kp, (ipo, easing) in zip(fc.keyframe_points, eases):
|
||||
kp.interpolation = ipo
|
||||
kp.easing = easing
|
||||
rig_action = rig.animation_data.action
|
||||
mover_action = mover.animation_data.action
|
||||
for act, rules in ((rig_action, {"location": "LINEAR", "scale": "CONSTANT"}),
|
||||
|
||||
+51
-2
@@ -3,8 +3,10 @@
|
||||
# generation (MFace legacy save, MPoly / MLoop, attribute layers, AttributeStorage), gzip and zstd compression, the
|
||||
# 5.0 header, layered actions. Reference values come from the current Blender opening each file
|
||||
# (tools/fixtures/_blend_ref.py: bpy values plus its glTF exporter's output). An old Blender that does not run is
|
||||
# skipped (its cases are missing; the test notes it).
|
||||
# tests/gen/blend_<ver>.luau { { name, data, ref } }
|
||||
# skipped (its cases are missing; the test notes it). Plus a few Blender 1.6x / 2.0x files from download.blender.org's
|
||||
# old demos (fetched, never committed; 32-bit pointers, big-endian SGI / PowerPC files among them), with references
|
||||
# from Blender 4.1 (5.0 dropped big-endian files).
|
||||
# tests/gen/blend_<ver>.luau { { name, data, ref } } (<ver>: 279, 293, 35, 41, cur, old)
|
||||
# tests/gen/blend_files.luau sibling files the scenes refer to ({ ["outside.png"] = bytes })
|
||||
import json, os, shutil, subprocess, tempfile
|
||||
|
||||
@@ -18,6 +20,52 @@ OLD = [
|
||||
]
|
||||
|
||||
|
||||
OLD_DEMOS = "https://download.blender.org/demo/old_demos/"
|
||||
OLD_FILES = ["escher.blend", "hairball.blend", "nmesh.blend", "relative.blend", "demo2.04.blend.gz"]
|
||||
|
||||
|
||||
def old_samples(ctx, tmp):
|
||||
import gzip, urllib.request
|
||||
out = os.path.join(tmp, "olddemos")
|
||||
os.makedirs(out)
|
||||
files = []
|
||||
for f in OLD_FILES:
|
||||
try:
|
||||
with urllib.request.urlopen(OLD_DEMOS + f, timeout=60) as r:
|
||||
data = r.read()
|
||||
except OSError as e:
|
||||
print("blend: could not fetch %s: %s" % (f, e))
|
||||
continue
|
||||
if f.endswith(".gz"):
|
||||
data = gzip.decompress(data)
|
||||
f = f[:-3].replace("2.04", "204")
|
||||
with open(os.path.join(out, f), "wb") as fh:
|
||||
fh.write(data)
|
||||
files.append(os.path.join(out, f))
|
||||
if not files:
|
||||
return []
|
||||
refdir = os.path.join(tmp, "oldref")
|
||||
os.makedirs(refdir)
|
||||
ref = os.path.join(ctx.root, "tools", "fixtures", "_blend_ref.py")
|
||||
ok, log = run(["nix", "shell"] + OLD[3][1] + ["-c", "blender", "-b", "--factory-startup", "--python", ref, "--", json.dumps(files), refdir])
|
||||
cases = []
|
||||
for p in files:
|
||||
rp = os.path.join(refdir, os.path.basename(p) + ".json")
|
||||
if not os.path.exists(rp):
|
||||
continue
|
||||
r = json.load(open(rp))
|
||||
if r.get("error"):
|
||||
continue
|
||||
g = r.get("gltf")
|
||||
if g:
|
||||
for k in ("bufferViews", "asset", "scene", "scenes", "extensionsUsed", "samplers"):
|
||||
g.pop(k, None)
|
||||
cases.append({"name": "old/" + os.path.basename(p), "data": open(p, "rb").read(), "ref": clean(r)})
|
||||
if not cases:
|
||||
print("blend: Blender 4.1 gave no reference for the old demos: " + log[-400:])
|
||||
return cases
|
||||
|
||||
|
||||
def env():
|
||||
e = dict(os.environ)
|
||||
e.pop("LD_LIBRARY_PATH", None) # the host's alsa / pipewire libraries need a newer glibc than old Blenders have
|
||||
@@ -87,6 +135,7 @@ def generate(ctx):
|
||||
for tag, _ in OLD + [("cur", None)]:
|
||||
if tag not in made:
|
||||
ctx.emit("blend_" + tag, [])
|
||||
ctx.emit("blend_old", old_samples(ctx, tmp))
|
||||
ctx.emit("blend_files", {"outside.png": sibling or b""})
|
||||
ctx.emit("blend_versions", sorted(made.keys()))
|
||||
shutil.rmtree(tmp, ignore_errors=True)
|
||||
@@ -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