int MeshBinder::setVertices(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); bool is3d=mesh->is3d(); int order=is3d?4:3; if (lua_type(L, 2) == LUA_TTABLE) { int n = lua_objlen(L, 2); for (int k = 0; k < n/order; ++k) { lua_rawgeti(L, 2, k * order + 1); int i = luaL_checkinteger(L, -1) - 1; lua_pop(L, 1); lua_rawgeti(L, 2, k * order + 2); float x = luaL_checknumber(L, -1); lua_pop(L, 1); lua_rawgeti(L, 2, k * order + 3); float y = luaL_checknumber(L, -1); lua_pop(L, 1); float z=0; if (is3d) { lua_rawgeti(L, 2, k * order + 4); z = luaL_checknumber(L, -1); lua_pop(L, 1); } mesh->setVertex(i, x, y, z); } } else { int n = lua_gettop(L) - 1; for (int k = 0; k < n/order; ++k) { int i = luaL_checkinteger(L, k * order + 2) - 1; float x = luaL_checknumber(L, k * order + 3); float y = luaL_checknumber(L, k * order + 4); float z=0; if (is3d) z= luaL_checknumber(L, k * order + 5); mesh->setVertex(i, x, y, z); } } return 0; }
int MeshBinder::setVertex(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); int i = luaL_checkinteger(L, 2) - 1; float x = luaL_checknumber(L, 3); float y = luaL_checknumber(L, 4); float z = luaL_optnumber(L, 5, 0.0); mesh->setVertex(i, x, y, z); return 0; }