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
+105
-5
@@ -166,6 +166,32 @@ local function same(got: any, want: any, eps: number): boolean
|
||||
return got == want
|
||||
end
|
||||
|
||||
-- custom properties: tables key by key (arrays element by element), numbers within 1e-5
|
||||
local function deepSame(got: any, want: any): boolean
|
||||
if type(want) == "table" then
|
||||
if type(got) ~= "table" then
|
||||
return false
|
||||
end
|
||||
for k, v in want do
|
||||
if not deepSame(got[k], v) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
for k in got do
|
||||
if want[k] == nil then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
if type(want) == "number" then
|
||||
return type(got) == "number" and near(got, want, 1e-5)
|
||||
end
|
||||
return got == want
|
||||
end
|
||||
|
||||
local DRIVEN = {} -- a reference value bpy evaluated through a driver: not compared
|
||||
|
||||
local function angleNear(a: number?, b: number, eps: number): boolean
|
||||
if not a then
|
||||
return false
|
||||
@@ -181,7 +207,7 @@ local REQUIRED: { [string]: { string } } = {
|
||||
COPY_SCALE = { "use_x", "use_y", "use_z", "use_offset", "power", "use_add", "use_make_uniform" },
|
||||
COPY_TRANSFORMS = { "mix_mode", "head_tail" },
|
||||
DAMPED_TRACK = { "track_axis", "head_tail" },
|
||||
LIMIT_ROTATION = { "use_limit_x", "use_limit_y", "use_limit_z", "min_x", "max_x", "min_z", "max_z", "use_transform_limit" },
|
||||
LIMIT_ROTATION = { "use_limit_x", "use_limit_y", "use_limit_z", "min_x", "max_x", "min_z", "max_z", "use_transform_limit", "use_legacy_behavior" },
|
||||
LIMIT_LOCATION = { "use_min_x", "use_max_x", "use_min_z", "use_max_z", "min_x", "max_x", "min_z", "max_z", "use_transform_limit" },
|
||||
CHILD_OF = { "inverse_matrix", "use_location_x", "use_rotation_y", "use_scale_x", "use_scale_z", "set_inverse_pending" },
|
||||
ACTION = { "action", "transform_channel", "frame_start", "frame_end", "min", "max", "mix_mode", "use_bone_object_action", "use_eval_time", "eval_time" },
|
||||
@@ -201,7 +227,7 @@ local BONE_KEYS = { "inherit_scale", "use_inherit_rotation", "use_local_location
|
||||
"bbone_custom_handle_start", "bbone_custom_handle_end", "use_endroll_as_inroll", "bbone_mapping_mode" }
|
||||
local COMMON = { "type", "name", "influence", "mute", "target", "subtarget", "owner_space", "target_space" }
|
||||
|
||||
local checked = { actions = 0, rigs = 0, constraints = 0, worlds = 0, meshes = 0, normals = 0, weights = 0, shapes = 0, frames = 0, skinned = 0, curves = 0, materials = 0, cameras = 0, lights = 0 }
|
||||
local checked = { drivers = 0, props = 0, actions = 0, rigs = 0, constraints = 0, worlds = 0, meshes = 0, normals = 0, weights = 0, shapes = 0, frames = 0, skinned = 0, curves = 0, materials = 0, cameras = 0, lights = 0 }
|
||||
local samples = {}
|
||||
|
||||
t:check(#Sets.old >= 4, "the old demo files were fetched (" .. #Sets.old .. ")")
|
||||
@@ -404,11 +430,16 @@ for _, tag in { "old", "279", "293", "35", "41", "cur" } do
|
||||
groupWeight[g[1] .. "/" .. (v - 1)] = g[2]
|
||||
end
|
||||
end
|
||||
local driven = {}
|
||||
for _, d in o.shape_key_drivers or {} do
|
||||
driven[d.data_path] = true
|
||||
end
|
||||
for k, s in mi.shapes do
|
||||
local e = keys[k] or {}
|
||||
local valueDriven = driven['key_blocks["' .. s.name .. '"].value']
|
||||
t:check(e.name == s.name and e.relative_key == s.relative and e.mute == s.mute and (e.vertex_group or "") == s.vertex_group
|
||||
and near(e.slider_min, s.slider_min, 1e-6) and near(e.slider_max, s.slider_max, 1e-6)
|
||||
and (o.shapeAction or near(e.value, s.value, 1e-6)), label .. ": " .. o.name .. " shape key " .. s.name .. " fields")
|
||||
and (o.shapeAction or valueDriven or near(e.value, s.value, 1e-6)), label .. ": " .. o.name .. " shape key " .. s.name .. " fields")
|
||||
end
|
||||
local ti = 0
|
||||
local worst = 0
|
||||
@@ -575,6 +606,9 @@ for _, tag in { "old", "279", "293", "35", "41", "cur" } do
|
||||
continue
|
||||
end
|
||||
t:check(want[k] ~= nil, what .. ": the reference has " .. k)
|
||||
if want[k] == DRIVEN then
|
||||
continue
|
||||
end
|
||||
local g = got[k]
|
||||
if k == "target" or k == "pole_target" or k == "custom_shape" then
|
||||
g = nameOf(g)
|
||||
@@ -603,6 +637,56 @@ for _, tag in { "old", "279", "293", "35", "41", "cur" } do
|
||||
t:check(got and got.palette == want.palette and got.normal and (not custom or nearList(got.normal, want.normal, 1e-5) and nearList(got.select, want.select, 1e-5) and nearList(got.active, want.active, 1e-5)), what .. ": colour " .. want.palette)
|
||||
end
|
||||
end
|
||||
local function compareDrivers(got: { any }?, want: { any }, what: string)
|
||||
local list = got or {}
|
||||
t:eq(#list, #want, what .. " drivers")
|
||||
for k, rd in want do
|
||||
local d = list[k] or { keys = {}, modifiers = {}, driver = { variables = {} } }
|
||||
local w = what .. " driver " .. rd.data_path
|
||||
t:check(d.data_path == rd.data_path and d.array_index == rd.array_index and d.extrapolation == rd.extrapolation, w)
|
||||
t:eq(#d.keys, #rd.keys, w .. " keys")
|
||||
for q, rk in rd.keys do
|
||||
local ck = d.keys[q] or {}
|
||||
t:check(nearList(ck.co, rk.co, 1e-5) and ck.interpolation == rk.interpolation, w .. " key " .. q)
|
||||
end
|
||||
local dr, rr = d.driver or { variables = {} }, rd.driver
|
||||
t:check(dr.type == rr.type and dr.expression == rr.expression and dr.use_self == rr.use_self, w .. " type / expression / use_self: " .. tostring(dr.type) .. " " .. tostring(dr.expression) .. " " .. tostring(dr.use_self))
|
||||
t:eq(#dr.variables, #rr.variables, w .. " variables")
|
||||
for q, rv in rr.variables do
|
||||
local v = dr.variables[q] or { targets = {} }
|
||||
t:check(v.name == rv.name and v.type == rv.type and #v.targets == #rv.targets, w .. " variable " .. rv.name)
|
||||
for i, rt in rv.targets do
|
||||
local tg = v.targets[i] or {}
|
||||
for _, key in { "id_type", "data_path", "bone_target", "transform_type", "transform_space", "rotation_mode", "context_property" } do
|
||||
t:check(tg[key] == rt[key], w .. " variable " .. rv.name .. " target " .. i .. " " .. key .. ": got " .. tostring(tg[key]) .. ", want " .. tostring(rt[key]))
|
||||
end
|
||||
t:check(same(nameOf(tg.id), rt.id, 0), w .. " variable " .. rv.name .. " target id")
|
||||
end
|
||||
end
|
||||
t:eq(#d.modifiers, #rd.modifiers, w .. " modifiers")
|
||||
for q, rm in rd.modifiers do
|
||||
local m = d.modifiers[q] or {}
|
||||
for key, rv in rm do
|
||||
if m[key] ~= nil or key == "type" then
|
||||
t:check(same(m[key], rv, 1e-5), w .. " modifier " .. rm.type .. " " .. key .. ": got " .. tostring(m[key]) .. ", want " .. tostring(rv))
|
||||
end
|
||||
end
|
||||
end
|
||||
checked.drivers += 1
|
||||
end
|
||||
end
|
||||
for _, o in ref.objects do
|
||||
local i = objects[o.name]
|
||||
if i and o.drivers then
|
||||
local e = scene.nodes[i].extras.blend
|
||||
t:check(deepSame(e.props or {}, o.props), label .. ": " .. o.name .. " props")
|
||||
compareDrivers(e.drivers, o.drivers, label .. ": " .. o.name)
|
||||
compareDrivers(e.data_drivers, o.data_drivers, label .. ": " .. o.name .. " data")
|
||||
local m = scene.nodes[i].mesh and scene.meshes[scene.nodes[i].mesh]
|
||||
compareDrivers(m and m.extras.blend.shape_key_drivers, o.shape_key_drivers, label .. ": " .. o.name .. " shape keys")
|
||||
checked.props += 1
|
||||
end
|
||||
end
|
||||
local POSE_KEYS = { "custom_shape", "custom_shape_transform", "custom_shape_translation", "custom_shape_rotation_euler",
|
||||
"custom_shape_scale_xyz", "use_custom_shape_bone_size", "lock_location", "lock_rotation", "lock_rotation_w",
|
||||
"lock_rotations_4d", "lock_scale", "rotation_mode", "ik_stretch", "location", "rotation_quaternion", "rotation_euler",
|
||||
@@ -636,8 +720,24 @@ for _, tag in { "old", "279", "293", "35", "41", "cur" } do
|
||||
end
|
||||
end
|
||||
compareTable(e, b.bone, bk, what)
|
||||
if b.pose.props then
|
||||
t:check(deepSame(e.props or {}, b.pose.props) and deepSame(e.bone_props or {}, b.pose.bone_props), what .. " props / bone_props")
|
||||
checked.props += 1
|
||||
end
|
||||
t:eq(#e.constraints, #b.pose.constraints, what .. " constraints")
|
||||
for k, rc in b.pose.constraints do
|
||||
-- bpy reports driven settings as evaluated; the file keeps the last stored value
|
||||
rc = table.clone(rc)
|
||||
for _, o in ref.objects do
|
||||
if o.name == armName then
|
||||
for _, d in o.drivers or {} do
|
||||
local key = string.match(d.data_path, '^pose%.bones%["' .. b.name:gsub("%p", "%%%0") .. '"%]%.constraints%["' .. rc.name:gsub("%p", "%%%0") .. '"%]%.([%w_]+)$')
|
||||
if key then
|
||||
rc[key] = DRIVEN
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local c = e.constraints[k] or {}
|
||||
local keys = table.clone(COMMON)
|
||||
for _, x in REQUIRED[rc.type] or {} do
|
||||
@@ -645,7 +745,7 @@ for _, tag in { "old", "279", "293", "35", "41", "cur" } do
|
||||
end
|
||||
compareTable(c, rc, keys, what .. " constraint " .. rc.name)
|
||||
for key, v in c do -- everything else the reader gives, where bpy has it
|
||||
if rc[key] ~= nil and type(v) ~= "table" and key ~= "target" and key ~= "pole_target" then
|
||||
if rc[key] ~= nil and rc[key] ~= DRIVEN and type(v) ~= "table" and key ~= "target" and key ~= "pole_target" then
|
||||
t:check(same(v, rc[key], 1e-5), what .. " constraint " .. rc.name .. " " .. key .. ": got " .. tostring(v) .. ", want " .. tostring(rc[key]))
|
||||
end
|
||||
end
|
||||
@@ -851,7 +951,7 @@ for _, tag in { "old", "279", "293", "35", "41", "cur" } do
|
||||
end
|
||||
end
|
||||
end
|
||||
t:note("checked: %d rigs, %d constraints, %d raw action curves", checked.rigs, checked.constraints, checked.actions)
|
||||
t:note("checked: %d rigs, %d constraints, %d raw action curves, %d drivers, %d property sets", checked.rigs, checked.constraints, checked.actions, checked.drivers, checked.props)
|
||||
t:note("checked: %d world matrices, %d meshes, %d corner normal sets, %d weight sets, %d shape key sets, %d f-curves, %d posed frames, %d skinned frames, %d materials, %d cameras, %d lights",
|
||||
checked.worlds, checked.meshes, checked.normals, checked.weights, checked.shapes, checked.curves, checked.frames, checked.skinned, checked.materials, checked.cameras, checked.lights)
|
||||
|
||||
|
||||
Reference in new issue
Block a user