diff --git a/b3d.lua b/b3d.lua index b15a261..4e3f61f 100644 --- a/b3d.lua +++ b/b3d.lua @@ -346,13 +346,25 @@ function get_animated_bone_properties(self, keyframe, interpolate) local bone_properties = {} local function get_props(node, 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 - 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 - 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 properties.bone_name = node.name table.insert(bone_properties, properties) @@ -366,4 +378,4 @@ function get_animated_bone_properties(self, keyframe, interpolate) end -- Export environment -return _ENV \ No newline at end of file +return _ENV