From 985901de9472283afab02079c4022c6d4c919e27 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sat, 23 Sep 2023 21:53:47 +0100 Subject: [PATCH] noodle around with StagedVoxelRegion --- .../utils/io/StagedVoxelRegion.lua | 5 +++ .../utils/io/voxeltools.lua | 44 +++++++++++++++++++ .../utils/parse/file/init.lua | 9 ++++ worldeditadditions_core/utils/parse/init.lua | 4 +- 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 worldeditadditions_core/utils/io/voxeltools.lua create mode 100644 worldeditadditions_core/utils/parse/file/init.lua diff --git a/worldeditadditions_core/utils/io/StagedVoxelRegion.lua b/worldeditadditions_core/utils/io/StagedVoxelRegion.lua index 70da9c2..7f4298a 100644 --- a/worldeditadditions_core/utils/io/StagedVoxelRegion.lua +++ b/worldeditadditions_core/utils/io/StagedVoxelRegion.lua @@ -1,3 +1,8 @@ +local weac = worldeditadditions_core + +local weaschem = weac.parse.file.weaschem + + --- A region of the world that is to be or has been saved to/from disk. -- This class exists to make moving things to/from disk easier and less complicated. -- diff --git a/worldeditadditions_core/utils/io/voxeltools.lua b/worldeditadditions_core/utils/io/voxeltools.lua new file mode 100644 index 0000000..d630e17 --- /dev/null +++ b/worldeditadditions_core/utils/io/voxeltools.lua @@ -0,0 +1,44 @@ +local weac = worldeditadditions_core +local Vector3 = weac.Vector3 + +--- Converts data in a VoxelManip to a raw data array for serialisation. +-- TODO: Figure out the specifics of how this fits into StagedVoxelRegion, and whether or not StagedVoxelRegion has too many overrides or not. Then implement the counterpart raw2voxelmanip & integrate into WEA + StagedVoxelRegion +-- @param voxelmanip VoxelManipulator The voxelmanip instance to extract data from. +-- @param pos1 Vector3 Position 1 that defines the region to extract data from. +-- @param pos2 Vector3 Position 2 that defines the region to extract data from. +local function voxelmanip2raw(voxelmanip, pos1, pos2) + + local pos1_sort, pos2_sort = Vector3.sort(pos1, pos2) + local size = pos2_sort - pos1_sort + + local data = voxelmanip:get_data() + local param2 = voxelmanip:get_param2_data() + + local pos1_manip, pos2_manip = voxelmanip:get_emerged_area() + local area = VoxelArea:new({ + MinEdge = pos1_manip, + MaxEdge = pos2_manip + }) + pos1_manip = Vector3.clone(pos1_manip) + pos2_manip = Vector3.clone(pos2_manip) + + local pos1_manip_sort, pos2_manip_sort = Vector3.sort(pos1_manip, pos2_manip) + + local result_data = {} + local result_param2 = {} + for z = pos2_sort.z, pos1_sort.z, -1 do + for x = pos2_sort.x, pos1_sort.x, -1 do + for y = pos2_sort.y, pos1_sort.y, -1 do + local here = Vector3.new(x, y, z) + local here_target = here - pos1_manip_sort + local here_target_i = here_target.z * size.y * size.x + here_target.y * size.x + here_target.x -- Minetest flat arrays start from 1 (I thought they started from 0?!?!?!), but WEA flat arrays start from 0. Hence, we don't +1 here, though at some point we'll hafta update eeeevvvveerrrryyything...... :-( + + local here_source_i = area:index(x, y, z) + result_data[here_target_i] = data[here_source_i] + result_param2[here_target_i] = param2[here_source_i] + end + end + end + + return result_data, result_param2 +end diff --git a/worldeditadditions_core/utils/parse/file/init.lua b/worldeditadditions_core/utils/parse/file/init.lua new file mode 100644 index 0000000..31bc0d1 --- /dev/null +++ b/worldeditadditions_core/utils/parse/file/init.lua @@ -0,0 +1,9 @@ + + +local localpath = wea_c.modpath.."/utils/parse/file/" + +--- Parsers specifically for file formats. +-- @namespace worldeditadditions_core.parse.file +return { + weaschem = dofile(localpath.."weaschem.lua") +} \ No newline at end of file diff --git a/worldeditadditions_core/utils/parse/init.lua b/worldeditadditions_core/utils/parse/init.lua index b33b79d..a36e958 100644 --- a/worldeditadditions_core/utils/parse/init.lua +++ b/worldeditadditions_core/utils/parse/init.lua @@ -24,7 +24,9 @@ wea_c.parse = { seed = dofile(wea_c.modpath.."/utils/parse/seed.lua"), chance = dofile(wea_c.modpath.."/utils/parse/chance.lua"), map = dofile(wea_c.modpath.."/utils/parse/map.lua"), - weighted_nodes = dofile(wea_c.modpath.."/utils/parse/weighted_nodes.lua") + weighted_nodes = dofile(wea_c.modpath.."/utils/parse/weighted_nodes.lua"), + + file = dofile(wea_c.modpath.."/utils/parse/file/init.lua") } dofile(wea_c.modpath.."/utils/parse/tokenise_commands.lua")