Improve b3d:get_animated_bone_properties

This commit is contained in:
Lars Mueller 2022-06-04 14:27:51 +02:00
parent b974113fa9
commit aef7ad5e6e

22
b3d.lua

@ -346,13 +346,25 @@ function get_animated_bone_properties(self, keyframe, interpolate)
local bone_properties = {} local bone_properties = {}
local function get_props(node, parent_bone_name) local function get_props(node, parent_bone_name)
local properties = {parent_bone_name = parent_bone_name} local properties = {parent_bone_name = parent_bone_name}
if node.keys and next(node.keys) ~= nil then
properties = modlib.table.add_all(properties, get_frame_values(node.keys)) if keyframe > 0 and node.keys and next(node.keys) ~= nil then
modlib.table.add_all(properties, get_frame_values(node.keys))
end end
for _, property in pairs{"position", "rotation", "scale"} do
properties[property] = properties[property] or modlib.table.copy(node[property]) if not properties.position then -- animation not present, fall back to node position
properties.position = modlib.table.copy(node.position)
end end
properties.rotation = modlib.quaternion.compose(node.rotation, properties.rotation)
if properties.rotation then -- animation is relative to node rotation
properties.rotation = modlib.quaternion.compose(node.rotation, properties.rotation)
else
properties.rotation = modlib.table.copy(node.rotation)
end
if not properties.scale then -- animation not present, fall back to node scale
properties.scale = modlib.table.copy(node.scale)
end
if node.bone then if node.bone then
properties.bone_name = node.name properties.bone_name = node.name
table.insert(bone_properties, properties) table.insert(bone_properties, properties)