00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "std/config.H"
00010 #include "mesh/mi.H"
00011
00012 #include <string>
00013
00014 void
00015 write_verts(const BMESH &mesh, ostream &os)
00016 {
00017 const int num = mesh.nverts();
00018
00019 int i;
00020 for (i = 0; i < num; i++) {
00021 CWpt &loc = mesh.bv(i)->loc();
00022 os << "v " << loc[0] << " " << loc[1] << " " << loc[2] << endl;
00023 }
00024 for (i = 0; i < num; i++) {
00025 Wvec n = mesh.bv(i)->norm();
00026 os << "vn " << n[0] << " " << n[1] << " " << n[2] << endl;
00027 }
00028 }
00029
00030 void
00031 write_faces(const BMESH &mesh, ostream &os, bool do_simple=false)
00032 {
00033 const int num = mesh.nfaces();
00034
00035 for (int i = 0; i < num; i++) {
00036 os << "f ";
00037 for (int v = 1; v <= 3; v++) {
00038 int k = mesh.bf(i)->v(v)->index()+1;
00039 os << k;
00040 if (!do_simple)
00041 os << "//" << k;
00042 os << ((v==3) ? "" : " ");
00043 }
00044 os << endl;
00045 }
00046 }
00047
00048 int
00049 main(int argc, char *argv[])
00050 {
00051
00052
00053
00054
00055
00056
00057
00058
00059 bool do_simple = false;
00060 if (argc == 2 && string(argv[1]) == "-s") {
00061 do_simple = true;
00062 } else if (argc != 1) {
00063 err_msg("Usage: %s [ -s ] < input.sm > output.sm", argv[0]);
00064 return 1;
00065 }
00066
00067 BMESHptr mesh = BMESH::read_jot_stream(cin);
00068 if (!mesh || mesh->empty())
00069 return 1;
00070
00071 if (Config::get_var_bool("JOT_RECENTER"))
00072 mesh->recenter();
00073
00074 if (Config::get_var_bool("JOT_PRINT_MESH"))
00075 mesh->print();
00076
00077
00078 write_verts(*mesh, cout);
00079
00080
00081 write_faces(*mesh, cout, do_simple);
00082
00083 return 0;
00084 }