diff --git a/xwall.lua b/xwall.lua index 5b9f757..fd74198 100644 --- a/xwall.lua +++ b/xwall.lua @@ -102,56 +102,35 @@ end function xwall.construct_node_box_data(node_box_list, center_node_box_list, node_box_line) local res = {} res.c0, res.c1, res.c2, res.c3, res.c4 = {}, {}, {}, {}, {} - local pos0, pos1, pos2, pos3, pos4 = #res.c0, #res.c1, #res.c2, #res.c3, #res.c4 - for i = 1, #node_box_list do - local v = node_box_list[i] - pos1 = pos1 + 1 - pos2 = pos2 + 1 - pos3 = pos3 + 1 - pos4 = pos4 + 1 - res.c1[pos1] = v - res.c2[pos2] = v - res.c3[pos3] = v - res.c4[pos4] = v + for _, v in pairs(node_box_list) do + table.insert(res.c1, v) + table.insert(res.c2, v) + table.insert(res.c3, v) + table.insert(res.c4, v) end - for i = 1, #node_box_list do - local v = node_box_list[i] - pos2 = pos2 + 1 - pos3 = pos3 + 1 - pos4 = pos4 + 1 - res.c2[pos2] = {v[3], v[2], v[1], v[6], v[5], v[4]} - res.c3[pos3] = {v[3], v[2], v[1], v[6], v[5], v[4]} - res.c4[pos4] = {v[3], v[2], v[1], v[6], v[5], v[4]} + for _, v in pairs(node_box_list) do + table.insert(res.c2, {v[3], v[2], v[1], v[6], v[5], v[4]}) + table.insert(res.c3, {v[3], v[2], v[1], v[6], v[5], v[4]}) + table.insert(res.c4, {v[3], v[2], v[1], v[6], v[5], v[4]}) end - for i = 1, #node_box_list do - local v = node_box_list[i] - pos3 = pos3 + 1 - pos4 = pos4 + 1 - res.c3[pos3] = {v[4], v[2], v[3]-.5, v[1], v[5], v[6]-.5} - res.c4[pos4] = {v[4], v[2], v[3]-.5, v[1], v[5], v[6]-.5} + for _, v in pairs(node_box_list) do + table.insert(res.c3, {v[4], v[2], v[3]-0.5, v[1], v[5], v[6]-0.5}) + table.insert(res.c4, {v[4], v[2], v[3]-0.5, v[1], v[5], v[6]-0.5}) end - for i = 1, #node_box_list do - local v = node_box_list[i] - pos4 = pos4 + 1 - res.c4[pos4] = {v[3]-.5, v[2], v[4], v[6]-.5, v[5], v[1]} + for _, v in pairs(node_box_list) do + table.insert(res.c4, {v[3]-0.5, v[2], v[4], v[6]-0.5, v[5], v[1]}) end - for i = 1, #center_node_box_list do - local v = center_node_box_list[i] - pos0 = pos0 + 1 - pos1 = pos1 + 1 - pos2 = pos2 + 1 - pos3 = pos3 + 1 - pos4 = pos4 + 1 - res.c0[pos0] = v - res.c1[pos1] = v - res.c2[pos2] = v - res.c3[pos3] = v - res.c4[pos4] = v + for _, v in pairs(center_node_box_list) do + table.insert(res.c0, v) + table.insert(res.c1, v) + table.insert(res.c2, v) + table.insert(res.c3, v) + table.insert(res.c4, v) end if #res.c0 < 1 then res.c0 = nil end