Skip to content

Commit

Permalink
added various asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
FatalistError committed Nov 17, 2023
1 parent 85731c0 commit d05eba5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
13 changes: 9 additions & 4 deletions modlib/read_b3d.lua
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function mtul.b3d_reader.read_from_stream(stream, ignore_chunks)
node.animation = elem
end
else
assert(not node_type, "Appgurueu decided to not put actual messages, so I'm not sure, but your .b3d file is fscked up lol. I dont even think this assert is needed.")
assert(not node_type, "Appgurueu decided to not put actual comments, so I'm not sure, but your .b3d file is fscked up lol. I dont even think this assert is needed.")
node_type = "pivot"
end
end
Expand Down Expand Up @@ -385,7 +385,7 @@ function mtul.b3d_reader.read_from_stream(stream, ignore_chunks)
local parent_left
left, parent_left = new_left, left
if possible_chunks and not possible_chunks[type] then
error("expected one of " .. table.concat(mtul.tbl.keys(possible_chunks), ", ") .. ", found " .. type)
error("expected one of " .. table.concat(mtul.tbl.keys(possible_chunks), ", ") .. ", found " .. type .. ". This is likely exporter error.")
end
local res = assert(chunks[type])()
assert(left == 0)
Expand All @@ -397,7 +397,8 @@ function mtul.b3d_reader.read_from_stream(stream, ignore_chunks)
--luckily most of the ground work is layed out for us already.

--also, Fatal here: for the sake of my reputation (which is nonexistent), typically I wouldn't nest these functions
--because I am not a physcopath and or a german named Lars, but for the sake of consistency it has to happen. (Not that its *always* a bad idea, but unless you're baking in parameters it's sort of useless and potentially wasteful)
--because I am not a physcopath and or a german named Lars, but for the sake of consistency it has to happen.
--(Not that its *always* a bad idea, but unless you're baking in parameters it's sort of useless and potentially wasteful)
local copy_path = mtul.table and mtul.table.shallow_copy or function(tbl)
local new_table = {}
for i, v in pairs(tbl) do
Expand All @@ -418,8 +419,12 @@ function mtul.b3d_reader.read_from_stream(stream, ignore_chunks)
local self = chunk{BB3D = true}
self.node_paths = {}
self.excluded_chunks = ignore_chunks and table.copy(ignore_chunks) or {}
assert(self.node, "no root node - model improperly exported. If using blender, ensure all objects are selected before exporting.")
make_paths(self.node, {}, self.node_paths)

--b3d metatable unimplemented
return setmetatable(self, mtul._b3d_metatable or {})
end
end

--- b3d table
-- @field node_paths
10 changes: 8 additions & 2 deletions nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function b3d_nodes.get_node_by_name(self, node_name, is_bone)
return this_node
end
end
error("MTUL-b3d, b3d_nodes: no node found by the name '"..tostring(node_name).."'")
--don't know why I'd ever just not return nil?
--error("MTUL-b3d, b3d_nodes: no node found by the name '"..tostring(node_name).."'")
end

--non-methods:
Expand All @@ -51,6 +52,7 @@ end
-- @return `scale` ordered table: {x, y, z}
--outputs need cleaning up.
function b3d_nodes.get_animated_local_trs(node, target_frame)
assert(target_frame, "no frame specified for TRS calculations")
local frames = node.keys
local key_index_before = 0 --index of the key before the target_frame.
for i, key in ipairs(frames) do
Expand Down Expand Up @@ -97,7 +99,7 @@ function b3d_nodes.get_node_global_transform(node, frame, outputs)
local global_transform
local rotation
for i, current_node in pairs(node.path) do
local pos_vec, rot_vec, scl_vec = b3d_nodes.get_animated_local_transform(current_node, frame)
local pos_vec, rot_vec, scl_vec = b3d_nodes.get_animated_local_trs(current_node, frame)
rot_vec.w = -rot_vec.w --b3d rotates the opposite way around the axis (I guess)
--find the transform
if not (outputs and outputs ~= "transform") then
Expand Down Expand Up @@ -144,6 +146,8 @@ end
--@return `z`
function b3d_nodes.get_node_global_position(self, node, is_bone, frame)
assert(self or not type(node)=="string")
assert(node, "cannot get position of a nil node")
assert(frame, "no frame specified!")
if type(node) == "string" then
node = b3d_nodes.get_node_by_name(self, node, is_bone)
end
Expand All @@ -159,6 +163,8 @@ end
--@return `rotation` quaternion rotation of the node (may not be normalized)
function b3d_nodes.get_node_rotation(self, node, is_bone, frame)
assert(self or not type(node)=="string")
assert(node, "cannot get rotation of a nil node")
assert(frame, "no frame specified!")
if type(node) == "string" then
node = b3d_nodes.get_node_by_name(self, node, is_bone)
end
Expand Down

0 comments on commit d05eba5

Please sign in to comment.