diff --git a/docs/LUAScript.md b/docs/LUAScript.md index fcbb4fcbd..dd54358df 100644 --- a/docs/LUAScript.md +++ b/docs/LUAScript.md @@ -158,6 +158,8 @@ They are available as e.g. `noise.noise2([...])`, `noise.fBm3([...])` and so on. * `maxs()`: The upper boundary of the region (inclusive). +* `size()`: The size of the region in voxels (`ivec3`). + * `setMins(mins)`: The lower boundary of the region - given as `ivec3`. * `setMaxs(maxs)`: The upper boundary of the region - given as `ivec3`. diff --git a/src/modules/voxelgenerator/LUAGenerator.cpp b/src/modules/voxelgenerator/LUAGenerator.cpp index 79cd9401a..e36b477d4 100644 --- a/src/modules/voxelgenerator/LUAGenerator.cpp +++ b/src/modules/voxelgenerator/LUAGenerator.cpp @@ -342,6 +342,12 @@ static int luaVoxel_region_maxs(lua_State* s) { return 1; } +static int luaVoxel_region_size(lua_State* s) { + const voxel::Region* region = luaVoxel_toRegion(s, 1); + clua_push(s, region->getDimensionsInVoxels()); + return 1; +} + static int luaVoxel_region_setmins(lua_State* s) { voxel::Region* region = luaVoxel_toRegion(s, 1); const glm::ivec3& mins = clua_tovec(s, 2); @@ -600,6 +606,7 @@ static void prepareState(lua_State* s) { {"center", luaVoxel_region_center}, {"mins", luaVoxel_region_mins}, {"maxs", luaVoxel_region_maxs}, + {"size", luaVoxel_region_size}, {"setMins", luaVoxel_region_setmins}, {"setMaxs", luaVoxel_region_setmaxs}, {"__tostring", luaVoxel_region_tostring},