static int Face(lua_State *L) { mesh_t *mesh = checkmesh(L, 1); unsigned int i = checkindex(L, 2); if(mesh->mFaces == NULL || mesh->mNumFaces == 0 || i >= mesh->mNumFaces) return luaL_argerror(L, 2, "out of range"); return pushface(L, &(mesh->mFaces[i])); }
static int Faces(lua_State *L) { unsigned int i; mesh_t *mesh = checkmesh(L, 1); lua_newtable(L); if(mesh->mFaces == NULL || mesh->mNumFaces == 0) return 1; for(i = 0; i < mesh->mNumFaces; i++) { pushface(L, &(mesh->mFaces[i])); lua_rawseti(L, -2, i+1); } return 1; }
std::vector<Triangle> getConvex(std::vector<TPoint> &p) { static std::vector<Triangle> ret; ret.clear(); nFace = 0; if(!init(p)) return ret; if (!isVisible(p, Face(0, 1, 2), p[3])) pushface(0, 1, 2); else pushface(0, 2, 1); if (!isVisible(p, Face(0, 1, 3), p[2])) pushface(0, 1, 3); else pushface(0, 3, 1); if (!isVisible(p, Face(0, 2, 3), p[1])) pushface(0, 2, 3); else pushface(0, 3, 2); if (!isVisible(p, Face(1, 2, 3), p[0])) pushface(1, 2, 3); else pushface(1, 3, 2); for (int a = 4; a < (int)p.size(); a++) { TPoint base = p[a]; for (int i = 1; i <= nFace; i++) { if (tmp[i].isOnConvex && isVisible(p, tmp[i], base)) { left = 0, right = 0; queue[++right] = tmp[i]; tmp[i].isOnConvex = false; while (left < right) { Face now = queue[++left]; if (!deal(p, std::make_pair(now.a, now.b), base)) pushface(now.a, now.b, a); if (!deal(p, std::make_pair(now.b, now.c), base)) pushface(now.b, now.c, a); if (!deal(p, std::make_pair(now.c, now.a), base)) pushface(now.c, now.a, a); } break; } } } for (int i = 1; i <= nFace; i++) { Face now = tmp[i]; if (now.isOnConvex) { ret.push_back(Triangle(p[now.a], p[now.b], p[now.c])); } } return ret; }