talpa/iomesh.cpp
// ---------------------------------------------------------
///
/// Write mesh in Wavefront OBJ format
///
// ---------------------------------------------------------
Write mesh in Wavefront OBJ format
Write mesh in Wavefront OBJ format
bool write_objfile(const NonDestructiveTriMesh &mesh, const std::vector<Vec3d> &x, const char *filename_format, ...)
{
#ifdef _MSC_VER
    va_list ap;
    va_start(ap, filename_format);
    int len=_vscprintf(filename_format, ap) 
    +1; 
    char *filename=new char[len];
    vsprintf(filename, filename_format, ap);
    std::ofstream output(filename, std::ofstream::binary);
    delete[] filename;
    va_end(ap);
#else
    va_list ap;
    va_start(ap, filename_format);
    char *filename;
    vasprintf(&filename, filename_format, ap);
    std::ofstream output(filename, std::ofstream::binary);
    std::free(filename);
    va_end(ap);
#endif    
    if(!output.good()) return false;
    output<<"# generated by editmesh"<<std::endl;
    for(unsigned int i=0; i<x.size(); ++i)
        output<<"v "<<x[i]<<std::endl;
    for(unsigned int t=0; t<mesh.num_triangles(); ++t)
        output<<"f "<<mesh.get_triangle(t)[0]+1<<' '<<mesh.get_triangle(t)[1]+1<<' '<<mesh.get_triangle(t)[2]+1<<std::endl; 
    return output.good();
}
bool write_objfile ( const NonDestructiveTriMesh & mesh , const std :: vector < Vec3d > & x , const char * filename_format , ... ) { #ifdef _MSC_VER va_list ap ; va_start ( ap , filename_format ) ; int len = _vscprintf ( filename_format , ap ) + 1 ; char * filename = new char [ len ] ; vsprintf ( filename , filename_format , ap ) ; std :: ofstream output ( filename , std :: ofstream :: binary ) ; delete [ ] filename ; va_end ( ap ) ; #else va_list ap ; va_start ( ap , filename_format ) ; char * filename ; vasprintf ( & filename , filename_format , ap ) ; std :: ofstream output ( filename , std :: ofstream :: binary ) ; std :: free ( filename ) ; va_end ( ap ) ; #endif if ( ! output . good ( ) ) return false ; output << " " << std :: endl ; for ( unsigned int i = 0 ; i < x . size ( ) ; ++ i ) output << " " << x [ i ] << std :: endl ; for ( unsigned int t = 0 ; t < mesh . num_triangles ( ) ; ++ t ) output << " " << mesh . get_triangle ( t ) [ 0 ] + 1 << ' ' << mesh . get_triangle ( t ) [ 1 ] + 1 << ' ' << mesh . get_triangle ( t ) [ 2 ] + 1 << std :: endl ; return output . good ( ) ; }
Write mesh in Wavefront OBJ format
Write mesh in Wavefront OBJ format
// _vscprintf doesn't count // terminating '\0' // correct for 1-based indexing in OBJ files