From 026191b780fc3465ad5b5259a91ca6f06b9a5753 Mon Sep 17 00:00:00 2001 From: Benjamin Wrensch Date: Sat, 18 Nov 2023 20:41:29 +0100 Subject: [PATCH] [add] (lua) copy function to voxel shape interface --- .github/workflows/build_plugins.yml | 3 ++ iolite_plugins/linux/KEEP_ME | 0 iolite_plugins/lua_plugin/init_state.cpp | 33 ++++++++++++++++++++++ iolite_plugins/lua_plugin/lua_plugin.h | 3 ++ iolite_plugins/update_build_metadata.py | 35 ++++++++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 iolite_plugins/linux/KEEP_ME create mode 100644 iolite_plugins/update_build_metadata.py diff --git a/.github/workflows/build_plugins.yml b/.github/workflows/build_plugins.yml index 864ae7a..001045c 100644 --- a/.github/workflows/build_plugins.yml +++ b/.github/workflows/build_plugins.yml @@ -16,10 +16,13 @@ jobs: cd iolite_plugins cmake -S . -B build -DCMAKE_BUILD_TYPE=Release cmake --build build --config Release + python update_build_metadata.py - name : "Archive plugins" uses: actions/upload-artifact@v3 with: name: plugins path: | iolite_plugins/linux/*.so + iolite_plugins/linux/*.json iolite_plugins/windows/*.dll + iolite_plugins/windows/*.json diff --git a/iolite_plugins/linux/KEEP_ME b/iolite_plugins/linux/KEEP_ME new file mode 100644 index 0000000..e69de29 diff --git a/iolite_plugins/lua_plugin/init_state.cpp b/iolite_plugins/lua_plugin/init_state.cpp index e4093f4..f3f13a6 100644 --- a/iolite_plugins/lua_plugin/init_state.cpp +++ b/iolite_plugins/lua_plugin/init_state.cpp @@ -2250,6 +2250,39 @@ void script_init_state(sol::state& s) // @param max U8Vec3 The max voxel coordinate of the area. // @param palette_index number The palette index to set. s["VoxelShape"]["fill"] = io_component_voxel_shape->fill; + // @function copy + // @summary Copies the given source shape into the target shape. + // @param target Ref The target voxel shape component. + // @param source Ref The source voxel shape component. + // clang-format on + s["VoxelShape"]["copy"] = [](io_ref_t target, io_ref_t source) { + const auto target_dim = io_cvt(io_component_voxel_shape->get_dim(target)); + const auto source_dim = io_cvt(io_component_voxel_shape->get_dim(source)); + + const auto target_data = io_component_voxel_shape->get_voxel_data(target); + const auto source_data = io_component_voxel_shape->get_voxel_data(source); + + const auto copy_dim = glm::min(target_dim, source_dim); + + for (uint32_t z = 0u; z < copy_dim.z; ++z) + { + const uint32_t szo = z * source_dim.x * source_dim.y; + const uint32_t tzo = z * target_dim.x * target_dim.y; + + for (uint32_t y = 0u; y < copy_dim.y; ++y) + { + const uint32_t syo = y * source_dim.x; + const uint32_t tyo = y * target_dim.x; + const uint32_t syzo = syo + szo; + const uint32_t tyzo = tyo + tzo; + + for (uint32_t x = 0u; x < copy_dim.x; ++x) + target_data[x + tyzo] = source_data[x + syzo]; + } + } + }; + // clang-format off + // @function get_dim // @summary Gets the dimensions of the shape in voxels. // @param component Ref The voxel shape component. diff --git a/iolite_plugins/lua_plugin/lua_plugin.h b/iolite_plugins/lua_plugin/lua_plugin.h index b22f4b1..e54bbc5 100644 --- a/iolite_plugins/lua_plugin/lua_plugin.h +++ b/iolite_plugins/lua_plugin/lua_plugin.h @@ -43,6 +43,9 @@ #define IO_USER_QUAT_TYPE glm::quat #define IO_USER_UVEC2_TYPE glm::uvec2 #define IO_USER_UVEC3_TYPE glm::uvec3 +#define IO_USER_U8VEC3_TYPE glm::u8vec3 +#define IO_USER_U16VEC3_TYPE glm::u16vec3 +#define IO_USER_IVEC3_TYPE glm::ivec3 #define IO_USER_UVEC4_TYPE glm::uvec4 #define IO_API_IMPLEMENTATION #include "iolite_api.h" diff --git a/iolite_plugins/update_build_metadata.py b/iolite_plugins/update_build_metadata.py new file mode 100644 index 0000000..09c9a4b --- /dev/null +++ b/iolite_plugins/update_build_metadata.py @@ -0,0 +1,35 @@ +import os +import json + + +def hash_djb2(b): + h = 5381 + for x in b: + h = ((h << 5) + h) + x + h &= 0xFFFFFFFF + return h + + +plugins = [ + {"name": "terrain", "filename": "IoliteTerrainPlugin"}, + {"name": "lua", "filename": "IoliteLuaPlugin"}, + {"name": "denoiser_oidn", "filename": "IoliteDenoiserOIDNPlugin"}, + {"name": "voxel_editing", "filename": "IoliteVoxelEditingPlugin"} +] +platforms = [("windows", "dll"), ("linux", "so")] + + +for plat in platforms: + for p in plugins: + dll_filepath = "{}/{}.{}".format(plat[0], p["filename"], plat[1]) + json_filepath = "{}/plugins.json".format(plat[0]) + + if os.path.isfile(dll_filepath): + with open(dll_filepath, "rb") as plugin: + plugin_data = plugin.read() + checksum = hash_djb2(plugin_data) + checksum_with_salt = hash_djb2(bytes("{}{}".format(checksum, "QmCHNP2nmwEozrB4SY4dG49bTKllQDtD"), "ascii")) + p["checksum"] = checksum_with_salt + + with open(json_filepath, "w") as plugins_json: + json.dump(plugins, plugins_json, indent=2)