Modify the coordinate z In the OBJ 3D model file to the opposite number.

Source: Internet
Author: User

The specific method is: open an OBJ file and findV X Y ZAnd then the Z string is processed as a symbol:

If it is "-", delete the symbol directly. If it is not "-" And the Z value is not 0, add "-" to the string of Z "-".

Example (original file box. OBJ)

#
# Object box01
#

V-39.306316-32.828358-29.183971
V-39.306316 33.259296-29.183971
V 39.726025 33.259296-29.183971
V 39.726025-32.828358-29.183971
V-39.306316-32.828358 26.914204
V 39.726025-32.828358 26.914204
V 39.726025 33.259296 26.914204
V-39.306316 33.259296 26.914204

-----------------------------------

Converted file (box. obj. Flip ):

#
# Object box01
#

V-39.306316-32.828358 29.183971
V-39.306316 33.259296 29.183971
V 39.726025 33.259296 29.183971
V 39.726025-32.828358 29.183971
V-39.306316-32.828358-26.914204
V 39.726025-32.828358-26.914204
V 39.726025 33.259296-26.914204
V-39.306316 33.259296-26.914204

Code implementation:

 

 1 #include <fstream.h> 2 #include <math.h> 3  4 bool work(const char* path) 5 { 6     char chs[1000]; 7     double x,y,z; 8     CString newPath(path); 9     newPath += ".flip";10     const char* chNewPath = newPath;11     ofstream opf(chNewPath);12     if (!opf.is_open()) return false;13     ifstream pf(path);14     if (!pf.is_open()) {opf.close();return false;}15 16     while (!pf.eof())17     {18         pf.getline(chs, 1000, '\n');19         if (sscanf(chs, "v %lf %lf %lf", &x, &y, &z)==3)20         {21             CString strChs(chs);22             int spacePos=strChs.ReverseFind(' ');23             char c=strChs.GetAt(spacePos+1);24 25             opf<<(LPCTSTR)(strChs.Left(spacePos+1));26             if (c=='-')27             {28                 opf<<(LPCTSTR)(strChs.Right(strChs.GetLength()-spacePos-2))<<endl;29             }30             else31             {32                 if (fabs(z)>1e-6) opf<<"-";33                 opf<<(LPCTSTR)(strChs.Right(strChs.GetLength()-spacePos-1))<<endl;34             }35         }36         else37         {38             opf << chs << endl;39         }40     }41 42     opf.close();43     pf.close();44     return true;45 }

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.