Browse Source

Merge pull request #1922 from kwuerl/issue-1167

Fix ply exporter to be conformant to spec respecting vertex colors.
Kim Kulling 7 years ago
parent
commit
6ef9e8848d
1 changed files with 13 additions and 13 deletions
  1. 13 13
      code/PlyExporter.cpp

+ 13 - 13
code/PlyExporter.cpp

@@ -194,16 +194,16 @@ PlyExporter::PlyExporter(const char* _filename, const aiScene* pScene, bool bina
 
 
     for (unsigned int n = PLY_EXPORT_HAS_COLORS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_COLOR_SETS; n <<= 1, ++c) {
     for (unsigned int n = PLY_EXPORT_HAS_COLORS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_COLOR_SETS; n <<= 1, ++c) {
         if (!c) {
         if (!c) {
-            mOutput << "property " << typeName << " r" << endl;
-            mOutput << "property " << typeName << " g" << endl;
-            mOutput << "property " << typeName << " b" << endl;
-            mOutput << "property " << typeName << " a" << endl;
+            mOutput << "property " << "uchar" << " red" << endl;
+            mOutput << "property " << "uchar" << " green" << endl;
+            mOutput << "property " << "uchar" << " blue" << endl;
+            mOutput << "property " << "uchar" << " alpha" << endl;
         }
         }
         else {
         else {
-            mOutput << "property " << typeName << " r" << c << endl;
-            mOutput << "property " << typeName << " g" << c << endl;
-            mOutput << "property " << typeName << " b" << c << endl;
-            mOutput << "property " << typeName << " a" << c << endl;
+            mOutput << "property " << "uchar" << " red" << c << endl;
+            mOutput << "property " << "uchar" << " green" << c << endl;
+            mOutput << "property " << "uchar" << " blue" << c << endl;
+            mOutput << "property " << "uchar" << " alpha" << c << endl;
         }
         }
     }
     }
 
 
@@ -288,13 +288,13 @@ void PlyExporter::WriteMeshVerts(const aiMesh* m, unsigned int components)
         for (unsigned int n = PLY_EXPORT_HAS_COLORS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_COLOR_SETS; n <<= 1, ++c) {
         for (unsigned int n = PLY_EXPORT_HAS_COLORS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_COLOR_SETS; n <<= 1, ++c) {
             if (m->HasVertexColors(c)) {
             if (m->HasVertexColors(c)) {
                 mOutput <<
                 mOutput <<
-                    " " << m->mColors[c][i].r <<
-                    " " << m->mColors[c][i].g <<
-                    " " << m->mColors[c][i].b <<
-                    " " << m->mColors[c][i].a;
+                    " " << (int)(m->mColors[c][i].r * 255) <<
+                    " " << (int)(m->mColors[c][i].g * 255) <<
+                    " " << (int)(m->mColors[c][i].b * 255) <<
+                    " " << (int)(m->mColors[c][i].a * 255);
             }
             }
             else {
             else {
-                mOutput << " -1.0 -1.0 -1.0 -1.0";
+                mOutput << " 0 0 0";
             }
             }
         }
         }