From 8a6acdde65135acfa05ffe6fff28b1ad848a6914 Mon Sep 17 00:00:00 2001 From: Benjamin Wrensch Date: Sat, 30 Mar 2024 10:08:22 +0100 Subject: [PATCH] [add] (lua) expose palette resources --- iolite_plugins/lua_plugin/init_state.cpp | 102 +++++++++++++++++++++++ iolite_plugins/lua_plugin/lua_plugin.cpp | 6 ++ iolite_plugins/lua_plugin/lua_plugin.h | 2 + 3 files changed, 110 insertions(+) diff --git a/iolite_plugins/lua_plugin/init_state.cpp b/iolite_plugins/lua_plugin/init_state.cpp index b322ed4..41b3056 100644 --- a/iolite_plugins/lua_plugin/init_state.cpp +++ b/iolite_plugins/lua_plugin/init_state.cpp @@ -250,6 +250,52 @@ inline auto calc_random_float_fast(io_uint64_t& seed) -> float // @summary Lists all properties exposed by this component interface. // @return table value Table containing the names and types of all the exposed properties. +// @namespace Resources +// @category Resources Dummy category. +// @hidden + +// @function get_type_id +// @summary Returns the type ID of the resource. +// @param component Ref The resource. +// @return number value The type ID of the resource. + +// @function create +// @summary Creates a new resource with the given name. +// @param name string The name of the new resource. + +// @function destroy +// @summary Destroys the provided resource. +// @param resource Ref The resource to destroy. + +// @function commit_changes +// @summary Commits all changes to the properties of the provided resource. +// @param resource Ref The resource to update. + +// @function get_num_active_resources +// @summary Returns the total number of active resources of this type. +// @return number value Total total number of active resources of this type. + +// @function is_alive +// @summary Returns true if the referenced resource is alive. +// @param resource Ref The resource. +// @return boolean value True if the resource is alive. + +// @function get_property +// @summary Returns the requested property as a variant. +// @param resource Ref The resource. +// @param property_name string The name of the property to retrieve. +// @return Variant value The property as a variant. + +// @function set_property +// @summary Sets the requested property to the provided variant value. +// @param resource Ref The resource. +// @param property_name string The name of the property to set. +// @param value Variant The value to set. + +// @function list_properties +// @summary Lists all properties exposed by this resource interface. +// @return table value Table containing the names and types of all the exposed properties. + // @namespace Interface // @category Interface Dummy category. // @hidden @@ -2597,6 +2643,23 @@ void script_init_state(sol::state& s) return properties; \ } +#define SHARED_RESOURCE_INTERFACE_IMPL(t_, i_) \ + t_["get_type_id"] = i_->base.get_type_id; \ + t_["create"] = i_->base.create; \ + t_["destroy"] = i_->base.destroy; \ + t_["commit_changes"] = [](io_ref_t resource) { if (i_->base.commit_changes) \ + i_->base.commit_changes(resource); }; \ + t_["get_num_active_resources"] = i_->base.get_num_active_resources; \ + t_["set_property"] = i_->base.set_property; \ + t_["get_property"] = i_->base.get_property; \ + t_["list_properties"] = []() { \ + uint32_t numProperties; \ + i_->base.list_properties(nullptr, &numProperties); \ + std::vector properties(numProperties); \ + i_->base.list_properties(properties.data(), &numProperties); \ + return properties; \ + } + s["CustomData"] = s.create_table(); s["CustomData"]["load"] = [&s]() { @@ -3249,6 +3312,45 @@ void script_init_state(sol::state& s) }; + s["Palette"] = s.create_table(); + s["Palette"]["load"] = [&s]() { + + SHARED_RESOURCE_INTERFACE_IMPL(s["Palette"], io_resource_palette); + + // @namespace Palette + // @category Palette_Resource Functions to interact with palettes. + // @copy_category Interface + // @copy_category Resources + + // @function set_color + // @summary Sets the color for the given palette index of the given palette. + // @param palette Ref The palette in question. + // @param palette_index number The palette index of the color to change. + // @param color Vec4 The color to set. + s["Particle"]["set_color"] = io_resource_palette->set_color; + + // @function get_color + // @summary Gets the color for the given palette index of the given palette. + // @param palette Ref The palette in question. + // @param palette_index number The palette index of the color to change. + // @return Vec4 value The color at the given palette index. + s["Particle"]["get_color"] = io_resource_palette->get_color; + + // @function set_material_parameters + // @summary Sets the material parameters for the given palette index of the given palette. + // @param palette Ref The palette in question. + // @param palette_index number The palette index of the material_parameters to change. + // @param material_parameters Vec4 The material parameters to set (roughness, matalmask, hardness, and emissive). + s["Particle"]["set_material_parameters"] = io_resource_palette->set_material_parameters; + + // @function get_material_parameters + // @summary Gets the material parameters for the given palette index of the given palette. + // @param palette Ref The palette in question. + // @param palette_index number The palette index of the material_parameters to change. + // @return Vec4 value The material parameters at the given palette index (roughness, metalmask, hardness, and emissive). + s["Particle"]["get_material_parameters"] = io_resource_palette->get_material_parameters; + }; + // Call into plugins and let them init. the state auto lua_callback_interface = (const io_plugin_lua_user_callack_i*)io_api_manager->find_first( diff --git a/iolite_plugins/lua_plugin/lua_plugin.cpp b/iolite_plugins/lua_plugin/lua_plugin.cpp index 128eef8..3744e40 100644 --- a/iolite_plugins/lua_plugin/lua_plugin.cpp +++ b/iolite_plugins/lua_plugin/lua_plugin.cpp @@ -65,6 +65,8 @@ const io_component_vehicle_i* io_component_vehicle = {}; const io_component_vehicle_wheel_i* io_component_vehicle_wheel = {}; const io_component_joint_i* io_component_joint = {}; +const io_resource_palette_i* io_resource_palette = {}; + // Interfaces we provide //----------------------------------------------------------------------------// io_user_events_i io_user_events = {}; @@ -828,6 +830,10 @@ IO_API_EXPORT int IO_API_CALL load_plugin(void* api_manager) io_component_joint = (const io_component_joint_i*)io_api_manager->find_first( IO_COMPONENT_JOINT_API_NAME); + io_resource_palette = + (const io_resource_palette_i*)io_api_manager->find_first( + IO_RESOURCE_PALETTE_API_NAME); + // Factory plugin interfaces io_plugin_terrain = (const io_plugin_terrain_i*)io_api_manager->find_first( IO_PLUGIN_TERRAIN_API_NAME); diff --git a/iolite_plugins/lua_plugin/lua_plugin.h b/iolite_plugins/lua_plugin/lua_plugin.h index e36b9c6..e9c385c 100644 --- a/iolite_plugins/lua_plugin/lua_plugin.h +++ b/iolite_plugins/lua_plugin/lua_plugin.h @@ -94,6 +94,8 @@ extern const io_component_vehicle_i* io_component_vehicle; extern const io_component_vehicle_wheel_i* io_component_vehicle_wheel; extern const io_component_joint_i* io_component_joint; +extern const io_resource_palette_i* io_resource_palette; + // Custom types and helpers //----------------------------------------------------------------------------// template struct lua_array_wrapper_t