model/blend: drivers (object, object data, shape keys: variables, targets, keys, f-curve modifiers) and custom properties (objects, pose bones, bones) as data; f-curve modifiers on raw action curves; limit rotation use_legacy_behavior; 5.0 bone hide driver move for older files
This commit is contained in:
1 parent
b4e1ffebd4
commit
a1a3971207
16 files changed
+2056
-605
No files matched your search
+352
-57
@@ -163734,9 +163734,9 @@ local __compat = __compat local buffer = __compat.buffer --!strict
|
||||
-- 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, 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.
|
||||
-- custom shapes, pose settings, constraint stacks), drivers and custom properties as extras (data, never evaluated).
|
||||
-- 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.
|
||||
-- NLA strips, driver and constraint evaluation, f-curve modifiers, linked libraries, collection instances.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = __include("core/Err")
|
||||
@@ -163826,7 +163826,7 @@ BlendFormat.ipo = Anim.ipo
|
||||
return BlendFormat
|
||||
end
|
||||
__FILES["model/blend/Anim"] = function()
|
||||
local __compat = __compat local bit32, __iter = __compat.bit32, __compat.__iter --!strict
|
||||
local __compat = __compat local bit32, type, __iter = __compat.bit32, __compat.type, __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
|
||||
@@ -163964,44 +163964,133 @@ local EASING= { [0] = "AUTO", [1] = "EASE_IN", [2] = "EASE_OUT", [3] = "EASE_IN_
|
||||
local HANDLE= { [0] = "FREE", [1] = "AUTO", [2] = "VECTOR", [3] = "ALIGNED", [4] = "AUTO_CLAMPED" }
|
||||
local ACT_FRAME_RANGE = 0x1000
|
||||
|
||||
-- FModifier.type, flag (FMODIFIER_FLAG_MUTED 8, RANGERESTRICT 16, USEINFLUENCE 32)
|
||||
local MOD_TYPE= {
|
||||
[1] = "GENERATOR", [2] = "FNGENERATOR", [3] = "ENVELOPE", [4] = "CYCLES", [5] = "NOISE", [6] = "FILTER", [7] = "PYTHON",
|
||||
[8] = "LIMITS", [9] = "STEPPED",
|
||||
}
|
||||
local CYCLE_MODE= { [0] = "NONE", [1] = "REPEAT", [2] = "REPEAT_OFFSET", [3] = "MIRROR" }
|
||||
local FN_TYPE= { [0] = "SIN", [1] = "COS", [2] = "TAN", [3] = "SQRT", [4] = "LN", [5] = "SINC" }
|
||||
local NOISE_BLEND= { [0] = "REPLACE", [1] = "ADD", [2] = "SUBTRACT", [3] = "MULTIPLY" }
|
||||
|
||||
local function bit(v, mask)
|
||||
return bit32.band(v or 0, mask) ~= 0
|
||||
end
|
||||
|
||||
local function modifier(f, m)
|
||||
local t = m:num("type") or 0
|
||||
local flag = m:num("flag") or 0
|
||||
local e= { type = MOD_TYPE[t] or tostring(t), name = m:str("name") }
|
||||
e.mute = bit(flag, 8)
|
||||
e.use_restricted_range = bit(flag, 16)
|
||||
e.use_influence = bit(flag, 32)
|
||||
e.influence = m:num("influence") or 1
|
||||
e.frame_start, e.frame_end = m:num("sfra") or 0, m:num("efra") or 0
|
||||
e.blend_in, e.blend_out = m:num("blendin") or 0, m:num("blendout") or 0
|
||||
local d = m:deref("data", 0)
|
||||
if not d then
|
||||
return e
|
||||
end
|
||||
local kind = e.type
|
||||
if kind == "GENERATOR" then
|
||||
-- mode 0 expanded polynomial, 1 factorised; flag FCM_GENERATOR_ADDITIVE 1
|
||||
e.mode = (d:num("mode") or 0) == 1 and"POLYNOMIAL_FACTORISED" or"POLYNOMIAL"
|
||||
e.use_additive = bit(d:num("flag"), 1)
|
||||
e.poly_order = d:num("poly_order") or 1
|
||||
local at, size = d:data("coefficients")
|
||||
local n = math.min(d:num("arraysize") or 0, math.floor(size / 4))
|
||||
local c = {}
|
||||
for k = 0, n - 1 do
|
||||
c[k + 1] = f.f32(f.buf, (at ) + k * 4)
|
||||
end
|
||||
e.coefficients = c
|
||||
elseif kind == "FNGENERATOR" then
|
||||
e.function_type = FN_TYPE[d:num("type") or 0]
|
||||
e.amplitude, e.phase_multiplier = d:num("amplitude"), d:num("phase_multiplier")
|
||||
e.phase_offset, e.value_offset = d:num("phase_offset"), d:num("value_offset")
|
||||
e.use_additive = bit(d:num("flag"), 1)
|
||||
elseif kind == "ENVELOPE" then
|
||||
e.reference_value, e.default_min, e.default_max = d:num("midval"), d:num("min"), d:num("max")
|
||||
local points = {}
|
||||
for _, p in __iter(d:array("data", "FCM_EnvelopeData")) do
|
||||
table.insert(points, { frame = p:num("time"), min = p:num("min"), max = p:num("max") })
|
||||
end
|
||||
e.control_points = points
|
||||
elseif kind == "CYCLES" then
|
||||
e.mode_before, e.mode_after = CYCLE_MODE[d:num("before_mode") or 1], CYCLE_MODE[d:num("after_mode") or 1]
|
||||
e.cycles_before, e.cycles_after = d:num("before_cycles") or 0, d:num("after_cycles") or 0
|
||||
elseif kind == "NOISE" then
|
||||
e.blend_type = NOISE_BLEND[d:num("modification") or 0]
|
||||
e.scale, e.strength, e.phase, e.offset, e.depth = d:num("size"), d:num("strength"), d:num("phase"), d:num("offset"), d:num("depth")
|
||||
elseif kind == "LIMITS" then
|
||||
-- flag FCM_LIMIT_XMIN 1, XMAX 2, YMIN 4, YMAX 8
|
||||
local r = d:sub("rect")
|
||||
local fl = d:num("flag")
|
||||
e.use_min_x, e.use_max_x, e.use_min_y, e.use_max_y = bit(fl, 1), bit(fl, 2), bit(fl, 4), bit(fl, 8)
|
||||
if r then
|
||||
e.min_x, e.max_x, e.min_y, e.max_y = r:num("xmin"), r:num("xmax"), r:num("ymin"), r:num("ymax")
|
||||
end
|
||||
elseif kind == "STEPPED" then
|
||||
-- the API's frame_start / frame_end here are the stepping limits (flag FCM_STEPPED_NO_BEFORE 1, NO_AFTER 2)
|
||||
e.frame_step, e.frame_offset = d:num("step_size"), d:num("offset")
|
||||
e.use_frame_start, e.use_frame_end = bit(d:num("flag"), 1), bit(d:num("flag"), 2)
|
||||
e.frame_start, e.frame_end = d:num("start_frame"), d:num("end_frame")
|
||||
end
|
||||
return e
|
||||
end
|
||||
|
||||
-- an f-curve as Blender's API shows it: { data_path, bone?, path, array_index, extrapolation, keys, modifiers }, and
|
||||
-- its keys' frame span
|
||||
function Anim.fcurve(f, fc)
|
||||
local lo, hi= math.huge, -math.huge
|
||||
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"
|
||||
local mods = {}
|
||||
for _, m in __iter(fc:list("modifiers", "FModifier")) do
|
||||
table.insert(mods, modifier(f, m))
|
||||
end
|
||||
entry.modifiers = mods
|
||||
return entry, lo, hi
|
||||
end
|
||||
|
||||
-- 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"
|
||||
local entry, a, b = Anim.fcurve(f, fc)
|
||||
lo, hi = math.min(lo, a), math.max(hi, b)
|
||||
table.insert(curves, entry)
|
||||
end
|
||||
if bit32.band(act:num("flag") or 0, ACT_FRAME_RANGE) ~= 0 and act:has("frame_start") then
|
||||
@@ -164670,6 +164759,8 @@ local function constraintData(e, kind, d, resolve)
|
||||
end
|
||||
e.use_transform_limit = bit(d:num("flag2"), 2)
|
||||
e.euler_order = EULER_ORDER[d:num("euler_order") or 0]
|
||||
-- LIMIT_ROT_LEGACY 8; files before 4.2 keep the old behaviour (Blender's versioning sets it)
|
||||
e.use_legacy_behavior = bit(flag, 8) or d.file.version < 402
|
||||
elseif kind == "LIMIT_LOCATION" or kind == "LIMIT_SCALE" then
|
||||
-- LIMIT_XMIN 1, XMAX 2, YMIN 4, YMAX 8, ZMIN 16, ZMAX 32; flag2 LIMIT_TRANSFORM 2
|
||||
for i, a in __iter(AXES) do
|
||||
@@ -164781,6 +164872,181 @@ end
|
||||
|
||||
return Armature
|
||||
end
|
||||
__FILES["model/blend/Driver"] = function()
|
||||
local __compat = __compat local buffer, bit32, type, __iter = __compat.buffer, __compat.bit32, __compat.type, __compat.__iter --!strict
|
||||
-- model/blend/Driver: drivers (AnimData.drivers: FCurves with a ChannelDriver, its DriverVars and DriverTargets) and
|
||||
-- ID properties (IDProperty groups: custom properties) as data, in Blender's Python API names. Never evaluated.
|
||||
-- Enums from DNA_anim_types.h and DNA_ID.h.
|
||||
local Blend = __include("containers/Blend")
|
||||
local Anim = __include("model/blend/Anim")
|
||||
|
||||
local Driver = {}
|
||||
|
||||
-- ChannelDriver.type; flag DRIVER_FLAG_USE_SELF 64
|
||||
|
||||
|
||||
local TYPE= { [0] = "AVERAGE", [1] = "SCRIPTED", [2] = "SUM", [3] = "MIN", [4] = "MAX" }
|
||||
local VAR_TYPE= { [0] = "SINGLE_PROP", [1] = "ROTATION_DIFF", [2] = "LOC_DIFF", [3] = "TRANSFORMS", [4] = "CONTEXT_PROP" }
|
||||
-- DriverTarget.transChan, rotation_mode (DTAR_ROTMODE_*), context_property
|
||||
local TRANSFORM= {
|
||||
[0] = "LOC_X", [1] = "LOC_Y", [2] = "LOC_Z", [3] = "ROT_X", [4] = "ROT_Y", [5] = "ROT_Z", [6] = "SCALE_X",
|
||||
[7] = "SCALE_Y", [8] = "SCALE_Z", [9] = "SCALE_AVG", [10] = "ROT_W",
|
||||
}
|
||||
local ROTATION_MODE= {
|
||||
[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 CONTEXT= { [0] = "ACTIVE_SCENE", [1] = "ACTIVE_VIEW_LAYER" }
|
||||
-- ID codes (two characters) to the API's id_type
|
||||
local ID_TYPE= {
|
||||
OB = "OBJECT", ME = "MESH", AR = "ARMATURE", KE = "KEY", MA = "MATERIAL", SC = "SCENE", WO = "WORLD", CA = "CAMERA",
|
||||
LA = "LIGHT", TE = "TEXTURE", AC = "ACTION", GR = "COLLECTION", NT = "NODETREE", IM = "IMAGE", TX = "TEXT",
|
||||
CU = "CURVE", LT = "LATTICE", MB = "META", SK = "SPEAKER", PA = "PARTICLE", LS = "LINESTYLE", GD = "GREASEPENCIL",
|
||||
MC = "MOVIECLIP", MK = "MASK", PL = "PALETTE", CF = "CACHEFILE", WS = "WORKSPACE", LP = "LIGHT_PROBE", VO = "VOLUME",
|
||||
PT = "POINTCLOUD", CV = "CURVES", GP = "GREASEPENCIL_V3", SO = "SOUND", VF = "FONT", BR = "BRUSH", LI = "LIBRARY",
|
||||
WM = "WINDOWMANAGER", SN = "SCREEN",
|
||||
}
|
||||
|
||||
local function bit(v, mask)
|
||||
return bit32.band(v or 0, mask) ~= 0
|
||||
end
|
||||
|
||||
local function idType(f, code)
|
||||
if not code or code == 0 then
|
||||
return "OBJECT"
|
||||
end
|
||||
local lo, hi = bit32.band(code, 255), bit32.band(bit32.rshift(code, 8), 255)
|
||||
local a, b = (f.little and{lo }or{hi})[1], (f.little and{hi }or{lo
|
||||
})[1] local s = string.char(a, b)
|
||||
return ID_TYPE[s] or s
|
||||
end
|
||||
|
||||
-- a DriverTarget: id resolved to a node (objects in the scene) or the ID's name; flag DTAR_FLAG_LOCALSPACE 4,
|
||||
-- DTAR_FLAG_LOCAL_CONSTS 8 (with LOCALSPACE: the API's LOCAL_SPACE, alone TRANSFORM_SPACE); options
|
||||
-- DTAR_OPTION_USE_FALLBACK 1
|
||||
local function target(f, t, resolve)
|
||||
local flag = t:num("flag") or 0
|
||||
local e= { id = resolve(t:deref("id", 0)), id_type = idType(f, t:num("idtype")) }
|
||||
e.data_path = t:cstring("rna_path") or ""
|
||||
e.bone_target = t:str("pchan_name") or ""
|
||||
e.transform_type = TRANSFORM[t:num("transChan") or 0]
|
||||
e.transform_space = not bit(flag, 4) and"WORLD_SPACE" or(bit(flag, 8) and"LOCAL_SPACE" or"TRANSFORM_SPACE"
|
||||
) e.rotation_mode = ROTATION_MODE[t:num("rotation_mode") or 0]
|
||||
e.context_property = CONTEXT[t:num("context_property") or 0]
|
||||
if t:has("fallback_value") then
|
||||
e.use_fallback_value = bit(t:num("options"), 1)
|
||||
e.fallback_value = t:num("fallback_value")
|
||||
end
|
||||
return e
|
||||
end
|
||||
|
||||
-- the driver f-curves of an AnimData: Anim.fcurve's fields plus driver = { type, expression, use_self, variables }
|
||||
function Driver.list(f, adt, resolve)
|
||||
local out = {}
|
||||
if not adt then
|
||||
return out
|
||||
end
|
||||
for _, fc in __iter(adt:list("drivers", "FCurve")) do
|
||||
local entry = Anim.fcurve(f, fc)
|
||||
local d = fc:deref("driver", 0, "ChannelDriver")
|
||||
if d then
|
||||
local variables = {}
|
||||
for _, v in __iter(d:list("variables", "DriverVar")) do
|
||||
local targets = {}
|
||||
local list = v:get("targets")
|
||||
local n = math.min(v:num("num_targets") or 1, (type(list) == "table" and((#list ))or(0)))
|
||||
for k = 1, n do
|
||||
table.insert(targets, target(f, list[k], resolve))
|
||||
end
|
||||
table.insert(variables, { name = v:str("name") or "", type = VAR_TYPE[v:num("type") or 0] or "SINGLE_PROP", targets = targets })
|
||||
end
|
||||
entry.driver = {
|
||||
type = TYPE[d:num("type") or 0] or "AVERAGE",
|
||||
expression = d:str("expression") or "",
|
||||
use_self = bit(d:num("flag"), 64),
|
||||
variables = variables,
|
||||
}
|
||||
end
|
||||
table.insert(out, entry)
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ ID properties
|
||||
-- IDProperty.type: STRING 0, INT 1, FLOAT 2, ARRAY 5, GROUP 6, ID 7, DOUBLE 8, IDPARRAY 9, BOOLEAN 10
|
||||
local function value(p, depth)
|
||||
local t = p:num("type") or -1
|
||||
local f = p.file
|
||||
local d = p:sub("data")
|
||||
if not d or depth > 32 then
|
||||
return nil
|
||||
end
|
||||
local valField = d.struct.byName.val
|
||||
local valAt = valField and d.offset + valField.offset
|
||||
if t == 1 then
|
||||
return d:num("val")
|
||||
elseif t == 10 then
|
||||
return (d:num("val") or 0) ~= 0
|
||||
elseif t == 2 then
|
||||
return (valAt and valAt + 4 <= buffer.len(f.buf) and{(f.f32(f.buf, valAt) )}or{nil
|
||||
})[1] elseif t == 8 then
|
||||
return (valAt and valAt + 8 <= buffer.len(f.buf) and{(f.f64(f.buf, valAt) )}or{nil
|
||||
})[1] elseif t == 0 then
|
||||
local at, size = d:data("pointer")
|
||||
if not at then
|
||||
return ""
|
||||
end
|
||||
local s = buffer.readstring(f.buf, at, math.min(size, math.max(p:num("len") or size, 0)))
|
||||
local z = string.find(s, "\0", 1, true)
|
||||
return (z and{(string.sub(s, 1, z - 1) )}or{s
|
||||
})[1] elseif t == 5 then
|
||||
local at, size = d:data("pointer")
|
||||
local sub = p:num("subtype") or 1
|
||||
local width = sub == 8 and 8 or(sub == 10 and 1 or 4
|
||||
) local n = math.min(p:num("len") or 0, math.floor(size / width))
|
||||
local out = table.create(n)
|
||||
for k = 0, n - 1 do
|
||||
local o = (at ) + k * width
|
||||
out[k + 1] = (sub == 2 and{(f.f32(f.buf, o) )}or{(sub == 8 and{(f.f64(f.buf, o) )}or{(sub == 10 and{(buffer.readu8(f.buf, o) ~= 0 )}or{(f.i32(f.buf, o)
|
||||
)})[1]})[1]})[1] end
|
||||
return out
|
||||
elseif t == 6 then
|
||||
local out = {}
|
||||
for _, c in __iter(d:list("group", "IDProperty")) do
|
||||
local name = c:str("name")
|
||||
if name then
|
||||
out[name] = value(c, depth + 1)
|
||||
end
|
||||
end
|
||||
return out
|
||||
elseif t == 7 then
|
||||
local id = d:deref("pointer", 0)
|
||||
return (id and{(id:idName() )}or{nil
|
||||
})[1] elseif t == 9 then
|
||||
local out = {}
|
||||
for k, c in __iter(d:array("pointer", "IDProperty")) do
|
||||
out[k] = value(c, depth + 1)
|
||||
end
|
||||
return out
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- a properties group as { [name] = number | boolean | string | array | table } (the pre-3.0 "_RNA_UI" metadata left out)
|
||||
function Driver.props(group)
|
||||
if not group or (group:num("type") or -1) ~= 6 then
|
||||
return nil
|
||||
end
|
||||
local out = value(group, 0)
|
||||
if type(out) ~= "table" then
|
||||
return nil
|
||||
end
|
||||
out._RNA_UI = nil
|
||||
return (next(out) ~= nil and{out }or{nil
|
||||
})[1]end
|
||||
|
||||
return Driver
|
||||
end
|
||||
__FILES["model/blend/Material"] = function()
|
||||
local __compat = __compat local buffer, bit32, type, __iter = __compat.buffer, __compat.bit32, __compat.type, __compat.__iter --!strict
|
||||
-- model/blend/Material: Blender materials to Scene PBR materials. With nodes: the Principled BSDF (the one feeding the
|
||||
@@ -166506,6 +166772,7 @@ local Prim = __include("model/blend/Prim")
|
||||
local Anim = __include("model/blend/Anim")
|
||||
local Material = __include("model/blend/Material")
|
||||
local Armature = __include("model/blend/Armature")
|
||||
local Driver = __include("model/blend/Driver")
|
||||
|
||||
local Read = {}
|
||||
|
||||
@@ -166924,6 +167191,25 @@ local names, list= {}, {}
|
||||
return names, list
|
||||
end
|
||||
|
||||
-- an object as a constraint target or custom shape: its node, else its name; widgets records custom shapes
|
||||
local function resolver(ctx, widgets)
|
||||
return function(ob)
|
||||
if not ob then
|
||||
return nil
|
||||
end
|
||||
local addr = ob.block and ob.block.addr
|
||||
if widgets and addr ~= nil and not ctx.widgets[addr] then
|
||||
ctx.widgets[addr] = ob
|
||||
table.insert(ctx.widgetOrder, addr)
|
||||
end
|
||||
local node = (addr ~= nil and{ctx.objects[addr] }or{nil
|
||||
})[1] if node then
|
||||
return node
|
||||
end
|
||||
return ob:idName()
|
||||
end
|
||||
end
|
||||
|
||||
-- the scene mesh of an object's mesh data (shared between objects with the same data, slots and armature)
|
||||
local function meshOf(ctx, ob, lines)
|
||||
local f = ctx.f
|
||||
@@ -166966,7 +167252,10 @@ local f = ctx.f
|
||||
) end
|
||||
end
|
||||
if #shapes > 1 then
|
||||
local names, list = shapeExtras(shapes, ref)
|
||||
local key = me:deref("key", 0, "Key")
|
||||
local kd = Driver.list(f, key and key:deref("adt", 0, "AnimData"), resolver(ctx, false))
|
||||
extras.shape_key_drivers = (#kd > 0 and{kd }or{nil
|
||||
})[1] local names, list = shapeExtras(shapes, ref)
|
||||
m.extras = { blend = extras, targetNames = names }
|
||||
extras.shape_keys = list
|
||||
extras.reference_key = (ref and{shapes[ref].name }or{nil
|
||||
@@ -167101,25 +167390,6 @@ local addr = ob.block and ob.block.addr
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ rigs
|
||||
-- an object as a constraint target or custom shape: its node, else its name; widgets records custom shapes
|
||||
local function resolver(ctx, widgets)
|
||||
return function(ob)
|
||||
if not ob then
|
||||
return nil
|
||||
end
|
||||
local addr = ob.block and ob.block.addr
|
||||
if widgets and addr ~= nil and not ctx.widgets[addr] then
|
||||
ctx.widgets[addr] = ob
|
||||
table.insert(ctx.widgetOrder, addr)
|
||||
end
|
||||
local node = (addr ~= nil and{ctx.objects[addr] }or{nil
|
||||
})[1] if node then
|
||||
return node
|
||||
end
|
||||
return ob:idName()
|
||||
end
|
||||
end
|
||||
|
||||
local function rigs(ctx)
|
||||
local target, shape = resolver(ctx, false), resolver(ctx, true)
|
||||
for node = 1, #ctx.scene.nodes do
|
||||
@@ -167132,7 +167402,30 @@ __DARKLUA_CONTINUE_16=true break
|
||||
if #list > 0 then
|
||||
extras.constraints = list
|
||||
end
|
||||
local info = ob.block and ctx.armatures[ob.block.addr]
|
||||
local id = ob:sub("id")
|
||||
extras.props = Driver.props(id and id:deref("properties", 0, "IDProperty"))
|
||||
local drivers = Driver.list(ctx.f, ob:deref("adt", 0, "AnimData"), target)
|
||||
extras.drivers = (#drivers > 0 and{drivers }or{nil
|
||||
})[1] local dataBlock = ob:target("data")
|
||||
local data = dataBlock and Blend.struct(ctx.f, dataBlock)
|
||||
local dataDrivers = (data and data:has("adt") and{(Driver.list(ctx.f, data:deref("adt", 0, "AnimData"), target) )}or{{}
|
||||
})[1] if ctx.f.version < 500 and dataBlock and dataBlock.code == "AR" then
|
||||
-- Blender 5.0 moved bone visibility to pose bones: its versioning moves bones["x"].hide drivers to the object
|
||||
local kept = {}
|
||||
for _, d in __iter(dataDrivers) do
|
||||
local bone = string.match(d.data_path, '^bones%["(.-)"%]%.hide$')
|
||||
if bone then
|
||||
d.data_path, d.bone, d.path = "pose." .. d.data_path, bone, "hide"
|
||||
table.insert(drivers, d)
|
||||
else
|
||||
table.insert(kept, d)
|
||||
end
|
||||
end
|
||||
dataDrivers = kept
|
||||
extras.drivers = (#drivers > 0 and{drivers }or{nil
|
||||
})[1] end
|
||||
extras.data_drivers = (#dataDrivers > 0 and{dataDrivers }or{nil
|
||||
})[1] local info = ob.block and ctx.armatures[ob.block.addr]
|
||||
if info then
|
||||
local cols = Armature.collections(info.arm, info.bones, info.pose)
|
||||
extras.bone_collections = cols.list
|
||||
@@ -167144,7 +167437,9 @@ __DARKLUA_CONTINUE_16=true break
|
||||
e[k] = v
|
||||
end
|
||||
e.collections = cols.byBone[name] or {}
|
||||
if pc then
|
||||
e.bone_props = Driver.props(bone:deref("prop", 0, "IDProperty"))
|
||||
e.props = (pc and{(Driver.props(pc:deref("prop", 0, "IDProperty")) )}or{nil
|
||||
})[1] if pc then
|
||||
Armature.pose(e, pc, target, shape)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user