merge ws/blendrig2

This commit is contained in:
4DBug committed 2026-11-02 23:58:36 -06:00
commit b4e1ffebd4
15 files changed
+1683 -560

No files matched your search

+266 -41
View File
@@ -163733,7 +163733,8 @@ local __compat = __compat local buffer = __compat.buffer --!strict
-- meshes of every storage generation (MFace, MPoly / MLoop, attribute layers, AttributeStorage) with UV maps, colour
-- attributes, custom normals, material slots; Principled BSDF materials; packed and external images; cameras; lights;
-- armatures, skins (vertex groups, top 4 weights), shape keys (relative keys, vertex groups); actions sampled into
-- channels; rig data (bone collections / layers, colours, custom shapes, pose settings, constraint stacks) as extras.
-- channels, and every action's raw f-curves in meta.blend.actions; rig data (bone collections / layers, colours,
-- custom shapes, pose settings, constraint stacks) as extras.
-- Not supported: modifiers (listed in meta.source.modifiers), curves / text / metaballs / grease pencil / volumes,
-- NLA strips, drivers, constraint evaluation, f-curve modifiers, linked libraries, collection instances.
@@ -163775,6 +163776,7 @@ local BlendFormat = {
function BlendFormat.sniff(r)
local head = r:peek(7)
if head == "BLENDER" then
@@ -163824,7 +163826,7 @@ BlendFormat.ipo = Anim.ipo
return BlendFormat
end
__FILES["model/blend/Anim"] = function()
local __compat = __compat local __iter = __compat.__iter --!strict
local __compat = __compat local bit32, __iter = __compat.bit32, __compat.__iter --!strict
-- model/blend/Anim: Blender actions (legacy bAction.curves, and the layered actions of 4.4+: layers -> strips ->
-- keyframe data -> channel bags matched by the AnimData slot handle) and f-curve evaluation: constant, linear,
-- bezier (handles shortened so the segment stays a function of time, as Blender does) and the Penner easing modes
@@ -163887,6 +163889,54 @@ return a.x < b.x
return { path = path, index = fc:num("array_index") or 0, keys = keys, extend = fc:num("extend") or 0, modifiers = #mods }
end
-- an action's f-curves: the legacy list, or (4.4+ layered actions) the channel bags of the strips of every layer whose
-- slot handle matches (handle nil: the first layer's first strip's first channel bag)
local function fcurves(f, act, handle)
local list= act:list("curves", "FCurve")
if #list > 0 or not act:has("layer_array") then
return list
end
local datas = act:pointers("strip_keyframe_data_array", act:num("strip_keyframe_data_array_num"))
for _, la in __iter(act:pointers("layer_array", act:num("layer_array_num"))) do
local lblk = la and Blend.resolve(f, la, act.block)
local layer = lblk and Blend.struct(f, lblk, 0, "ActionLayer")
if layer then
for _, sa in __iter(layer:pointers("strip_array", layer:num("strip_array_num"))) do
local sblk = sa and Blend.resolve(f, sa, act.block)
local strip = sblk and Blend.struct(f, sblk, 0, "ActionStrip")
local di = strip and strip:num("data_index")
local dblk = di and datas[di + 1] and Blend.resolve(f, datas[di + 1], act.block)
local kd = dblk and Blend.struct(f, dblk, 0, "ActionStripKeyframeData")
if kd then
for _, ba in __iter(kd:pointers("channelbag_array", kd:num("channelbag_array_num"))) do
local bblk = ba and Blend.resolve(f, ba, act.block)
local bag = bblk and (Blend.struct(f, bblk, 0, "ActionChannelBag") or Blend.struct(f, bblk, 0, "ActionChannelbag"))
if bag and (handle == nil or (bag:num("slot_handle") or 0) == handle) then
for _, ca in __iter(bag:pointers("fcurve_array", bag:num("fcurve_array_num"))) do
local cblk = ca and Blend.resolve(f, ca, act.block)
local fc = cblk and Blend.struct(f, cblk, 0, "FCurve")
if fc then
table.insert(list, fc)
end
end
if handle == nil then
return list
end
end
end
end
if handle == nil then
return list
end
end
end
if handle == nil then
return list
end
end
return list
end
function Anim.curves(f, adt)
if not adt then
return nil, nil
@@ -163895,41 +163945,8 @@ if not adt then
if not act then
return nil, nil
end
local list= act:list("curves", "FCurve")
if #list == 0 and act:has("layer_array") then
local handle = adt:num("slot_handle") or 0
local datas = act:pointers("strip_keyframe_data_array", act:num("strip_keyframe_data_array_num"))
for _, la in __iter(act:pointers("layer_array", act:num("layer_array_num"))) do
local lblk = la and Blend.resolve(f, la, act.block)
local layer = lblk and Blend.struct(f, lblk, 0, "ActionLayer")
if layer then
for _, sa in __iter(layer:pointers("strip_array", layer:num("strip_array_num"))) do
local sblk = sa and Blend.resolve(f, sa, act.block)
local strip = sblk and Blend.struct(f, sblk, 0, "ActionStrip")
local di = strip and strip:num("data_index")
local dblk = di and datas[di + 1] and Blend.resolve(f, datas[di + 1], act.block)
local kd = dblk and Blend.struct(f, dblk, 0, "ActionStripKeyframeData")
if kd then
for _, ba in __iter(kd:pointers("channelbag_array", kd:num("channelbag_array_num"))) do
local bblk = ba and Blend.resolve(f, ba, act.block)
local bag = bblk and (Blend.struct(f, bblk, 0, "ActionChannelBag") or Blend.struct(f, bblk, 0, "ActionChannelbag"))
if bag and (bag:num("slot_handle") or 0) == handle then
for _, ca in __iter(bag:pointers("fcurve_array", bag:num("fcurve_array_num"))) do
local cblk = ca and Blend.resolve(f, ca, act.block)
local fc = cblk and Blend.struct(f, cblk, 0, "FCurve")
if fc then
table.insert(list, fc)
end
end
end
end
end
end
end
end
end
local out= {}
for _, fc in __iter(list) do
for _, fc in __iter(fcurves(f, act, adt:num("slot_handle") or 0)) do
local c = curve(f, fc)
if c then
table.insert(out, c)
@@ -163938,6 +163955,67 @@ if not adt then
return out, act:idName()
end
-- ------------------------------------------------------------------------------------------------ raw actions
local INTERPOLATION= {
[0] = "CONSTANT", [1] = "LINEAR", [2] = "BEZIER", [3] = "BACK", [4] = "BOUNCE", [5] = "CIRC", [6] = "CUBIC",
[7] = "ELASTIC", [8] = "EXPO", [9] = "QUAD", [10] = "QUART", [11] = "QUINT", [12] = "SINE",
}
local EASING= { [0] = "AUTO", [1] = "EASE_IN", [2] = "EASE_OUT", [3] = "EASE_IN_OUT" }
local HANDLE= { [0] = "FREE", [1] = "AUTO", [2] = "VECTOR", [3] = "ALIGNED", [4] = "AUTO_CLAMPED" }
local ACT_FRAME_RANGE = 0x1000
-- an action as Blender's API shows it: frame_range (the manual range, else the keys' span, at least one frame) and
-- every f-curve with its keyframe points
function Anim.raw(f, act)
local curves= {}
local lo, hi= math.huge, -math.huge
for _, fc in __iter(fcurves(f, act, nil)) do
local path = fc:cstring("rna_path") or ""
local kind, who, rest = Anim.split(path)
local keys= {}
for _, b in __iter(fc:array("bezt", "BezTriple")) do
local v = b:vec("vec")
if v and #v >= 9 then
local x= v[4]
local k= { co = { x, v[5] }, handle_left = { v[1], v[2] }, handle_right = { v[7], v[8] } }
k.interpolation = INTERPOLATION[b:num("ipo") or 2] or "BEZIER"
k.easing = EASING[b:num("easing") or 0] or "AUTO"
k.handle_left_type, k.handle_right_type = HANDLE[b:num("h1") or 0], HANDLE[b:num("h2") or 0]
k.back, k.amplitude, k.period = b:num("back") or 1.70158, b:num("amplitude") or 0.8, b:num("period") or 4.1
table.insert(keys, k)
lo, hi = math.min(lo, x), math.max(hi, x)
end
end
if #keys == 0 then
for _, p in __iter(fc:array("fpt", "FPoint")) do
local v = p:vec("vec")
if v and #v >= 2 then
local x= v[1]
local k= { co = { x, v[2] } }
k.interpolation = "LINEAR"
table.insert(keys, k)
lo, hi = math.min(lo, x), math.max(hi, x)
end
end
end
local entry= { data_path = path, path = (kind == "pose.bones" and{rest }or{path})[1], keys = keys }
entry.bone = (kind == "pose.bones" and{who }or{nil
})[1] entry.array_index = fc:num("array_index") or 0
entry.extrapolation = (fc:num("extend") or 0) == 1 and"LINEAR" or"CONSTANT"
table.insert(curves, entry)
end
if bit32.band(act:num("flag") or 0, ACT_FRAME_RANGE) ~= 0 and act:has("frame_start") then
lo = act:num("frame_start") or 0
hi = act:num("frame_end") or 0
elseif lo > hi then
lo, hi = 0, 0
end
if hi <= lo then
hi = lo + 1
end
return { frame_range = { lo, hi }, curves = curves }
end
-- pre-2.5 IPO curves (Object.ipo / Key.ipo): the curve's adrcode picks the channel; object rotations are in units of
-- 10 degrees; the interpolation and extrapolation (0 constant, 1 linear; cyclic ones as constant) are per curve
local OB_ADR= {
@@ -164175,8 +164253,10 @@ local __compat = __compat local buffer, bit32, type, __iter = __compat.buffer, _
-- armature space, deform, connect, wire), bone collections (4.x BoneCollection arrays and lists; before 4.0 the layers
-- and bone groups converted as Blender 4.0's versioning does), bone colours (BoneColor; bone group colours before 4.0),
-- pose bones (custom shapes, locks, rotation mode, IK settings) and constraint stacks (bConstraint and the data structs
-- of IK, copy rotation / location / scale / transforms, damped track, limit rotation / location / scale, child of; the
-- common fields for the rest). Flags from DNA_armature_types.h, DNA_action_types.h, DNA_constraint_types.h.
-- of IK, copy rotation / location / scale / transforms, damped track, limit rotation / location / scale, child of,
-- action, transform, stretch to, armature, floor, limit distance, track to, locked track; the common fields for the
-- rest), bone inheritance and b-bone settings, the stored pose basis. Flags from DNA_armature_types.h,
-- DNA_action_types.h, DNA_constraint_types.h.
local Blend = __include("containers/Blend")
local Armature = {}
@@ -164234,6 +164314,33 @@ local PCHAN_DRAW_NO_CUSTOM_BONE_SIZE = 1
local LOCK_LOC, LOCK_ROT, LOCK_SCALE, LOCK_ROTW, LOCK_ROT4D = { 1, 2, 4 }, { 8, 16, 32 }, { 64, 128, 256 }, 512, 1024
local IK_NO_DOF, IK_LIMIT = { 1, 2, 4 }, { 8, 16, 32 }
local AXES = { "x", "y", "z" }
local XYZ= { [0] = "X", [1] = "Y", [2] = "Z" }
-- bActionConstraint.type, .mix_mode
local ACTION_CHANNEL= {
[0] = "ROTATION_X", [1] = "ROTATION_Y", [2] = "ROTATION_Z", [10] = "SCALE_X", [11] = "SCALE_Y", [12] = "SCALE_Z",
[20] = "LOCATION_X", [21] = "LOCATION_Y", [22] = "LOCATION_Z",
}
local ACTION_MIX= { [0] = "AFTER_FULL", [1] = "AFTER", [2] = "BEFORE", [3] = "BEFORE_FULL", [4] = "BEFORE_SPLIT", [5] = "AFTER_SPLIT" }
local MAP= { [0] = "LOCATION", [1] = "ROTATION", [2] = "SCALE" }
-- the driver target rotation modes (DTAR_ROTMODE_*)
local FROM_ROT= {
[0] = "AUTO", [1] = "XYZ", [2] = "XZY", [3] = "YXZ", [4] = "YZX", [5] = "ZXY", [6] = "ZYX", [7] = "QUATERNION",
[8] = "SWING_TWIST_X", [9] = "SWING_TWIST_Y", [10] = "SWING_TWIST_Z",
}
local MIX_LOC= { [0] = "ADD", [1] = "REPLACE" }
local MIX_ROT= { [0] = "ADD", [1] = "REPLACE", [2] = "BEFORE", [3] = "AFTER" }
local MIX_SCALE= { [0] = "REPLACE", [1] = "MULTIPLY" }
local VOLUME= { [0] = "VOLUME_XZX", [1] = "VOLUME_X", [2] = "VOLUME_Z", [3] = "NO_VOLUME" }
local KEEP_AXIS= { [0] = "PLANE_X", [1] = "SWING_Y", [2] = "PLANE_Z" }
local FLOOR= { [0] = "FLOOR_X", [1] = "FLOOR_Y", [2] = "FLOOR_Z", [3] = "FLOOR_NEGATIVE_X", [4] = "FLOOR_NEGATIVE_Y", [5] = "FLOOR_NEGATIVE_Z" }
local DIST_MODE= { [0] = "LIMITDIST_INSIDE", [1] = "LIMITDIST_OUTSIDE", [2] = "LIMITDIST_ONSURFACE" }
local UP= { [0] = "UP_X", [1] = "UP_Y", [2] = "UP_Z" }
local LOCK= { [0] = "LOCK_X", [1] = "LOCK_Y", [2] = "LOCK_Z" }
-- Bone.inherit_scale_mode, bbone_prev_type / bbone_next_type, bbone_mapping_mode
local INHERIT_SCALE= { [0] = "FULL", [1] = "FIX_SHEAR", [2] = "AVERAGE", [3] = "NONE", [4] = "NONE_LEGACY", [5] = "ALIGNED" }
local HANDLE_TYPE= { [0] = "AUTO", [1] = "ABSOLUTE", [2] = "RELATIVE", [3] = "TANGENT" }
local MAPPING= { [0] = "STRAIGHT", [1] = "CURVED" }
local BONE_HINGE, BONE_NO_SCALE, BONE_NO_LOCAL_LOCATION, BONE_RELATIVE_PARENTING, BONE_ADD_PARENT_END_ROLL = 0x200, 0x8000, 0x400000, 0x800000, 0x1000000
local function bit(v, mask)
return bit32.band(v or 0, mask) ~= 0
@@ -164408,7 +164515,35 @@ local flag = bone:num("flag") or 0
head_local = vec3(bone, "arm_head"),
tail_local = vec3(bone, "arm_tail"),
roll = bone:num("arm_roll"),
use_inherit_rotation = not bit(flag, BONE_HINGE),
use_local_location = not bit(flag, BONE_NO_LOCAL_LOCATION),
use_relative_parent = bit(flag, BONE_RELATIVE_PARENTING),
}
local ism = bone:num("inherit_scale_mode")
e.inherit_scale = (ism and{INHERIT_SCALE[ism] }or{(bit(flag, BONE_NO_SCALE) and"NONE_LEGACY" or"FULL") -- BONE_NO_SCALE before 2.81
})[1] e.bbone_segments = bone:num("segments") or 1
e.bbone_x, e.bbone_z = bone:num("xwidth"), bone:num("zwidth")
e.bbone_easein, e.bbone_easeout = bone:num("ease1") or 1, bone:num("ease2") or 1
e.bbone_rollin, e.bbone_rollout = bone:num("roll1") or 0, bone:num("roll2") or 0
e.bbone_curveinx, e.bbone_curveinz = bone:num("curveInX") or 0, bone:num("curveInY") or 0 -- curveInY is the API's z
e.bbone_curveoutx, e.bbone_curveoutz = bone:num("curveOutX") or 0, bone:num("curveOutY") or 0
for _, side in __iter({ "in", "out" }) do
local cap = side == "in" and"In" or"Out"
local v = vec3(bone, "scale_" .. side)
if not v then
-- before 3.0: scaleIn (x) and scale_in_y (z); before 2.8 one value for both
local x = bone:num("scale" .. cap) or 1
v = { x, 1, bone:num("scale_" .. side .. "_y") or x }
end
e["bbone_scale" .. side] = v
end
e.bbone_handle_type_start = HANDLE_TYPE[bone:num("bbone_prev_type") or 0]
e.bbone_handle_type_end = HANDLE_TYPE[bone:num("bbone_next_type") or 0]
local prev, nxt = bone:deref("bbone_prev", 0, "Bone"), bone:deref("bbone_next", 0, "Bone")
e.bbone_custom_handle_start = (prev and{(prev:str("name") )}or{nil
})[1] e.bbone_custom_handle_end = (nxt and{(nxt:str("name") )}or{nil
})[1] e.use_endroll_as_inroll = (bone:has("bbone_flag") and{(bit(bone:num("bbone_flag"), 1) )}or{(bit(flag, BONE_ADD_PARENT_END_ROLL)
)})[1] e.bbone_mapping_mode = MAPPING[bone:num("bbone_mapping_mode") or 0]
if bone:has("color") then
e.color = boneColor(bone)
elseif pc and pose then
@@ -164455,10 +164590,72 @@ local function constraintData(e, kind, d, resolve)
e.invert_x, e.invert_y, e.invert_z = bit(flag, 16), bit(flag, 32), bit(flag, 64)
e.use_offset = bit(flag, 128)
elseif kind == "COPY_SCALE" then
-- SIZELIKE_X 1, Y 2, Z 4, OFFSET 8
-- SIZELIKE_X 1, Y 2, Z 4, OFFSET 8, MULTIPLY 16 (use_add is its inverse), UNIFORM 32
e.use_x, e.use_y, e.use_z = bit(flag, 1), bit(flag, 2), bit(flag, 4)
e.use_offset = bit(flag, 8)
e.use_add = not bit(flag, 16)
e.use_make_uniform = bit(flag, 32)
e.power = d:num("power") or 1
elseif kind == "ACTION" then
-- flag: ACTCON_BONE_USE_OBJECT_ACTION 1, ACTCON_USE_EVAL_TIME 2
local act = d:deref("act", 0, "bAction")
e.action = (act and{(act:idName() )}or{nil
})[1] e.transform_channel = ACTION_CHANNEL[d:num("type") or 20]
e.frame_start, e.frame_end = d:num("start") or 1, d:num("end") or 1
e.min, e.max = d:num("min") or 0, d:num("max") or 0
e.mix_mode = ACTION_MIX[d:num("mix_mode") or 0]
e.use_bone_object_action = bit(flag, 1)
e.use_eval_time = bit(flag, 2)
e.eval_time = d:num("eval_time") or 0
elseif kind == "TRANSFORM" then
e.map_from, e.map_to = MAP[d:num("from") or 0], MAP[d:num("to") or 0]
local map = d.struct.byName.map
for i, a in __iter(AXES) do
local o = map and d.offset + map.offset + i - 1
e["map_to_" .. a .. "_from"] = XYZ[(o and o < buffer.len(d.file.buf) and{(buffer.readu8(d.file.buf, o) )}or{(i - 1)})[1] ]
end
e.use_motion_extrapolate = (d:num("expo") or 0) ~= 0
e.from_rotation_mode = FROM_ROT[d:num("from_rotation_mode") or 0]
e.to_euler_order = EULER_ORDER[d:num("to_euler_order") or 0]
e.mix_mode = MIX_LOC[d:num("mix_mode_loc") or 0]
e.mix_mode_rot = MIX_ROT[d:num("mix_mode_rot") or 0]
e.mix_mode_scale = MIX_SCALE[d:num("mix_mode_scale") or 0]
for _, side in __iter({ "from", "to" }) do
for _, suffix in __iter({ "", "_rot", "_scale" }) do
local lo, hi = d:vec(side .. "_min" .. suffix), d:vec(side .. "_max" .. suffix)
for i, a in __iter(AXES) do
e[side .. "_min_" .. a .. suffix] = lo and lo[i] or 0
e[side .. "_max_" .. a .. suffix] = hi and hi[i] or 0
end
end
end
elseif kind == "STRETCH_TO" then
-- STRETCHTOCON_USE_BULGE_MIN 1, MAX 2
e.rest_length = d:num("orglength")
e.bulge = d:num("bulge")
e.volume = VOLUME[d:num("volmode") or 0]
e.keep_axis = KEEP_AXIS[d:num("plane") or 0]
e.use_bulge_min, e.use_bulge_max = bit(flag, 1), bit(flag, 2)
e.bulge_min, e.bulge_max, e.bulge_smooth = d:num("bulge_min"), d:num("bulge_max"), d:num("bulge_smooth")
elseif kind == "ARMATURE" then
-- CONSTRAINT_ARMATURE_QUATERNION 1, ENVELOPE 2, CUR_LOCATION 4
e.use_deform_preserve_volume, e.use_bone_envelopes, e.use_current_location = bit(flag, 1), bit(flag, 2), bit(flag, 4)
elseif kind == "FLOOR" then
-- flag: MINMAX_USEROT 4
e.floor_location = FLOOR[d:num("minmaxflag") or 2]
e.offset = d:num("offset") or 0
e.use_rotation = bit(flag, 4)
elseif kind == "LIMIT_DISTANCE" then
e.distance = d:num("dist")
e.limit_mode = DIST_MODE[d:num("mode") or 0]
elseif kind == "TRACK_TO" then
-- reserved1 the track axis, reserved2 the up axis; flags TARGET_Z_UP 1
e.track_axis = TRACK[d:num("reserved1") or 1]
e.up_axis = UP[d:num("reserved2") or 2]
e.use_target_z = bit(d:num("flags"), 1)
elseif kind == "LOCKED_TRACK" then
e.track_axis = TRACK[d:num("trackflag") or 1]
e.lock_axis = LOCK[d:num("lockflag") or 2]
elseif kind == "COPY_TRANSFORMS" then
e.mix_mode = TRANS_MIX[d:num("mix_mode") or 0]
e.remove_target_shear = bit(flag, 1)
@@ -164571,7 +164768,15 @@ function Armature.pose(e, pc, resolve, shape)
e["ik_stiffness_" .. a] = stiff and stiff[i] or 0
end
e.pose_color = (pc:has("color") and{(boneColor(pc) )}or{nil
})[1] e.constraints = Armature.constraints(pc, resolve)
})[1] -- the stored basis (rotation_quaternion w, x, y, z; rotation_axis_angle angle, x, y, z)
e.location = vec3(pc, "loc", { 0, 0, 0 })
local q = pc:vec("quat")
e.rotation_quaternion = q and #q >= 4 and{ q[1], q[2], q[3], q[4] } or{ 1, 0, 0, 0 }
e.rotation_euler = vec3(pc, "eul", { 0, 0, 0 })
local axis = (vec3(pc, "rotAxis", { 0, 1, 0 }) )
e.rotation_axis_angle = { pc:num("rotAngle") or 0, axis[1], axis[2], axis[3] }
e.scale = vec3(pc, "size", nil) or vec3(pc, "scale", { 1, 1, 1 })
e.constraints = Armature.constraints(pc, resolve)
end
return Armature
@@ -166320,6 +166525,7 @@ local Scene = Types.Scene
local OB_EMPTY, OB_MESH, OB_LAMP, OB_CAMERA, OB_ARMATURE = 0, 1, 10, 11, 25
local PARSKEL, PARBONE = 4, 7
local LA_LOCAL, LA_SUN, LA_SPOT, LA_HEMI, LA_AREA = 0, 1, 2, 3, 4
@@ -167300,8 +167506,27 @@ local o= opts or {}
end
end
skins(ctx)
local mb= {}
if next(ctx.armatures) ~= nil then
scene.meta.blend = { widgets = widgetList(ctx), bone_color_sets = Armature.colorSets() }
mb.widgets = widgetList(ctx)
mb.bone_color_sets = Armature.colorSets()
end
-- every action in the file by name (assigned or not: action constraints and the NLA refer to them)
if o.rawActions ~= false then
local acts= {}
for _, b in __iter(Blend.blocks(f, "AC")) do
local act = Blend.struct(f, b, 0, "bAction")
local name = act and act:idName()
if act and name and not acts[name] then
acts[name] = Anim.raw(f, act)
end
end
if next(acts) ~= nil then
mb.actions = acts
end
end
if next(mb) ~= nil then
scene.meta.blend = mb
end
if o.animations ~= false then
animations(ctx)