Redo get_animated_bone_properties

This commit is contained in:
Lars Mueller 2021-02-06 11:55:43 +01:00
parent 311ff9cb10
commit a462b313f1

39
b3d.lua

@ -327,7 +327,9 @@ end
local binary_search_frame = modlib.table.binary_search_comparator(function(a, b) local binary_search_frame = modlib.table.binary_search_comparator(function(a, b)
return modlib.table.default_comparator(a, b.frame) return modlib.table.default_comparator(a, b.frame)
end) end)
function calculate_absolute_bone_properties(self, keyframe, interpolate)
--> [bonename] = { position = vector, rotation = quaternion, scale = vector }
function get_animated_bone_properties(self, keyframe, interpolate)
local function get_frame_values(keys) local function get_frame_values(keys)
local values = keys[keyframe] local values = keys[keyframe]
if values and values.frame == keyframe then if values and values.frame == keyframe then
@ -354,29 +356,24 @@ function calculate_absolute_bone_properties(self, keyframe, interpolate)
scale = (a.scale and b.scale and modlib.vector.interpolate(a.scale, b.scale, ratio)) or a.scale or b.scale, scale = (a.scale and b.scale and modlib.vector.interpolate(a.scale, b.scale, ratio)) or a.scale or b.scale,
} }
end end
local absolute_bone_properties = {} local bone_properties = {}
local function calculate_absolute_properties(self, parent_properties) local function get_props(node)
local properties = { local properties = {}
name = self.name, if node.keys and next(node.keys) ~= nil then
position = self.position, properties = modlib.table.add_all(properties, get_frame_values(node.keys))
rotation = self.rotation,
scale = self.scale
}
if self.keys and next(self.keys) ~= nil then
properties = modlib.table.add_all(properties, get_frame_values(self.keys))
end end
if parent_properties then for _, property in pairs{"position", "rotation", "scale"} do
properties.position = modlib.vector.add(parent_properties.position, properties.position) properties[property] = properties[property] or modlib.table.copy(node[property])
properties.rotation = modlib.quaternion.multiply(parent_properties.rotation, properties.rotation)
properties.scale = modlib.vector.multiply(parent_properties.scale, properties.scale)
end end
if self.bone then if node.bone then
table.insert(absolute_bone_properties, properties) assert(not bone_properties[node.name])
bone_properties[node.name] = properties
end end
for _, child in ipairs(self.children or {}) do for _, child in pairs(node.children or {}) do
calculate_absolute_properties(child, properties) get_props(child)
end end
end end
calculate_absolute_properties(self.node) get_props(self.node)
return absolute_bone_properties return bone_properties
end
end end