Skip to content

Commit

Permalink
[add] (lua) copy function to voxel shape interface
Browse files Browse the repository at this point in the history
  • Loading branch information
begla committed Nov 18, 2023
1 parent c11b342 commit 966014a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build_plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ${{ secrets.IOLITE_PLUGIN_SALT }}
- 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
Empty file added iolite_plugins/linux/KEEP_ME
Empty file.
33 changes: 33 additions & 0 deletions iolite_plugins/lua_plugin/init_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions iolite_plugins/lua_plugin/lua_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
36 changes: 36 additions & 0 deletions iolite_plugins/update_build_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import json
import sys


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, sys.argv[1]), "ascii"))
p["checksum"] = checksum_with_salt

with open(json_filepath, "w") as plugins_json:
json.dump(plugins, plugins_json, indent=2)

0 comments on commit 966014a

Please sign in to comment.