inline void set_pix(Bvert* v, ProxySurface* p, CPIXEL& pix) { // change the vert location to match the given pixel location, // not changing depth: v->set_loc(Wpt(XYpt(pix))); PixelsData::set_pix(v, p, pix); // also store it for next time }
inline void read_vert(LMESH* mesh, istream& in) { double x, y, z; in >> x >> y >> z; skip_line(in); assert(mesh); mesh->add_vertex(Wpt(x,y,z)); }
Wpt ProxySurface::getWptfromUV(CUVpt& uv) { VEXEL u_vec = _u_o - _o; VEXEL v_vec = _v_o - _o; PIXEL newpix = _o + u_vec*uv[0] + v_vec*uv[1]; Wpt cc = VIEW::peek_cam()->data()->center(); return Wpt(XYpt(newpix), cc); }
inline Wpt center (Wpt_list& pts, ARRAY<int>& N) { Wpt ret = Wpt(0); for (int i = 0; i < N.num(); i++) { ret += pts[N[i]]; } return ret / N.num(); }
/****************************************************************************** Write out a jot .sm file. ******************************************************************************/ void write_sm() { LMESHptr mesh = make_shared<LMESH>(); int i=0; //******** Build the mesh ******** err_adv(debug, "read ply file: %d vertices, %d faces\n", nverts, nfaces); err_adv(debug, "building mesh:"); // Add vertices to mesh err_adv(debug, " adding vertices..."); for (i = 0; i < nverts; i++) mesh->add_vertex(Wpt(vlist[i]->x, vlist[i]->y, vlist[i]->z)); err_adv(debug, " done\n"); // Add per-vertex colors if needed if (per_vertex_color) { err_adv(debug, " adding colors..."); for (i = 0; i < nverts; i++) mesh->bv(i)->set_color(COLOR(vlist[i]->r, vlist[i]->g, vlist[i]->b)); err_adv(debug, " done\n"); } // Add faces err_adv(debug, " adding faces..."); for (i = 0; i < nfaces; i++) add_face(mesh, flist[i]); err_adv(debug, " done\n"); //******** Filter the mesh ******** err_adv(debug, "filtering mesh..."); // Remove any isolated vertices for (i=mesh->nverts()-1; i>=0; i--) { if (mesh->bv(i)->degree() == 0) { mesh->remove_vertex(mesh->bv(i)); } } mesh->changed(); // Remove duplicate vertices while we're at it mesh->remove_duplicate_vertices(false); // don't keep the bastards // Check for consistent orientation of normals bool is_bad = false; for (i=0; i<mesh->nedges(); i++) if (!mesh->be(i)->consistent_orientation()) is_bad = true; if (is_bad) err_msg("Warning: inconsistently oriented triangles -- can't fix"); // Optional: recenter mesh if (Config::get_var_bool("JOT_RECENTER")) mesh->recenter(); // Optional: print stats if (Config::get_var_bool("JOT_PRINT_MESH")) mesh->print(); err_adv(debug, "done\n"); //******** Write mesh ******** err_adv(debug, "writing mesh..."); mesh->write_stream(cout); err_adv(debug, "done\n"); }
void ProxySurface::create_proxy_surface() { // create it only if needed if (_proxy_mesh || !_patch) { return; } _proxy_mesh = new BMESH; mlib::NDCZpt a_t, c_t; _patch->mesh()->get_bb().ndcz_bounding_box(_patch->obj_to_ndc(),a_t,c_t); // Clamp the min and max to screen a_t[0] = max(a_t[0],-1.0); a_t[1] = max(a_t[1],-1.0); c_t[0] = min(c_t[0], 1.0); c_t[1] = min(c_t[1], 1.0); BBOXpix bb = BBOXpix(PIXEL(a_t), PIXEL(c_t)); double len = max(bb.width(),bb.height()); PIXEL a_p(a_t); XYpt a = XYpt(a_p); XYpt b = XYpt(a_p + VEXEL(len, 0)); XYpt c = XYpt(a_p + VEXEL(len,len)); XYpt d = XYpt(a_p + VEXEL( 0,len)); Wpt cc = VIEW::peek_cam()->data()->center(); // create a quad organized in XY space // first create vertices (XY square in CCW order): _proxy_mesh->add_vertex(Wpt(a, cc)); _proxy_mesh->add_vertex(Wpt(b, cc)); _proxy_mesh->add_vertex(Wpt(c, cc)); _proxy_mesh->add_vertex(Wpt(d, cc)); // now create the quad: Patch* pa = _proxy_mesh->new_patch(); _proxy_mesh->add_quad(0,1,2,3, UVpt(0,0), UVpt(1,0), UVpt(1,1), UVpt(0,1), pa); UVdata::set(_proxy_mesh->bv(0), (UVpt(0,0))); UVdata::set(_proxy_mesh->bv(1), (UVpt(1,0))); UVdata::set(_proxy_mesh->bv(2), (UVpt(1,1))); UVdata::set(_proxy_mesh->bv(3), (UVpt(0,1))); put_vert_grid(UVpt(0,0), _proxy_mesh->bv(0)); put_vert_grid(UVpt(1,0), _proxy_mesh->bv(1)); put_vert_grid(UVpt(1,1), _proxy_mesh->bv(2)); put_vert_grid(UVpt(0,1), _proxy_mesh->bv(3)); _o = _proxy_mesh->bv(0)->pix(); _u_o = _proxy_mesh->bv(1)->pix(); _v_o = _proxy_mesh->bv(3)->pix(); // grow more quads if needed, though it is never needed (yet): while (grow_proxy_surface() > 0) ; // finish up: _proxy_mesh->changed(); }