mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add Lua API function to resolve node/collision/selection boxes (#13964)
This commit is contained in:
parent
4859cf44ce
commit
f2b99332d9
13 changed files with 159 additions and 28 deletions
|
@ -1110,7 +1110,7 @@ void push_nodebox(lua_State *L, const NodeBox &box)
|
|||
case NODEBOX_FIXED:
|
||||
lua_pushstring(L, "fixed");
|
||||
lua_setfield(L, -2, "type");
|
||||
push_box(L, box.fixed);
|
||||
push_aabb3f_vector(L, box.fixed);
|
||||
lua_setfield(L, -2, "fixed");
|
||||
break;
|
||||
case NODEBOX_WALLMOUNTED:
|
||||
|
@ -1127,17 +1127,17 @@ void push_nodebox(lua_State *L, const NodeBox &box)
|
|||
lua_pushstring(L, "connected");
|
||||
lua_setfield(L, -2, "type");
|
||||
const auto &c = box.getConnected();
|
||||
push_box(L, c.connect_top);
|
||||
push_aabb3f_vector(L, c.connect_top);
|
||||
lua_setfield(L, -2, "connect_top");
|
||||
push_box(L, c.connect_bottom);
|
||||
push_aabb3f_vector(L, c.connect_bottom);
|
||||
lua_setfield(L, -2, "connect_bottom");
|
||||
push_box(L, c.connect_front);
|
||||
push_aabb3f_vector(L, c.connect_front);
|
||||
lua_setfield(L, -2, "connect_front");
|
||||
push_box(L, c.connect_back);
|
||||
push_aabb3f_vector(L, c.connect_back);
|
||||
lua_setfield(L, -2, "connect_back");
|
||||
push_box(L, c.connect_left);
|
||||
push_aabb3f_vector(L, c.connect_left);
|
||||
lua_setfield(L, -2, "connect_left");
|
||||
push_box(L, c.connect_right);
|
||||
push_aabb3f_vector(L, c.connect_right);
|
||||
lua_setfield(L, -2, "connect_right");
|
||||
// half the boxes are missing here?
|
||||
break;
|
||||
|
@ -1148,16 +1148,6 @@ void push_nodebox(lua_State *L, const NodeBox &box)
|
|||
}
|
||||
}
|
||||
|
||||
void push_box(lua_State *L, const std::vector<aabb3f> &box)
|
||||
{
|
||||
lua_createtable(L, box.size(), 0);
|
||||
u8 i = 1;
|
||||
for (const aabb3f &it : box) {
|
||||
push_aabb3f(L, it);
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void push_palette(lua_State *L, const std::vector<video::SColor> *palette)
|
||||
{
|
||||
|
|
|
@ -83,9 +83,6 @@ void push_content_features (lua_State *L,
|
|||
|
||||
void push_nodebox (lua_State *L,
|
||||
const NodeBox &box);
|
||||
void push_box (lua_State *L,
|
||||
const std::vector<aabb3f> &box);
|
||||
|
||||
void push_palette (lua_State *L,
|
||||
const std::vector<video::SColor> *palette);
|
||||
|
||||
|
|
|
@ -364,20 +364,20 @@ aabb3f read_aabb3f(lua_State *L, int index, f32 scale)
|
|||
return box;
|
||||
}
|
||||
|
||||
void push_aabb3f(lua_State *L, aabb3f box)
|
||||
void push_aabb3f(lua_State *L, aabb3f box, f32 divisor)
|
||||
{
|
||||
lua_createtable(L, 6, 0);
|
||||
lua_pushnumber(L, box.MinEdge.X);
|
||||
lua_pushnumber(L, box.MinEdge.X / divisor);
|
||||
lua_rawseti(L, -2, 1);
|
||||
lua_pushnumber(L, box.MinEdge.Y);
|
||||
lua_pushnumber(L, box.MinEdge.Y / divisor);
|
||||
lua_rawseti(L, -2, 2);
|
||||
lua_pushnumber(L, box.MinEdge.Z);
|
||||
lua_pushnumber(L, box.MinEdge.Z / divisor);
|
||||
lua_rawseti(L, -2, 3);
|
||||
lua_pushnumber(L, box.MaxEdge.X);
|
||||
lua_pushnumber(L, box.MaxEdge.X / divisor);
|
||||
lua_rawseti(L, -2, 4);
|
||||
lua_pushnumber(L, box.MaxEdge.Y);
|
||||
lua_pushnumber(L, box.MaxEdge.Y / divisor);
|
||||
lua_rawseti(L, -2, 5);
|
||||
lua_pushnumber(L, box.MaxEdge.Z);
|
||||
lua_pushnumber(L, box.MaxEdge.Z / divisor);
|
||||
lua_rawseti(L, -2, 6);
|
||||
}
|
||||
|
||||
|
@ -409,6 +409,16 @@ std::vector<aabb3f> read_aabb3f_vector(lua_State *L, int index, f32 scale)
|
|||
return boxes;
|
||||
}
|
||||
|
||||
void push_aabb3f_vector(lua_State *L, const std::vector<aabb3f> &boxes, f32 divisor)
|
||||
{
|
||||
lua_createtable(L, boxes.size(), 0);
|
||||
int i = 1;
|
||||
for (const aabb3f &box : boxes) {
|
||||
push_aabb3f(L, box, divisor);
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
}
|
||||
|
||||
size_t read_stringlist(lua_State *L, int index, std::vector<std::string> *result)
|
||||
{
|
||||
if (index < 0)
|
||||
|
|
|
@ -110,11 +110,13 @@ void push_v2s16 (lua_State *L, v2s16 p);
|
|||
void push_v2s32 (lua_State *L, v2s32 p);
|
||||
void push_v2u32 (lua_State *L, v2u32 p);
|
||||
void push_v3s16 (lua_State *L, v3s16 p);
|
||||
void push_aabb3f (lua_State *L, aabb3f box);
|
||||
void push_aabb3f (lua_State *L, aabb3f box, f32 divisor = 1.0f);
|
||||
void push_ARGB8 (lua_State *L, video::SColor color);
|
||||
void pushFloatPos (lua_State *L, v3f p);
|
||||
void push_v3f (lua_State *L, v3f p);
|
||||
void push_v2f (lua_State *L, v2f p);
|
||||
void push_aabb3f_vector (lua_State *L, const std::vector<aabb3f> &boxes,
|
||||
f32 divisor = 1.0f);
|
||||
|
||||
void warn_if_field_exists(lua_State *L, int table,
|
||||
const char *fieldname,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue