lua_bindings, client/api: clear_voxel_geometry, clear_voxel_physics_boxes

This commit is contained in:
Perttu Ahola 2014-10-15 00:58:21 +03:00
parent 1728d15b43
commit d19ec84717
2 changed files with 61 additions and 0 deletions

View File

@ -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,

View File

@ -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<CustomGeometry>();
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<RigidBody>();
if(body)
node->RemoveComponent(body);
PODVector<CollisionShape*> previous_shapes;
node->GetComponents<CollisionShape>(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