merge ws/blendrig2
This commit is contained in:
commit
b4e1ffebd4
15 files changed
+1683
-560
No files matched your search
@@ -61,6 +61,54 @@ local function curve(f: Blend.File, fc: Blend.View): Curve?
|
||||
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: Blend.File, act: Blend.View, handle: number?): { Blend.View }
|
||||
local list: { Blend.View } = 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 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 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 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 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: Blend.File, adt: Blend.View?): ({ Curve }?, string?)
|
||||
if not adt then
|
||||
return nil, nil
|
||||
@@ -69,41 +117,8 @@ function Anim.curves(f: Blend.File, adt: Blend.View?): ({ Curve }?, string?)
|
||||
if not act then
|
||||
return nil, nil
|
||||
end
|
||||
local list: { Blend.View } = 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 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 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 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 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: { Curve } = {}
|
||||
for _, fc in list do
|
||||
for _, fc in fcurves(f, act, adt:num("slot_handle") or 0) do
|
||||
local c = curve(f, fc)
|
||||
if c then
|
||||
table.insert(out, c)
|
||||
@@ -112,6 +127,67 @@ function Anim.curves(f: Blend.File, adt: Blend.View?): ({ Curve }?, string?)
|
||||
return out, act:idName()
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ raw actions
|
||||
local INTERPOLATION: { [number]: string } = {
|
||||
[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: { [number]: string } = { [0] = "AUTO", [1] = "EASE_IN", [2] = "EASE_OUT", [3] = "EASE_IN_OUT" }
|
||||
local HANDLE: { [number]: string } = { [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: Blend.File, act: Blend.View): { [string]: any }
|
||||
local curves: { { [string]: any } } = {}
|
||||
local lo: number, hi: number = math.huge, -math.huge
|
||||
for _, fc in fcurves(f, act, nil) do
|
||||
local path = fc:cstring("rna_path") or ""
|
||||
local kind, who, rest = Anim.split(path)
|
||||
local keys: { { [string]: any } } = {}
|
||||
for _, b in fc:array("bezt", "BezTriple") do
|
||||
local v = b:vec("vec")
|
||||
if v and #v >= 9 then
|
||||
local x: number = v[4]
|
||||
local k: { [string]: any } = { 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 fc:array("fpt", "FPoint") do
|
||||
local v = p:vec("vec")
|
||||
if v and #v >= 2 then
|
||||
local x: number = v[1]
|
||||
local k: { [string]: any } = { 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: { [string]: any } = { data_path = path, path = if kind == "pose.bones" then rest else path, keys = keys }
|
||||
entry.bone = if kind == "pose.bones" then who else nil
|
||||
entry.array_index = fc:num("array_index") or 0
|
||||
entry.extrapolation = if (fc:num("extend") or 0) == 1 then "LINEAR" else "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: { [number]: { any } } = {
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
-- 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 = require("@rosetta/containers/Blend")
|
||||
|
||||
local Armature = {}
|
||||
@@ -62,6 +64,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: { [number]: string } = { [0] = "X", [1] = "Y", [2] = "Z" }
|
||||
-- bActionConstraint.type, .mix_mode
|
||||
local ACTION_CHANNEL: { [number]: string } = {
|
||||
[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: { [number]: string } = { [0] = "AFTER_FULL", [1] = "AFTER", [2] = "BEFORE", [3] = "BEFORE_FULL", [4] = "BEFORE_SPLIT", [5] = "AFTER_SPLIT" }
|
||||
local MAP: { [number]: string } = { [0] = "LOCATION", [1] = "ROTATION", [2] = "SCALE" }
|
||||
-- the driver target rotation modes (DTAR_ROTMODE_*)
|
||||
local FROM_ROT: { [number]: string } = {
|
||||
[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: { [number]: string } = { [0] = "ADD", [1] = "REPLACE" }
|
||||
local MIX_ROT: { [number]: string } = { [0] = "ADD", [1] = "REPLACE", [2] = "BEFORE", [3] = "AFTER" }
|
||||
local MIX_SCALE: { [number]: string } = { [0] = "REPLACE", [1] = "MULTIPLY" }
|
||||
local VOLUME: { [number]: string } = { [0] = "VOLUME_XZX", [1] = "VOLUME_X", [2] = "VOLUME_Z", [3] = "NO_VOLUME" }
|
||||
local KEEP_AXIS: { [number]: string } = { [0] = "PLANE_X", [1] = "SWING_Y", [2] = "PLANE_Z" }
|
||||
local FLOOR: { [number]: string } = { [0] = "FLOOR_X", [1] = "FLOOR_Y", [2] = "FLOOR_Z", [3] = "FLOOR_NEGATIVE_X", [4] = "FLOOR_NEGATIVE_Y", [5] = "FLOOR_NEGATIVE_Z" }
|
||||
local DIST_MODE: { [number]: string } = { [0] = "LIMITDIST_INSIDE", [1] = "LIMITDIST_OUTSIDE", [2] = "LIMITDIST_ONSURFACE" }
|
||||
local UP: { [number]: string } = { [0] = "UP_X", [1] = "UP_Y", [2] = "UP_Z" }
|
||||
local LOCK: { [number]: string } = { [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: { [number]: string } = { [0] = "FULL", [1] = "FIX_SHEAR", [2] = "AVERAGE", [3] = "NONE", [4] = "NONE_LEGACY", [5] = "ALIGNED" }
|
||||
local HANDLE_TYPE: { [number]: string } = { [0] = "AUTO", [1] = "ABSOLUTE", [2] = "RELATIVE", [3] = "TANGENT" }
|
||||
local MAPPING: { [number]: string } = { [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: number?, mask: number): boolean
|
||||
return bit32.band(v or 0, mask) ~= 0
|
||||
@@ -236,7 +265,35 @@ function Armature.bone(bone: Blend.View, pc: Blend.View?, pose: Blend.View?): {
|
||||
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 = if ism then INHERIT_SCALE[ism] else (if bit(flag, BONE_NO_SCALE) then "NONE_LEGACY" else "FULL") -- BONE_NO_SCALE before 2.81
|
||||
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 { "in", "out" } do
|
||||
local cap = if side == "in" then "In" else "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 = if prev then prev:str("name") else nil
|
||||
e.bbone_custom_handle_end = if nxt then nxt:str("name") else nil
|
||||
e.use_endroll_as_inroll = if bone:has("bbone_flag") then bit(bone:num("bbone_flag"), 1) else bit(flag, BONE_ADD_PARENT_END_ROLL)
|
||||
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
|
||||
@@ -283,10 +340,72 @@ local function constraintData(e: { [string]: any }, kind: string, d: Blend.View,
|
||||
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 = if act then act:idName() else nil
|
||||
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 AXES do
|
||||
local o = map and d.offset + map.offset + i - 1
|
||||
e["map_to_" .. a .. "_from"] = XYZ[if o and o < buffer.len(d.file.buf) then buffer.readu8(d.file.buf, o) else i - 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 { "from", "to" } do
|
||||
for _, suffix in { "", "_rot", "_scale" } do
|
||||
local lo, hi = d:vec(side .. "_min" .. suffix), d:vec(side .. "_max" .. suffix)
|
||||
for i, a in 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)
|
||||
@@ -399,6 +518,14 @@ function Armature.pose(e: { [string]: any }, pc: Blend.View, resolve: Resolve, s
|
||||
e["ik_stiffness_" .. a] = stiff and stiff[i] or 0
|
||||
end
|
||||
e.pose_color = if pc:has("color") then boneColor(pc) else nil
|
||||
-- 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 = if q and #q >= 4 then { q[1], q[2], q[3], q[4] } else { 1, 0, 0, 0 }
|
||||
e.rotation_euler = vec3(pc, "eul", { 0, 0, 0 })
|
||||
local axis = vec3(pc, "rotAxis", { 0, 1, 0 }) :: { number }
|
||||
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
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ export type Options = {
|
||||
scene: string?, -- the scene to read (default: the file's current scene)
|
||||
sampleStep: number?, -- frames between animation samples (default 1)
|
||||
animations: boolean?, -- default true
|
||||
rawActions: boolean?, -- every action's f-curves in meta.blend.actions (default true)
|
||||
resolve: ((uri: string) -> any)?,
|
||||
files: { [string]: any }?,
|
||||
maxVertices: number?,
|
||||
@@ -1013,8 +1014,27 @@ function Read.scene(f: Blend.File, opts: Options?): (Types.Scene?, string?)
|
||||
end
|
||||
end
|
||||
skins(ctx)
|
||||
local mb: { [string]: any } = {}
|
||||
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: { [string]: any } = {}
|
||||
for _, b in 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)
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
-- 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.
|
||||
|
||||
@@ -38,6 +39,7 @@ export type DecodeOptions = {
|
||||
scene: string?, -- a scene by name (default: the file's current scene)
|
||||
sampleStep: number?, -- frames between animation samples (default 1)
|
||||
animations: boolean?, -- default true
|
||||
rawActions: boolean?, -- every action's f-curves and keys in meta.blend.actions (default true)
|
||||
resolve: ((uri: string) -> any)?, -- external images
|
||||
files: { [string]: any }?,
|
||||
maxBytes: number?, -- decompressed size limit (default 2^31)
|
||||
|
||||
Reference in new issue
Block a user