From fa6bab75912840168c7814d9157bf11bc5be4224 Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Wed, 13 Oct 2021 15:29:56 +0200 Subject: [PATCH] fix export ply scalar precision on texcoords --- wrap/io_trimesh/export_ply.h | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/wrap/io_trimesh/export_ply.h b/wrap/io_trimesh/export_ply.h index 4f120237..3823c337 100644 --- a/wrap/io_trimesh/export_ply.h +++ b/wrap/io_trimesh/export_ply.h @@ -104,7 +104,9 @@ public: const int DGTS = vcg::tri::io::Precision::digits(); const int DGTVQ = vcg::tri::io::Precision::digits(); const int DGTVR = vcg::tri::io::Precision::digits(); + const int DGTVT = vcg::tri::io::Precision::digits(); const int DGTFQ = vcg::tri::io::Precision::digits(); + const int DGTFT = vcg::tri::io::Precision::digits(); bool saveTexIndexFlag = false; if(binary) h=hbin; @@ -202,9 +204,11 @@ public: } if( ( HasPerVertexTexCoord(m) && pi.mask & Mask::IOM_VERTTEXCOORD ) ) { + const char* rdtp = vcg::tri::io::Precision::typeName(); fprintf(fpout, - "property float texture_u\n" - "property float texture_v\n"); + "property %s texture_u\n" + "property %s texture_v\n", + rdtp, rdtp); } for(size_t i=0;i::typeName(); fprintf(fpout, - "property list uchar float texcoord\n" ); + "property list uchar %s texcoord\n", rdtp ); } // The texture index information has to be saved for each face (if necessary) both for PerVert and PerWedg if( saveTexIndexFlag && @@ -493,10 +498,10 @@ public: fwrite(&r,sizeof(typename VertexType::RadiusType),1,fpout); } - if( HasPerVertexTexCoord(m) && (pi.mask & Mask::IOM_VERTTEXCOORD) ) - { - t = ScalarType(vp->T().u()); fwrite(&t,sizeof(ScalarType),1,fpout); - t = ScalarType(vp->T().v()); fwrite(&t,sizeof(ScalarType),1,fpout); + if( HasPerVertexTexCoord(m) && (pi.mask & Mask::IOM_VERTTEXCOORD) ){ + typename VertexType::TexCoordType::ScalarType t; + t = ScalarType(vp->T().u()); fwrite(&t,sizeof(typename VertexType::TexCoordType::ScalarType),1,fpout); + t = ScalarType(vp->T().v()); fwrite(&t,sizeof(typename VertexType::TexCoordType::ScalarType),1,fpout); } for(size_t i=0;iR()); if( HasPerVertexTexCoord(m) && (pi.mask & Mask::IOM_VERTTEXCOORD) ) - fprintf(fpout,"%f %f",vp->T().u(),vp->T().v()); + fprintf(fpout,"%.*g %.*g",DGTVT,vp->T().u(),vp->T().v()); for(size_t i=0;iV(k)->T().u(); t[k*2+1] = fp->V(k)->T().v(); } - fwrite(t,sizeof(float),6,fpout); + fwrite(t,sizeof(typename FaceType::TexCoordType::ScalarType),6,fpout); } else if( HasPerWedgeTexCoord(m) && (pi.mask & Mask::IOM_WEDGTEXCOORD) ) { fwrite(&b6char,sizeof(char),1,fpout); - float t[6]; + typename FaceType::TexCoordType::ScalarType t[6]; for(int k=0;k<3;++k) { t[k*2+0] = fp->WT(k).u(); t[k*2+1] = fp->WT(k).v(); } - fwrite(t,sizeof(float),6,fpout); + fwrite(t,sizeof(typename FaceType::TexCoordType::ScalarType),6,fpout); } if(saveTexIndexFlag) @@ -778,7 +783,8 @@ public: { fprintf(fpout,"%d ",fp->VN()*2); for(int k=0;kVN();++k) - fprintf(fpout,"%f %f " + fprintf(fpout,"%.*g %.*g " + ,DGTFT ,fp->V(k)->T().u() ,fp->V(k)->T().v() );