From d19ec847171f74840422b2cd904b608e0f7b97c3 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 15 Oct 2014 00:58:21 +0300 Subject: [PATCH] lua_bindings, client/api: clear_voxel_geometry, clear_voxel_physics_boxes --- client/api.lua | 20 +++++++++++++++++++ src/lua_bindings/voxel.cpp | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/client/api.lua b/client/api.lua index 0fe53f5..12de515 100644 --- a/client/api.lua +++ b/client/api.lua @@ -134,6 +134,16 @@ function buildat.safe.set_voxel_lod_geometry(lod, safe_node, safe_buffer) __buildat_set_voxel_lod_geometry(lod, node, buffer) end +function buildat.safe.clear_voxel_geometry(safe_node) + if not getmetatable(safe_node) or + getmetatable(safe_node).type_name ~= "Node" then + error("node is not a sandboxed Node instance") + end + node = getmetatable(safe_node).unsafe + + __buildat_clear_voxel_geometry(node) +end + function buildat.safe.set_voxel_physics_boxes(safe_node, safe_buffer) if not getmetatable(safe_node) or getmetatable(safe_node).type_name ~= "Node" then @@ -154,6 +164,16 @@ function buildat.safe.set_voxel_physics_boxes(safe_node, safe_buffer) __buildat_set_voxel_physics_boxes(node, buffer) end +function buildat.safe.clear_voxel_physics_boxes(safe_node) + if not getmetatable(safe_node) or + getmetatable(safe_node).type_name ~= "Node" then + error("node is not a sandboxed Node instance") + end + node = getmetatable(safe_node).unsafe + + __buildat_clear_voxel_physics_boxes(node) +end + local Vector3_prototype = { x = 0, y = 0, diff --git a/src/lua_bindings/voxel.cpp b/src/lua_bindings/voxel.cpp index 25b1ea7..ebed454 100644 --- a/src/lua_bindings/voxel.cpp +++ b/src/lua_bindings/voxel.cpp @@ -209,6 +209,24 @@ static int l_set_voxel_lod_geometry(lua_State *L) return 0; } +// clear_voxel_geometry(node: Node) +static int l_clear_voxel_geometry(lua_State *L) +{ + tolua_Error tolua_err; + + GET_TOLUA_STUFF(node, 1, Node); + + log_d(MODULE, "clear_voxel_geometry(): node=%p", node); + + CustomGeometry *cg = node->GetComponent(); + if(cg) + node->RemoveComponent(cg); + //cg->Clear(); + //cg->Commit(); + + return 0; +} + // set_voxel_physics_boxes(node, buffer: VectorBuffer) static int l_set_voxel_physics_boxes(lua_State *L) { @@ -240,6 +258,27 @@ static int l_set_voxel_physics_boxes(lua_State *L) return 0; } +// clear_voxel_physics_boxes(node) +static int l_clear_voxel_physics_boxes(lua_State *L) +{ + tolua_Error tolua_err; + + GET_TOLUA_STUFF(node, 1, Node); + + log_d(MODULE, "clear_voxel_physics_boxes(): node=%p", node); + + RigidBody *body = node->GetComponent(); + if(body) + node->RemoveComponent(body); + + PODVector previous_shapes; + node->GetComponents(previous_shapes); + for(size_t i = 0; i < previous_shapes.Size(); i++) + node->RemoveComponent(previous_shapes[i]); + + return 0; +} + void init_voxel(lua_State *L) { #define DEF_BUILDAT_FUNC(name){ \ @@ -250,7 +289,9 @@ void init_voxel(lua_State *L) DEF_BUILDAT_FUNC(set_8bit_voxel_geometry); DEF_BUILDAT_FUNC(set_voxel_geometry); DEF_BUILDAT_FUNC(set_voxel_lod_geometry); + DEF_BUILDAT_FUNC(clear_voxel_geometry); DEF_BUILDAT_FUNC(set_voxel_physics_boxes); + DEF_BUILDAT_FUNC(clear_voxel_physics_boxes); } } // namespace lua_bindingss