From ddf16392dab7ecae0e56ab9861f7fc92e60e3ebe Mon Sep 17 00:00:00 2001 From: FatalErr42O <58855799+FatalError42O@users.noreply.github.com> Date: Thu, 21 Dec 2023 13:41:33 -0800 Subject: [PATCH] made read frames offset by -1 to match irrlicht behavior --- README.md | 1 + modlib/read_b3d.lua | 3 ++- nodes.lua | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 571d500..fd4ec34 100644 --- a/README.md +++ b/README.md @@ -17,5 +17,6 @@ features: todo: * allow use of `get_node_by_name()` without CPML. (move to b3d_reader or set alias?) * document b3d table contents (I already wrote most of the documentation in modlib's wiki...) +* finish b3d writer (NOTE: must offset "frame" by +1 as the reader is modified to match irrlicht) Without Appgurue's Modlib this would not be possible, and while I personally have my issues with it, it still provides useful tools, and it's worth looking into for libraries. diff --git a/modlib/read_b3d.lua b/modlib/read_b3d.lua index 459e932..3e482a0 100644 --- a/modlib/read_b3d.lua +++ b/modlib/read_b3d.lua @@ -275,7 +275,8 @@ function mtul.b3d_reader.read_from_stream(stream, ignore_chunks) } while content() do local frame = {} - frame.frame = int() + --minetest uses a zero indexed frame system, so for consistency, we offset it by 1 + frame.frame = int()-1 if position then frame.position = vector3() end diff --git a/nodes.lua b/nodes.lua index 1dcda54..588b627 100644 --- a/nodes.lua +++ b/nodes.lua @@ -56,8 +56,8 @@ function b3d_nodes.get_animated_local_trs(node, target_frame) local frames = node.keys local key_index_before = 0 --index of the key before the target_frame. for i, key in ipairs(frames) do - --pick the closest frame we find that's less then the target - if key.frame < target_frame then + --pick the closest frame we find that's less then the target. Also allow it to pick itself if this is an option. + if (key.frame <= target_frame) then key_index_before = i else break --we've reached the end of our possible frames to use.