int MeshBinder::setIndices(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); if (lua_type(L, 2) == LUA_TTABLE) { int n = lua_objlen(L, 2); for (int k = 0; k < n/2; ++k) { lua_rawgeti(L, 2, k * 2 + 1); int i = luaL_checkinteger(L, -1) - 1; lua_pop(L, 1); lua_rawgeti(L, 2, k * 2 + 2); int index = luaL_checknumber(L, -1) - 1; lua_pop(L, 1); mesh->setIndex(i, index); } } else { int n = lua_gettop(L) - 1; for (int k = 0; k < n/2; ++k) { int i = luaL_checkinteger(L, k * 2 + 2) - 1; int index = luaL_checknumber(L, k * 2 + 3) - 1; mesh->setIndex(i, index); } } return 0; }
int MeshBinder::setTextureCoordinateArray(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); std::vector<float> textureCoordinates; if (lua_type(L, 2) == LUA_TTABLE) { int n = lua_objlen(L, 2); n = (n / 2) * 2; textureCoordinates.resize(n); for (int i = 0; i < n; ++i) { lua_rawgeti(L, 2, i + 1); textureCoordinates[i] = luaL_checknumber(L, -1); lua_pop(L, 1); } } else { int n = lua_gettop(L) - 1; n = (n / 2) * 2; textureCoordinates.resize(n); for (int i = 0; i < n; ++i) textureCoordinates[i] = luaL_checknumber(L, i + 2); } mesh->setTextureCoordinateArray(&textureCoordinates[0], textureCoordinates.size()); return 0; }
int MeshBinder::setVertexArray(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); std::vector<float> vertices; int order=mesh->is3d()?3:2; if (lua_type(L, 2) == LUA_TTABLE) { int n = lua_objlen(L, 2); n = (n / order) * order; vertices.resize(n); for (int i = 0; i < n; ++i) { lua_rawgeti(L, 2, i + 1); vertices[i] = luaL_checknumber(L, -1); lua_pop(L, 1); } } else { int n = lua_gettop(L) - 1; n = (n / order) * order; vertices.resize(n); for (int i = 0; i < n; ++i) vertices[i] = luaL_checknumber(L, i + 2); } mesh->setVertexArray(&vertices[0], vertices.size()); return 0; }
int MeshBinder::setIndexArray(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); std::vector<unsigned short> indices; if (lua_type(L, 2) == LUA_TTABLE) { int n = lua_objlen(L, 2); indices.resize(n); for (int i = 0; i < n; ++i) { lua_rawgeti(L, 2, i + 1); indices[i] = luaL_checkinteger(L, -1) - 1; lua_pop(L, 1); } } else { int n = lua_gettop(L) - 1; indices.resize(n); for (int i = 0; i < n; ++i) indices[i] = luaL_checkinteger(L, i + 2) - 1; } mesh->setIndexArray(&indices[0], indices.size()); return 0; }
/** Adds a cloud mesh */ XRESULT GSky::AddCloudMesh(const std::string& file) { GMesh* cm = new GMesh; cm->LoadMesh(file); CloudMeshes.push_back(cm); return XR_SUCCESS; }
int MeshBinder::destruct(lua_State *L) { void* ptr = *(void**)lua_touserdata(L, 1); GMesh* mesh = static_cast<GMesh*>(ptr); mesh->unref(); return 0; }
int MeshBinder::clearTexture(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); mesh->clearTexture(); return 0; }
static int domfilename(int argc, char const** argv) { TIMER(_mfilename); assertx(argc>1); assertx(!mesh.numVertices()); RFile is(argv[1]); mesh.read(is()); return 2; }
int MeshBinder::resizeTextureCoordinateArray(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); mesh->resizeTextureCoordinateArray(luaL_checkinteger(L, 2)); return 0; }
int MeshBinder::getTextureCoordinateArraySize(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); lua_pushinteger(L, mesh->getTextureCoordinateArraySize()); return 1; }
int MeshBinder::setTexture(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); TextureBase* textureBase = static_cast<TextureBase*>(binder.getInstance("TextureBase", 2)); mesh->setTexture(textureBase); return 0; }
int MeshBinder::setPrimitiveType(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); ShaderProgram::ShapeType prim=(ShaderProgram::ShapeType) luaL_checkinteger(L,2); mesh->setPrimitiveType(prim); return 0; }
int MeshBinder::setTextureSlot(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); int slot=luaL_checkinteger(L,2); TextureBase* textureBase = static_cast<TextureBase*>(binder.getInstance("TextureBase", 3)); mesh->setTextureSlot(slot,textureBase); return 0; }
int MeshBinder::setIndex(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); int i = luaL_checkinteger(L, 2) - 1; int index = luaL_checkinteger(L, 3) - 1; mesh->setIndex(i, index); return 0; }
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::setTextureCoordinate(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); int i = luaL_checkinteger(L, 2) - 1; float u = luaL_checknumber(L, 3); float v = luaL_checknumber(L, 4); mesh->setTextureCoordinate(i, u, v); return 0; }
int MeshBinder::setColor(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); int i = luaL_checkinteger(L, 2) - 1; unsigned int color = luaL_checkinteger(L, 3); float alpha = luaL_optnumber(L, 4, 1.0); mesh->setColor(i, color, alpha); 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; }
int MeshBinder::getIndex(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); int i = luaL_checkinteger(L, 2) - 1; if (i < 0 || i >= mesh->getVertexArraySize()) return luaL_error(L, "The supplied index is out of bounds."); unsigned short index; mesh->getIndex(i, &index); lua_pushinteger(L, (int)index + 1); return 1; }
int MeshBinder::getTextureCoordinate(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); int i = luaL_checkinteger(L, 2) - 1; if (i < 0 || i >= mesh->getVertexArraySize()) return luaL_error(L, "The supplied index is out of bounds."); float u, v; mesh->getTextureCoordinate(i, &u, &v); lua_pushnumber(L, u); lua_pushnumber(L, v); return 2; }
int main(int argc, char const** argv) { SHOWDF("Created using\n%s",CreateHeader(argc,argv)); Options opts; OPTSDC(opts,filename, "name : point data (can be -)"); OPTSDC(opts,mfilename, "name : initial mesh (can be -)"); OPTSPC(opts,crep, "v: set constant for representation energy"); OPTSDC(opts,reconstruct,": apply surface reconstruction schedule"); OPTSDC(opts,simplify, ": apply mesh simplification schedule"); opts.c("",":"); OPTSPC(opts,spring, "tension : set spring constant"); opts.c("",":"); OPTSDC(opts,gfit, "niter : do global fit (0=until convergence)"); OPTSDC(opts,fgfit, "niter : use conjugate gradients"); OPTSDC(opts,stoc, ": do local stochastic mesh operations"); OPTSDC(opts,lfit, "ni nli : do ni iters, each nli local fits"); OPTSDC(opts,four1split, ": do global four-to-one split"); OPTSDC(opts,outmesh, "filename : output current mesh to file"); opts.c("",":"); OPTSDC(opts,pclp, ": print projections onto mesh (lines)"); OPTSDC(opts,record, ": print mesh changes on cout, -noout"); OPTSDC(opts,spawn, "'command': send record to popen"); OPTSFC(opts,nooutput, ": don't print final mesh on stdout"); OPTSPC(opts,verb, "i : verbosity level (1=avg,2=more,3=lots)"); opts.c("",":"); OPTSPC(opts,crbf, "ratio : set repr. energy boundary factor"); OPTSPC(opts,spbf, "ratio : set spring constant boundary factor"); OPTSPC(opts,fliter, "factor : modify # local iters done in stoc"); OPTSPC(opts,feswaasym, "f : set drss threshold (fraction of crep)"); signal(SIGUSR1,HHSIG_PF(sigUSR1)); signal(SIGUSR2,HHSIG_PF(sigUSR2)); TIMER(Meshfit); opts.allmustparse(); if (!opts.parse(argc,argv)) { opts.problem(argc,argv); return 1; } perhapsinitialize(); SHOWDF("\n"); analyzemesh("FINAL"); ETIMER(Meshfit); CleanUp(); SHOWDF("\n"),SHOWDF("EndMeshfit\n"); if (!nooutput) { meshtransform(xformi); mesh.write(cout); } if (filespawn) { delete ospawn; pclose(filespawn); } mesh.clear(); pt.clear(); return 0; }
static void perhapsinitialize() { assertx(pt.n && mesh.numVertices()); assertw1(spring>0); // just warn user if (pt.cmf[0]) return; // already initialized computexform(); initialprojection(); }
static void computexform() { Bbox bb; bb.clear(); NEST { for (int i=0;i<pt.n;i++) bb.takeunion(pt.co[i]); } ForMeshVertex(mesh,v) { bb.takeunion(mesh.point(v)); } EndFor;
int MeshBinder::getColor(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); int i = luaL_checkinteger(L, 2) - 1; if (i < 0 || i >= mesh->getVertexArraySize()) return luaL_error(L, "The supplied index is out of bounds."); unsigned int color; float alpha; mesh->getColor(i, &color, &alpha); lua_pushinteger(L, color); lua_pushnumber(L, alpha); return 2; }
int MeshBinder::getVertex(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); int i = luaL_checkinteger(L, 2) - 1; if (i < 0 || i >= mesh->getVertexArraySize()) return luaL_error(L, "The supplied index is out of bounds."); int order=mesh->is3d()?3:2; float x, y, z; mesh->getVertex(i, &x, &y, &z); lua_pushnumber(L, x); lua_pushnumber(L, y); if (order==3) lua_pushnumber(L, z); return order; }
int MeshBinder::setColorArray(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); std::vector<unsigned int> colors; std::vector<float> alphas; if (lua_type(L, 2) == LUA_TTABLE) { int n = lua_objlen(L, 2); n /= 2; colors.resize(n); alphas.resize(n); for (int i = 0; i < n; ++i) { lua_rawgeti(L, 2, i * 2 + 1); colors[i] = luaL_checkinteger(L, -1); lua_pop(L, 1); lua_rawgeti(L, 2, i * 2 + 2); alphas[i] = luaL_checknumber(L, -1); lua_pop(L, 1); } } else { int n = lua_gettop(L) - 1; n /= 2; colors.resize(n); alphas.resize(n); for (int i = 0; i < n; ++i) { colors[i] = luaL_checkinteger(L, i * 2 + 2); alphas[i] = luaL_checknumber(L, i * 2 + 3); } } mesh->setColorArray(&colors[0], &alphas[0], colors.size()); return 0; }
int MeshBinder::setColors(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); if (lua_type(L, 2) == LUA_TTABLE) { int n = lua_objlen(L, 2); for (int k = 0; k < n/3; ++k) { lua_rawgeti(L, 2, k * 3 + 1); int i = luaL_checkinteger(L, -1) - 1; lua_pop(L, 1); lua_rawgeti(L, 2, k * 3 + 2); unsigned int color = luaL_checkinteger(L, -1); lua_pop(L, 1); lua_rawgeti(L, 2, k * 3 + 3); float alpha = luaL_checknumber(L, -1); lua_pop(L, 1); mesh->setColor(i, color, alpha); } } else { int n = lua_gettop(L) - 1; for (int k = 0; k < n/3; ++k) { int i = luaL_checkinteger(L, k * 3 + 2) - 1; unsigned int color = luaL_checkinteger(L, k * 3 + 3); float alpha = luaL_checknumber(L, k * 3 + 4); mesh->setColor(i, color, alpha); } } return 0; }
int MeshBinder::setTextureCoordinates(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); if (lua_type(L, 2) == LUA_TTABLE) { int n = lua_objlen(L, 2); for (int k = 0; k < n/3; ++k) { lua_rawgeti(L, 2, k * 3 + 1); int i = luaL_checkinteger(L, -1) - 1; lua_pop(L, 1); lua_rawgeti(L, 2, k * 3 + 2); float u = luaL_checknumber(L, -1); lua_pop(L, 1); lua_rawgeti(L, 2, k * 3 + 3); float v = luaL_checknumber(L, -1); lua_pop(L, 1); mesh->setTextureCoordinate(i, u, v); } } else { int n = lua_gettop(L) - 1; for (int k = 0; k < n/3; ++k) { int i = luaL_checkinteger(L, k * 3 + 2) - 1; float u = luaL_checknumber(L, k * 3 + 3); float v = luaL_checknumber(L, k * 3 + 4); mesh->setTextureCoordinate(i, u, v); } } return 0; }
int main() { if (0) { } else if (getenv_bool("PARTIAL_SPHERE")) { auto func_eval = [](const Point& p) { return p[0]<.3f ? k_Contour_undefined : dist(p, Point(.5f, .5f, .5f))-.4f; }; GMesh mesh; { Contour3DMesh<decltype(func_eval)> contour(50, &mesh, func_eval); // or 6 contour.march_near(Point(.9f, .5f, .5f)); } mesh.write(std::cout); } else if (getenv_bool("SPHERE")) { do_sphere(); } else if (getenv_bool("MONKEY")) { do_monkey(); } else if (getenv_bool("DENSE_MONKEY")) { do_densemonkey(); } else { testmesh(); test2D(); test3D(); } }
int MeshBinder::setGenericArray(lua_State *L) { Binder binder(L); GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1)); int index=luaL_checkinteger(L,2); ShaderProgram::DataType type=(ShaderProgram::DataType) luaL_checkinteger(L,3); int mult=luaL_checkinteger(L,4); int count=luaL_checkinteger(L,5); luaL_checktype(L, 6, LUA_TTABLE); int n = luaL_getn(L, 6); /* get size of table */ if (n!=(mult*count)) { lua_pushstring(L,"Actual array length doesn't match size multiple and count values"); lua_error(L); } void *ptr; switch (type) { case ShaderProgram::DBYTE: case ShaderProgram::DUBYTE: { char *p=(char *) malloc(mult*count); ptr=p; for (int i=1; i<=n; i++) { lua_rawgeti(L, 6, i); /* push t[i] */ *(p++)=luaL_checkinteger(L,-1); lua_pop(L,1); } break; } case ShaderProgram::DSHORT: case ShaderProgram::DUSHORT: { short *p=(short *) malloc(mult*count*2); ptr=p; for (int i=1; i<=n; i++) { lua_rawgeti(L, 6, i); /* push t[i] */ *(p++)=luaL_checkinteger(L,-1); lua_pop(L,1); } break; } case ShaderProgram::DINT: { int *p=(int *) malloc(mult*count); ptr=p; for (int i=1; i<=n; i++) { lua_rawgeti(L, 6, i); /* push t[i] */ *(p++)=luaL_checkinteger(L,-1); lua_pop(L,1); } break; } case ShaderProgram::DFLOAT: { float *p=(float *) malloc(mult*count); ptr=p; for (int i=1; i<=n; i++) { lua_rawgeti(L, 6, i); /* push t[i] */ *(p++)=luaL_checknumber(L,-1); lua_pop(L,1); } break; } } mesh->setGenericArray(index,ptr,type,mult,count); return 0; }